/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:       #1a1a2e;
  --brand-mid:   #16213e;
  --accent:      #e94560;
  --accent-lt:   #ff6b81;
  --text:        #1c1c1e;
  --text-muted:  #6b7280;
  --border:      #e5e7eb;
  --bg:          #f8f9fb;
  --white:       #ffffff;
  --sidebar-w:   220px;
  --radius:      8px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --green:       #16a34a;
  --yellow:      #ca8a04;
  --red:         #dc2626;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App Shell ────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--brand);
  color: #c9d1d9;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
}
.sidebar-logo { padding: 20px 16px 12px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-sublabel { font-size: 10px; color: rgba(255,255,255,.4); text-transform: uppercase; letter-spacing: .08em; margin-top: 4px; }
.sidebar-nav { list-style: none; padding: 8px 0; flex: 1; }
.sidebar-nav li a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; color: #c9d1d9; font-size: 13.5px;
  border-left: 3px solid transparent; transition: all .15s;
}
.sidebar-nav li a:hover, .sidebar-nav li.active a {
  background: rgba(255,255,255,.06); color: #fff;
  border-left-color: var(--accent); text-decoration: none;
}
.nav-icon { font-size: 14px; width: 18px; text-align: center; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.sidebar-user { display: block; color: rgba(255,255,255,.5); margin-bottom: 4px; }
.logout-link { color: rgba(255,255,255,.35); font-size: 11px; }
.logout-link:hover { color: var(--accent-lt); }

/* ── Main Content ─────────────────────────────────────────── */
.main-content { margin-left: var(--sidebar-w); flex: 1; padding: 28px 32px; max-width: 1400px; }

/* ── Page Header ──────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header p { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 14px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border); background: var(--white);
  color: var(--text); transition: all .15s; line-height: 1;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #c73652; border-color: #c73652; color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-group { display: flex; gap: 6px; }

/* ── Cards ────────────────────────────────────────────────── */
.card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h2 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--border); background: var(--bg); border-radius: 0 0 var(--radius) var(--radius); }

/* ── Stats ────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.stat-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; text-align: center; box-shadow: var(--shadow); }
.stat-num { font-size: 32px; font-weight: 700; color: var(--brand); }
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 4px; }

/* ── Tables ───────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th { text-align: left; padding: 10px 14px; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); border-bottom: 2px solid var(--border); }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tbody tr:hover { background: #fafafa; }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ── Badges ───────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-draft    { background: #f3f4f6; color: var(--text-muted); }
.badge-sent     { background: #dbeafe; color: #1d4ed8; }
.badge-approved { background: #d1fae5; color: #065f46; }
.badge-archived { background: #f3f4f6; color: #9ca3af; }
.badge-A { background: #fef3c7; color: #92400e; }
.badge-B { background: #dbeafe; color: #1e40af; }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .04em; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; color: var(--text);
  background: var(--white); transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(233,69,96,.12);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 20px; }
.form-full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }

/* ── Flash Messages ───────────────────────────────────────── */
.flash { padding: 10px 16px; border-radius: var(--radius); margin-bottom: 18px; font-size: 13.5px; border-left: 4px solid; }
.flash-success { background: #d1fae5; border-color: var(--green); color: #065f46; }
.flash-error   { background: #fee2e2; border-color: var(--red); color: #991b1b; }
.flash-info    { background: #dbeafe; border-color: #3b82f6; color: #1e40af; }
.flash-warning { background: #fef9c3; border-color: var(--yellow); color: #713f12; }

/* ── Login Page ───────────────────────────────────────────── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--brand); }
.login-box { background: var(--white); border-radius: 12px; padding: 40px; width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-sublabel { color: var(--text-muted); font-size: 12px; margin-top: 6px; }
.login-footer { text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 24px; }
.login-form .btn { margin-top: 6px; }

/* ── Estimate Builder ─────────────────────────────────────── */
.estimate-shell { display: grid; grid-template-columns: 300px 1fr; gap: 20px; }
.filter-panel { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; height: fit-content; position: sticky; top: 20px; }
.filter-panel h3 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 12px; }
.filter-section { margin-bottom: 16px; border-bottom: 1px solid var(--border); padding-bottom: 16px; }
.filter-section:last-child { border-bottom: none; margin-bottom: 0; }
.filter-section label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 5px; }
.filter-section select, .filter-section input { width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 5px; font-size: 13px; }

.estimate-body { display: flex; flex-direction: column; gap: 16px; }
.estimate-meta { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }

.line-items { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); }
.line-item-row { display: grid; grid-template-columns: 2fr 80px 100px 100px 90px 36px; gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.line-item-row:last-child { border-bottom: none; }
.line-item-header { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); background: var(--bg); }
.line-item-name { font-weight: 500; font-size: 13.5px; }
.line-item-note { font-size: 11.5px; color: var(--text-muted); }

.estimate-totals { background: var(--brand); color: #fff; border-radius: var(--radius); padding: 20px; }
.totals-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13.5px; }
.totals-row.grand { font-size: 18px; font-weight: 700; border-top: 1px solid rgba(255,255,255,.2); padding-top: 10px; margin-top: 6px; }
.totals-row.recurring { color: rgba(255,255,255,.7); font-size: 12px; margin-top: 8px; }

/* ── Catalog Grid ─────────────────────────────────────────── */
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.catalog-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; cursor: pointer; transition: all .15s; }
.catalog-card:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(233,69,96,.12); }
.catalog-card.package { border-left: 3px solid var(--accent); }
.catalog-card h4 { font-size: 13.5px; font-weight: 600; margin-bottom: 4px; }
.catalog-card .price { font-weight: 700; color: var(--accent); font-size: 14px; margin-top: 8px; }
.catalog-card .cat-tag { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }

/* ── Tabs ─────────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab { padding: 8px 16px; font-size: 13px; font-weight: 500; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Mechanism Config ─────────────────────────────────────── */
.tier-table { width: 100%; font-size: 13px; }
.tier-table th { background: var(--bg); padding: 6px 10px; text-align: left; font-weight: 600; font-size: 11.5px; }
.tier-table td { padding: 6px 10px; }
.tier-table input { width: 100%; padding: 4px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; }
.add-tier-btn { font-size: 12px; color: var(--accent); cursor: pointer; margin-top: 6px; display: inline-flex; align-items: center; gap: 4px; border: none; background: none; padding: 0; }
.add-tier-btn:hover { text-decoration: underline; }

/* ── Utilities ────────────────────────────────────────────── */
.mt-4 { margin-top: 24px; }
.mt-2 { margin-top: 12px; }
.mb-4 { margin-bottom: 24px; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-sm { font-size: 12px; }
.font-bold { font-weight: 700; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.hidden { display: none !important; }
.w-full { width: 100%; }
code { font-family: monospace; background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.section-title { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.empty-state { text-align: center; padding: 48px; color: var(--text-muted); }
.empty-state h3 { font-size: 16px; margin-bottom: 6px; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 16px; }
  .estimate-shell { grid-template-columns: 1fr; }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .line-item-row { grid-template-columns: 1fr; }
}
