:root {
  --ink: #151515;
  --muted: #6c6c72;
  --surface: #ffffff;
  --canvas: #ececef;
  --line: #dedee3;
  --soft: #f6f6f8;
  --accent: #e60000;
  --accent-dark: #b90000;
  --blue-soft: #e9f2fa;
  --input: #fff7d8;
  --shadow: 0 18px 50px rgba(18, 18, 22, .12);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.auth-page {
  min-height: 100vh;
  color: #fff;
  background: #09090b;
}

.login-shell {
  position: relative;
  min-height: 100vh;
  padding: 46px 28px;
  display: grid;
  place-items: center;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 11% 14%, rgba(226, 0, 0, .18), transparent 28%),
    radial-gradient(circle at 91% 76%, rgba(143, 0, 0, .28), transparent 34%),
    linear-gradient(122deg, #08080a 0%, #141416 50%, #240506 100%);
}

.login-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -3;
  opacity: .24;
  background-image:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 80px 80px;
  mask-image: linear-gradient(to bottom, #000, transparent 75%);
}

.login-orb {
  position: absolute;
  z-index: -2;
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(224,0,0,.42), rgba(68,0,0,.08));
  filter: blur(.2px);
  box-shadow: inset 0 0 60px rgba(255,255,255,.045), 0 35px 100px rgba(0,0,0,.35);
}

.login-orb-top { width: 330px; height: 330px; top: -165px; right: 7%; }
.login-orb-bottom { width: 270px; height: 270px; bottom: -145px; left: 8%; }

.login-frame {
  position: relative;
  z-index: 1;
  width: min(1100px, 100%);
  min-height: 610px;
  display: grid;
  grid-template-columns: 1.12fr .88fr;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 27px;
  background: rgba(18,18,21,.92);
  box-shadow: 0 38px 120px rgba(0,0,0,.52);
  backdrop-filter: blur(22px);
}

.login-story {
  min-width: 0;
  padding: 56px 58px 42px;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(160deg, rgba(255,255,255,.035), transparent 48%),
    rgba(18,18,21,.72);
}

.login-brand-row { display: flex; align-items: center; gap: 16px; }
.login-brand-logo {
  width: 145px;
  height: 54px;
  flex: none;
  border-radius: 9px;
  background-color: #fff;
  background-image: url("ag-header.png");
  background-repeat: no-repeat;
  background-size: 425px auto;
  background-position: -10px -14px;
  box-shadow: 0 12px 30px rgba(0,0,0,.3);
}
.login-brand-row strong { display: block; font-size: 16px; }
.login-brand-row span { display: block; margin-top: 5px; color: #c6c6cb; font-size: 9px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; }

.login-story-copy { margin: auto 0; max-width: 560px; padding: 44px 0; }
.login-kicker, .login-card-kicker { margin: 0 0 16px; color: #ff5b5b; font-size: 10px; font-weight: 800; letter-spacing: .19em; text-transform: uppercase; }
.login-story-copy h1 { margin: 0; max-width: 560px; font-size: clamp(37px, 4vw, 55px); line-height: 1.06; letter-spacing: -.045em; font-weight: 650; }
.login-story-copy > p:last-child { max-width: 530px; margin: 24px 0 0; color: #c7c7cc; font-size: 14px; line-height: 1.7; }

.login-story-footer { margin-top: auto; }
.login-badges { display: flex; flex-wrap: wrap; gap: 9px; }
.login-badges span { position: relative; padding: 9px 12px 9px 30px; color: #e7e7ea; border: 1px solid rgba(255,255,255,.13); border-radius: 9px; background: rgba(255,255,255,.035); font-size: 10px; font-weight: 700; }
.login-badges span::before { content: "✓"; position: absolute; left: 11px; top: 8px; color: #ff5b5b; font-weight: 900; }
.login-story-footer > p { margin: 12px 0 0; color: #a9a9b0; font-size: 10px; }
.login-story-footer i { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: #e60000; box-shadow: 0 0 0 4px rgba(230,0,0,.14); }

.login-panel {
  padding: 34px;
  display: grid;
  place-items: center;
  border-left: 1px solid rgba(255,255,255,.12);
  background: linear-gradient(145deg, rgba(255,255,255,.012), rgba(230,0,0,.035));
}

.login-card {
  width: 100%;
  max-width: 430px;
  padding: 38px 36px 32px;
  color: #202027;
  background: #fff;
  border: 1px solid rgba(0,0,0,.04);
  border-radius: 21px;
  box-shadow: 0 26px 65px rgba(0,0,0,.34);
}

.login-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.login-card-kicker { margin-bottom: 14px; color: #bd0000; }
.login-card h2 { margin: 0; font-size: 28px; line-height: 1.15; letter-spacing: -.035em; font-weight: 650; }
.login-card-head p:last-child { margin: 10px 0 0; color: #787884; font-size: 12px; line-height: 1.5; }
.login-card-mark { width: 46px; height: 46px; flex: none; display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, #ef0000, #a90000); border-radius: 13px; box-shadow: 0 10px 24px rgba(215,0,0,.25); font-size: 14px; font-weight: 900; }

.login-alert { margin: 22px 0 -5px; padding: 11px 13px; color: #8b0000; background: #fff0f0; border: 1px solid #ffc9c9; border-radius: 9px; font-size: 11px; font-weight: 700; line-height: 1.45; }
.login-form { margin-top: 28px; display: grid; gap: 18px; }
.login-field { display: grid; gap: 8px; color: #3e3e46; font-size: 11px; font-weight: 750; }
.login-input-wrap { position: relative; }
.login-input-wrap input { width: 100%; height: 51px; padding: 0 72px 0 44px; color: #17171b; background: #fff; border: 1px solid #d9d9df; border-radius: 10px; outline: none; font-size: 13px; box-shadow: 0 3px 10px rgba(20,20,25,.025); }
.login-input-wrap input::placeholder { color: #9292a0; }
.login-input-wrap input:focus { border-color: #d40000; box-shadow: 0 0 0 4px rgba(215,0,0,.09); }
.login-input-icon { position: absolute; z-index: 2; left: 15px; top: 50%; transform: translateY(-50%); width: 20px; color: #a2a2ad; text-align: center; font-size: 15px; font-weight: 800; pointer-events: none; }
.login-lock-icon { font-size: 8px; }
.password-toggle { position: absolute; right: 7px; top: 7px; height: 37px; padding: 0 10px; color: #8a0000; background: #fff4f4; border: 0; border-radius: 7px; font-size: 10px; font-weight: 800; }
.password-toggle:hover { background: #ffe9e9; }

.login-submit { height: 52px; margin-top: 4px; padding: 0 19px; display: flex; align-items: center; justify-content: center; gap: 13px; color: #fff; background: linear-gradient(135deg, #eb0000, #aa0000); border: 0; border-radius: 10px; box-shadow: 0 13px 28px rgba(205,0,0,.24); font-weight: 800; }
.login-submit:hover { background: linear-gradient(135deg, #fc1111, #bc0000); transform: translateY(-1px); }
.login-submit:disabled { opacity: .72; cursor: wait; transform: none; }
.login-submit span:last-child { font-size: 23px; line-height: 1; }

.login-security-note { margin-top: 22px; padding-top: 18px; display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; border-top: 1px solid #ececf0; }
.login-security-note p { margin: 0; color: #7a7a86; font-size: 10px; line-height: 1.5; }
.login-shield { width: 22px; height: 22px; display: grid; place-items: center; color: #b10000; background: #fff0f0; border-radius: 7px; font-size: 11px; font-weight: 900; }

.logout-form { margin: 0; }
.logout-btn { min-height: 38px; padding: 9px 13px; color: #fff; background: transparent; border: 1px solid rgba(255,255,255,.2); border-radius: 9px; font-weight: 750; }
.logout-btn:hover { color: #fff; background: rgba(230,0,0,.24); border-color: rgba(255,70,70,.55); }

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: 74px;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(18, 18, 20, .97);
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(16px);
}

.brand-lockup { display: flex; align-items: center; gap: 13px; min-width: 0; }
.app-logo {
  width: 112px;
  height: 42px;
  flex: none;
  border-radius: 6px;
  background-color: #fff;
  background-image: url("ag-header.png");
  background-repeat: no-repeat;
  background-size: 330px auto;
  background-position: -8px -11px;
}
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.app-topbar .eyebrow { color: #f15a5a; }
.app-topbar h1 { margin: 0; font-size: 18px; line-height: 1.1; }
.topbar-actions, .preview-toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.save-state { display: inline-flex; align-items: center; gap: 7px; margin-right: 4px; color: #c8c8cc; font-size: 12px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #51d88a; box-shadow: 0 0 0 4px rgba(81,216,138,.12); }

.btn, .icon-btn, .mini-btn, .doc-tab, .add-another {
  border: 0;
  border-radius: 9px;
  font-weight: 750;
  transition: background .18s ease, color .18s ease, border-color .18s ease, transform .18s ease;
}
.btn { min-height: 38px; padding: 9px 14px; }
.btn:hover, .icon-btn:hover, .mini-btn:hover, .add-another:hover { transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 8px 22px rgba(230,0,0,.22); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: #fff; color: #222; border: 1px solid #d7d7dc; }
.app-topbar .btn-ghost { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.16); }
.btn-add { background: #171719; color: #fff; padding-inline: 13px; white-space: nowrap; }

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 470px) minmax(600px, 1fr);
  min-height: calc(100vh - 74px);
}

.editor-panel {
  padding: 22px;
  background: #f8f8fa;
  border-right: 1px solid #d8d8de;
  overflow: auto;
}

.editor-heading, .preview-toolbar, .card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.editor-heading h2, .preview-toolbar h2 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
.item-count-pill { padding: 7px 10px; border-radius: 999px; background: #fff; border: 1px solid var(--line); color: var(--muted); font-size: 12px; white-space: nowrap; }
.item-count-pill strong { color: var(--ink); }

.draft-row { display: grid; grid-template-columns: 1fr auto auto; gap: 7px; margin: 16px 0; }
.icon-btn { padding: 0 10px; background: #fff; color: #333; border: 1px solid var(--line); font-size: 12px; }
.danger-text { color: #bd1515; }

.form-card {
  margin: 12px 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: 0 4px 15px rgba(18,18,22,.035);
  overflow: hidden;
}
.form-card > summary {
  padding: 15px 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.form-card > summary::-webkit-details-marker { display: none; }
.form-card > summary::after { content: "+"; color: var(--muted); font-size: 19px; font-weight: 500; }
.form-card[open] > summary::after { content: "−"; }
.form-card[open] > summary { border-bottom: 1px solid var(--line); }
.form-grid { padding: 16px; display: grid; gap: 13px; }
.two-col { grid-template-columns: 1fr 1fr; }
.nested-grid { padding: 0; }
.field-wide { grid-column: 1 / -1; }
.field-group { display: grid; gap: 6px; min-width: 0; }
.field-group > span { color: #45454c; font-size: 11px; font-weight: 800; letter-spacing: .015em; }
.field-group em { display: block; color: var(--accent); font-style: normal; font-size: 9px; font-weight: 700; margin-top: 2px; }
.field-control {
  width: 100%;
  min-height: 39px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cdced4;
  border-radius: 8px;
  outline: none;
}
textarea.field-control { resize: vertical; line-height: 1.45; }
.field-control:focus { border-color: #202024; box-shadow: 0 0 0 3px rgba(0,0,0,.08); }
.important-field .field-control { background: var(--input); border-color: #e4c653; }
.input-with-action { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.mini-btn { min-width: 52px; background: #f0f0f2; border: 1px solid #d1d1d5; color: #242429; }

.items-card { padding: 17px; overflow: visible; }
.items-card h3 { margin: 0; font-size: 18px; }
.helper-text { margin: 11px 0 15px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.line-items { display: grid; gap: 10px; }
.line-item-card { border: 1px solid #d8d8dd; border-radius: 11px; background: #fbfbfc; overflow: hidden; }
.line-item-head { padding: 8px 10px; display: flex; align-items: center; justify-content: space-between; background: #f0f0f3; border-bottom: 1px solid #dedee3; }
.line-item-number { font-size: 11px; font-weight: 900; }
.line-item-actions { display: flex; gap: 4px; }
.item-action { min-width: 28px; height: 27px; padding: 0 6px; border: 1px solid #d3d3d8; border-radius: 6px; background: #fff; color: #4e4e55; font-size: 11px; font-weight: 800; }
.item-action.remove { color: #c00; }
.line-item-fields { padding: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.line-item-fields .description-field { grid-column: 1 / -1; }
.line-item-fields .field-control { background: var(--input); font-size: 12px; }
.item-amount { grid-column: 1 / -1; display: flex; justify-content: space-between; padding-top: 2px; color: var(--muted); font-size: 11px; }
.item-amount strong { color: var(--ink); font-size: 12px; }
.add-another { width: 100%; margin-top: 11px; padding: 12px; border: 1.5px dashed #a7a7ad; background: #fff; color: #2e2e34; }
.items-summary { margin-top: 13px; padding-top: 12px; display: grid; gap: 7px; border-top: 1px solid var(--line); }
.items-summary span { display: flex; justify-content: space-between; gap: 20px; color: var(--muted); font-size: 11px; }
.items-summary strong { color: var(--ink); }
.grand-summary { margin-top: 3px; padding-top: 9px; border-top: 1px solid var(--line); color: var(--ink) !important; font-weight: 800; }
.grand-summary strong { color: var(--accent); font-size: 14px; }
.data-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }

.preview-panel { min-width: 0; padding: 22px; background: #e9e9ec; }
.preview-toolbar { position: sticky; top: 74px; z-index: 25; margin: -22px -22px 0; padding: 18px 22px 14px; background: rgba(242,242,244,.94); border-bottom: 1px solid #d5d5da; backdrop-filter: blur(12px); }
.page-count { color: var(--muted); font-size: 12px; font-weight: 700; }
.document-tabs { position: sticky; top: 145px; z-index: 24; margin: 0 -22px; padding: 9px 22px; display: flex; gap: 7px; overflow-x: auto; background: rgba(242,242,244,.94); border-bottom: 1px solid #d7d7dc; scrollbar-width: thin; }
.doc-tab { padding: 8px 11px; background: transparent; color: #626269; white-space: nowrap; font-size: 11px; border: 1px solid transparent; }
.doc-tab.active { color: #fff; background: #19191c; }
.pdf-hint { max-width: 210mm; margin: 14px auto 0; padding: 9px 12px; color: #5d4b05; background: #fff8d8; border: 1px solid #eddd8b; border-radius: 9px; font-size: 11px; text-align: center; }
.preview-canvas { display: grid; gap: 24px; padding: 18px 0 60px; justify-items: center; }
.document-section { display: grid; gap: 24px; width: 100%; justify-items: center; }
.document-section.is-hidden-screen { display: none; }
.document-section-title { width: min(210mm, 100%); margin: 3px 0 -14px; color: #717178; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }

.a4-page {
  position: relative;
  width: 210mm;
  height: 297mm;
  overflow: hidden;
  color: #111;
  background: #fff;
  box-shadow: var(--shadow);
  font-family: Arial, Helvetica, sans-serif;
  flex: none;
}
.letterhead-header, .letterhead-watermark, .letterhead-footer { position: absolute; left: 0; width: 100%; pointer-events: none; user-select: none; }
.letterhead-header { top: 0; height: 44mm; object-fit: fill; }
.letterhead-watermark { top: 48mm; height: 205mm; object-fit: fill; opacity: .82; }
.letterhead-footer { bottom: 0; height: 37mm; object-fit: fill; }
.page-content { position: absolute; z-index: 2; top: 47mm; left: 13mm; right: 13mm; bottom: 39mm; display: flex; flex-direction: column; }
.doc-title { margin: 0 0 4mm; text-align: center; font-size: 17pt; line-height: 1; font-weight: 800; }
.doc-subtitle { margin: -1mm 0 3mm; text-align: center; font-size: 8pt; font-weight: 700; letter-spacing: .08em; }
.doc-meta-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8mm; margin-bottom: 3mm; font-size: 8.6pt; font-weight: 700; }
.doc-meta-row > :last-child { text-align: right; }
.doc-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 8pt; line-height: 1.17; background: rgba(255,255,255,.8); }
.doc-table th, .doc-table td { border: .45pt solid #777; padding: 1.5mm 1.2mm; vertical-align: top; overflow-wrap: anywhere; }
.doc-table th { vertical-align: middle; text-align: center; font-weight: 800; background: rgba(250,250,250,.88); }
.doc-table td.num { text-align: right; white-space: nowrap; }
.doc-table td.center { text-align: center; vertical-align: middle; }
.doc-table .item-row td { vertical-align: middle; }
.doc-table .column-index td { padding: .8mm; text-align: center; font-weight: 800; }
.document-info-grid { display: grid; grid-template-columns: 1fr 1fr; border: .45pt solid #777; border-bottom: 0; font-size: 8.2pt; line-height: 1.25; background: rgba(255,255,255,.82); }
.info-cell { min-height: 22mm; padding: 1.6mm; border-right: .45pt solid #777; }
.info-cell:last-child { border-right: 0; }
.info-cell strong { font-weight: 800; }
.info-split { display: grid; grid-template-columns: 25mm 1fr; }
.info-label { font-weight: 800; }
.tax-id-grid { display: grid; grid-template-columns: 1fr 1fr; border: .45pt solid #777; border-bottom: 0; background: rgba(255,255,255,.82); }
.tax-id-cell { display: grid; grid-template-columns: 27mm 1fr; padding: 1.5mm; border-right: .45pt solid #777; font-size: 8pt; }
.tax-id-cell:last-child { border-right: 0; }
.totals-row td, .totals-row th { font-weight: 800; vertical-align: middle; }
.amount-words { padding: 3mm 1mm; border: .45pt solid #777; border-top: 0; font-size: 8.2pt; font-weight: 800; }
.continuation-note { padding: 2.2mm 1.4mm; border: .45pt solid #777; border-top: 0; font-size: 8pt; font-weight: 800; }
.signature-block { margin-top: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14mm; text-align: center; font-size: 8pt; }
.signature-line { padding-top: 1mm; border-top: .6pt solid #222; }
.single-signature { margin-top: auto; width: 42mm; padding-top: 1mm; border-top: .6pt solid #222; font-size: 8pt; }
.page-number { position: absolute; right: 13mm; bottom: 37.6mm; z-index: 3; color: #69696f; font: 7pt Arial, sans-serif; }
.empty-items { height: 28mm; text-align: center; vertical-align: middle !important; color: #777; font-style: italic; }

.challan-customer { min-height: 32mm; }
.challan-table .item-row td { height: 10mm; }
.challan-summary td { font-weight: 800; vertical-align: middle; }
.remarks-block { margin-top: 8mm; font-size: 8.2pt; line-height: 1.8; }

.sales-table .item-row td { height: 11mm; line-height: 1.25; }
.invoice-table .item-row td { height: 13mm; line-height: 1.25; }
.invoice-top-grid { display: grid; grid-template-columns: .92fr 1.08fr; border: .45pt solid #777; border-bottom: 0; font-size: 8.1pt; line-height: 1.25; background: rgba(255,255,255,.83); }
.invoice-top-left, .invoice-top-right { border-right: .45pt solid #777; }
.invoice-top-right { border-right: 0; }
.invoice-box { padding: 1.4mm; border-bottom: .45pt solid #777; }
.invoice-box:last-child { border-bottom: 0; }
.invoice-box.customer-box { min-height: 40mm; }
.invoice-box.po-box { min-height: 37mm; }
.invoice-box.invoice-number-box { min-height: 19mm; }
.invoice-box.delivery-box { min-height: 23mm; }
.invoice-box.bank-box { min-height: 29mm; }
.invoice-box.remarks-box { min-height: 8mm; }
.invoice-signoff { width: 78mm; margin-top: auto; padding: 6mm 0 0 1mm; align-self: flex-start; font-size: 8.3pt; line-height: 1.55; font-weight: 700; }
.invoice-signed-by { margin-bottom: 5mm; font-weight: 700; }
.invoice-signoff-company { margin-bottom: 1.2mm; font-weight: 800; }

.undertaking-content { font-size: 10pt; line-height: 1.38; }
.undertaking-content .doc-title { margin-bottom: 10mm; }
.undertaking-intro { margin-bottom: 14mm; }
.undertaking-list { margin: 0; padding-left: 13mm; display: grid; gap: 13mm; }
.undertaking-validity { margin-top: 13mm; font-weight: 800; }
.undertaking-quote { margin-top: 12mm; }
.undertaking-signoff { margin-top: auto; display: grid; grid-template-columns: 1fr auto; gap: 10mm; align-items: end; }
.undertaking-location { display: grid; gap: 6mm; }

.toast { position: fixed; z-index: 100; right: 18px; bottom: 18px; max-width: 360px; padding: 12px 15px; color: #fff; background: #1d1d20; border-radius: 10px; box-shadow: 0 14px 40px rgba(0,0,0,.24); font-size: 12px; font-weight: 700; opacity: 0; transform: translateY(16px); pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #b80000; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 410px minmax(520px, 1fr); }
  .editor-panel, .preview-panel { padding: 16px; }
  .preview-toolbar { margin: -16px -16px 0; padding: 16px; }
  .document-tabs { margin-inline: -16px; padding-inline: 16px; }
}

@media (max-width: 920px) {
  .login-shell { padding: 24px; }
  .login-frame { width: min(560px, 100%); min-height: auto; grid-template-columns: 1fr; }
  .login-story { padding: 28px 32px 24px; }
  .login-story-copy { margin: 30px 0 0; padding: 0; }
  .login-story-copy h1 { font-size: 34px; }
  .login-story-copy > p:last-child { margin-top: 14px; }
  .login-story-footer { margin-top: 25px; }
  .login-panel { padding: 28px; border-left: 0; border-top: 1px solid rgba(255,255,255,.12); }
  .app-topbar { position: relative; align-items: flex-start; }
  .save-state { display: none; }
  .app-shell { display: block; }
  .editor-panel { border-right: 0; border-bottom: 1px solid #d8d8de; }
  .preview-toolbar { top: 0; }
  .document-tabs { top: 80px; }
  .preview-canvas { overflow-x: auto; justify-items: start; }
  .a4-page { transform-origin: top left; }
}

@media (max-width: 620px) {
  .login-shell { padding: 14px; place-items: start center; }
  .login-orb-top { width: 220px; height: 220px; top: -120px; right: -60px; }
  .login-orb-bottom { width: 180px; height: 180px; bottom: -100px; left: -60px; }
  .login-frame { border-radius: 20px; }
  .login-story { padding: 23px 22px 20px; }
  .login-brand-logo { width: 118px; height: 45px; background-size: 350px auto; background-position: -8px -11px; }
  .login-brand-row strong { font-size: 14px; }
  .login-story-copy h1 { font-size: 29px; }
  .login-story-copy > p:last-child { font-size: 12px; }
  .login-badges span { padding: 7px 9px 7px 26px; font-size: 9px; }
  .login-badges span::before { left: 9px; top: 6px; }
  .login-panel { padding: 14px; }
  .login-card { padding: 27px 20px 23px; border-radius: 16px; }
  .login-card h2 { font-size: 24px; }
  .login-card-mark { width: 40px; height: 40px; }
  .login-form { margin-top: 23px; }
  .app-topbar { padding: 10px 12px; flex-direction: column; }
  .brand-lockup { width: 100%; }
  .app-logo { width: 92px; height: 36px; }
  .topbar-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .logout-form, .logout-form .btn { width: 100%; }
  .topbar-actions .btn { padding: 8px 7px; font-size: 11px; }
  .editor-panel, .preview-panel { padding: 12px; }
  .two-col, .line-item-fields { grid-template-columns: 1fr; }
  .field-wide, .line-item-fields .description-field, .item-amount { grid-column: 1; }
  .card-title-row { align-items: center; }
  .btn-add { font-size: 11px; }
  .preview-toolbar { margin: -12px -12px 0; padding: 14px 12px; display: block; }
  .preview-toolbar-actions { margin-top: 10px; }
  .document-tabs { top: 119px; margin-inline: -12px; padding-inline: 12px; }
  .a4-page { width: 210mm; }
}

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

@media print {
  html, body { width: 210mm; min-width: 210mm; background: #fff !important; }
  .app-topbar, .editor-panel, .preview-toolbar, .document-tabs, .pdf-hint, .document-section-title, .toast { display: none !important; }
  .app-shell, .preview-panel, .preview-canvas, .document-section { display: block !important; width: 210mm !important; margin: 0 !important; padding: 0 !important; background: #fff !important; }
  .document-section.is-hidden-screen { display: block !important; }
  body[data-print-target="challan"] .document-section:not([data-doc="challan"]),
  body[data-print-target="sales-tax"] .document-section:not([data-doc="sales-tax"]),
  body[data-print-target="invoice"] .document-section:not([data-doc="invoice"]),
  body[data-print-target="undertaking"] .document-section:not([data-doc="undertaking"]) { display: none !important; }
  .a4-page { width: 210mm !important; height: 297mm !important; margin: 0 !important; box-shadow: none !important; break-after: page; page-break-after: always; }
  .a4-page:last-child { break-after: auto; page-break-after: auto; }
}
