:root {
  --navy: #17233f;
  --navy-2: #21345e;
  --ink: #182033;
  --muted: #687189;
  --line: #dfe4ed;
  --line-dark: #b9c1ce;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --surface-3: #eef2f8;
  --accent: #2f62e9;
  --accent-hover: #2354d6;
  --accent-soft: #eaf0ff;
  --green: #138a61;
  --green-soft: #e8f7f1;
  --amber: #b45d00;
  --amber-soft: #fff2df;
  --red: #c33636;
  --red-soft: #ffeded;
  --shadow-sm: 0 4px 14px rgba(29, 43, 77, 0.07);
  --shadow-md: 0 16px 40px rgba(20, 32, 59, 0.12);
  --shadow-lg: 0 28px 80px rgba(13, 24, 49, 0.22);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --header-h: 74px;
  --page-ratio: 1.4142;
  --preview-scale: .82;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--surface-2); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 6% 2%, rgba(47, 98, 233, .09), transparent 28rem),
    linear-gradient(180deg, #f9fbff 0%, #f4f6fa 100%);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }
svg { width: 1.25em; height: 1.25em; fill: currentColor; flex: 0 0 auto; }
.hidden { display: none !important; }

.app-header {
  height: var(--header-h);
  padding: 0 clamp(18px, 4vw, 54px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,.9);
  border-bottom: 1px solid rgba(204, 212, 225, .8);
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(14px);
}
.brand-wrap { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 13px;
  display: grid; place-items: center;
  color: white; font-weight: 850; letter-spacing: -.04em;
  background: linear-gradient(145deg, var(--navy), #32559b);
  box-shadow: 0 9px 24px rgba(23,35,63,.23);
}
.brand-wrap h1 { margin: 0; font-size: 18px; line-height: 1.1; letter-spacing: -.02em; }
.brand-wrap p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.header-actions { display: flex; gap: 10px; align-items: center; }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px;
  font-size: 12px; font-weight: 700; background: var(--surface);
  color: var(--muted);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa3b5; box-shadow: 0 0 0 4px rgba(154,163,181,.15); }
.status-online { color: var(--green); border-color: #bfe5d7; background: var(--green-soft); }
.status-online .status-dot { background: var(--green); box-shadow: 0 0 0 4px rgba(19,138,97,.14); }
.status-local { color: var(--amber); border-color: #f0d6b0; background: var(--amber-soft); }
.status-local .status-dot { background: var(--amber); box-shadow: 0 0 0 4px rgba(180,93,0,.13); }
.status-error { color: var(--red); border-color: #f0c4c4; background: var(--red-soft); }
.status-error .status-dot { background: var(--red); }

.view { width: min(1480px, 100%); margin: 0 auto; }
.dashboard-view { padding: clamp(20px, 4vw, 46px) clamp(16px, 4vw, 54px) 64px; }
.hero-card {
  min-height: 340px;
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr);
  align-items: center;
  padding: clamp(30px, 5vw, 68px);
  border-radius: 30px;
  color: white;
  background:
    radial-gradient(circle at 80% 20%, rgba(113,150,255,.34), transparent 28%),
    linear-gradient(135deg, #111c35 0%, #1d315d 52%, #3158a8 100%);
  box-shadow: 0 26px 70px rgba(21,40,82,.25);
}
.hero-card::before {
  content: ""; position: absolute; width: 340px; height: 340px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.12); right: -80px; top: -150px;
  box-shadow: 0 0 0 44px rgba(255,255,255,.025), 0 0 0 88px rgba(255,255,255,.018);
}
.hero-copy { position: relative; z-index: 1; max-width: 720px; }
.eyebrow { display: inline-block; text-transform: uppercase; letter-spacing: .11em; font-size: 11px; font-weight: 850; color: #7d8cad; }
.hero-card .eyebrow { color: #c1d0ff; }
.hero-card h2 { margin: 12px 0 14px; font-size: clamp(34px, 5vw, 57px); line-height: 1.02; letter-spacing: -.045em; max-width: 650px; }
.hero-card p { margin: 0; max-width: 670px; font-size: clamp(15px, 1.5vw, 18px); line-height: 1.65; color: rgba(255,255,255,.78); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 30px; }

.hero-sheet { position: relative; z-index: 1; display: grid; place-items: center; perspective: 1000px; }
.mini-sheet {
  width: 250px; aspect-ratio: 1 / 1.414;
  background: white; border-radius: 5px; padding: 24px 19px; color: #1d263a;
  transform: rotate(5deg) rotateY(-8deg);
  box-shadow: 0 38px 70px rgba(4,11,27,.36);
}
.mini-heading { height: 9px; width: 62%; margin: 0 auto 8px; background: #27334e; border-radius: 5px; }
.mini-subheading { height: 4px; width: 82%; margin: 0 auto 24px; background: #c4cad5; border-radius: 3px; }
.mini-grid { display: grid; grid-template-columns: 1.3fr .8fr .8fr .8fr; border: 1px solid #687189; }
.mini-grid span { height: 24px; border-right: 1px solid #aab1be; border-bottom: 1px solid #aab1be; }
.mini-grid span:nth-child(4n) { border-right: 0; }
.mini-grid span:nth-last-child(-n+4) { border-bottom: 0; }
.mini-total { margin: 18px 0 0 auto; width: 42%; height: 34px; border: 1px solid #687189; }

.btn {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 10px 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 800; font-size: 13px;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease, border-color .16s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-large { min-height: 50px; padding: 12px 20px; font-size: 14px; border-radius: 13px; }
.btn-primary { background: var(--accent); color: white; box-shadow: 0 8px 20px rgba(47,98,233,.24); }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 11px 26px rgba(47,98,233,.3); }
.hero-card .btn-primary { background: white; color: var(--navy); box-shadow: 0 12px 28px rgba(0,0,0,.19); }
.hero-card .btn-primary:hover { background: #f3f6ff; }
.btn-secondary { background: white; color: var(--ink); border-color: var(--line); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { border-color: #c4cbd8; background: #fbfcff; }
.hero-card .btn-secondary { color: white; border-color: rgba(255,255,255,.25); background: rgba(255,255,255,.09); box-shadow: none; }
.hero-card .btn-secondary:hover { background: rgba(255,255,255,.15); }
.btn-danger { background: var(--red); color: white; }
.btn-danger-outline { background: white; color: var(--red); border-color: #efbcbc; }
.btn-block { width: 100%; }
.icon-btn {
  width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 11px;
  display: inline-grid; place-items: center; background: white; color: var(--ink);
  transition: background .16s, border-color .16s, transform .16s;
}
.icon-btn:hover { background: var(--surface-2); border-color: #c2cad8; transform: translateY(-1px); }
.icon-btn.small { width: 32px; height: 32px; border-radius: 8px; font-size: 17px; font-weight: 800; }
.text-btn { border: 0; background: transparent; color: var(--accent); font-weight: 800; font-size: 13px; padding: 4px 0; }
.text-btn.danger { color: var(--red); }

.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 22px 0 38px; }
.stat-card {
  min-height: 100px; padding: 20px 22px;
  display: flex; align-items: center; gap: 16px;
  background: rgba(255,255,255,.86); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.stat-icon { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; color: var(--accent); background: var(--accent-soft); }
.stat-card span { display: block; font-size: 23px; font-weight: 850; letter-spacing: -.03em; }
.stat-card p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }

.files-section { background: rgba(255,255,255,.72); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: clamp(20px, 3vw, 34px); box-shadow: var(--shadow-sm); }
.section-heading { display: flex; justify-content: space-between; gap: 18px; align-items: end; margin-bottom: 22px; }
.section-heading h2 { margin: 5px 0 0; font-size: 27px; letter-spacing: -.03em; }
.list-tools { display: flex; align-items: center; gap: 10px; }
.search-box {
  min-width: min(320px, 42vw); height: 42px; padding: 0 12px;
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 11px; background: white; color: #8b94a7;
}
.search-box input { width: 100%; border: 0; outline: none; color: var(--ink); background: transparent; font-size: 13px; }
.empty-state { padding: 46px 16px 38px; text-align: center; }
.empty-illustration { width: 116px; height: 116px; margin: 0 auto 16px; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: #7795e8; }
.empty-illustration svg { width: 76px; height: 76px; }
.empty-illustration svg path:first-child { fill: white; stroke: currentColor; stroke-width: 2; }
.empty-illustration svg path:not(:first-child) { fill: none; stroke: currentColor; stroke-width: 2; }
.empty-state h3 { margin: 0; font-size: 20px; }
.empty-state p { color: var(--muted); margin: 8px 0 18px; }
.loading-state { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 56px; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 3px solid #dce3f1; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.files-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.file-card {
  position: relative; overflow: hidden; padding: 18px;
  border: 1px solid var(--line); border-radius: 15px; background: white;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.file-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: #c6cfdf; }
.file-card-top { display: flex; gap: 12px; align-items: flex-start; }
.file-icon { width: 42px; height: 48px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.file-card-copy { min-width: 0; flex: 1; }
.file-card h3 { margin: 0; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .file-customer { margin: 5px 0 0; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.file-card-amount { font-size: 15px; color: var(--ink); font-weight: 850; }
.file-card-actions { display: flex; gap: 8px; margin-top: 14px; }
.file-card-actions .btn { flex: 1; min-height: 36px; padding: 8px 11px; }
.file-card-actions .icon-btn { width: 36px; height: 36px; }

/* Editor */
.editor-view { width: 100%; max-width: none; }
.editor-toolbar {
  min-height: 76px; padding: 13px clamp(14px, 3vw, 36px);
  position: sticky; top: var(--header-h); z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  border-bottom: 1px solid var(--line); background: rgba(255,255,255,.95); backdrop-filter: blur(14px);
}
.editor-toolbar-left, .editor-toolbar-actions { display: flex; align-items: center; gap: 10px; }
.editor-toolbar-left h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.editor-toolbar-left p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.editor-title-row { display: flex; gap: 9px; align-items: center; }
.save-state { font-size: 10px; padding: 4px 7px; border-radius: 999px; color: var(--amber); background: var(--amber-soft); font-weight: 800; }
.save-state.saved { color: var(--green); background: var(--green-soft); }
.save-state.saving { color: var(--accent); background: var(--accent-soft); }
.editor-layout { min-height: calc(100vh - var(--header-h) - 76px); display: grid; grid-template-columns: minmax(430px, 560px) minmax(0, 1fr); }
.form-panel { border-right: 1px solid var(--line); background: #f8faff; padding: 22px; overflow: auto; }
.editor-intro { padding: 20px; margin-bottom: 14px; border-radius: 16px; color: white; background: linear-gradient(135deg, var(--navy), #2e4e8d); box-shadow: var(--shadow-md); }
.format-badge { display: inline-block; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 850; color: #d8e2ff; background: rgba(255,255,255,.12); }
.editor-intro h3 { margin: 13px 0 5px; font-size: 19px; }
.editor-intro p { margin: 0; font-size: 12px; color: rgba(255,255,255,.7); line-height: 1.5; }
.form-section { margin-bottom: 12px; border: 1px solid var(--line); border-radius: 15px; background: white; overflow: hidden; box-shadow: 0 3px 12px rgba(31,43,70,.04); }
.form-section summary { min-height: 54px; padding: 13px 16px; list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 850; }
.form-section summary::-webkit-details-marker { display: none; }
.form-section summary > span:first-child { flex: 1; display: flex; align-items: center; gap: 10px; }
.form-section summary > svg { transition: transform .2s; color: var(--muted); }
.form-section[open] summary > svg { transform: rotate(180deg); }
.form-section[open] summary { border-bottom: 1px solid var(--line); }
.section-number { width: 24px; height: 24px; border-radius: 8px; display: inline-grid; place-items: center; color: var(--accent); background: var(--accent-soft); font-size: 11px; }
.count-badge { min-width: 25px; height: 23px; padding: 0 7px; display: grid; place-items: center; border-radius: 999px; background: var(--surface-3); color: var(--muted); font-size: 10px; }
.form-section-body { padding: 16px; display: grid; gap: 13px; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.three-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.full { grid-column: 1 / -1; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > span { font-size: 10px; color: #5e687e; font-weight: 800; text-transform: uppercase; letter-spacing: .045em; }
.field input, .field textarea, .field select, .canvas-toolbar select {
  width: 100%; border: 1px solid #d8deea; border-radius: 9px; background: #fff;
  color: var(--ink); outline: none; padding: 10px 11px; font-size: 13px;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 70px; line-height: 1.45; }
.field input:focus, .field textarea:focus, .field select:focus, .canvas-toolbar select:focus { border-color: #7fa0f5; box-shadow: 0 0 0 3px rgba(47,98,233,.1); }
.field input::placeholder, .field textarea::placeholder { color: #a8afbd; }
.rows-editor { display: grid; gap: 12px; }
.rows-editor:empty::before { content: "No trip rows. Add a row to begin."; display: block; padding: 22px 14px; border: 1px dashed #cbd3e1; border-radius: 11px; text-align: center; color: var(--muted); font-size: 12px; background: #fafcff; }
.trip-row-card { border: 1px solid #dce2ec; border-radius: 12px; background: #fafbfe; overflow: hidden; }
.trip-row-header { min-height: 42px; padding: 8px 11px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #e4e8f0; }
.trip-row-header strong { font-size: 12px; }
.row-actions { display: flex; gap: 5px; }
.row-move-btn, .row-delete-btn { width: 29px; height: 29px; display: grid; place-items: center; border-radius: 7px; border: 1px solid #d8deea; background: white; color: var(--muted); font-size: 12px; }
.row-delete-btn { color: var(--red); }
.trip-row-fields { padding: 11px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.signature-use-card { padding: 11px; display: flex; gap: 12px; align-items: center; border-radius: 11px; border: 1px solid var(--line); background: #fafbfe; }
.signature-thumb { width: 118px; height: 62px; display: grid; place-items: center; overflow: hidden; border: 1px dashed #cbd3df; border-radius: 8px; background: white; color: var(--muted); font-size: 10px; text-align: center; }
.signature-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.toggle-row { display: flex; align-items: center; gap: 8px; font-weight: 750; font-size: 12px; }
.toggle-row input { width: 17px; height: 17px; accent-color: var(--accent); }

.live-preview-panel { min-width: 0; background: #e8edf5; display: flex; flex-direction: column; }
.preview-panel-header { min-height: 68px; padding: 13px 22px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #d5dce8; background: rgba(239,243,249,.92); }
.preview-panel-header h3 { margin: 4px 0 0; font-size: 16px; }
.preview-zoom-controls { display: flex; align-items: center; gap: 8px; }
.preview-zoom-controls span { min-width: 42px; text-align: center; font-size: 11px; font-weight: 800; color: var(--muted); }
.inline-preview-viewport { min-height: 0; flex: 1; overflow: auto; padding: 34px; display: grid; justify-content: center; align-content: start; }
.invoice-page-wrap { transform-origin: top center; transform: scale(var(--preview-scale)); margin-bottom: calc((var(--preview-scale) - 1) * 100%); }

/* Shared invoice / print preview */
.invoice-sheet {
  width: 210mm;
  min-height: 297mm;
  padding: 8mm;
  background: white;
  color: #101010;
  box-shadow: 0 18px 45px rgba(20,30,48,.22);
  font-family: "Times New Roman", Times, serif;
  font-size: 10pt;
  line-height: 1.15;
}
.invoice-sheet.size-A5 { width: 148mm; min-height: 210mm; font-size: 7.5pt; }
.invoice-sheet.size-Letter { width: 216mm; min-height: 279mm; }
.invoice-sheet.size-Legal { width: 216mm; min-height: 356mm; }
.invoice-sheet.landscape.size-A4 { width: 297mm; min-height: 210mm; }
.invoice-sheet.landscape.size-A5 { width: 210mm; min-height: 148mm; }
.invoice-sheet.landscape.size-Letter { width: 279mm; min-height: 216mm; }
.invoice-sheet.landscape.size-Legal { width: 356mm; min-height: 216mm; }
.invoice-border { min-height: calc(100% - 0px); border: 2px solid #111; display: flex; flex-direction: column; }
.invoice-head { text-align: center; padding: 4mm 5mm 2.5mm; }
.invoice-business-name { margin: 0 0 1.5mm; font-family: Arial, sans-serif; font-size: 17pt; font-weight: 800; letter-spacing: .01em; }
.invoice-contact-line { margin: .6mm 0; font-size: 9pt; }
.invoice-title { margin: 3.8mm 0 1mm; font-size: 14pt; text-decoration: underline; font-weight: 800; }
.invoice-customer { margin: 0 0 1mm; font-size: 13pt; font-weight: 800; text-transform: uppercase; }
.invoice-customer-gstin { text-align: right; font-size: 9pt; font-weight: 700; padding-right: 1mm; }
.invoice-meta { min-height: 9mm; display: grid; grid-template-columns: 1fr 1fr; border-top: 1.5px solid #111; border-bottom: 1.5px solid #111; }
.invoice-meta > div { display: flex; align-items: center; gap: 2mm; padding: 1.8mm 3mm; }
.invoice-meta > div:last-child { justify-content: flex-end; }
.invoice-table-wrap { overflow: hidden; }
.invoice-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 7.7pt; }
.invoice-table th, .invoice-table td { border-right: 1px solid #222; border-bottom: 1px solid #222; padding: 1.1mm .8mm; text-align: center; vertical-align: middle; word-break: break-word; }
.invoice-table th:last-child, .invoice-table td:last-child { border-right: 0; }
.invoice-table th { font-family: Arial, sans-serif; font-size: 7pt; white-space: nowrap; font-weight: 750; background: #f3f3f3; }
.invoice-table td.name-cell, .invoice-table th.name-cell { text-align: left; }
.invoice-table td.amount-cell { text-align: right; padding-right: 1.5mm; }
.invoice-table .blank-row td { height: 7mm; }
.invoice-table col.sr { width: 4%; } .invoice-table col.name { width: 20%; }
.invoice-table col.km { width: 8%; } .invoice-table col.total-km { width: 6%; }
.invoice-table col.extra-km { width: 8%; } .invoice-table col.time { width: 8%; }
.invoice-table col.total-time { width: 6%; } .invoice-table col.extra-time { width: 9%; }
.invoice-table col.parking { width: 8%; } .invoice-table col.amount { width: 11%; }
.invoice-lower { display: grid; grid-template-columns: 1fr 33mm; min-height: 58mm; border-bottom: 1px solid #111; }
.invoice-lower-left { padding: 5mm 3mm 2mm; position: relative; }
.duty-slip-line { display: grid; grid-template-columns: 48mm 1fr; max-width: 110mm; gap: 2mm; margin-bottom: 6mm; }
.duty-slip-value { border-bottom: 1px solid #111; min-height: 4mm; }
.amount-words { margin-top: 2mm; min-height: 14mm; }
.signature-block { position: absolute; right: 8mm; bottom: 5mm; width: 60mm; text-align: center; }
.signature-heading { font-weight: 700; }
.signature-image-wrap { height: 23mm; margin: 1mm auto; display: grid; place-items: end center; }
.signature-image-wrap img { max-width: 52mm; max-height: 22mm; object-fit: contain; }
.signature-designation { font-weight: 700; }
.invoice-totals { align-self: start; border-left: 1px solid #111; }
.total-row { min-height: 8mm; display: grid; grid-template-columns: 1fr; border-bottom: 1px solid #111; }
.total-row.split { grid-template-columns: 1fr 1fr; }
.total-row .total-label { padding: 1.5mm 2mm; text-align: right; font-weight: 700; }
.total-row .total-value { padding: 1.5mm 2mm; text-align: right; font-family: Arial, sans-serif; font-size: 10pt; font-weight: 700; border-left: 1px solid #111; }
.total-row.spacer { min-height: 8mm; }
.total-row.grand .total-label, .total-row.balance .total-label { font-size: 9pt; }
.total-row.balance .total-value { font-size: 11pt; }
.invoice-footer { margin-top: auto; }
.footer-id-row { display: grid; grid-template-columns: 1.5fr 1fr 1fr; border-bottom: 1px solid #111; font-weight: 700; }
.footer-id-row > div { padding: 1.2mm 2mm; }
.footer-terms { padding: 1.6mm 2.5mm 2.2mm; font-size: 7.5pt; }
.footer-terms p { margin: .8mm 0; }
.invoice-sheet.size-A5 .invoice-business-name { font-size: 12pt; }
.invoice-sheet.size-A5 .invoice-title { font-size: 10pt; }
.invoice-sheet.size-A5 .invoice-customer { font-size: 9pt; }
.invoice-sheet.size-A5 .invoice-table { font-size: 5.3pt; }
.invoice-sheet.size-A5 .invoice-table th { font-size: 4.8pt; }
.invoice-sheet.size-A5 .invoice-lower { grid-template-columns: 1fr 25mm; min-height: 40mm; }
.invoice-sheet.size-A5 .signature-block { width: 43mm; }
.invoice-sheet.size-A5 .signature-image-wrap { height: 15mm; }

/* Dialogs */
dialog { border: 0; padding: 0; color: var(--ink); }
dialog::backdrop { background: rgba(12,21,40,.58); backdrop-filter: blur(5px); }
.app-dialog { width: min(920px, calc(100vw - 28px)); max-height: calc(100vh - 28px); border-radius: 22px; background: white; box-shadow: var(--shadow-lg); overflow: hidden; }
.dialog-header { min-height: 91px; padding: 22px 24px; display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 4px 0 4px; font-size: 24px; letter-spacing: -.03em; }
.dialog-header p { margin: 0; color: var(--muted); font-size: 12px; }
.dialog-close { flex: 0 0 auto; }
.format-dialog { width: min(780px, calc(100vw - 28px)); }
.format-grid { padding: 22px; }
.format-card { width: 100%; padding: 15px; display: grid; grid-template-columns: 135px 1fr auto; align-items: center; gap: 18px; border: 1px solid var(--line); border-radius: 17px; background: #fff; text-align: left; color: inherit; transition: border-color .18s, box-shadow .18s, transform .18s; }
.format-card:hover { border-color: #94aceb; box-shadow: var(--shadow-md); transform: translateY(-2px); }
.format-thumb { height: 155px; border-radius: 12px; background: #e9edf5; display: grid; place-items: center; overflow: hidden; }
.format-paper { width: 92px; height: 130px; padding: 10px 7px; background: white; box-shadow: 0 8px 20px rgba(25,36,60,.17); display: flex; flex-direction: column; align-items: center; }
.format-paper b { font-family: serif; font-size: 7px; margin-bottom: 4px; }
.format-paper > span { width: 75%; height: 2px; background: #c1c6d0; margin: 1px; }
.format-paper em { margin: 8px 0 5px; font-size: 6px; font-weight: 800; font-style: normal; text-decoration: underline; }
.format-mini-table { width: 100%; height: 42px; border: 1px solid #666; background: repeating-linear-gradient(to bottom, transparent 0 7px, #bbb 7px 8px), repeating-linear-gradient(to right, transparent 0 13px, #bbb 13px 14px); }
.format-mini-total { width: 42%; height: 14px; margin: 5px 0 0 auto; border: 1px solid #777; }
.format-card-copy h3 { margin: 0; font-size: 17px; }
.format-card-copy > div { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.format-card-copy p { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.recommended-badge { padding: 4px 7px; border-radius: 999px; color: var(--green); background: var(--green-soft); font-size: 9px; font-weight: 850; text-transform: uppercase; letter-spacing: .06em; }
.format-arrow { color: var(--muted); }

.signature-dialog { width: min(760px, calc(100vw - 28px)); }
.signature-tabs, .preview-tabs { display: flex; padding: 0 22px; border-bottom: 1px solid var(--line); background: #fafbfe; }
.signature-tab, .preview-tab { min-height: 51px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: 13px; font-weight: 800; padding: 0 15px; display: inline-flex; align-items: center; gap: 7px; }
.signature-tab.active, .preview-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.signature-panel { padding: 22px; min-height: 320px; }
.signature-drop-zone { height: 170px; border: 2px dashed #cdd5e3; border-radius: 15px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; color: var(--muted); background: #fafcff; cursor: pointer; transition: border-color .15s, background .15s; }
.signature-drop-zone:hover, .signature-drop-zone.dragover { border-color: #7fa0f5; background: #f3f7ff; }
.signature-drop-zone svg { width: 34px; height: 34px; color: var(--accent); }
.signature-drop-zone strong { color: var(--ink); }
.signature-drop-zone span { font-size: 11px; }
.large-signature-preview { margin-top: 15px; min-height: 100px; border: 1px solid var(--line); border-radius: 12px; display: grid; place-items: center; background: white; color: var(--muted); font-size: 12px; overflow: hidden; }
.large-signature-preview img { max-width: 90%; max-height: 130px; object-fit: contain; }
.canvas-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 9px; font-size: 12px; color: var(--muted); }
.canvas-toolbar label { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.canvas-toolbar select { width: auto; padding: 7px 9px; }
.signature-canvas-wrap { border: 1px solid #cbd3e0; border-radius: 12px; overflow: hidden; background: repeating-linear-gradient(0deg, #fff, #fff 27px, #f0f2f6 28px); touch-action: none; }
.signature-canvas-wrap canvas { display: block; width: 100%; height: 245px; cursor: crosshair; touch-action: none; }
.dialog-footer { min-height: 72px; padding: 13px 22px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); background: #fafbfe; }
.dialog-footer-actions { display: flex; gap: 9px; align-items: center; }
.current-signature-summary { font-size: 11px; color: var(--muted); }

.preview-dialog { width: min(1260px, calc(100vw - 24px)); height: min(900px, calc(100vh - 24px)); max-height: calc(100vh - 24px); }
.preview-dialog-header { min-height: 78px; }
.preview-header-actions { display: flex; align-items: center; gap: 9px; }
.preview-dialog-body { height: calc(100% - 130px); overflow: hidden; background: #e8edf5; }
.full-preview-panel { height: 100%; overflow: auto; padding: 28px; }
.print-preview-panel { display: grid; justify-content: center; align-content: start; }
.print-preview-panel .invoice-sheet { box-shadow: 0 16px 50px rgba(17,28,50,.2); }
.excel-preview-panel { background: #f0f3f8; }
.excel-shell { min-width: 1120px; background: white; border: 1px solid #bdc5d2; box-shadow: var(--shadow-md); }
.excel-formula-bar { height: 34px; display: flex; border-bottom: 1px solid #c5ccd7; background: #f7f8fa; font: 12px Arial, sans-serif; }
.excel-name-box { width: 75px; padding: 8px; border-right: 1px solid #c5ccd7; text-align: center; }
.excel-fx { width: 38px; display: grid; place-items: center; font-style: italic; color: #5c6574; }
.excel-formula-value { padding: 8px; flex: 1; color: #5c6574; }
.excel-grid { border-collapse: collapse; width: 100%; table-layout: fixed; font: 11px Arial, sans-serif; }
.excel-grid th, .excel-grid td { border: 1px solid #cbd1db; min-width: 74px; height: 26px; padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.excel-grid thead th { background: #edf0f4; color: #586170; text-align: center; font-weight: 500; }
.excel-grid .row-number { width: 42px; min-width: 42px; background: #edf0f4; color: #586170; text-align: center; font-weight: 500; }
.excel-grid .merged-title { font-size: 18px; font-weight: 700; text-align: center; height: 34px; }
.excel-grid .merged-center { text-align: center; font-weight: 700; }
.excel-grid .sheet-label { font-weight: 700; }
.excel-grid .sheet-table-head { font-weight: 700; text-align: center; background: #f5f5f5; white-space: normal; }
.excel-grid .number-cell { text-align: right; }
.excel-grid .thick-top { border-top: 2px solid #222; }
.excel-grid .thick-bottom { border-bottom: 2px solid #222; }
.excel-grid .thick-left { border-left: 2px solid #222; }
.excel-grid .thick-right { border-right: 2px solid #222; }
.excel-sheet-tabs { height: 35px; display: flex; align-items: end; padding-left: 44px; border-top: 1px solid #c5ccd7; background: #f2f4f7; }
.excel-sheet-tab { min-width: 100px; height: 31px; padding: 8px 16px; background: white; border: 1px solid #bfc7d3; border-bottom: 2px solid #2b8f5b; text-align: center; font: 11px Arial, sans-serif; }

.confirm-dialog { width: min(420px, calc(100vw - 28px)); padding: 28px; text-align: center; }
.confirm-icon { width: 62px; height: 62px; margin: 0 auto 16px; display: grid; place-items: center; border-radius: 50%; color: var(--red); background: var(--red-soft); }
.confirm-icon svg { width: 28px; height: 28px; }
.confirm-dialog h2 { margin: 0; font-size: 22px; }
.confirm-dialog p { margin: 9px 0 22px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.centered { justify-content: center; }

.toast-region { position: fixed; z-index: 1000; top: 90px; right: 18px; display: grid; gap: 10px; pointer-events: none; }
.toast { min-width: 270px; max-width: 390px; padding: 13px 15px; display: flex; align-items: flex-start; gap: 10px; border-radius: 12px; border: 1px solid var(--line); background: white; box-shadow: var(--shadow-md); animation: toastIn .24s ease both; pointer-events: auto; }
.toast.success { border-color: #bfe4d6; } .toast.error { border-color: #efc0c0; } .toast.info { border-color: #c8d5f4; }
.toast-icon { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: white; font-size: 12px; font-weight: 900; background: var(--accent); }
.toast.success .toast-icon { background: var(--green); } .toast.error .toast-icon { background: var(--red); }
.toast-copy strong { display: block; font-size: 12px; }
.toast-copy p { margin: 3px 0 0; font-size: 11px; color: var(--muted); line-height: 1.4; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px) translateX(10px); } }

@media (max-width: 1100px) {
  .hero-card { grid-template-columns: 1fr 280px; }
  .editor-layout { grid-template-columns: 470px minmax(0,1fr); }
  .editor-toolbar-actions .btn { padding-inline: 11px; }
}
@media (max-width: 900px) {
  :root { --header-h: 64px; }
  .app-header { padding: 0 16px; }
  .brand-mark { width: 38px; height: 38px; }
  .status-pill { display: none; }
  .hero-card { grid-template-columns: 1fr; min-height: auto; }
  .hero-sheet { display: none; }
  .stats-row { grid-template-columns: 1fr; gap: 10px; }
  .stat-card { min-height: 80px; }
  .editor-toolbar { top: var(--header-h); align-items: flex-start; flex-direction: column; }
  .editor-toolbar-actions { width: 100%; }
  .editor-toolbar-actions .btn { flex: 1; }
  .editor-layout { display: block; }
  .form-panel { border-right: 0; }
  .live-preview-panel { display: none; }
}
@media (max-width: 640px) {
  .dashboard-view { padding: 15px 12px 42px; }
  .hero-card { border-radius: 22px; padding: 28px 22px; }
  .hero-card h2 { font-size: 37px; }
  .hero-actions { flex-direction: column; }
  .hero-actions .btn { width: 100%; }
  .section-heading { align-items: stretch; flex-direction: column; }
  .list-tools { width: 100%; }
  .search-box { min-width: 0; flex: 1; }
  .files-section { border-radius: 18px; padding: 18px 13px; }
  .files-grid { grid-template-columns: 1fr; }
  .editor-toolbar { padding: 11px 12px; }
  .editor-toolbar-actions { gap: 7px; }
  .editor-toolbar-actions .btn { font-size: 0; gap: 0; min-width: 44px; }
  .editor-toolbar-actions .btn svg { font-size: 16px; }
  .form-panel { padding: 13px; }
  .two-col, .three-col { grid-template-columns: 1fr; }
  .trip-row-fields { grid-template-columns: 1fr 1fr; }
  .dialog-header { padding: 18px; }
  .dialog-header h2 { font-size: 20px; }
  .format-grid, .signature-panel { padding: 15px; }
  .format-card { grid-template-columns: 95px 1fr; gap: 13px; }
  .format-thumb { height: 120px; }
  .format-paper { transform: scale(.78); }
  .format-arrow { display: none; }
  .dialog-footer { align-items: stretch; flex-direction: column; }
  .dialog-footer-actions { width: 100%; }
  .dialog-footer-actions .btn { flex: 1; }
  .canvas-toolbar { align-items: flex-start; flex-wrap: wrap; }
  .canvas-toolbar label { margin-left: 0; }
  .preview-header-actions .btn { font-size: 0; }
  .preview-header-actions .btn svg { font-size: 15px; }
  .full-preview-panel { padding: 14px; }
  .toast-region { left: 12px; right: 12px; top: 74px; }
  .toast { min-width: 0; max-width: none; width: 100%; }
}

@media print {
  body { background: white !important; }
  .app-header, .dashboard-view, .editor-toolbar, .form-panel, .live-preview-panel, dialog, .toast-region { display: none !important; }
}

/* Keep the bordered invoice frame stretched to the selected page height. */
.invoice-sheet { display: flex; flex-direction: column; }
.invoice-border { flex: 1 0 auto; width: 100%; }


/* v3: split bill number, sharing and PWA install */
.install-app-btn { min-height: 40px; white-space: nowrap; }
.bill-number-fields {
  display: grid;
  grid-template-columns: minmax(76px, .8fr) auto minmax(90px, 1fr) auto minmax(90px, 1fr);
  gap: 8px;
  align-items: end;
}
.bill-number-separator {
  align-self: end;
  display: grid;
  place-items: center;
  min-height: 39px;
  color: var(--muted);
  font-weight: 900;
}
.share-render-host {
  position: fixed;
  left: -20000px;
  top: 0;
  z-index: -1;
  background: #fff;
  pointer-events: none;
}
.share-render-host .invoice-sheet { box-shadow: none !important; margin: 0 !important; }
@media (display-mode: standalone) { .install-app-btn { display: none !important; } }
@media (max-width: 900px) {
  .install-app-btn { width: 42px; padding: 0; font-size: 0; gap: 0; }
  .install-app-btn svg { font-size: 17px; }
}
@media (max-width: 640px) {
  .bill-number-fields { grid-template-columns: 1fr auto 1fr; }
  .bill-number-fields .field:last-of-type { grid-column: 1 / -1; }
  .bill-number-fields .bill-number-separator:last-of-type { display: none; }
}
