/* bill.st.is — minimal UI in the spirit of shadcn/ui (zinc palette) */
:root {
  --bg: #ffffff;
  --bg-subtle: #fafafa;
  --fg: #09090b;
  --muted: #71717a;
  --muted-bg: #f4f4f5;
  --border: #e4e4e7;
  --input: #e4e4e7;
  --ring: rgba(9, 9, 11, .12);
  --primary: #18181b;
  --primary-fg: #fafafa;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #15803d;
  --success-bg: #f0fdf4;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04);
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--fg); background: var(--bg-subtle); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.h2 { font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.h3 { font-size: 16px; font-weight: 600; }
.h4 { font-size: 14px; font-weight: 600; }
.mt { margin-top: 8px; }
.muted { color: var(--muted); }
.measure { max-width: 62ch; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
[hidden] { display: none !important; }
.icon { flex: none; display: block; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, .85); backdrop-filter: saturate(180%) blur(8px); -webkit-backdrop-filter: saturate(180%) blur(8px); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1240px; margin: 0 auto; height: 56px; padding: 0 24px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; text-decoration: none; letter-spacing: -.01em; }
.nav { display: flex; gap: 4px; }
.nav-link { padding: 6px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav-link:hover { color: var(--fg); background: var(--muted-bg); }
.nav-link.is-active { color: var(--fg); background: var(--muted-bg); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar-right form { margin: 0; }

/* Segmented language switch */
.seg { display: inline-flex; padding: 2px; background: var(--muted-bg); border-radius: 7px; }
.seg-item { padding: 3px 9px; font-size: 12px; font-weight: 600; text-decoration: none; color: var(--muted); border-radius: 5px; }
.seg-item.is-active { background: var(--bg); color: var(--fg); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

/* Layout */
.container { max-width: 1240px; margin: 0 auto; padding: 28px 24px 120px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-size: 13px; margin-bottom: 6px; }
.back-link:hover { color: var(--fg); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }
.grid-2-tight { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-5 { grid-template-columns: 1.1fr 1fr 1fr .8fr 1fr; }
.settings { display: flex; flex-direction: column; gap: 16px; max-width: 760px; }
.narrow { max-width: 640px; }

/* Card */
.card { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
.bill-form > .card { margin-bottom: 16px; }
.card-flush { padding: 0; overflow: hidden; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; letter-spacing: -.005em; }
.card-sub { margin: -8px 0 14px; font-size: 13px; }
.empty { text-align: center; padding: 48px 24px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty .btn { margin-top: 12px; }
.empty-icon { width: 44px; height: 44px; border-radius: 10px; background: var(--muted-bg); display: grid; place-items: center; color: var(--muted); margin-bottom: 4px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 500; }
.hint { font-size: 12px; color: var(--muted); }
.input { width: 100%; height: 36px; padding: 0 10px; font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--input); border-radius: 6px; box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; -webkit-appearance: none; appearance: none; }
textarea.input { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.45; }
select.input { padding-right: 30px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; }
.input:focus { outline: none; border-color: #a1a1aa; box-shadow: 0 0 0 3px var(--ring); }
.input::placeholder { color: #a1a1aa; }
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
.input.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(220, 38, 38, .12); }
.input-sm { height: 32px; padding: 0 8px; font-size: 13px; }
.input-file { height: auto; padding: 6px; }
.input-icon { position: relative; flex: 1; max-width: 420px; }
.input-icon .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.input-icon .input { padding-left: 34px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 16px; }
.form-row-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; font: inherit; font-weight: 500; white-space: nowrap; text-decoration: none; border: 1px solid transparent; border-radius: 6px; cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover { background: #27272a; }
.btn-outline { background: var(--bg); border-color: var(--input); box-shadow: var(--shadow); }
.btn-outline:hover { background: var(--muted-bg); }
.btn-ghost { background: transparent; color: var(--fg); }
.btn-ghost:hover { background: var(--muted-bg); }
.btn-danger-ghost { color: var(--muted); }
.btn-danger-ghost:hover { color: var(--danger); background: var(--danger-bg); }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 32px; height: 32px; padding: 0; }
.btn-block { width: 100%; }

/* Alerts */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); margin-bottom: 16px; }
.alert .icon { margin-top: 2px; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert-error { border-color: #fecaca; background: var(--danger-bg); color: #991b1b; }
.alert-success { border-color: #bbf7d0; background: var(--success-bg); color: #166534; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th { height: 40px; padding: 0 14px; text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--bg); white-space: nowrap; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--bg-subtle); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }
.actions { width: 1%; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }
.row-actions form { margin: 0; }
.link-strong { font-weight: 600; text-decoration: none; }
.link-strong:hover { text-decoration: underline; text-underline-offset: 3px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 16px; }

/* Line items */
.items { width: 100%; min-width: 1060px; border-collapse: separate; border-spacing: 0; }
.items th { font-size: 12px; font-weight: 500; color: var(--muted); text-align: left; padding: 0 4px 8px; white-space: nowrap; }
.items th.num { text-align: right; }
.items td { padding: 3px 4px; vertical-align: middle; }
.items tfoot td { padding-top: 12px; border-top: 1px solid var(--border); font-weight: 600; font-variant-numeric: tabular-nums; }
.items tfoot td.muted { font-weight: 500; }
.items .c-qty { width: 76px; }
.items .c-size { width: 132px; }
.items .c-grade { width: 96px; }
.items .c-proc { width: 92px; }
.items .c-pack { width: 132px; }
.items .c-weight { width: 100px; }
.items .c-price { width: 96px; }
.items .c-amount { width: 116px; }
.items .c-del { width: 36px; text-align: right; }
.items .amt { padding-right: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pack { display: flex; align-items: center; gap: 4px; }
.pack span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.pack .input { min-width: 0; }
.items-foot { display: flex; align-items: center; gap: 16px; margin-top: 12px; flex-wrap: wrap; }

/* Summary */
.summary { margin: 0; display: flex; flex-direction: column; }
.summary > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 0; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-variant-numeric: tabular-nums; }
.summary .sep { border-top: 1px dashed var(--border); }
.summary .total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 12px; }
.summary .total dt { color: var(--fg); font-weight: 600; }
.summary .total dd { font-size: 20px; font-weight: 600; letter-spacing: -.01em; }

/* Sticky action bar */
.form-actions { position: sticky; bottom: 0; z-index: 10; display: flex; flex-direction: row-reverse; justify-content: flex-start; gap: 8px; margin: 8px -24px 0; padding: 12px 24px; background: rgba(250, 250, 250, .9); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-top: 1px solid var(--border); }

/* Status lines */
.saved-note { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.saved-note .icon { color: var(--success); }
.status-list { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.status-list li { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; }
.status-list .icon { margin-top: 3px; color: var(--muted); }
.status-list .is-ok .icon { color: var(--success); }
.status-list .is-warn .icon { color: #b45309; }

/* Settings: logo */
.logo-preview { display: flex; align-items: center; justify-content: center; min-height: 96px; padding: 16px; border: 1px dashed var(--border); border-radius: var(--radius); background: var(--bg-subtle); margin-bottom: 14px; }
.logo-preview img { max-height: 72px; max-width: 100%; }
.logo-upload { display: flex; gap: 8px; align-items: center; }
.logo-upload .input-file { flex: 1; }
.logo-options { display: flex; gap: 8px; margin-top: 10px; }
.logo-options form { margin: 0; }

/* Auth pages */
.auth-body { min-height: 100vh; display: flex; flex-direction: column; }
.auth-top { display: flex; justify-content: flex-end; padding: 16px 20px; }
.auth-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0 20px 80px; gap: 20px; }
.auth-brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; }
.auth-card { width: 100%; max-width: 380px; padding: 28px; display: flex; flex-direction: column; gap: 6px; }
.auth-card form { margin-top: 14px; }
.auth-card .alert { margin: 10px 0 0; }

@media (max-width: 900px) {
  .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .container { padding: 20px 16px 120px; }
  .topbar-inner { padding: 0 16px; gap: 12px; }
  .brand span { display: none; }
  .hide-sm { display: none; }
  .nav-link { padding: 6px 8px; }
  .grid-2-tight { grid-template-columns: 1fr; }
  .form-actions { margin: 8px -16px 0; padding: 12px 16px; }
  .table td, .table th { padding-left: 10px; padding-right: 10px; }
  .logo-upload { flex-direction: column; align-items: stretch; }
}
@media print {
  .topbar, .form-actions { display: none; }
}
