/* ========== Lumen Invoice — Design System ========== */
:root {
  --bg: #f7f5f0;
  --bg-elev: #ffffff;
  --bg-soft: #f0ede5;
  --ink: #1a1814;
  --ink-soft: #5a554c;
  --ink-muted: #8a8579;
  --line: #e6e1d6;
  --line-strong: #d4cec0;
  --accent: #1a1814;
  --accent-fg: #f7f5f0;
  --highlight: #d4ff3a;
  --success: #2d6a4f;
  --success-bg: #d8f3dc;
  --warning: #b8860b;
  --warning-bg: #fef3c7;
  --danger: #9d2932;
  --danger-bg: #fee2e2;
  --info: #1e40af;
  --info-bg: #dbeafe;
  --shadow-sm: 0 1px 2px rgba(26,24,20,0.04);
  --shadow: 0 4px 24px rgba(26,24,20,0.06);
  --shadow-lg: 0 24px 48px -12px rgba(26,24,20,0.18);
  --radius: 14px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Geist", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* ========== App Layout ========== */
.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }

/* ========== Sidebar ========== */
.sidebar {
  background: var(--ink);
  color: var(--accent-fg);
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand-mark {
  width: 38px; height: 38px;
  background: var(--highlight);
  color: var(--ink);
  border-radius: 10px;
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  font-style: italic;
}
.brand-text { line-height: 1.1; }
.brand-name { font-family: var(--font-display); font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.brand-sub { font-size: 11px; color: rgba(247,245,240,0.5); letter-spacing: 0.12em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(247,245,240,0.7);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.nav-item svg { opacity: 0.7; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: var(--accent-fg); }
.nav-item:hover svg { opacity: 1; }
.nav-item.active {
  background: var(--accent-fg);
  color: var(--ink);
}
.nav-item.active svg { opacity: 1; }
.nav-divider { height: 1px; background: rgba(255,255,255,0.08); margin: 12px 0; }

.sidebar-bottom { margin-top: auto; }
.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px;
  background: rgba(255,255,255,0.04);
  border-radius: var(--radius-sm);
}
.user-avatar {
  width: 36px; height: 36px;
  background: var(--highlight);
  color: var(--ink);
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 11px; color: rgba(247,245,240,0.5); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 6px;
  color: rgba(247,245,240,0.6);
  transition: all 0.15s;
}
.logout:hover { background: rgba(255,255,255,0.08); color: var(--accent-fg); }

/* ========== Main ========== */
.main { padding: 32px 40px; max-width: 1400px; width: 100%; }

/* ========== Page Header ========== */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 32px; flex-wrap: wrap; }
.page-title-block h1 {
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 500;
  letter-spacing: -0.025em;
  line-height: 1.1;
}
.page-title-block h1 em { font-style: italic; font-weight: 400; }
.page-title-block .page-sub { color: var(--ink-muted); margin-top: 6px; font-size: 14px; }
.page-actions { display: flex; gap: 10px; align-items: center; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--line-strong); background: var(--bg-soft); }
.btn-primary {
  background: var(--ink);
  color: var(--accent-fg);
  border-color: var(--ink);
}
.btn-primary:hover { background: #2a2620; border-color: #2a2620; }
.btn-accent {
  background: var(--highlight);
  color: var(--ink);
  border-color: var(--highlight);
  font-weight: 600;
}
.btn-accent:hover { background: #c2eb33; border-color: #c2eb33; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-danger { color: var(--danger); border-color: var(--line); }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger-bg); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-icon { padding: 8px; }

/* ========== Cards ========== */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.card-flat { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-title { font-size: 13px; font-weight: 500; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.08em; }

/* ========== Stats Grid ========== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 32px; }
.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
}
.stat-card.featured {
  background: var(--ink);
  color: var(--accent-fg);
  border-color: var(--ink);
}
.stat-card.featured .stat-label { color: rgba(247,245,240,0.6); }
.stat-card.featured .stat-trend { color: var(--highlight); }
.stat-label { font-size: 12px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 500; }
.stat-value { font-family: var(--font-display); font-size: 32px; font-weight: 500; letter-spacing: -0.02em; margin-top: 8px; line-height: 1; }
.stat-meta { font-size: 12px; color: var(--ink-muted); margin-top: 8px; }
.stat-card.featured .stat-meta { color: rgba(247,245,240,0.6); }

/* ========== Tables ========== */
.table-wrap { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  padding: 14px 20px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}
.table td { padding: 16px 20px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-soft); }
.table .num { font-variant-numeric: tabular-nums; text-align: right; }
.table .actions { text-align: right; white-space: nowrap; }
.table-empty { padding: 60px 20px; text-align: center; color: var(--ink-muted); }
.table-empty h3 { font-family: var(--font-display); font-size: 22px; font-weight: 500; color: var(--ink); margin-bottom: 6px; }

/* ========== Badges ========== */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-draft { background: var(--bg-soft); color: var(--ink-muted); }
.badge-sent { background: var(--info-bg); color: var(--info); }
.badge-paid { background: var(--success-bg); color: var(--success); }
.badge-overdue { background: var(--danger-bg); color: var(--danger); }
.badge-cancelled { background: var(--bg-soft); color: var(--ink-muted); text-decoration: line-through; }
.badge-accepted { background: var(--success-bg); color: var(--success); }
.badge-rejected { background: var(--danger-bg); color: var(--danger); }
.badge-expired { background: var(--bg-soft); color: var(--ink-muted); }

/* ========== Forms ========== */
.form-grid { display: grid; gap: 18px; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 500; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  transition: border-color 0.15s;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--ink);
}
.field textarea { resize: vertical; min-height: 80px; font-family: inherit; }
.field .hint { font-size: 11px; color: var(--ink-muted); }
.field.required label::after { content: ' *'; color: var(--danger); }

/* ========== Auth Pages ========== */
.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
}
.auth-side {
  background: var(--ink);
  color: var(--accent-fg);
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.auth-side::before {
  content: '';
  position: absolute;
  top: -100px; right: -100px;
  width: 400px; height: 400px;
  background: radial-gradient(circle, var(--highlight) 0%, transparent 70%);
  opacity: 0.15;
  filter: blur(40px);
}
.auth-side .brand { padding: 0; }
.auth-quote {
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.02em;
  position: relative;
  z-index: 1;
}
.auth-quote em { font-style: italic; color: var(--highlight); }
.auth-side-foot { font-size: 12px; color: rgba(247,245,240,0.5); }

.auth-form-side { display: grid; place-items: center; padding: 32px; }
.auth-form { width: 100%; max-width: 380px; }
.auth-form h1 { font-family: var(--font-display); font-size: 32px; font-weight: 500; letter-spacing: -0.02em; margin-bottom: 8px; }
.auth-form h1 em { font-style: italic; }
.auth-form > p { color: var(--ink-muted); margin-bottom: 28px; }
.auth-form .field { margin-bottom: 16px; }
.auth-form .btn { width: 100%; justify-content: center; padding: 12px; }
.auth-form .alt { text-align: center; margin-top: 20px; font-size: 13px; color: var(--ink-muted); }
.auth-form .alt a { color: var(--ink); font-weight: 500; border-bottom: 1px solid var(--line-strong); }

/* ========== Flash ========== */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 13px; font-weight: 500; }
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error { background: var(--danger-bg); color: var(--danger); }
.flash-info { background: var(--info-bg); color: var(--info); }

/* ========== Document Editor ========== */
.doc-editor { display: grid; grid-template-columns: 1fr 320px; gap: 24px; }
.doc-main { display: flex; flex-direction: column; gap: 16px; }
.doc-sidebar { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 32px; align-self: start; }

.items-table { width: 100%; border-collapse: collapse; }
.items-table th { text-align: left; padding: 8px 10px; font-size: 11px; font-weight: 500; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.items-table td { padding: 6px 4px; vertical-align: top; }
.items-table input, .items-table select {
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  width: 100%;
  font-size: 13px;
}
.items-table input:hover, .items-table select:hover { background: var(--bg-soft); }
.items-table input:focus, .items-table select:focus { background: var(--bg-elev); border-color: var(--ink); outline: none; }
.items-table .col-pos { width: 36px; color: var(--ink-muted); text-align: center; padding-top: 14px; }
.items-table .col-qty { width: 90px; }
.items-table .col-unit { width: 70px; }
.items-table .col-price { width: 130px; }
.items-table .col-tax { width: 90px; }
.items-table .col-total { width: 130px; text-align: right; padding-right: 10px; padding-top: 14px; font-variant-numeric: tabular-nums; font-weight: 500; }
.items-table .col-del { width: 40px; }
.del-btn { background: transparent; border: none; color: var(--ink-muted); padding: 6px; border-radius: 6px; }
.del-btn:hover { background: var(--danger-bg); color: var(--danger); }

.totals-box { display: grid; gap: 8px; }
.totals-row { display: flex; justify-content: space-between; padding: 6px 0; font-variant-numeric: tabular-nums; }
.totals-row.total { border-top: 2px solid var(--ink); margin-top: 8px; padding-top: 14px; font-size: 18px; font-weight: 600; font-family: var(--font-display); }

/* ========== Toolbar ========== */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 20px; }
.toolbar .search { flex: 1; max-width: 360px; }
.toolbar .search input { padding-left: 36px; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-muted); pointer-events: none; }

/* ========== Empty State ========== */
.empty {
  text-align: center;
  padding: 80px 24px;
  background: var(--bg-elev);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}
.empty h3 { font-family: var(--font-display); font-size: 26px; font-weight: 500; margin-bottom: 8px; }
.empty p { color: var(--ink-muted); margin-bottom: 20px; max-width: 360px; margin-left: auto; margin-right: auto; }

/* ========== Two-column layout ========== */
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; }
@media (max-width: 1100px) { .two-col, .doc-editor { grid-template-columns: 1fr; } .doc-sidebar { position: static; } }
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; align-items: center; padding: 16px; gap: 16px; overflow-x: auto; }
  .nav { flex-direction: row; flex: none; }
  .nav-divider { display: none; }
  .sidebar-bottom { margin-left: auto; margin-top: 0; }
  .user-info { display: none; }
  .main { padding: 20px; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .auth-page { grid-template-columns: 1fr; }
  .auth-side { display: none; }
}

/* ========== Print (PDF) ========== */
@media print {
  body { background: white; }
  .no-print { display: none !important; }
}

/* ========== Logo Upload ========== */
.logo-upload { display: flex; gap: 16px; align-items: center; }
.logo-preview {
  width: 120px; height: 120px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  display: grid; place-items: center;
  background: var(--bg-soft);
  overflow: hidden;
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ========== Customer card chips ========== */
.chip {
  display: inline-flex; padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  font-size: 11px;
  color: var(--ink-soft);
  font-family: var(--font-mono);
}
