:root {
  --accent: #2f6f4f;
  --accent-dark: #1f5138;
  --accent-light: #eaf3ee;
  --accent-glow: rgba(47, 111, 79, .18);
  --accent-2: #1c4b7c;          /* secondary accent — void/info actions, distinct from danger red */
  --accent-2-light: #e8eff8;

  /* Neutral gray scale — replaces one-off hex values previously scattered through tables/panels */
  --gray-50:  #fafbfc;
  --gray-100: #f4f6f7;
  --gray-200: #e6e8eb;
  --gray-300: #d7dade;
  --gray-400: #b9bfc6;
  --gray-500: #8b929b;
  --gray-600: #6b7280;
  --gray-700: #4b5158;
  --gray-800: #2c3036;
  --gray-900: #14171c;

  --border: var(--gray-200);
  --border-strong: var(--gray-300);
  --bg: var(--gray-100);
  --card: #ffffff;
  --text: var(--gray-900);
  --text-secondary: var(--gray-600);
  --text-success: #1e7a34;
  --text-danger: #c02f27;

  --radius: 12px;
  --radius-lg: 18px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 32, .05), 0 1px 1px rgba(16, 24, 32, .04);
  --shadow-md: 0 8px 20px rgba(16, 24, 32, .08), 0 2px 6px rgba(16, 24, 32, .05);
  --shadow-lg: 0 24px 56px rgba(16, 24, 32, .18), 0 8px 20px rgba(16, 24, 32, .08);
  --shadow-pop: 0 30px 70px rgba(15, 25, 35, .28), 0 10px 24px rgba(15, 25, 35, .12);
  --sidebar-w: 256px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  /* Type scale — every font-size in this file resolves to one of these eight steps. */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 16px;
  --fs-lg: 20px;
  --fs-xl: 28px;
  --fs-2xl: 32px;
  --fs-3xl: 40px;

  /* Regular weight (400) is the default everywhere (body text, inputs,
     table cells). A single step up (500) is used in a short deliberate
     list of emphasis spots — wordmark, buttons, headings, stat values,
     badges — never higher than that. */
  --weight: 400;
  --weight-medium: 500;
  --weight-bold: 500;
  --tracking-label: .03em;

  --panel-padding: 24px;
  --gap-icon: 8px;

  --ease: cubic-bezier(.2, .7, .3, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-weight: var(--weight);
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { font-weight: var(--weight-bold); }
button, input, select, textarea {
  font-weight: var(--weight);
  font-family: inherit;
}

a { color: var(--accent); }

svg { display: block; }

::selection { background: var(--accent-glow); color: var(--text); }

/* Subtle entrance animation for main content — applied selectively via JS-free CSS on load */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ========================================================================
   Wordmark — "Invoice" in near-black, "Singapore" in brand green, always
   the same single weight, distinguished only by color. Used in the auth
   visual pane (hero size, .wordmark-hero), the sidebar brand block, and
   the PDF header.
   ======================================================================== */
.wordmark { font-weight: var(--weight-bold); letter-spacing: -.01em; }
.wordmark .wm-invoice { color: var(--text); }
.wordmark .wm-singapore { color: var(--accent); }
.wordmark.on-dark .wm-invoice { color: #fff; }
.wordmark.on-dark .wm-singapore { color: #a7ecc6; }
.wordmark.hero { font-size: var(--fs-3xl); letter-spacing: -.02em; }

/* ========================================================================
   Shared text utilities — replaces one-off inline style="color:...;
   font-size:...;margin-top:-8px" blocks that were repeated across views.
   ======================================================================== */
.sub-text { font-size: var(--fs-sm); color: var(--text-secondary); }
.sub-text.tight { margin-top: -8px; }
.sub-text.success { color: var(--text-success); }
.sub-text.danger { color: var(--text-danger); }
.loading-state { color: var(--text-secondary); padding: 40px 0; text-align: center; }
.spinner-dot { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: btn-spin .6s linear infinite; }
.wa-connect-box { max-width: 320px; text-align: center; }
.wa-qr-img { width: 240px; height: 240px; border-radius: var(--radius); border: 1px solid var(--border); }

/* ========================================================================
   Auth pages — 70/30 split (login), form pane can widen to ~38-40% when
   content needs it (signup wizard)
   ======================================================================== */
.auth-split {
  min-height: 100vh;
  display: flex;
}

.auth-visual-pane {
  flex: 0 0 60%;
  max-width: 60%;
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, #16382a 0%, var(--accent-dark) 45%, var(--accent) 100%);
  color: #fff;
  padding: 56px 64px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* Abstract document illustration — dotted grid + layered invoice cards, no
   external image asset needed, duotone on the brand gradient. */
.auth-visual-art {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255,255,255,.14) 1px, transparent 1px);
  background-size: 26px 26px;
  -webkit-mask-image: radial-gradient(ellipse 70% 70% at 70% 40%, #000 0%, transparent 72%);
  mask-image: radial-gradient(ellipse 70% 70% at 70% 40%, #000 0%, transparent 72%);
}
.auth-visual-cards {
  position: absolute;
  right: 8%;
  top: 50%;
  transform: translateY(-50%);
  width: 340px;
  height: 400px;
}
.auth-visual-cards .doc-card {
  position: absolute;
  width: 260px;
  height: 340px;
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.18);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  padding: 22px;
}
.auth-visual-cards .doc-card.back { top: 0; left: 0; transform: rotate(-7deg); opacity: .55; }
.auth-visual-cards .doc-card.front { top: 34px; left: 46px; box-shadow: var(--shadow-pop); background: rgba(255,255,255,.1); }
.auth-visual-cards .doc-line { height: 8px; border-radius: 4px; background: rgba(255,255,255,.28); margin-bottom: 12px; }
.auth-visual-cards .doc-line.w60 { width: 60%; }
.auth-visual-cards .doc-line.w80 { width: 80%; }
.auth-visual-cards .doc-line.w40 { width: 40%; }
.auth-visual-cards .doc-total { margin-top: 24px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.24); display: flex; justify-content: space-between; align-items: center; }
.auth-visual-cards .doc-total .amt { font-size: var(--fs-md); color: #a7ecc6; }
.auth-visual-cards .doc-check {
  position: absolute;
  bottom: -14px;
  left: -14px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #a7ecc6;
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
}

.auth-visual-head { position: relative; z-index: 1; }
.auth-visual-tagline { font-size: var(--fs-lg); color: rgba(255,255,255,.9); margin: 14px 0 0; max-width: 380px; line-height: 1.4; }
.auth-visual-foot { position: relative; z-index: 1; font-size: var(--fs-xs); color: rgba(255,255,255,.6); }
.auth-visual-foot a { color: rgba(255,255,255,.85); }

.auth-form-pane {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 40px;
  background: var(--card);
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  animation: fade-up .35s var(--ease);
}

.auth-shell .auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px;
  box-shadow: var(--shadow-md);
}

.auth-card h1 {
  font-size: var(--fs-xl);
  margin: 0 0 6px;
  letter-spacing: -.01em;
}

.auth-card .sub {
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  margin-bottom: 26px;
}

.field { margin-bottom: 18px; }

.field label {
  display: block;
  font-size: var(--fs-sm);
  margin-bottom: 7px;
  color: var(--text);
}

.field input, .field select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
  background: #fff;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-light);
}

/* ========================================================================
   Buttons — flat fills, no gradients. Only one .primary should be visible
   per action group; other actions use the default (bordered) or a
   semantic variant (.danger / .void).
   ======================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-icon);
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 13px 22px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
  font-weight: var(--weight-bold);
  letter-spacing: -.005em;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  width: 100%;
  transition: background-color .15s var(--ease), box-shadow .15s var(--ease), transform .12s var(--ease);
  box-shadow: 0 1px 2px rgba(16,24,32,.08);
}

.btn:hover { background: var(--accent-dark); box-shadow: 0 4px 14px var(--accent-glow); transform: translateY(-1px); }
.btn:active { transform: translateY(0); background: var(--accent-dark); }

.btn.loading, .btn-sm.loading {
  color: transparent !important;
  pointer-events: none;
  position: relative;
}
.btn.loading::after, .btn-sm.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 15px;
  height: 15px;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spin .6s linear infinite;
}
.btn-sm.loading::after {
  border-color: rgba(47, 111, 79, .25);
  border-top-color: var(--accent);
}
.btn-sm.primary.loading::after {
  border-color: rgba(255, 255, 255, .45);
  border-top-color: #fff;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

.btn.secondary {
  background: #fff;
  color: var(--text);
  border: 1.5px solid var(--border-strong);
  box-shadow: none;
}
.btn.secondary:hover { background: var(--bg); box-shadow: none; transform: none; }

.btn-row { display: flex; gap: 10px; margin-top: 20px; }
.btn-row .btn { width: auto; flex: 1; }

/* ---------- OAuth buttons — standard convention: outlined, full width,
   provider icon left-aligned, label centered alongside it ---------- */
.oauth-row { display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }

.oauth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-icon);
  border: 1.5px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 11px;
  font-size: var(--fs-sm);
  font-weight: var(--weight-bold);
  text-decoration: none;
  color: var(--text);
  transition: border-color .15s, background .15s;
}
.oauth-btn svg, .oauth-btn img { flex-shrink: 0; }
.oauth-btn:hover { border-color: var(--border-strong); background: var(--bg); }

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  margin: 20px 0;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: var(--fs-sm); margin-bottom: 16px; border: 1px solid transparent; }
.alert.err { background: #fdeceb; color: var(--text-danger); border-color: #f6c6c1; }
.alert.ok { background: #e9f7ee; color: var(--text-success); border-color: #bfe6cb; }

.foot-link { text-align: center; margin-top: 20px; font-size: var(--fs-sm); color: var(--text-secondary); }
.foot-link a { text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Signup wizard ---------- */
.wizard-steps { display: flex; gap: 6px; margin-bottom: 24px; }
.wizard-steps span { flex: 1; height: 4px; border-radius: 2px; background: var(--border); transition: background .2s; }
.wizard-steps span.active { background: var(--accent); }
.wizard-panel { display: none; animation: fade-up .25s var(--ease); }
.wizard-panel.active { display: block; }
.skip-link { display: block; text-align: center; font-size: var(--fs-xs); color: var(--text-secondary); margin-top: 12px; text-decoration: underline; cursor: pointer; }
.skip-link:hover { color: var(--text); }

.plan-option {
  display: flex; align-items: flex-start; gap: 10px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; margin-bottom: 10px; cursor: pointer;
  transition: border-color .15s;
}
.plan-option:hover { border-color: var(--border-strong); }
.plan-option input { margin-top: 3px; }
.plan-option .name { font-size: var(--fs-base); }
.plan-option .meta { display: block; font-size: var(--fs-xs); color: var(--text-secondary); margin-top: 2px; }

/* ========================================================================
   App shell (dashboard+)
   ======================================================================== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

.sidebar .brand {
  font-size: var(--fs-md);
  margin: 4px 0 26px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  gap: 9px;
}

.sidebar .group-label { font-size: var(--fs-xs); font-weight: var(--weight-medium); text-transform: uppercase; letter-spacing: var(--tracking-label); color: var(--text-secondary); margin: 18px 12px 8px; }
.sidebar a.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--gray-800);
  text-decoration: none;
  font-size: var(--fs-sm);
  margin-bottom: 2px;
  position: relative;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.sidebar a.nav-item svg { flex-shrink: 0; opacity: .7; transition: opacity .15s; }
.sidebar a.nav-item:hover { background: var(--bg); }
.sidebar a.nav-item:hover svg { opacity: 1; }
.sidebar a.nav-item.active {
  background: var(--accent-light);
  color: var(--accent-dark);
  font-weight: var(--weight-medium);
}
.sidebar a.nav-item.active svg { opacity: 1; }
.sidebar a.nav-item.active::before {
  content: "";
  position: absolute; left: -14px; top: 50%; transform: translateY(-50%);
  width: 4px; height: 20px; border-radius: 0 4px 4px 0;
  background: var(--accent);
}

/* Dead-end nav entries — no route behind them yet. Muted, non-interactive,
   labeled instead of silently failing on click. */
.sidebar a.nav-item.coming-soon {
  color: var(--gray-500);
  cursor: default;
  pointer-events: none;
}
.sidebar a.nav-item.coming-soon svg { opacity: .4; }
.sidebar a.nav-item.coming-soon .label { display: flex; align-items: center; gap: 7px; }
.soon-pill {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--gray-500);
  background: var(--gray-100);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
  line-height: 1.4;
}

.main { flex: 1; min-width: 0; }

.topbar {
  height: 66px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.85);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
  backdrop-filter: blur(10px) saturate(1.4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.content { padding: 30px; max-width: 1360px; animation: fade-up .3s var(--ease); }

/* ---------- User menu (avatar + dropdown) ---------- */
.user-menu { position: relative; }
.user-menu-trigger {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; cursor: pointer; padding: 6px 10px 6px 6px;
  border-radius: 999px;
  transition: background .12s;
}
.user-menu-trigger:hover { background: var(--bg); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: var(--fs-xs); font-weight: var(--weight-medium); flex-shrink: 0;
  letter-spacing: .02em;
}
.user-menu-trigger .who { text-align: left; line-height: 1.25; }
.user-menu-trigger .who strong { display: block; font-size: var(--fs-sm); color: var(--text); font-weight: var(--weight-medium); }
.user-menu-trigger .who span { display: block; font-size: var(--fs-xs); color: var(--text-secondary); }
.user-menu-trigger .chev { color: var(--text-secondary); margin-left: 2px; transition: transform .15s; }
.user-menu.open .chev { transform: rotate(180deg); }

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 210px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 7px;
  opacity: 0;
  transform: translateY(-8px) scale(.98);
  pointer-events: none;
  transition: opacity .18s var(--ease), transform .18s var(--ease);
  z-index: 40;
}
.user-menu.open .user-menu-dropdown { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.user-menu-dropdown a, .user-menu-dropdown .dd-item {
  display: flex; align-items: center; gap: var(--gap-icon);
  padding: 10px 11px; border-radius: var(--radius-sm);
  font-size: var(--fs-sm); color: var(--text); text-decoration: none;
  cursor: pointer;
}
.user-menu-dropdown a:hover, .user-menu-dropdown .dd-item:hover { background: var(--bg); }
.user-menu-dropdown .dd-sep { height: 1px; background: var(--border); margin: 6px 4px; }
.user-menu-dropdown .dd-item.danger { color: var(--text-danger); }

.empty-state {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 52px 24px;
  text-align: center;
  color: var(--text-secondary);
  background: #fff;
}

/* ---------- Metric cards — value is the loudest element via size + full
   contrast color, never weight; label stays small/secondary above it ---------- */
.metric-cards { display: flex; gap: 18px; margin-bottom: var(--space-6); flex-wrap: wrap; }
.metric-card {
  flex: 1; min-width: 190px; background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--panel-padding); box-shadow: var(--shadow-sm);
  display: flex; align-items: flex-start; gap: 14px;
  transition: box-shadow .2s var(--ease), transform .2s var(--ease);
}
.metric-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.metric-card .icon {
  width: 40px; height: 40px; border-radius: var(--radius-sm); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.metric-card .label { font-size: var(--fs-xs); color: var(--text-secondary); margin-bottom: 6px; }
.metric-card .value { font-size: var(--fs-2xl); font-weight: var(--weight-bold); color: var(--text); letter-spacing: -.02em; }
.metric-card .icon.blue { background: #e6f0fb; color: #1a5ea8; }
.metric-card .icon.purple { background: #f1eafb; color: #6a3fa0; }
.metric-card .icon.red { background: #fdecea; color: var(--text-danger); }
.metric-card .icon.green { background: var(--accent-light); color: var(--accent-dark); }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: var(--space-6) 0 14px; }
.section-head h2 { font-size: var(--fs-md); font-weight: var(--weight-medium); margin: 0; }
.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: var(--space-6); }

/* ---------- Page chrome ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 10px; }
.page-head h1 { font-size: var(--fs-lg); margin: 0; letter-spacing: -.01em; }

.list-toolbar { display: flex; flex-direction: column; gap: var(--space-3); margin-bottom: var(--space-5); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters a, .filters button.chip {
  padding: 7px 14px; border-radius: 999px; border: 1.5px solid var(--border); background: #fff;
  font-size: var(--fs-xs); text-decoration: none; color: var(--text); cursor: pointer;
  transition: all .15s var(--ease);
}
.filters a:hover, .filters button.chip:hover { border-color: var(--border-strong); }
.filters a.active, .filters button.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: var(--weight-medium); }

.search-bar { max-width: 340px; }
.search-bar input {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: var(--fs-sm); background: #fff; transition: border-color .15s, box-shadow .15s;
}
.search-bar input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-light); }

/* ========================================================================
   Tables
   ======================================================================== */
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.data-table th { text-align: left; font-size: var(--fs-xs); font-weight: var(--weight-medium); text-transform: uppercase; letter-spacing: var(--tracking-label); color: var(--text-secondary); padding: 13px 16px; border-bottom: 1px solid var(--border); background: var(--gray-50); }
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gray-50); }
.data-table a.row-link { color: var(--text); text-decoration: none; display: block; }
.data-table a.row-link:hover { color: var(--accent); }
.data-table td.actions-col { width: 1%; white-space: nowrap; }

.row-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: none; color: var(--text-secondary);
  cursor: pointer; transition: background .12s, color .12s, border-color .12s, transform .1s;
}
.icon-btn:hover { background: var(--bg); color: var(--text); transform: translateY(-1px); }
.icon-btn.danger:hover { background: #fdecea; color: var(--text-danger); border-color: #f5c2be; }
.icon-btn.void:hover { background: var(--accent-2-light); color: var(--accent-2); border-color: #c7d7ea; }
.icon-btn[disabled] { opacity: .3; cursor: not-allowed; pointer-events: none; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; border-radius: 999px; font-size: var(--fs-xs); font-weight: var(--weight-medium); letter-spacing: var(--tracking-label); text-transform: uppercase; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge.draft { background: var(--gray-100); color: var(--gray-700); }
.badge.sent { background: #e6f0fb; color: #1a5ea8; }
.badge.accepted, .badge.paid, .badge.signed, .badge.connected, .badge.verified, .badge.approved { background: #e6f7ec; color: var(--text-success); }
.badge.expired, .badge.overdue, .badge.error { background: #fdecea; color: var(--text-danger); }
.badge.partial, .badge.pending, .badge.pending_verification, .badge.pending_price_approval, .badge.partially_converted { background: #fef3e0; color: #a3690a; }
.badge.converted { background: var(--gray-100); color: var(--gray-700); }
.badge.cancelled, .badge.rejected { background: #fdecea; color: var(--text-danger); }
.badge.planning { background: var(--gray-100); color: var(--gray-700); }
.badge.in_progress { background: #e6f0fb; color: #1a5ea8; }
.badge.delivered { background: #e6f7ec; color: var(--text-success); }
.badge.closed { background: var(--gray-100); color: var(--gray-700); }

.billing-stage-tag { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: var(--weight-medium); letter-spacing: var(--tracking-label); text-transform: uppercase; background: var(--accent-2-light); color: var(--accent-2); margin-left: 8px; }

.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.plan-card { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; background: #fff; display: flex; flex-direction: column; gap: 10px; }
.plan-card.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.plan-card h3 { margin: 0; font-size: var(--fs-md); font-weight: var(--weight-bold); }
.plan-card .plan-price { font-size: var(--fs-xl); font-weight: var(--weight-bold); }
.plan-card .plan-price small { font-size: var(--fs-xs); font-weight: var(--weight); color: var(--text-secondary); }
.plan-card ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-sm); color: var(--text-secondary); flex: 1; }
.plan-card ul li::before { content: "\2713"; margin-right: 7px; color: var(--text-success); }
.plan-card ul li.off { color: var(--gray-400); }
.plan-card ul li.off::before { content: "\2013"; color: var(--gray-400); }
.paypal-btn-slot { min-height: 35px; }

/* ========================================================================
   Card forms / panels — one padding scale, applied consistently; use
   .panel-compact for smaller inline notes instead of one-off inline styles.
   ======================================================================== */
.panel { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--panel-padding); margin-bottom: 22px; box-shadow: var(--shadow-sm); }
.panel h2 { font-size: var(--fs-md); font-weight: var(--weight-medium); margin: 0 0 18px; }
.panel.panel-compact { padding: 14px 22px; }
.panel.panel-note { color: var(--text-secondary); font-size: var(--fs-sm); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.field-inline { margin-bottom: 16px; }
.field-inline label { display: block; font-size: var(--fs-xs); margin-bottom: 7px; color: var(--text); }
.field-inline input, .field-inline select, .field-inline textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: var(--fs-sm);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
  background: #fff;
}
.field-inline input:focus, .field-inline select:focus, .field-inline textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-light);
}
.checkbox-row { display: flex; align-items: center; gap: 9px; font-size: var(--fs-sm); margin-bottom: 16px; }
.checkbox-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

.uen-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 280px;
  overflow-y: auto;
  z-index: 20;
  margin-top: 6px;
  animation: fade-up .15s var(--ease);
}
.uen-result-item { padding: 11px 14px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); transition: background .1s; }
.uen-result-item:last-child { border-bottom: none; }
.uen-result-item:hover { background: var(--accent-light); }
.uen-result-item .name { }
.uen-result-item .meta { font-size: var(--fs-xs); color: var(--text-secondary); margin-top: 2px; }
.uen-result-item .status-badge { font-size: 10px; padding: 1px 7px; border-radius: 999px; background: #fef3e0; color: #a3690a; margin-left: 6px; }
.uen-result-empty { padding: 14px; font-size: var(--fs-xs); color: var(--text-secondary); text-align: center; }

.uen-search-wrap { position: relative; }
.uen-search-spinner {
  position: absolute;
  right: 12px;
  top: 36px;
  width: 15px;
  height: 15px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: btn-spin .6s linear infinite;
  display: none;
}
.uen-search-spinner.show { display: block; }

.items-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.items-table th { text-align: left; font-size: var(--fs-xs); font-weight: var(--weight-medium); text-transform: uppercase; letter-spacing: var(--tracking-label); color: var(--text-secondary); padding: 8px; }
.items-table td { padding: 5px; }
.items-table input { width: 100%; padding: 8px 10px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: var(--fs-sm); transition: border-color .15s, box-shadow .15s; }
.items-table input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.items-table td.num-col { width: 96px; }
.items-table td.action-col { width: 34px; }
.remove-row {
  background: none; border: none; color: var(--text-danger); cursor: pointer; font-size: 17px; line-height: 1;
  width: 26px; height: 26px; border-radius: 6px; transition: background .12s;
}
.remove-row:hover { background: #fdecea; }

.btn-sm {
  display: inline-flex; align-items: center; gap: var(--gap-icon);
  padding: 8px 15px; border-radius: var(--radius-sm); font-size: var(--fs-sm); font-weight: var(--weight-bold);
  border: 1.5px solid var(--border); background: #fff; color: var(--text);
  cursor: pointer; text-decoration: none;
  transition: background .12s var(--ease), border-color .12s, box-shadow .15s var(--ease), transform .1s;
}
.btn-sm:hover { background: var(--bg); border-color: var(--border-strong); transform: translateY(-1px); }
.btn-sm:active { transform: translateY(0); }
.btn-sm.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-sm.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-sm.danger { color: var(--text-danger); border-color: #f5c2be; }
.btn-sm.danger:hover { background: #fdecea; border-color: #f0a9a2; }
.btn-sm.void { color: var(--accent-2); border-color: #c7d7ea; }
.btn-sm.void:hover { background: var(--accent-2-light); }
.btn-sm[disabled] { opacity: .45; cursor: not-allowed; pointer-events: none; transform: none; }

.prefix-input { width: 100px; padding: 6px 8px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: var(--fs-sm); }

.summary-line { display: flex; justify-content: space-between; padding: 7px 0; font-size: var(--fs-sm); }
/* Web summary total: emphasis via size + full-contrast color only — bold is
   reserved for the printed PDF total (see views/pdf/document.php). */
.summary-line.grand { font-size: var(--fs-lg); font-weight: var(--weight-bold); color: var(--text); border-top: 1.5px solid var(--border); margin-top: 8px; padding-top: 12px; }

.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.detail-header h1 { font-size: var(--fs-lg); letter-spacing: -.01em; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.upload-row { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.upload-preview {
  width: 68px; height: 68px; border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--gray-50);
}
.upload-preview img { max-width: 100%; max-height: 100%; }

/* ---------- Back link ---------- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--gap-icon);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  text-decoration: none;
  margin-bottom: 16px;
  transition: color .12s, transform .12s;
}
.back-link:hover { color: var(--accent); transform: translateX(-2px); }
.back-link svg { color: inherit; }

/* ========================================================================
   Toasts
   ======================================================================== */
.toast-container {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  min-width: 240px;
  max-width: 360px;
  padding: 13px 18px;
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  color: #fff;
  background: var(--gray-800);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateX(24px);
  transition: opacity .25s var(--ease), transform .25s var(--ease);
  border-left: 4px solid rgba(255,255,255,.35);
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast.ok { background: #1c6b34; border-left-color: #6fe39a; }
.toast.err { background: #9c2b23; border-left-color: #ff9b93; }

/* ========================================================================
   Confirm modal
   ======================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 16, 20, 0);
  -webkit-backdrop-filter: blur(0px);
  backdrop-filter: blur(0px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
  transition: background .22s var(--ease), backdrop-filter .22s var(--ease);
  padding: 20px;
}
.modal-overlay.show {
  background: rgba(12, 16, 20, .55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.modal-box {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 400px;
  transform: scale(.94) translateY(6px);
  opacity: 0;
  transition: transform .22s var(--ease), opacity .22s var(--ease);
  box-shadow: var(--shadow-pop);
}
.modal-overlay.show .modal-box { transform: scale(1) translateY(0); opacity: 1; }
.modal-title { font-size: var(--fs-md); font-weight: var(--weight-medium); margin: 0 0 9px; letter-spacing: -.005em; }
.modal-message { font-size: var(--fs-sm); color: var(--text-secondary); margin: 0 0 22px; line-height: 1.55; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-actions .btn-sm { padding: 9px 18px; font-size: var(--fs-sm); }
.modal-box.wide { max-width: 480px; }
.modal-close { position: absolute; top: 18px; right: 18px; background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: 4px; line-height: 0; }
.modal-close:hover { color: var(--text); }

/* ---------- Integration cards (Settings > Integrations) ---------- */
.integration-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.integration-row:last-child { border-bottom: none; }
.integration-info { display: flex; align-items: center; gap: 12px; }
.integration-icon { width: 40px; height: 40px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; background: var(--gray-50); flex-shrink: 0; }
.integration-row h3 { margin: 0; font-size: var(--fs-sm); font-weight: var(--weight-medium); }
.integration-row .sub-text { margin: 2px 0 0; }
.integration-actions { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider { position: absolute; inset: 0; background: var(--border-strong); transition: background .18s var(--ease); border-radius: 999px; cursor: pointer; }
.switch .slider::before { content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px; background: #fff; transition: transform .18s var(--ease); border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:disabled + .slider { opacity: .5; cursor: not-allowed; }

/* OAuth connect buttons inside the setup modal */
.oauth-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 11px 16px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: #fff; font-size: var(--fs-sm); font-weight: var(--weight-medium); cursor: pointer; transition: border-color .15s, background .15s; text-decoration: none; color: var(--text); margin-bottom: 10px; box-sizing: border-box; }
.oauth-btn:hover { border-color: var(--border-strong); background: var(--gray-50); }
.oauth-divider { display: flex; align-items: center; gap: 10px; margin: 18px 0 14px; color: var(--text-secondary); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: var(--tracking-label); }
.oauth-divider::before, .oauth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.manual-smtp-toggle { background: none; border: none; color: var(--accent); font-size: var(--fs-sm); font-weight: var(--weight-medium); cursor: pointer; padding: 4px 0; }

/* ---------- Signature pad ---------- */
.sig-tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1.5px solid var(--border); }
.sig-tab { padding: 9px 16px; font-size: var(--fs-xs); color: var(--text-secondary); cursor: pointer; border-bottom: 2px solid transparent; transition: color .15s; }
.sig-tab:hover { color: var(--text); }
.sig-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.sig-panel { display: none; }
.sig-panel.active { display: block; }
.sig-canvas-wrap canvas { border: 1.5px solid var(--border); border-radius: var(--radius); touch-action: none; cursor: crosshair; width: 100%; max-width: 400px; height: 150px; background: #fff; }
.sig-type-input {
  width: 100%; max-width: 400px; padding: 16px; border: 1.5px solid var(--border); border-radius: var(--radius);
  font-family: 'Dancing Script', cursive; font-size: var(--fs-2xl); background: #fff;
}
.sig-upload-drop {
  width: 100%; max-width: 400px; border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  padding: 22px; text-align: center; color: var(--text-secondary); font-size: var(--fs-sm);
}
.sig-preview { margin-top: 12px; max-width: 300px; max-height: 100px; }
.sig-preview img { max-width: 100%; max-height: 100px; border-radius: var(--radius-sm); }

/* ========================================================================
   Mobile
   ======================================================================== */
.menu-toggle {
  display: none;
  background: none; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  width: 38px; height: 38px; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text);
}
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(12,16,20,.5); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); z-index: 45;
}

/* Tablet: icon-only sidebar, no drawer needed yet */
@media (max-width: 900px) and (min-width: 641px) {
  .sidebar {
    width: 72px;
    padding: 16px 10px;
  }
  .sidebar .brand span.wordmark, .sidebar .group-label, .sidebar a.nav-item span.label { display: none; }
  .sidebar .brand { justify-content: center; padding: 10px 0; }
  .sidebar a.nav-item { justify-content: center; }
  .sidebar a.nav-item.active::before { left: -10px; }
  .content { padding: 20px; }
  .user-menu-trigger .who { display: none; }
}

/* Phone: sidebar becomes an off-canvas drawer, opened via hamburger */
@media (max-width: 640px) {
  .menu-toggle { display: flex; }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 264px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .25s var(--ease);
    box-shadow: var(--shadow-pop);
  }
  .app-shell.nav-open .sidebar { transform: translateX(0); }
  .app-shell.nav-open .sidebar-overlay { display: block; }

  .topbar { padding: 0 14px; gap: 10px; }
  .content { padding: 16px; }

  .user-menu-trigger .who { display: none; }
  .user-menu-dropdown { right: -6px; }
  #notifDropdown { width: calc(100vw - 28px); max-width: 320px; }

  .metric-cards { flex-direction: column; }
  .grid-2 { grid-template-columns: 1fr; }

  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr { border-bottom: 1px solid var(--border); padding: 12px 16px; }
  .data-table td { border-bottom: none; padding: 4px 0; }
  .data-table td[data-label]::before { content: attr(data-label) ": "; color: var(--text-secondary); }

  /* Editable line-item tables (quote/invoice/credit-note/recurring-invoice
     forms) have real <input> cells, so they can't reflow into stacked rows
     the way read-only .data-table does — scroll horizontally instead. */
  .items-table { display: block; overflow-x: auto; }
  .items-table thead, .items-table tbody { display: table; width: 100%; min-width: 480px; }

  .auth-split { flex-direction: column; }
  .auth-visual-pane {
    flex: 0 0 auto; max-width: none; max-height: 130px; padding: 22px 24px;
    justify-content: center;
  }
  .auth-visual-art, .auth-visual-cards, .auth-visual-foot { display: none; }
  .wordmark.hero { font-size: var(--fs-lg); }
  .auth-visual-tagline { font-size: var(--fs-sm); margin-top: 6px; }
  .auth-form-pane { padding: 30px 20px 42px; max-width: none; }
}

@media (min-width: 641px) and (max-width: 980px) {
  .auth-visual-pane { flex-basis: 46%; max-width: 46%; padding: 40px; }
  .wordmark.hero { font-size: var(--fs-2xl); }
}
