/* ==========================================================================
   Admin Stylesheet - Invoice Generator Dashboard, Installer and Auth
   ========================================================================== */

/* ─── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  /* Surfaces */
  --surface: #FFFFFF;
  --paper: #FAFAFA;
  --linen: #F3F4F3;
  --sidebar: #FFFFFF;
  /* Text Scale */
  --ink: #0A0A0A;
  --body: #3C3E3D;
  --muted: #7A7B7B;
  /* Border */
  --hairline: #E5E5E5;
  --border-mid: #D4D4D4;
  /* Accent */
  --primary: #056DFF;
  --primary-hover: #045EDE;
  --primary-highlight: #619EFF;
  --primary-grad-start: #3C87FF;
  --primary-grad-end: #056DFF;
  --primary-wash: #EFF6FF;
  --primary-border: #BFDBFE;
  --primary-text: #0450C0;
  /* Button Neutrals */
  --btn-ink: #171717;
  --btn-border: rgba(10, 10, 10, 0.10);
  --btn-border-hover: rgba(10, 10, 10, 0.16);
  /* Status */
  --success: #16A34A;
  --success-bg: #F0FDF4;
  --success-border: #BBF7D0;
  --info: #1D4ED8;
  --info-bg: #EFF6FF;
  --info-border: #BFDBFE;
  --warn: #B45309;
  --warn-bg: #FFFBEB;
  --warn-border: #FDE68A;
  --danger: #DC2626;
  --danger-bg: #FEF2F2;
  --danger-border: #FECACA;
  /* Radius */
  --r-xs: 5px;
  --r-sm: 8px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-btn: 8px;
  --r-btn-sm: 6px;
  --r-pill: 50px;
}

/* ─── Base ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; box-shadow: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: Inter, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--body);
  background: var(--paper);
}
a { color: var(--ink); }
h1, h2, h3 { color: var(--ink); letter-spacing: -0.02em; line-height: 1.2; margin: 0; }
code { font-family: "JetBrains Mono", ui-monospace, Menlo, monospace; font-size: 12px; background: var(--linen); padding: 1px 5px; border-radius: 4px; }
.mono { font-family: "JetBrains Mono", ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.grow { flex: 1 1 auto; }

/* ─── Buttons ───────────────────────────────────────────────────────────── */
/* Base button: rounded rectangle (not a pill), real 1px border, no shadow */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--r-btn);
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, filter .15s ease;
}
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

/* Sizes */
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: var(--r-btn-sm); }
.btn-lg { height: 40px; padding: 0 16px; gap: 8px; }
.btn-block { width: 100%; }

/* Primary: 1px top highlight line over a vertical blue gradient */
.btn-primary {
  color: #FFFFFF;
  background:
    linear-gradient(var(--primary-highlight), var(--primary-highlight)) top / 100% 1px no-repeat,
    linear-gradient(180deg, var(--primary-grad-start), var(--primary-grad-end));
  border-color: var(--primary-hover);
}
.btn-primary:hover { filter: brightness(0.94); }
.btn-primary:active { filter: brightness(0.88); }

/* Secondary */
.btn-secondary { background: var(--surface); color: var(--btn-ink); border-color: var(--btn-border); }
.btn-secondary:hover { background: var(--paper); border-color: var(--btn-border-hover); }

/* Ghost */
.btn-ghost { background: transparent; color: var(--btn-ink); border-color: transparent; }
.btn-ghost:hover { background: var(--linen); }

/* Danger */
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger-border); }
.btn-danger:hover { background: var(--danger-bg); }

/* Link */
.btn-link { background: none; border: 0; padding: 0; height: auto; min-height: 32px; color: var(--muted); font-weight: 500; text-decoration: underline; }

/* Touch targets on mobile */
@media (max-width: 760px) {
  .btn { height: 44px; }
  .btn-sm { height: 36px; }
  .btn-link { height: auto; }
}

/* ─── Forms ─────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--ink); }
.field small { font-weight: 400; }
input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
}
textarea { min-height: 64px; resize: vertical; }
input[type="file"] { padding: 8px; }
input[type="radio"] { width: auto; min-height: 0; accent-color: var(--primary); }
input:hover, select:hover, textarea:hover { border-color: var(--border-mid); }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; justify-content: flex-start; }

/* ─── Alerts & Badges ───────────────────────────────────────────────────── */
.alert { padding: 12px 14px; margin-bottom: 16px; border: 1px solid; border-radius: var(--r-sm); font-size: 13.5px; }
.alert-success { color: #15803D; background: var(--success-bg); border-color: var(--success-border); }
.alert-error { color: var(--danger); background: var(--danger-bg); border-color: var(--danger-border); }

.badge {
  display: inline-block;
  padding: 2px 10px;
  font-size: 11.5px;
  font-weight: 700;
  border: 1px solid;
  border-radius: var(--r-pill);
  white-space: nowrap;
}
/* Status badge on card */
.badge-draft { color: var(--muted); background: var(--paper); border-color: var(--hairline); }
.badge-sent { color: var(--info); background: var(--info-bg); border-color: var(--info-border); }
.badge-paid { color: var(--success); background: var(--success-bg); border-color: var(--success-border); }
.badge-overdue { color: var(--danger); background: var(--danger-bg); border-color: var(--danger-border); }
.badge-void { color: var(--muted); background: var(--linen); border-color: var(--hairline); text-decoration: line-through; }

.tag {
  display: inline-block;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--primary-wash);
  border: 1px solid var(--primary-border);
  border-radius: var(--r-pill);
}

/* ─── Auth & Installer ──────────────────────────────────────────────────── */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 12px;
}
.auth-card-wide { max-width: 560px; }
.auth-brand { margin-bottom: 22px; }
.auth-brand h1 { margin-top: 10px; font-size: 26px; font-weight: 800; letter-spacing: -0.03em; }
.auth-title { font-size: 17px; margin-bottom: 18px; }

/* Installer stepper */
.stepper { display: flex; gap: 6px; padding: 0; margin: 0 0 22px; list-style: none; font-size: 12px; color: var(--muted); }
.stepper li { flex: 1; display: flex; align-items: center; gap: 6px; padding-top: 8px; border-top: 2px solid var(--hairline); }
.stepper span { display: inline-flex; width: 20px; height: 20px; align-items: center; justify-content: center; border-radius: 50%; border: 1px solid var(--hairline); font-size: 11px; }
.stepper li.active { color: var(--ink); font-weight: 600; border-color: var(--primary); }
.stepper li.active span { background: var(--primary); border-color: var(--primary); color: #FFFFFF; }
.stepper li.done { border-color: var(--ink); color: var(--ink); }
.checklist { list-style: none; padding: 0; margin: 0 0 18px; display: flex; flex-direction: column; gap: 8px; }
.checklist li { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--hairline); border-radius: var(--r-sm); }
.checklist .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.checklist .ok .dot { background: var(--success); }
.checklist .fail { border-color: var(--danger-border); background: var(--danger-bg); color: var(--danger); }
.checklist .fail .dot { background: var(--danger); }

/* ─── Admin Shell ───────────────────────────────────────────────────────── */
.admin-body { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  width: 240px;
  height: 100vh;
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  background: var(--sidebar);
  border-right: 1px solid var(--hairline);
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; border-bottom: 1px solid var(--hairline); }
.brand-mark { display: inline-flex; width: 32px; height: 32px; align-items: center; justify-content: center; border-radius: 8px; background: var(--ink); color: #FFFFFF; font-weight: 800; }
.brand-name { font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; margin-top: 14px; flex: 1; }
.sidebar-nav a { display: flex; align-items: center; min-height: 40px; padding: 0 12px; border-radius: var(--r-sm); text-decoration: none; color: var(--body); font-weight: 500; }
.sidebar-nav a:hover { background: var(--paper); color: var(--ink); }
.sidebar-nav a.active { background: var(--primary-wash); color: var(--primary-text); font-weight: 700; border-left: 2px solid var(--primary); padding-left: 10px; }
.sidebar-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 14px; border-top: 1px solid var(--hairline); }
.user-name { font-weight: 600; color: var(--ink); font-size: 13px; }
.user-meta { font-size: 12px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--hairline);
}
.page-title { font-size: 19px; flex: 1; }
.nav-toggle { display: none; }
.content { padding: 24px 28px 48px; max-width: 1240px; width: 100%; }

/* ─── Cards, Stats & Tables ─────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-md); padding: 20px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h2 { font-size: 15px; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-md); padding: 18px; }
.stat-accent { background: var(--primary-wash); border-color: var(--primary-border); }
.stat-label { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.stat-value { margin-top: 6px; font-size: 22px; font-weight: 800; color: var(--ink); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-note { margin-top: 4px; font-size: 12px; color: var(--muted); }

.table-wrap { overflow-x: auto; margin: 0 -20px; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  padding: 10px 20px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--paper);
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}
.table th.num { text-align: right; }
.table td { padding: 12px 20px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
.table tbody tr:hover { background: var(--paper); }
.table td a { font-weight: 600; text-decoration: none; }
.table td a:hover { color: var(--primary-text); }
.actions-col { width: 1%; text-align: right; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters .field { min-width: 150px; }
.filters .grow { flex: 1 1 240px; }
.filter-actions { display: flex; gap: 8px; }
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; }
.pagination a { display: inline-flex; min-width: 36px; min-height: 36px; align-items: center; justify-content: center; border: 1px solid var(--btn-border); border-radius: var(--r-btn); text-decoration: none; font-size: 13px; color: var(--btn-ink); }
.pagination a:hover { background: var(--paper); border-color: var(--btn-border-hover); }
.pagination a.active { color: #FFFFFF; background: linear-gradient(var(--primary-highlight), var(--primary-highlight)) top / 100% 1px no-repeat, linear-gradient(180deg, var(--primary-grad-start), var(--primary-grad-end)); border-color: var(--primary-hover); }

/* ─── Invoice Form ──────────────────────────────────────────────────────── */
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.form-side { position: sticky; top: 84px; }
.summary-card { display: flex; flex-direction: column; gap: 12px; }
.summary-total { font-size: 26px; font-weight: 800; color: var(--ink); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.summary-words { font-size: 12.5px; color: var(--muted); margin-top: -6px; }

.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--hairline); border-radius: var(--r-btn); background: var(--paper); }
.segmented label { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 12px; border-radius: var(--r-btn-sm); font-size: 12.5px; font-weight: 600; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--surface); color: var(--ink); border: 1px solid var(--hairline); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--primary); }

.items { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; counter-reset: item; }
.item-row { border: 1px solid var(--hairline); border-radius: var(--r-sm); padding: 12px; background: var(--paper); }
.item-head { display: flex; align-items: center; gap: 10px; }
.item-no { flex: none; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--surface); border: 1px solid var(--hairline); font-size: 12px; font-weight: 700; }
.item-no::before { counter-increment: item; content: counter(item); }
.item-title { font-weight: 600; }
.item-body { display: flex; gap: 12px; margin-top: 10px; align-items: flex-start; }
.item-price { display: grid; grid-template-columns: 70px 100px 130px; gap: 10px; }
[data-mode="lump"] .item-only { display: none; }
[data-mode="item"] .lump-only { display: none; }

/* ─── Settings ──────────────────────────────────────────────────────────── */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.settings-grid .card { margin-bottom: 0; }
.logo-row { display: flex; gap: 16px; align-items: center; }
.logo-preview { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; border: 1px solid var(--hairline); flex: none; }
.logo-empty { display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 800; color: var(--muted); background: var(--paper); }

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-layout { grid-template-columns: 1fr; }
  .form-side { position: static; }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; left: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .nav-toggle { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .content { padding: 18px 16px 40px; }
  .topbar-cta { display: none; }
  .item-body { flex-direction: column; }
  .item-body .field.grow { width: 100%; }
  .item-price { grid-template-columns: 1fr 1fr; width: 100%; }
  .item-price .field:last-child { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .card-head .segmented { width: 100%; }
  .segmented label { flex: 1; justify-content: center; }
  .auth-card { padding: 24px 18px; }
}
