/* ==========================================================================
   Invoice Manager — premium theme
   Palette: deep navy sidebar + warm gold accent, soft neutral canvas.
   ========================================================================== */

:root {
  --navy-950: #0b1220;
  --navy-900: #0f172a;
  --navy-800: #16213a;
  --navy-700: #1f2c4a;
  --gold: #c9a227;
  --gold-light: #e6c766;
  --gold-dark: #a8841c;
  --canvas: #f5f6fa;
  --card: #ffffff;
  --ink: #1e2433;
  --ink-soft: #5b6478;
  --ink-faint: #9aa2b4;
  --line: #e7e9f0;
  --green: #15803d;
  --green-bg: #e9f9ee;
  --amber: #b45309;
  --amber-bg: #fff4e0;
  --red: #b91c1c;
  --red-bg: #fdeaea;
  --blue: #1d4ed8;
  --blue-bg: #eaf0fe;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { font-family: 'Sora', 'Plus Jakarta Sans', sans-serif; margin: 0 0 4px; color: var(--ink); letter-spacing: -0.01em; }
.num, td.num, .money { font-variant-numeric: tabular-nums; }

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy-950), var(--navy-900) 60%, var(--navy-800));
  color: #cfd6e6;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--gold-light), var(--gold-dark));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--navy-950); font-size: 15px;
  flex-shrink: 0;
}
.brand-text { font-family: 'Sora', sans-serif; font-weight: 700; color: #fff; font-size: 15.5px; line-height: 1.2; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-text small { display: block; font-family: 'Plus Jakarta Sans', sans-serif; font-weight: 500; color: var(--gold-light); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; margin-top: 2px; }

.nav { flex: 1; padding: 14px 12px; overflow-y: auto; }
.nav-section-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6b7590; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin-bottom: 2px; border-radius: 9px;
  color: #b9c1d6; font-size: 13.8px; font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.nav a .ic { width: 18px; text-align: center; opacity: .85; }
.nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav a.active { background: rgba(201,162,39,0.16); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }

.sidebar-footer { padding: 14px 16px 18px; border-top: 1px solid rgba(255,255,255,0.08); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255,255,255,0.1); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: var(--gold-light); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; }
.logout-btn { background: none; border: none; color: #9aa4bb; cursor: pointer; font-size: 12.5px; padding: 0; font-family: inherit; }
.logout-btn:hover { color: #fff; }

.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 32px; background: transparent;
}
.topbar h1 { font-size: 21px; }
.topbar .sub { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.container { padding: 4px 32px 48px; max-width: 1180px; }

/* ---------------- Cards ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 20px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-header h2 { font-size: 16px; }
.card-accent { border-left: 3px solid var(--gold); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-card .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-faint); font-weight: 600; }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 6px; font-family: 'Sora', sans-serif; }
.stat-card.gold { border-top: 3px solid var(--gold); }
.stat-card.green .value { color: var(--green); }
.stat-card.amber .value { color: var(--amber); }
.stat-card.red .value { color: var(--red); }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: transform .05s ease, background .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--gold-light), var(--gold-dark)); color: var(--navy-950); box-shadow: 0 4px 14px -4px rgba(201,162,39,.55); }
.btn-primary:hover { filter: brightness(1.04); }
.btn-dark { background: var(--navy-900); color: #fff; }
.btn-dark:hover { background: var(--navy-800); }
.btn-outline { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-outline:hover { border-color: var(--ink-faint); }
.btn-danger { background: var(--red-bg); color: var(--red); border-color: #f3c9c9; }
.btn-danger:hover { background: #fbdada; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: transparent; }
.btn-ghost:hover { background: var(--canvas); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-icon { width: 32px; height: 32px; padding: 0; }

/* ---------------- Forms ---------------- */
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=date],
input[type=password], input[type=file], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink); font-size: 13.8px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,162,39,.15); }
textarea { resize: vertical; min-height: 70px; }
.field { margin-bottom: 16px; }
.field-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 4px; }
.field-hint { font-size: 11.5px; color: var(--ink-faint); margin-top: 4px; }
.inline-add { display: flex; gap: 8px; align-items: flex-end; }
.inline-add select { flex: 1; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; font-weight: 500; color: var(--ink); }

fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 18px; }
legend { font-weight: 700; font-size: 13px; padding: 0 8px; color: var(--ink); }

/* ---------------- Tables ---------------- */
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-faint); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line);
}
tbody td { padding: 12px; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbff; }
.table-wrap { overflow-x: auto; }
td.right, th.right { text-align: right; }

/* ---------------- Badges ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-gray { background: #eef0f5; color: var(--ink-soft); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-gold { background: #fbf1d6; color: var(--gold-dark); }

/* ---------------- Alerts ---------------- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 16px; }
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid #bfe8cc; }
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid #f3c9c9; }
.alert-info { background: var(--blue-bg); color: var(--blue); border: 1px solid #cddcfb; }

/* ---------------- Filters / toolbar ---------------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 18px; }
.toolbar .field { margin-bottom: 0; min-width: 150px; }
.search-box { position: relative; }

/* ---------------- Segmented toggle (Active / Cancelled / Trash etc.) ---------------- */
.segmented { display: inline-flex; background: #eef0f5; border-radius: 10px; padding: 3px; gap: 2px; }
.segmented a, .segmented button {
  padding: 7px 14px; border-radius: 8px; font-size: 12.8px; font-weight: 600; color: var(--ink-soft);
  border: none; background: transparent; cursor: pointer; font-family: inherit;
}
.segmented a.active, .segmented button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* Toggle switch (used for e.g. cancel-vs-delete action mode) */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background: #d5d8e2; border-radius: 999px; transition: .15s; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + .slider { background: var(--gold); }
.switch input:checked + .slider:before { transform: translateX(18px); }
.switch-label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-left: 8px; vertical-align: middle; }

/* ---------------- Modal ---------------- */
.modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5);
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal { background: #fff; border-radius: var(--radius); padding: 24px; width: 100%; max-width: 440px; box-shadow: 0 24px 60px -12px rgba(0,0,0,.35); }
.modal h3 { margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------------- Login page ---------------- */
.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, #1a2544, var(--navy-950) 60%);
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 18px; padding: 40px 36px; width: 100%; max-width: 380px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.5);
}
.login-brand { display: flex; flex-direction: column; align-items: center; margin-bottom: 22px; }
.login-brand .brand-mark { width: 48px; height: 48px; font-size: 20px; margin-bottom: 12px; }
.login-brand h1 { font-size: 18px; }
.login-brand p { color: var(--ink-soft); font-size: 12.5px; margin: 4px 0 0; }

/* ---------------- Invoice items table (form) ---------------- */
.items-table th, .items-table td { padding: 8px 6px; }
.items-table input, .items-table select { padding: 7px 8px; font-size: 13px; }
.remove-row { color: var(--red); cursor: pointer; font-weight: 700; background: none; border: none; font-size: 16px; }
.totals-box { max-width: 320px; margin-left: auto; margin-top: 12px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13.5px; color: var(--ink-soft); }
.totals-box .row.grand { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; font-size: 16px; font-weight: 700; color: var(--ink); }

/* ---------------- Misc ---------------- */
.empty-state { text-align: center; padding: 50px 20px; color: var(--ink-faint); }
.empty-state .icon { font-size: 34px; margin-bottom: 10px; }
.muted { color: var(--ink-faint); }
.small { font-size: 12px; }
.flex { display: flex; gap: 8px; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
hr.divider { border: none; border-top: 1px solid var(--line); margin: 18px 0; }
.pill-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.pill-tabs a { padding: 10px 4px; margin-right: 18px; font-size: 13.5px; font-weight: 600; color: var(--ink-faint); border-bottom: 2px solid transparent; }
.pill-tabs a.active { color: var(--ink); border-color: var(--gold); }

.permissions-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.perm-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.perm-item input { width: auto; margin-top: 2px; }
.perm-item .t { font-weight: 600; font-size: 13px; }

/* ==========================================================================
   Responsive
   ========================================================================== */

/* Mobile topbar (hamburger + brand) — hidden on desktop, shown under 900px */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(180deg, var(--navy-950), var(--navy-900));
  position: sticky;
  top: 0;
  z-index: 60;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.hamburger-btn {
  width: 40px; height: 40px; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: rgba(255,255,255,0.08); border: none; border-radius: 9px; cursor: pointer;
}
.hamburger-btn span { display: block; width: 18px; height: 2px; background: #fff; border-radius: 2px; }
.mobile-topbar-brand { display: flex; align-items: center; gap: 9px; color: #fff; font-family: 'Sora', sans-serif; font-weight: 700; font-size: 14.5px; min-width: 0; }
.mobile-topbar-brand img { height: 26px; max-width: 90px; object-fit: contain; }
.mobile-topbar-brand .brand-mark { width: 26px; height: 26px; font-size: 12px; }
.mobile-topbar-brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-close-btn { display: none; }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,.55);
  z-index: 70; opacity: 0; transition: opacity .2s ease;
}
.sidebar-backdrop.open { display: block; opacity: 1; }

/* Tablet & phone: off-canvas sidebar drawer */
@media (max-width: 900px) {
  .mobile-topbar { display: flex; }
  .app-shell { flex-direction: column; }

  .sidebar {
    position: fixed;
    width: min(300px, 84vw);
    height: 100vh;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 80;
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 32px -8px rgba(0,0,0,.4); }
  .sidebar-close-btn {
    display: flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; margin-left: auto; flex-shrink: 0;
    background: rgba(255,255,255,0.08); border: none; border-radius: 8px;
    color: #fff; font-size: 15px; cursor: pointer;
  }
  body.nav-open { overflow: hidden; }

  .main { margin-left: 0; }
  .nav { display: block; }

  .topbar { padding: 18px 18px 4px; flex-wrap: wrap; gap: 10px; }
  .topbar h1 { font-size: 19px; }
  .container { padding: 4px 18px 40px; }
}

/* Phones */
@media (max-width: 640px) {
  html, body { font-size: 14px; }
  .container { padding: 4px 14px 36px; }
  .topbar { padding: 16px 14px 4px; }
  .topbar h1 { font-size: 18px; }
  .card { padding: 16px 16px; border-radius: 10px; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .stat-card { padding: 13px 14px; }
  .stat-card .value { font-size: 19px; }
  .field-row { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .field { min-width: 0; width: 100%; }
  .permissions-grid { grid-template-columns: 1fr; }
  .modal { padding: 18px; max-width: 100%; margin: 0 8px; }
  .card-header { flex-wrap: wrap; gap: 8px; }
  .btn { min-height: 40px; }
  input[type=text], input[type=email], input[type=tel], input[type=number], input[type=date],
  input[type=password], input[type=file], select, textarea { font-size: 16px; } /* prevents iOS auto-zoom on focus */
  .login-card { padding: 30px 22px; border-radius: 14px; }
  .pill-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .pill-tabs a { white-space: nowrap; }
}

/* Card-style tables for narrow screens — apply the "responsive-table" class
   to any <table> whose rows should stack as cards instead of scrolling
   horizontally. Requires a data-label="Column Name" attribute on each <td>. */
@media (max-width: 700px) {
  table.responsive-table thead { display: none; }
  table.responsive-table, table.responsive-table tbody, table.responsive-table tr, table.responsive-table td {
    display: block; width: 100%;
  }
  table.responsive-table tr {
    border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px;
    padding: 4px 0; background: #fff; box-shadow: var(--shadow);
  }
  table.responsive-table tr:hover { background: #fff; }
  table.responsive-table td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 9px 14px; border-bottom: 1px dashed var(--line); text-align: right;
  }
  table.responsive-table td:last-child { border-bottom: none; }
  table.responsive-table td::before {
    content: attr(data-label); font-weight: 600; color: var(--ink-soft); font-size: 12px;
    text-align: left; flex-shrink: 0;
  }
  table.responsive-table td[data-label=""]::before { display: none; }
  table.responsive-table td[data-label=""] { justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
  table.responsive-table td.right { text-align: right; }
  table.responsive-table .empty-state { padding: 30px 14px; }
}

/* Editable invoice line-items table: keep it a real scrollable table rather
   than stacking, since users are actively editing multiple fields per row. */
@media (max-width: 640px) {
  .items-table { min-width: 640px; }
  .items-table input, .items-table select { min-height: 38px; }
  .remove-row { font-size: 20px; padding: 6px; }
  .totals-box { max-width: 100%; }
}

