/* Movi Invoice — design system: tokens, base elements and shared components. */
:root {
  /* Brand */
  --orange-600: #C2410C;   /* primary actions: 5.2:1 with white text */
  --orange-500: #E8590C;   /* brand mark, accents, large display */
  --orange-100: #FFE8D9;
  --orange-50: #FFF5EE;
  --ink-900: #141414;
  --ink-800: #232120;
  --ink-700: #3A3632;

  /* Warm neutrals */
  --bg: #FBF8F4;
  --surface: #FFFFFF;
  --surface-2: #F6F2EC;
  --border: #E8E2DA;
  --border-strong: #D6CEC4;
  --text: #141414;
  --text-muted: #625A52;
  --text-faint: #8A8178;

  /* Status */
  --green-700: #17703B; --green-50: #EAF6EE;
  --blue-700: #1D4F91;  --blue-50: #EAF1FB;
  --amber-700: #8A5A00; --amber-50: #FDF4E1;
  --red-700: #B42318;   --red-50: #FDECEA;

  /* Type */
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-xs: 0.75rem; --fs-sm: 0.875rem; --fs-md: 1rem; --fs-lg: 1.125rem; --fs-xl: 1.375rem; --fs-2xl: 1.75rem; --fs-3xl: 2.375rem;

  /* Space, radius, elevation */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px; --s12: 48px; --s16: 64px;
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 20px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 20, 0.06);
  --shadow-md: 0 4px 16px rgba(20, 20, 20, 0.07), 0 1px 3px rgba(20, 20, 20, 0.05);
  --shadow-lg: 0 18px 48px rgba(20, 20, 20, 0.12);
  --focus: 0 0 0 3px rgba(232, 89, 12, 0.35);
  --header-h: 60px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: var(--fs-md); line-height: 1.5; color: var(--text);
  background: var(--bg); -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
}
img { max-width: 100%; display: block; }
a { color: var(--orange-600); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--ink-900); }
h1, h2, h3, h4 { margin: 0 0 var(--s3); line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-2xl); font-weight: 750; }
h2 { font-size: var(--fs-xl); font-weight: 700; }
h3 { font-size: var(--fs-lg); font-weight: 650; }
p { margin: 0 0 var(--s3); }
small, .small { font-size: var(--fs-sm); }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--ink-900); color: #fff; padding: 8px 12px; border-radius: var(--r-sm); z-index: 1000; }
.skip-link:focus { left: 8px; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }

/* Layout helpers */
.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 var(--s4); }
.stack > * + * { margin-top: var(--s4); }
.row { display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.grid { display: grid; gap: var(--s4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 42px; padding: 0 var(--s4); border-radius: var(--r-md); border: 1px solid transparent;
  font: inherit; font-size: var(--fs-sm); font-weight: 600; line-height: 1; cursor: pointer; text-decoration: none;
  transition: background-color .15s, border-color .15s, color .15s; white-space: nowrap; user-select: none;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--orange-600); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #A8370A; color: #fff; }
.btn-dark { background: var(--ink-900); color: #fff; }
.btn-dark:hover:not(:disabled) { background: var(--ink-700); color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover:not(:disabled) { border-color: var(--ink-900); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--surface); color: var(--red-700); border-color: #F3C5C0; }
.btn-danger:hover:not(:disabled) { background: var(--red-50); color: var(--red-700); }
.btn-sm { min-height: 34px; padding: 0 var(--s3); font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn-lg { min-height: 50px; padding: 0 var(--s6); font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn-icon { width: 38px; padding: 0; }
.btn .spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-800); }
.field .hint { font-size: var(--fs-xs); color: var(--text-muted); }
.field .error { font-size: var(--fs-xs); color: var(--red-700); font-weight: 600; }
.req::after { content: " *"; color: var(--orange-600); }
.input, select.input, textarea.input {
  width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; /* 16px avoids iOS zoom */
}
textarea.input { min-height: 84px; resize: vertical; line-height: 1.45; }
.input:hover { border-color: #BDB3A7; }
.input:focus { outline: none; border-color: var(--orange-500); box-shadow: var(--focus); }
.input[aria-invalid="true"] { border-color: var(--red-700); }
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
.input-sm { min-height: 36px; padding: 6px 9px; font-size: 15px; border-radius: var(--r-sm); }
.check { display: flex; align-items: flex-start; gap: var(--s2); font-size: var(--fs-sm); cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--orange-600); flex: none; }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--r-md); overflow: hidden; background: var(--surface); flex-wrap: wrap; }
.segmented label { display: flex; align-items: center; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { padding: 9px 14px; font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); border-right: 1px solid var(--border); }
.segmented label:last-child span { border-right: 0; }
.segmented input:checked + span { background: var(--ink-900); color: #fff; }
.segmented input:focus-visible + span { box-shadow: inset var(--focus); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; font-weight: 650; margin-bottom: var(--s3); }

/* Cards & panels */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.card-pad { padding: var(--s6); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s6); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.card-body { padding: var(--s6); }
@media (max-width: 600px) { .card-pad, .card-body { padding: var(--s4); } .card-head { padding: var(--s3) var(--s4); } }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 650; border: 1px solid transparent; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-draft { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }
.badge-issued { background: var(--blue-50); color: var(--blue-700); }
.badge-sent { background: var(--blue-50); color: var(--blue-700); }
.badge-paid { background: var(--green-50); color: var(--green-700); }
.badge-partially_paid { background: var(--amber-50); color: var(--amber-700); }
.badge-overdue { background: var(--red-50); color: var(--red-700); }
.badge-cancelled { background: var(--surface-2); color: var(--text-faint); text-decoration: line-through; }
.badge-plain::before { display: none; }
.tag { display: inline-block; padding: 2px 8px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); }
.tag-orange { background: var(--orange-50); border-color: var(--orange-100); color: var(--orange-600); }

/* Alerts */
.alert { padding: var(--s3) var(--s4); border-radius: var(--r-md); border: 1px solid; font-size: var(--fs-sm); }
.alert-info { background: var(--blue-50); border-color: #C9DAF2; color: #173E73; }
.alert-warn { background: var(--amber-50); border-color: #F1DDAE; color: #6B4600; }
.alert-error { background: var(--red-50); border-color: #F3C5C0; color: #8E1C13; }
.alert-success { background: var(--green-50); border-color: #BFE3CB; color: #125A2F; }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th { text-align: left; font-size: var(--fs-xs); font-weight: 650; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover td { background: var(--orange-50); }
.table .num { text-align: right; white-space: nowrap; }
/* Responsive tables become cards on small screens */
@media (max-width: 720px) {
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); }
  .table.responsive td { border: 0; padding: 2px 0; display: flex; justify-content: space-between; gap: var(--s3); text-align: right; }
  .table.responsive td::before { content: attr(data-label); color: var(--text-muted); font-size: var(--fs-xs); font-weight: 600; text-align: left; }
  .table.responsive td.primary { font-weight: 650; font-size: var(--fs-md); }
  .table.responsive td.primary::before { display: none; }
}

/* Empty state */
.empty { text-align: center; padding: var(--s12) var(--s4); color: var(--text-muted); }
.empty h3 { color: var(--text); }

/* Toasts */
.toasts { position: fixed; z-index: 900; right: var(--s4); bottom: var(--s4); display: flex; flex-direction: column; gap: var(--s2); max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink-900); color: #fff; padding: 12px 16px; border-radius: var(--r-md); box-shadow: var(--shadow-lg); font-size: var(--fs-sm); display: flex; gap: var(--s3); align-items: flex-start; }
.toast.error { background: #7A1A12; }
.toast button { background: none; border: 0; color: inherit; cursor: pointer; font-size: 18px; line-height: 1; margin-left: auto; }
@media (max-width: 720px) { .toasts { left: var(--s4); right: var(--s4); bottom: calc(76px + env(safe-area-inset-bottom)); max-width: none; } }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 20, 20, .45); z-index: 800; display: flex; align-items: center; justify-content: center; padding: var(--s4); }
.modal { background: var(--surface); border-radius: var(--r-xl); width: 100%; max-width: 560px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
.modal.wide { max-width: 820px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: var(--s4) var(--s6); border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: var(--fs-lg); }
.modal-body { padding: var(--s6); overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s4) var(--s6); border-top: 1px solid var(--border); flex-wrap: wrap; }
@media (max-width: 600px) {
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { border-radius: var(--r-xl) var(--r-xl) 0 0; max-height: 92vh; }
  .modal-body { padding: var(--s4); }
  .modal-foot { padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
}

/* Brand mark */
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink-900); font-weight: 800; letter-spacing: -0.02em; font-size: 1.15rem; }
.brand svg, .brand .brand-mark { width: 30px; height: 30px; flex: none; }
.brand .brand-full { display: block; width: auto; max-width: 220px; }
.brand b { color: var(--orange-500); font-weight: 800; }
.brand small { display: block; font-size: 10px; font-weight: 600; color: var(--text-faint); letter-spacing: .04em; text-transform: uppercase; margin-top: -2px; }

.divider { height: 1px; background: var(--border); border: 0; margin: var(--s6) 0; }
.kbd { font-family: var(--mono); font-size: var(--fs-xs); background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; }

/* Icons inside controls */
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-sm svg { width: 15px; height: 15px; }
