/* ====================================================
   AdSwift Billing — Enterprise SaaS Design System
   Inspired by Apple, Stripe, Linear, Vercel & Framer
==================================================== */

/* ===== Brand Design Tokens ===== */
:root {
  --navy: #0A192F;
  --navy-light: #112240;
  --navy-surface: #1d3557;
  --blue: #0066FF;
  --blue-hover: #0052cc;
  --blue-soft: #e6f0ff;
  --blue-glow: rgba(0, 102, 255, 0.18);
  --bg: #F5F7FA;
  --panel: #FFFFFF;
  --ink: #0F172A;
  --ink-secondary: #475569;
  --muted: #64748B;
  --line: #E2E8F0;
  --line-dark: rgba(255, 255, 255, 0.08);
  --danger: #EF4444;
  --success: #10B981;
  --warning: #F59E0B;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow-subtle: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-card: 0 4px 20px -2px rgba(10, 25, 47, 0.05), 0 2px 6px -1px rgba(10, 25, 47, 0.03);
  --shadow-hover: 0 12px 30px -5px rgba(10, 25, 47, 0.1), 0 4px 12px -2px rgba(10, 25, 47, 0.05);
  --font: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --display: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-w: 240px;
  --transition: 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }

/* ===== App Layout ===== */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ===== Sidebar (Deep Navy #0A192F) ===== */
.app-sidebar {
  background: var(--navy);
  color: #94A3B8;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--line-dark);
  z-index: 10;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 18px 18px;
  border-bottom: 1px solid var(--line-dark);
}

.sidebar-logo {
  width: 38px;
  height: 38px;
  object-fit: contain;
  background: #FFFFFF;
  border-radius: 10px;
  padding: 4px;
  flex-shrink: 0;
}

.sidebar-name {
  margin: 0;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: -0.01em;
}

.sidebar-sub {
  margin: 2px 0 0;
  font-size: 0.72rem;
  color: #64748B;
  font-weight: 500;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  color: #94A3B8;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  background: transparent;
  text-align: left;
  width: 100%;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
  transition: all var(--transition);
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #FFFFFF;
}

.nav-item:hover svg { opacity: 1; color: #FFFFFF; }

.nav-item.active {
  background: rgba(0, 102, 255, 0.12);
  color: #66A3FF;
  font-weight: 600;
  border-left: 3px solid var(--blue);
}

.nav-item.active svg { opacity: 1; color: var(--blue); }

.nav-item-action {
  background: var(--blue);
  color: #FFFFFF;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 102, 255, 0.3);
  margin-bottom: 12px;
}

.nav-item-action svg { color: #FFFFFF; opacity: 1; }

.nav-item-action:hover {
  background: var(--blue-hover);
  color: #FFFFFF;
  box-shadow: 0 6px 20px rgba(0, 102, 255, 0.4);
  transform: translateY(-1px);
}

.sidebar-footer {
  padding: 12px 12px 20px;
  border-top: 1px solid var(--line-dark);
}

.nav-logout { color: #F87171; }
.nav-logout:hover { background: rgba(239, 68, 68, 0.12); color: #FCA5A5; }

/* ===== Main Canvas ===== */
.app-main {
  padding: 36px 40px 56px;
  overflow: auto;
  background: var(--bg);
}

/* ===== Page Header ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.025em;
}

.page-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.page-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ===== Flash Messages ===== */
.flash {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 24px;
  font-weight: 500;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-subtle);
}

.flash-success {
  background: #F0FDF4;
  color: #15803D;
  border: 1px solid #BBF7D0;
}

.flash-error {
  background: #FEF2F2;
  color: #B91C1C;
  border: 1px solid #FECACA;
}

/* ===== Stat Cards (Linear/Stripe inspired) ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 20px;
  margin-bottom: 36px;
}

.stat-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
  transition: all var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: #CBD5E1;
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  border: 1px solid var(--line);
}

.stat-icon svg {
  width: 20px;
  height: 20px;
  color: var(--ink);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
  margin: 0 0 6px;
}

.stat-value {
  font-family: var(--display);
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--ink);
  margin: 0;
  letter-spacing: -0.02em;
}

/* ===== Table Card ===== */
.table-wrap {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--line);
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: #FFFFFF;
  gap: 12px;
  flex-wrap: wrap;
}

.table-header h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.table-filter {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all var(--transition);
}

.filter-btn:hover, .filter-btn.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #FFFFFF;
  box-shadow: 0 2px 8px rgba(0, 102, 255, 0.25);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  padding: 14px 20px;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  text-align: left;
  background: #F8FAFC;
  border-bottom: 1px solid var(--line);
}

.data-table td {
  padding: 16px 20px;
  font-size: 0.88rem;
  border-bottom: 1px solid #F1F5F9;
  vertical-align: middle;
  color: #1E293B;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr {
  transition: background var(--transition);
}

.data-table tbody tr:hover { background: #F8FAFC; }

.table-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ===== Status Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.badge-draft    { background: #F1F5F9; color: #475569; }
.badge-sent     { background: #FEF3C7; color: #B45309; }
.badge-paid     { background: #DCFCE7; color: #15803D; }
.badge-lead     { background: #E0F2FE; color: #0369A1; }
.badge-client   { background: #DCFCE7; color: #15803D; }
.badge-inactive { background: #F1F5F9; color: #475569; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:hover  { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--blue);
  color: #FFFFFF;
  box-shadow: 0 4px 14px rgba(0, 102, 255, 0.25);
}

.btn-primary:hover {
  background: var(--blue-hover);
  box-shadow: 0 6px 20px rgba(0, 102, 255, 0.35);
}

.btn-secondary {
  background: #FFFFFF;
  color: var(--ink);
  border-color: var(--line);
  box-shadow: var(--shadow-subtle);
}

.btn-secondary:hover {
  background: #F8FAFC;
  border-color: #CBD5E1;
}

.btn-danger {
  background: #FEF2F2;
  color: var(--danger);
  border-color: #FECACA;
}

.btn-danger:hover { background: var(--danger); color: #FFFFFF; }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
}

.btn-ghost-light {
  background: #E6F0FF;
  color: var(--blue);
  border-color: #B3D1FF;
}

.btn-ghost-light:hover { background: #CCE0FF; }

/* ===== Forms (Light) ===== */
.form-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--line);
  padding: 32px;
}

.form-grid {
  display: grid;
  gap: 18px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-secondary);
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #FFFFFF;
  color: var(--ink);
  font-size: 0.9rem;
  outline: none;
  transition: all var(--transition);
}

.form-control:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-glow);
}

.form-control textarea { resize: vertical; min-height: 84px; }
select.form-control { cursor: pointer; }

.form-section-title {
  font-family: var(--display);
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  letter-spacing: -0.01em;
}

/* ===== Bill Editor ===== */
.bill-editor {
  display: grid;
  grid-template-columns: minmax(360px, 440px) 1fr;
  gap: 0;
  min-height: calc(100vh - 56px);
  margin: -36px -40px -56px;
}

.bill-form-panel {
  background: var(--navy);
  color: #94A3B8;
  padding: 24px 20px 32px;
  overflow-y: auto;
  max-height: 100vh;
  border-right: 1px solid var(--line-dark);
}

.bill-preview-panel {
  padding: 28px 32px 48px;
  overflow: auto;
  background: var(--bg);
}

/* Dark form panels inside bill editor */
.bill-form-panel .panel {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line-dark);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.bill-form-panel .panel h2 {
  margin: 0 0 14px;
  font-family: var(--display);
  font-size: 0.92rem;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: -0.01em;
}

.bill-form-panel label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.78rem;
  color: #94A3B8;
  font-weight: 500;
}

.bill-form-panel label:last-child { margin-bottom: 0; }

.bill-form-panel input,
.bill-form-panel select,
.bill-form-panel textarea {
  width: 100%;
  border: 1px solid var(--line-dark);
  background: rgba(15, 23, 42, 0.6);
  color: #F8FAFC;
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  transition: all var(--transition);
}

.bill-form-panel input:focus,
.bill-form-panel select:focus,
.bill-form-panel textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.25);
}

.bill-form-panel textarea { resize: vertical; min-height: 68px; }
.bill-form-panel select option { background: var(--navy); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-head h2 { margin: 0; }

.row-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.row-three {
  display: grid;
  grid-template-columns: 0.7fr 1fr 1fr;
  gap: 10px;
}

.items-list {
  display: grid;
  gap: 12px;
}

.item-card {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--line-dark);
  border-radius: 12px;
  padding: 12px;
}

.item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.item-top span {
  font-size: 0.76rem;
  color: #94A3B8;
  font-weight: 600;
}

.btn-dark-ghost {
  background: transparent;
  color: #66A3FF;
  border: 1px dashed rgba(0, 102, 255, 0.4);
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 8px;
}

.btn-dark-ghost:hover { background: rgba(0, 102, 255, 0.1); color: #99C2FF; }

.btn-dark-danger {
  background: transparent;
  color: #F87171;
  border: none;
  padding: 4px 8px;
  font-size: 0.78rem;
  cursor: pointer;
  border-radius: 6px;
}

.btn-dark-danger:hover { background: rgba(239, 68, 68, 0.15); }

.bill-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  position: sticky;
  bottom: 0;
  padding-top: 12px;
  background: linear-gradient(180deg, transparent, var(--navy) 30%);
}

.bill-actions .btn-primary-dark {
  grid-column: 1 / -1;
  background: var(--blue);
  color: #FFFFFF;
  box-shadow: 0 4px 16px rgba(0, 102, 255, 0.4);
  padding: 12px 20px;
  font-weight: 700;
  font-size: 0.95rem;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.preview-toolbar p {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  color: var(--ink);
  font-size: 1.05rem;
}

.total-badge {
  background: var(--navy);
  color: #FFFFFF;
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.92rem;
  font-family: var(--display);
  box-shadow: 0 4px 12px rgba(10, 25, 47, 0.15);
}

/* ===== Login Screen ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--navy);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--navy-light);
  border: 1px solid var(--line-dark);
  border-radius: 20px;
  padding: 36px 32px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
  color: #FFFFFF;
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  background: #FFFFFF;
  border-radius: 14px;
  padding: 6px;
  margin-bottom: 16px;
}

.login-title {
  margin: 0;
  font-family: var(--display);
  font-size: 1.5rem;
  font-weight: 800;
  color: #FFFFFF;
  letter-spacing: -0.02em;
}

.login-sub {
  margin: 6px 0 0;
  font-size: 0.88rem;
  color: #94A3B8;
}

.login-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #FCA5A5;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 500;
  margin-bottom: 20px;
  text-align: center;
}

.login-form label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: #CBD5E1;
  margin-bottom: 16px;
}

.login-form input {
  width: 100%;
  margin-top: 8px;
  padding: 12px 14px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--line-dark);
  border-radius: 10px;
  color: #FFFFFF;
  font-size: 0.95rem;
  outline: none;
  transition: all var(--transition);
}

.login-form input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.25);
}

.login-btn {
  width: 100%;
  margin-top: 8px;
  padding: 13px;
  background: var(--blue);
  border: none;
  border-radius: 10px;
  color: #FFFFFF;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 102, 255, 0.35);
  transition: all var(--transition);
}

.login-btn:hover {
  background: var(--blue-hover);
  box-shadow: 0 6px 20px rgba(0, 102, 255, 0.5);
  transform: translateY(-1px);
}



/* ===== A4 Document — Exact Canva Match ===== */
.sheet-scroll {
  display: flex;
  justify-content: center;
  /* In preview context, constrain height and allow scroll so the A4 stays visible */
  overflow: auto;
}

.document {
  width: 210mm;
  min-height: 297mm;
  box-sizing: border-box;
  background: #fff;
  color: #1a2433;
  padding: 10mm 14mm 8mm;
  box-shadow: var(--shadow);
  position: relative;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  page-break-after: avoid;
  page-break-inside: avoid;
}

/* --- Header --- */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 0;
}

.doc-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.doc-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
}

.doc-brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  font-weight: 800;
  color: #111827;
  text-transform: uppercase;
}

.doc-tagline {
  margin: 3px 0 0;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  color: #6b7280;
  font-weight: 500;
  text-transform: uppercase;
}

.doc-title-block { text-align: right; }

.doc-title-block h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 2rem;
  color: #3d8bfd;
  letter-spacing: 0.08em;
  font-weight: 800;
  text-transform: uppercase;
}

.doc-website {
  display: none; /* shown below accent line via doc-website-row */
}

/* --- Accent line: blue left portion, grey right --- */
.accent-line {
  height: 3px;
  margin: 10px 0 0;
  background: linear-gradient(90deg, #3d8bfd 0 30%, #d1dce8 30% 100%);
  border-radius: 0;
}

/* Website row below accent line, right-aligned */
.doc-website-row {
  display: flex;
  justify-content: flex-end;
  margin: 6px 0 16px;
}

.doc-website-row span {
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  color: #374151;
  font-weight: 600;
  text-transform: uppercase;
}

/* Footer accent (same style) */
.accent-line.footer-line {
  margin: 20px 0 12px;
}

/* --- Meta (Invoice To + Invoice No) --- */
.doc-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 18px;
}

.doc-label {
  margin: 0 0 4px;
  color: #374151;
  font-size: 0.85rem;
  font-weight: 400;
}

.doc-client-name {
  margin: 2px 0 4px;
  font-size: 1.08rem;
  font-weight: 700;
  color: #111827;
}

.doc-muted {
  margin: 1px 0;
  color: #4b5563;
  font-size: 0.84rem;
  line-height: 1.5;
  white-space: pre-line;
}

.doc-invoice-meta {
  text-align: right;
  font-size: 0.88rem;
  color: #374151;
  min-width: 160px;
}

.doc-invoice-meta p { margin: 0 0 3px; }
.doc-invoice-meta strong { font-weight: 700; }

/* --- Items Table --- */
.items-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-bottom: 0;
}

.items-table th {
  background: #3d8bfd !important;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
  color: #fff !important;
  font-size: 0.8rem;
  letter-spacing: 0.07em;
  padding: 9px 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.items-table td {
  padding: 9px 10px;
  font-size: 0.88rem;
  border-bottom: 1px solid #e8f0fa;
  color: #1a2433;
}

.items-table tbody tr:nth-child(even) { background: #edf4ff; }
.items-table tbody tr:nth-child(odd)  { background: #fff; }

.col-no    { width: 9%;  text-align: center; }
.col-desc  { width: 43%; text-align: left; }
.col-qty   { width: 12%; text-align: center; }
.col-price { width: 18%; text-align: right; }
.col-total { width: 18%; text-align: right; }

/* --- Sub Total Row --- */
.totals-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 40px;
  padding: 12px 10px 0;
  font-size: 0.9rem;
  color: #374151;
}

.totals-row span { font-weight: 400; }
.totals-row strong { font-weight: 700; min-width: 70px; text-align: right; }

/* --- Payment Section (Canva exact) --- */
.pay-section {
  margin: 18px 0 0;
}

/* Two side-by-side blue label bars */
.pay-labels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 0;
}

.pay-label-box {
  background: #3d8bfd !important;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
  color: #fff !important;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  padding: 9px 12px;
  text-transform: uppercase;
}

.pay-label-box.grand {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
}

.pay-label-box.grand .grand-amt {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

/* Payment details as plain text below */
.pay-details {
  font-size: 0.86rem;
  color: #1a2433;
  margin-top: 10px;
  line-height: 1.7;
}

.pay-details p { margin: 0; }

/* Separator line (short, below pay details) */
.pay-separator {
  width: 220px;
  height: 1px;
  background: #d1dce8;
  margin: 14px 0 14px;
}

/* --- Flex spacer — pushes footer down naturally without overflow --- */
.doc-spacer {
  flex: 1;
  min-height: 8px;
  max-height: 60px;
}

/* --- Footer block (thanks + terms + signature) --- */
.footer-block {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-top: 0;
  padding-top: 4px;
}

.footer-left { flex: 1; }

.footer-thanks {
  margin: 0 0 14px;
  font-weight: 700;
  font-size: 0.92rem;
  color: #111827;
}

.footer-terms-label {
  margin: 0 0 5px;
  font-weight: 700;
  font-size: 0.85rem;
  color: #111827;
}

.footer-terms-text {
  margin: 0;
  max-width: 260px;
  color: #4b5563;
  font-size: 0.78rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

/* Signature block */
.sign-block {
  text-align: right;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.sign-stamp-img {
  width: 110px !important;
  max-width: 110px !important;
  height: auto !important;
  max-height: 90px !important;
  object-fit: contain !important;
  display: block !important;
  margin-bottom: 2px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.06));
}

.sign-name {
  margin: 0 0 4px;
  font-family: "Segoe Script", "Brush Script MT", "Dancing Script", cursive;
  font-size: 1.3rem;
  color: #1f2937;
  line-height: 1.2;
}

.sign-company {
  margin: 0;
  font-weight: 700;
  font-size: 0.88rem;
  color: #111827;
}

.sign-title {
  margin: 2px 0 0;
  font-weight: 700;
  font-size: 0.84rem;
  color: #111827;
}

.doc-contact {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 8px;
  align-items: start;
}

.contact-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 0.76rem;
  color: #374151;
  line-height: 1.45;
}

.contact-item p { margin: 0; }

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
  background: var(--blue);
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
}

.icon.phone {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M22 16.92v3a2 2 0 0 1-2.18 2 19.8 19.8 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.12 4.18 2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.96.36 1.9.7 2.81a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45c.91.34 1.85.57 2.81.7A2 2 0 0 1 22 16.92z'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M22 16.92v3a2 2 0 0 1-2.18 2 19.8 19.8 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.12 4.18 2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.96.36 1.9.7 2.81a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45c.91.34 1.85.57 2.81.7A2 2 0 0 1 22 16.92z'/%3E%3C/svg%3E");
}

.icon.mail {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M4 4h16v16H4z'/%3E%3Cpath d='m22 6-10 7L2 6'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M4 4h16v16H4z'/%3E%3Cpath d='m22 6-10 7L2 6'/%3E%3C/svg%3E");
}

.icon.pin {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M12 21s7-4.5 7-11a7 7 0 1 0-14 0c0 6.5 7 11 7 11z'/%3E%3Ccircle cx='12' cy='10' r='2.5'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M12 21s7-4.5 7-11a7 7 0 1 0-14 0c0 6.5 7 11 7 11z'/%3E%3Ccircle cx='12' cy='10' r='2.5'/%3E%3C/svg%3E");
}

/* ===== Autocomplete ===== */
.autocomplete-wrap {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #1a2d4a;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.autocomplete-item {
  padding: 10px 13px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: rgba(61,139,253,0.2); }

.autocomplete-name {
  font-size: 0.88rem;
  color: #e8f0fc;
  font-weight: 600;
}

.autocomplete-sub {
  font-size: 0.76rem;
  color: #7b9cc0;
  margin-top: 2px;
}

/* ===== Login Page ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(61,139,253,0.18) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(15,27,45,0.6) 0%, transparent 60%),
    linear-gradient(145deg, #0c1626 0%, #142033 100%);
}

.login-card {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 44px 40px;
  width: 100%;
  max-width: 420px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 32px 80px rgba(0,0,0,0.5);
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  background: #fff;
  border-radius: 16px;
  padding: 8px;
  margin-bottom: 14px;
}

.login-title {
  font-family: var(--display);
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  margin: 0 0 4px;
}

.login-sub {
  font-size: 0.85rem;
  color: #7b9cc0;
  margin: 0;
}

.login-form label {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 0.8rem;
  color: #9eb2cd;
  letter-spacing: 0.03em;
}

.login-form input {
  width: 100%;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(8,14,24,0.6);
  color: #f3f7ff;
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
  font-size: 0.95rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.login-form input:focus {
  border-color: rgba(61,139,253,0.7);
  box-shadow: 0 0 0 3px rgba(61,139,253,0.18);
}

.login-btn {
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, #3d8bfd, #245ec4);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 8px 24px rgba(36,94,196,0.4);
  margin-top: 4px;
}

.login-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px rgba(36,94,196,0.5);
}

.login-error {
  background: rgba(224,84,84,0.12);
  color: #ff9999;
  border: 1px solid rgba(224,84,84,0.25);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.88rem;
  margin-bottom: 16px;
  text-align: center;
}

/* ===== Client quick-info card in view page ===== */
.view-actions-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.proposal-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.proposal-box svg {
  width: 20px;
  height: 20px;
  color: var(--blue);
  flex-shrink: 0;
}

.proposal-box a { color: var(--blue); font-weight: 600; }
.proposal-box a:hover { text-decoration: underline; }

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  color: #c5d3e8;
  margin-bottom: 14px;
}

.empty-state h3 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: 1.1rem;
  color: var(--ink);
}

.empty-state p { margin: 0 0 20px; font-size: 0.88rem; }

/* ===== Confirm dialog ===== */
.confirm-card {
  max-width: 480px;
  margin: 60px auto;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 32px 36px;
  text-align: center;
}

.confirm-card .danger-icon {
  width: 56px;
  height: 56px;
  background: rgba(224,84,84,0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}

.confirm-card .danger-icon svg {
  width: 28px;
  height: 28px;
  color: var(--danger);
}

.confirm-card h2 {
  font-family: var(--display);
  font-size: 1.25rem;
  margin: 0 0 8px;
  color: var(--ink);
}

.confirm-card p {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 0.9rem;
}

.confirm-btns {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ===== Status select inline ===== */
select.status-select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .bill-editor {
    grid-template-columns: 1fr;
  }

  .bill-form-panel {
    max-height: none;
  }

  .bill-preview-panel {
    padding-top: 8px;
  }

  .document {
    width: min(100%, 210mm);
    transform-origin: top center;
  }
}

@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    position: fixed;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    z-index: 200;
  }

  .app-sidebar.open {
    transform: translateX(0);
  }

  .app-main {
    padding: 20px 16px 32px;
  }

  .form-row, .form-row-3 {
    grid-template-columns: 1fr;
  }
}

@page {
  size: A4 portrait;
  margin: 0;
}

/* ===== Print ===== */
@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  html, body {
    width: 210mm !important;
    height: 297mm !important;
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  /* Hide everything except the document */
  body > * { display: none !important; }

  /* Show only the sheet-scroll div containing the document */
  .app-layout {
    display: contents !important;
  }

  .app-sidebar,
  .view-actions-bar,
  .proposal-box,
  .page-header,
  .preview-toolbar {
    display: none !important;
  }

  .app-main {
    display: contents !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .sheet-scroll {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 210mm !important;
    height: 297mm !important;
    overflow: hidden !important;
  }

  .document {
    box-shadow: none !important;
    width: 210mm !important;
    min-height: 0 !important;
    height: 297mm !important;
    max-height: 297mm !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 10mm 14mm 8mm !important;
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
  }

  .doc-spacer {
    flex: 1 !important;
    max-height: none !important;
  }
}
