/* components.css — every component from Archive ui_style, Theme.md tokens. */

.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }               /* grid items default min-width:auto → cards overflow */
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 18px 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 18px;
  min-width: 0;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

/* Clean, subtle lift when the pointer enters any card. */
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-3);
  border-color: var(--border-strong);
}

/* Card header row: title on the left, a compact control on the right. */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h3 { margin: 0; }
/* Compact financial-year chip (dashboard filter). */
.select.fy-chip { width: auto; max-width: 150px; padding: 4px 26px 4px 10px; font-size: var(--fs-xs); line-height: 1.2; font-weight: var(--fw-medium); border-radius: var(--radius-pill); }

.kpi .label { color: var(--text-muted); font-size: var(--fs-xs); overflow-wrap: anywhere; }
.kpi .value {
  font-size: clamp(18px, 3.4vw, var(--fs-2xl));
  font-weight: var(--fw-bold); margin-top: 5px;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.15;
}
.kpi .hint { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 4px; overflow-wrap: anywhere; }

/* KPI metric cards — one solid colour per metric (no side line). Each card is
   filled, bordered and lightly animated so the dashboard reads at a glance. */
.kpi {
  position: relative;
  border: 1px solid var(--border);
  overflow: hidden;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  animation: kpi-in var(--dur-slow) var(--ease) backwards;
}
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow-3); }
@keyframes kpi-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .kpi { animation: none; } .card:hover, .kpi:hover { transform: none; } }

/* Text on a filled KPI card is always light. */
.kpi[class*="accent-"] { color: #fff; background-image: linear-gradient(135deg, rgba(255, 255, 255, .22), rgba(0, 0, 0, .14)); }
.kpi[class*="accent-"] .label { color: rgba(255, 255, 255, .9); }
.kpi[class*="accent-"] .hint { color: rgba(255, 255, 255, .82); }
.kpi[class*="accent-"] .value { color: #fff; }

.kpi.accent-blue  { background-color: var(--kpi-blue);  border-color: var(--kpi-blue); }
.kpi.accent-green { background-color: var(--kpi-green); border-color: var(--kpi-green); }
.kpi.accent-amber { background-color: var(--kpi-amber); border-color: var(--kpi-amber); }
.kpi.accent-red   { background-color: var(--kpi-red);   border-color: var(--kpi-red); }
.kpi.accent-teal  { background-color: var(--kpi-teal);  border-color: var(--kpi-teal); }
.kpi.accent-violet { background-color: var(--kpi-violet); border-color: var(--kpi-violet); }

/* Consolidated "Business Status" card */
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 4px 0 16px; }
.stat-mini { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; min-width: 0; }
.stat-mini .n { font-size: var(--fs-xl); font-weight: var(--fw-bold); font-variant-numeric: tabular-nums; }
.stat-mini .l { font-size: var(--fs-xs); color: var(--text-muted); overflow-wrap: anywhere; }
.stat-mini.blue  { background: var(--primary-soft); border-color: var(--primary); } .stat-mini.blue  .n { color: var(--primary); }
.stat-mini.red   { background: var(--danger-soft);  border-color: var(--danger); }  .stat-mini.red   .n { color: var(--danger); }
.stat-mini.amber { background: var(--warning-soft); border-color: var(--warning); } .stat-mini.amber .n { color: var(--warning); }
.stat-mini.teal  { background: var(--info-soft);    border-color: var(--info); }    .stat-mini.teal  .n { color: var(--info); }
.status-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.status-cols h4 { margin: 0 0 4px; font-size: var(--fs-sm); color: var(--text-muted); }

/* Dashboard row: chart + business status (was an inline 2fr 1fr 1fr grid). */
.dash-row { display: grid; gap: 16px; grid-template-columns: 2fr 1fr; align-items: stretch; }
.dash-row > * { min-width: 0; }
.dash-row > .card { display: flex; flex-direction: column; }

/* Toolbar */
.toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .left, .toolbar .right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .seg { display: inline-flex; gap: 8px; align-items: center; }

/* Pagination (long lists + audit log) */
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }
.pager .pager-size { max-width: 120px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:disabled:hover { background: var(--surface); }

/* Buttons */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  font: inherit;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.primary:active { background: var(--primary-active); }
.btn.danger { color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 5px 9px; font-size: var(--fs-xs); border-radius: 5px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.row-actions { white-space: nowrap; }
.row-actions .btn + .btn { margin-left: 6px; }

/* Forms */
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  outline: none;
  font: inherit;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.search { min-width: 220px; }

/* Table */
/* Table. The wrap is the scroll container with a viewport-bounded height, so the
   header can stay pinned while the rows scroll (see thead sticky below). */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); max-height: calc(100vh - var(--topbar-h) - 190px); }
.table { width: 100%; border-collapse: collapse; min-width: 760px; font-size: var(--fs-sm); }
.table th, .table td { padding: 8px 9px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table th { background: var(--table-head-bg); color: var(--table-head-text); font-size: var(--fs-xs); font-weight: var(--fw-medium); }
/* Sticky header: pinned to the top of the .table-wrap scroll area. */
.table thead th { position: sticky; top: 0; z-index: 2; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
/* Compact sizing: short columns stop eating horizontal space. Headers may
   wrap to two lines; values never wrap so numbers stay aligned. */
.table th.tight, .table td.tight { width: 1%; }
.table th.num, .table td.num { width: 1%; text-align: right; font-variant-numeric: tabular-nums; }
.table th.tight, .table th.num { white-space: normal; line-height: 1.15; vertical-align: bottom; }
.table td.tight, .table td.num { white-space: nowrap; }
.table td.text .clip { display: block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Actions column stays reachable while the table scrolls sideways (mobile).
   width:1% + nowrap keeps it as narrow as its buttons — the table never
   stretches it to fill leftover space. */
.table th.col-actions, .table td.row-actions { position: sticky; right: 0; background: var(--surface); box-shadow: -6px 0 8px -6px rgba(16, 24, 40, .18); width: 1%; white-space: nowrap; text-align: right; padding-left: 8px; padding-right: 8px; }
.table th.col-actions { background: var(--table-head-bg); z-index: 3; }
.table td.row-actions { vertical-align: middle; }
.table td.row-actions .btn { padding-left: 8px; padding-right: 8px; }
.table tbody tr:hover td.row-actions { background: var(--surface-2); }

/* Badge (status) */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 8px; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: var(--fw-bold);
  background: var(--primary-soft); color: var(--primary);
}
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }

/* Modal */
.modal {
  position: fixed; inset: 0;
  background: var(--overlay);
  display: none; align-items: center; justify-content: center;
  padding: 18px;
  z-index: var(--z-modal);
}
.modal.show { display: flex; }
.modal-box {
  background: var(--surface);
  width: min(900px, 100%);
  max-height: 92vh; overflow: auto;
  border-radius: 10px;
  box-shadow: var(--shadow-3);
  color: var(--text);
}
.modal-head { padding: 17px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 10px; position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--surface); z-index: 2; }

/* Forms in modals */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.field label { display: block; font-size: var(--fs-xs); font-weight: var(--fw-bold); margin-bottom: 5px; }
.full { grid-column: 1 / -1; }
textarea.input { resize: vertical; min-height: 52px; line-height: 1.45; }
input[type="date"].input { min-height: 38px; }
/* Client contacts — repeatable rows (name / mobile / email) */
.contact-row { display: grid; grid-template-columns: 1.2fr 1fr 1.4fr auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.date-warn { grid-column: 1 / -1; color: var(--danger); font-size: var(--fs-xs); margin-top: -6px; line-height: 1.3; }

/* Document line editor + totals */
.line-table { width: 100%; border-collapse: collapse; }
.line-table th, .line-table td { border-bottom: 1px solid var(--border); padding: 7px; }
.line-table input { min-width: 80px; }
.totals { margin-left: auto; width: min(360px, 100%); margin-top: 15px; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; }
.totals .grand { font-weight: var(--fw-bold); font-size: var(--fs-md); border-top: 1px solid var(--border); margin-top: 5px; padding-top: 10px; }

/* Misc */
.empty { text-align: center; padding: 45px; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.hidden { display: none !important; }

/* Top progress */
.topprogress {
  position: fixed; top: 0; left: 0;
  height: 3px; width: 0; opacity: 0;
  background: var(--brand-gradient);
  z-index: var(--z-progress);
  pointer-events: none;
}

/* Toast */
.toast {
  position: fixed; right: 18px; bottom: 18px;
  z-index: var(--z-toast);
  display: none;
  max-width: 360px;
  padding: 12px 15px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-3);
}
.toast.show { display: block; }
.toast.error { border-color: var(--danger); color: var(--danger); background: var(--surface); }

/* Skeleton (loading placeholders) */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s var(--ease) infinite;
  border-radius: var(--radius-sm);
}
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; background: var(--surface-2); }
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton.text { height: 1em; margin: 0.5em 0; }
.skeleton.title { height: 1.5em; width: 60%; margin: 0.5em 0; }
.skeleton.avatar { width: 40px; height: 40px; border-radius: 50%; }
.skeleton.card { padding: 18px; }
.skeleton.kpi { height: 100px; }
.skeleton.table-row { height: 44px; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: min(440px, 100%); text-align: center; }
.logo-box {
  width: 64px; height: 64px; border-radius: 16px;
  background: var(--brand-gradient); color: #fff;
  display: grid; place-items: center;
  margin: 0 auto 15px; font-weight: var(--fw-bold); font-size: var(--fs-xl);
}

/* Chart (dashboard) */
.chart { height: 270px; display: flex; align-items: end; gap: 10px; overflow: auto; padding: 20px 5px 5px; }
.bar-group { min-width: 65px; text-align: center; height: 100%; display: flex; flex-direction: column; justify-content: end; }
.bars { height: 190px; display: flex; gap: 3px; align-items: end; justify-content: center; }
.bar { width: 12px; min-height: 2px; border-radius: 4px 4px 0 0; background: var(--chart-1); }
.bar.rec { background: var(--chart-2); }
.bar.exp { background: var(--chart-3); }
.bar-label { font-size: 10px; color: var(--text-muted); margin-top: 5px; }

/* Line chart (dashboard monthly business) — series: Invoiced/Received/Expenses/Outstanding */
.line-chart { position: relative; display: flex; flex-direction: column; flex: 1 1 auto; }
.chart-scroll { flex: 1 1 auto; display: flex; align-items: center; overflow-x: auto; overflow-y: hidden; }
.chart-scroll svg { display: block; width: 100%; min-width: 600px; height: auto; }
.cgrid { stroke: var(--border); stroke-width: 1; }
.caxis { fill: var(--text-muted); font-size: 12px; }
.cguide { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; transition: opacity var(--dur-fast) var(--ease); }
.cline { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.cdot { stroke: var(--surface); stroke-width: 1.5; }
.chit { fill: transparent; cursor: crosshair; }
.cline.c1 { stroke: var(--chart-1); } .cdot.c1 { fill: var(--chart-1); }
.cline.c2 { stroke: var(--chart-2); } .cdot.c2 { fill: var(--chart-2); }
.cline.c3 { stroke: var(--chart-3); } .cdot.c3 { fill: var(--chart-3); }
.cline.c4 { stroke: var(--chart-4); } .cdot.c4 { fill: var(--chart-4); }

.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 11px; color: var(--text-muted); margin-top: 8px; }
.chart-legend .clg {
  background: none; border: 0; padding: 0; margin: 0;
  font: inherit; color: inherit; cursor: pointer;
  display: inline-flex; align-items: center;
}
.chart-legend .clg:hover { color: var(--text); }
.chart-legend .clg.off { opacity: .35; text-decoration: line-through; }
.chart-legend .clg:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: 3px; }
.chart-legend .chart-reset {
  background: none; border: 0; padding: 0; margin-left: auto;
  font: inherit; font-size: 11px; color: var(--primary); cursor: pointer; text-decoration: underline;
}
.chart-legend .chart-reset:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: 3px; }
.chart-legend .clg::before { content: ""; display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.chart-legend .clg.c1::before { background: var(--chart-1); }
.chart-legend .clg.c2::before { background: var(--chart-2); }
.chart-legend .clg.c3::before { background: var(--chart-3); }
.chart-legend .clg.c4::before { background: var(--chart-4); }

.chart-tip {
  position: absolute; z-index: var(--z-dropdown);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-3); padding: 8px 10px;
  font-size: 12px; min-width: 160px; pointer-events: none;
}
.chart-tip b { display: block; margin-bottom: 4px; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; padding: 1px 0; }
.chart-tip .tip-row i { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.chart-tip .tip-row i.c1 { background: var(--chart-1); }
.chart-tip .tip-row i.c2 { background: var(--chart-2); }
.chart-tip .tip-row i.c3 { background: var(--chart-3); }
.chart-tip .tip-row i.c4 { background: var(--chart-4); }

/* Theme builder — colour swatches */
.theme-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 12px; }
.swatch { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.swatch input[type="color"] { width: 34px; height: 26px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); padding: 0; }
.theme-presets { display: flex; gap: 8px; flex-wrap: wrap; }
.preset { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: var(--radius-sm); padding: 6px 10px; cursor: pointer; font: inherit; }
.preset:hover { background: var(--surface-2); }
.preset-strip { display: inline-flex; border: 1px solid var(--border); border-radius: 3px; overflow: hidden; }
.preset-strip i { width: 10px; height: 16px; display: block; }
.theme-group { margin-bottom: 10px; }
.theme-group-t { font-size: 11px; font-weight: var(--fw-bold); color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }

/* User Guide rendered inside the app (Settings → User Guide). Mirrors .lp-doc
   from landing.css but for the SPA, using tokens only (Theme.md §2). */
.guide-doc { max-width: 900px; line-height: var(--lh-normal); }
.guide-doc h1 { font-size: var(--fs-2xl); margin: 0 0 var(--sp-2); }
.guide-doc h2 { font-size: var(--fs-xl); margin-top: var(--sp-7); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.guide-doc h3 { font-size: var(--fs-lg); margin-top: var(--sp-5); }
.guide-doc h4 { font-size: var(--fs-md); margin-top: var(--sp-4); }
.guide-doc p, .guide-doc li, .guide-doc td { color: var(--text-muted); }
.guide-doc ul, .guide-doc ol { padding-left: var(--sp-6); }
.guide-doc li { margin: 3px 0; }
.guide-doc a { color: var(--primary); }
.guide-doc code { background: var(--surface-2); padding: 1px 5px; border-radius: var(--radius-sm); font-family: var(--font-mono); font-size: var(--fs-sm); }
.guide-doc blockquote { margin: var(--sp-4) 0; padding: var(--sp-3) var(--sp-4); border-left: 3px solid var(--border-strong); background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.guide-doc blockquote p { margin: 0; }
.guide-doc pre { overflow-x: auto; padding: var(--sp-3) var(--sp-4); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.guide-doc pre code { background: none; padding: 0; }
.guide-doc table { width: auto; max-width: 100%; border-collapse: collapse; margin: var(--sp-4) 0; }
.guide-doc th, .guide-doc td { border: 1px solid var(--border); padding: var(--sp-2) var(--sp-3); text-align: left; }
.guide-doc th { background: var(--surface-2); font-weight: var(--fw-semibold); }
.guide-doc :where(h2, h3)[id] { scroll-margin-top: var(--sp-5); }
