@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;500;600;700;800&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;1,9..40,400&display=swap');

/* ─── Tokens ────────────────────────────────────────────── */
:root {
  --bg:          #0b0d13;
  --surface:     #111420;
  --surface-2:   #181c2a;
  --surface-3:   #1f2333;
  --border:      #252b3b;
  --border-2:    #2e3548;
  --text:        #dde2f0;
  --text-muted:  #6b7491;
  --text-dim:    #4a5068;
  --accent:      #e8991a;
  --accent-2:    #f5b540;
  --accent-glow: rgba(232, 153, 26, 0.18);
  --paid:        #2ebd7a;
  --paid-bg:     rgba(46, 189, 122, 0.12);
  --unpaid:      #e8991a;
  --unpaid-bg:   rgba(232, 153, 26, 0.12);
  --overdue:     #e05252;
  --overdue-bg:  rgba(224, 82, 82, 0.12);
  --radius-sm:   6px;
  --radius:      10px;
  --radius-lg:   16px;
  --sidebar-w:   240px;
  --header-h:    60px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg:   0 8px 48px rgba(0,0,0,0.6);
  --font-body:   'DM Sans', sans-serif;
  --font-display:'Syne', sans-serif;
}

/* ─── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }
img { display: block; max-width: 100%; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* ─── Auth layout ────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 60% 40% at 50% -10%, rgba(232,153,26,0.07) 0%, transparent 70%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}
.auth-logo span { color: var(--text-muted); font-weight: 400; }

.auth-tagline {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 2rem;
}

.auth-card h1 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  color: var(--text);
}
.auth-card .subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 1.75rem;
}

/* ─── Forms ─────────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.4rem;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.65rem 0.85rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-group textarea { resize: vertical; min-height: 90px; }
.form-group select { appearance: none; cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-row.thirds { grid-template-columns: 1fr 1fr 1fr; }

.form-hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 0.3rem;
}

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #0b0d13;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: #0b0d13; }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-2); }
.btn-danger {
  background: transparent;
  color: var(--overdue);
  border-color: rgba(224,82,82,0.3);
}
.btn-danger:hover { background: var(--overdue-bg); }
.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.82rem; }
.btn-full { width: 100%; justify-content: center; padding: 0.75rem; }
.btn-icon { padding: 0.5rem; }

/* ─── Flash messages ─────────────────────────────────────── */
.flash-list { list-style: none; margin-bottom: 1rem; }
.flash-item {
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  border: 1px solid;
}
.flash-item.success { background: var(--paid-bg); color: var(--paid); border-color: rgba(46,189,122,0.3); }
.flash-item.error { background: var(--overdue-bg); color: var(--overdue); border-color: rgba(224,82,82,0.3); }
.flash-item.info { background: var(--unpaid-bg); color: var(--unpaid); border-color: rgba(232,153,26,0.3); }

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  padding: 1.5rem 0;
}

.sidebar-brand {
  padding: 0 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.sidebar-brand-name {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-brand-label {
  font-size: 0.7rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.sidebar-logo-img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 6px;
  margin-bottom: 0.5rem;
}

.sidebar-nav { flex: 1; padding: 0 0.75rem; }
.sidebar-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  font-weight: 600;
  padding: 0.6rem 0.5rem 0.3rem;
  margin-top: 0.5rem;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.12s;
  margin-bottom: 1px;
}
.sidebar-nav a:hover { background: var(--surface-2); color: var(--text); }
.sidebar-nav a.active {
  background: var(--accent-glow);
  color: var(--accent);
}
.sidebar-nav a svg { flex-shrink: 0; opacity: 0.7; }
.sidebar-nav a.active svg { opacity: 1; }

.sidebar-footer {
  padding: 1rem 1.5rem 0;
  border-top: 1px solid var(--border);
}
.sidebar-footer a {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.sidebar-footer a:hover { color: var(--overdue); }

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  padding: 2.5rem 2.5rem 4rem;
  max-width: 1100px;
}

/* ─── Page header ────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
  gap: 1rem;
}
.page-header-left h1 {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.page-header-left p {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.2rem;
}
.page-actions { display: flex; gap: 0.5rem; align-items: center; }

/* ─── Stat cards ─────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}
.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.stat-value.accent { color: var(--accent); }
.stat-value.paid { color: var(--paid); }

/* ─── Tables ─────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.table-header h2 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--text);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }
td a { color: var(--text); font-weight: 500; }
td a:hover { color: var(--accent); }

.table-empty {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}
.table-empty .empty-icon { font-size: 2.5rem; margin-bottom: 0.5rem; opacity: 0.4; }

/* ─── Status badges ──────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-paid    { background: var(--paid-bg);   color: var(--paid); }
.badge-unpaid  { background: var(--unpaid-bg); color: var(--unpaid); }
.badge-overdue { background: var(--overdue-bg); color: var(--overdue); }
.badge-claimed   { background: var(--paid-bg);   color: var(--paid); }
.badge-unclaimed { background: var(--surface-3); color: var(--text-muted); }

/* ─── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.card + .card { margin-top: 1rem; }
.card-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.card-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.6rem;
  font-size: 0.875rem;
}
.card-row:last-child { margin-bottom: 0; }
.card-row-label { color: var(--text-muted); flex-shrink: 0; }
.card-row-value { color: var(--text); text-align: right; }

/* ─── Invoice detail layout ──────────────────────────────── */
.invoice-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.5rem;
  align-items: start;
}

.invoice-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}
.invoice-number {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

/* ─── Line items form ────────────────────────────────────── */
.line-items-table { width: 100%; border-collapse: collapse; }
.line-items-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.line-items-table td { padding: 0.4rem 0.5rem; border: none; vertical-align: middle; }
.line-items-table tr:hover td { background: transparent; }
.line-items-table input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.55rem 0.7rem;
  width: 100%;
  outline: none;
}
.line-items-table input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.line-items-table .col-desc { width: 45%; }
.line-items-table .col-qty  { width: 12%; }
.line-items-table .col-price{ width: 18%; }
.line-items-table .col-total{ width: 18%; text-align: right; color: var(--text-muted); font-size: 0.85rem; padding-right: 0.5rem; }
.line-items-table .col-del  { width: 7%; text-align: center; }

.add-line-btn {
  margin-top: 0.75rem;
  font-size: 0.82rem;
  color: var(--accent);
  cursor: pointer;
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  width: 100%;
  text-align: left;
  transition: all 0.12s;
}
.add-line-btn:hover { border-color: var(--accent); background: var(--accent-glow); }

.del-row-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color 0.12s;
}
.del-row-btn:hover { color: var(--overdue); }

/* ─── Invoice totals ─────────────────────────────────────── */
.totals-block {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.totals-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  padding: 0.2rem 0;
  color: var(--text-muted);
}
.totals-row.grand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 0.4rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-display);
}

/* ─── Partner block ──────────────────────────────────────── */
.partner-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-top: 1rem;
}
.partner-block-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

/* ─── Access code display ────────────────────────────────── */
.code-box {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.85rem;
  font-family: 'Courier New', monospace;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--accent);
}

/* ─── Platform admin ─────────────────────────────────────── */
.platform-shell {
  min-height: 100vh;
  background: var(--bg);
}
.platform-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.platform-brand {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.platform-brand span { color: var(--text-muted); font-weight: 400; font-size: 0.85rem; }
.platform-main { padding: 2.5rem; max-width: 1000px; margin: 0 auto; }

/* ─── Customer portal ────────────────────────────────────── */
.portal-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.portal-brand {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.portal-brand img { height: 28px; width: auto; object-fit: contain; }
.portal-main { padding: 2.5rem; max-width: 860px; margin: 0 auto; }

/* ─── Invoice detail (read-only) ─────────────────────────── */
.invoice-view {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.invoice-view-header {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.invoice-view-body { padding: 2rem; }
.invoice-view-brands {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.brand-block { flex: 1; }
.brand-block-name {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.2rem;
}
.brand-block-info { font-size: 0.8rem; color: var(--text-muted); line-height: 1.7; }
.brand-divider {
  width: 1px;
  background: var(--border);
  align-self: stretch;
  margin: 0.5rem 0;
}

/* ─── Utilities ──────────────────────────────────────────── */
.mt-1  { margin-top: 0.5rem; }
.mt-2  { margin-top: 1rem; }
.mt-3  { margin-top: 1.5rem; }
.mb-1  { margin-bottom: 0.5rem; }
.mb-2  { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.text-right { text-align: right; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.section-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}
.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
  transition: color 0.12s;
}
.back-link:hover { color: var(--text); }

/* ─── Responsive ─────────────────────────────────────────── */

/* Mobile-only elements hidden on desktop */
.mobile-topbar { display: none; }
.mobile-nav-drawer { display: none; }
.mobile-nav-overlay { display: none; }

@media (max-width: 768px) {

  /* Hide desktop sidebar entirely */
  .shell > nav.sidebar { display: none; }

  /* Mobile top bar */
  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 54px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    z-index: 300;
    gap: 0.75rem;
  }

  /* Hamburger button */
  .hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.4rem;
    flex-shrink: 0;
  }
  .hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text-muted);
    border-radius: 2px;
    transition: background 0.15s;
  }
  .hamburger:hover span { background: var(--text); }

  /* Dim overlay */
  .mobile-nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 400;
  }
  .mobile-nav-overlay.open { display: block; }

  /* Slide-in drawer */
  .mobile-nav-drawer {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 260px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    z-index: 500;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
  }
  .mobile-nav-drawer.open { transform: translateX(0); }
  .mobile-nav-drawer .sidebar-footer {
    margin-top: auto;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
  }

  /* Push main content below topbar */
  .main-content {
    margin-left: 0;
    margin-top: 54px;
    padding: 1.25rem 1rem 3rem;
  }

  /* Stack invoice layout columns */
  .invoice-layout { grid-template-columns: 1fr; }

  /* Stack form rows */
  .form-row,
  .form-row.thirds { grid-template-columns: 1fr; }

  /* Stat grid: 1 column */
  .stat-grid { grid-template-columns: 1fr; }

  /* Page header stacks */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  /* Tables scroll horizontally */
  .table-wrap { overflow-x: auto; }

  /* Platform & portal */
  .platform-main,
  .portal-main { padding: 1.25rem 1rem 3rem; }

  /* Compact line items on small screens */
  .line-items-table .col-qty,
  .line-items-table .col-price { display: none; }
  .line-items-table .col-desc  { width: 70%; }
  .line-items-table .col-total { width: 22%; }
}
