@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --subtle: #f4f4f5;
  --line: #e4e4e7;
  --line-2: #d4d4d8;
  --ink: #09090b;
  --ink-2: #3f3f46;
  --muted: #71717a;
  --faint: #a1a1aa;
  --primary: #09090b;
  --on-primary: #fafafa;
  --focus: rgba(9, 9, 11, 0.1);
  --danger: #dc2626;
  --ok: #16a34a;

  --s-new: #d97706;
  --s-ready: #2563eb;
  --s-with_accountant: #7c3aed;
  --s-paid: #16a34a;

  --r: 10px;
  --r-lg: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.14), 0 2px 8px rgba(0, 0, 0, 0.06);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b;
    --panel: #111113;
    --subtle: #18181b;
    --line: #27272a;
    --line-2: #3f3f46;
    --ink: #fafafa;
    --ink-2: #d4d4d8;
    --muted: #a1a1aa;
    --faint: #71717a;
    --primary: #fafafa;
    --on-primary: #09090b;
    --focus: rgba(250, 250, 250, 0.14);
    --danger: #f87171;
    --ok: #4ade80;
    --s-new: #fbbf24;
    --s-ready: #60a5fa;
    --s-with_accountant: #a78bfa;
    --s-paid: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ── Top bar ───────────────────────────────────────────────────────── */

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 64px;
  padding: 0 24px;
  max-width: 1200px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; }
.brand .mark {
  width: 26px; height: 26px; border-radius: 8px;
  background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.brand .sub { color: var(--faint); font-weight: 500; }
.top .spacer { flex: 1; }

.me { position: relative; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--subtle); border: 1px solid var(--line);
  display: grid; place-items: center; overflow: hidden;
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
  min-width: 220px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.menu .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu .who b { display: block; font-weight: 600; }
.menu .who span { color: var(--muted); font-size: 12.5px; }
.menu button, .menu a {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 8px; font-size: 13.5px;
}
.menu button:hover, .menu a:hover { background: var(--subtle); }

/* ── Buttons & fields ──────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: 999px;
  font-size: 13.5px; font-weight: 500; white-space: nowrap;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.05s;
}
.btn:hover { border-color: var(--line-2); background: var(--subtle); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { opacity: 0.88; background: var(--primary); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--subtle); }
.btn.lg { height: 46px; font-size: 14.5px; font-weight: 600; }
.btn.block { width: 100%; }
.btn.icon { width: 36px; padding: 0; }
.btn.danger:hover { color: var(--danger); border-color: var(--danger); background: transparent; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.field > span em { font-style: normal; color: var(--faint); font-weight: 400; }

.input, select.input, textarea.input {
  width: 100%; height: 42px; padding: 0 13px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
textarea.input { height: auto; min-height: 84px; padding: 11px 13px; resize: vertical; line-height: 1.5; }
.input::placeholder { color: var(--faint); }
.input:hover { border-color: var(--line-2); }
.input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px var(--focus); }
.input:disabled, .input[readonly] { background: var(--subtle); color: var(--ink-2); }
select.input { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%2371717a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.input.sm { height: 36px; border-radius: 999px; padding: 0 14px; }
select.input.sm { padding-right: 32px; }

input[type='checkbox'] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

.error {
  font-size: 13px; color: var(--danger);
  padding: 10px 12px; border-radius: var(--r);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
}

/* ── Upload page ───────────────────────────────────────────────────── */

.upload {
  max-width: 460px;
  margin: 0 auto;
  padding: 7vh 20px 80px;
}
.upload h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.025em; margin-bottom: 24px; }
.upload form { display: grid; gap: 16px; }

.drop {
  position: relative;
  display: grid; place-items: center;
  min-height: 188px; padding: 24px;
  border: 1.5px dashed var(--line-2); border-radius: var(--r-lg);
  background: var(--panel);
  text-align: center; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop:hover, .drop.over { border-color: var(--ink); background: var(--subtle); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop .icon {
  width: 44px; height: 44px; margin: 0 auto 12px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--subtle); color: var(--ink-2);
}
.drop.over .icon { background: var(--panel); }
.drop b { display: block; font-weight: 600; font-size: 14.5px; }
.drop small { color: var(--muted); font-size: 13px; }
.drop.has-file { border-style: solid; border-color: var(--line); }
.file-chip { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; }
.file-chip .fi {
  width: 40px; height: 48px; flex-shrink: 0; border-radius: 8px;
  display: grid; place-items: center; font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
  background: var(--subtle); color: var(--ink-2); border: 1px solid var(--line);
}
.file-chip .meta { flex: 1; min-width: 0; }
.file-chip .meta b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-chip .meta small { display: block; }
.file-chip .x { position: relative; z-index: 2; }

.done { text-align: center; padding-top: 6vh; }
.done .tick {
  width: 56px; height: 56px; margin: 0 auto 18px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--primary); color: var(--on-primary);
  animation: pop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
.done h2 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.done p { color: var(--muted); margin: 6px 0 24px; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── Invoices list ─────────────────────────────────────────────────── */

.list { max-width: 1200px; margin: 0 auto; padding: 12px 24px 120px; }
.list-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 12px 0 22px; }
.list-head h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.025em; }
.unpaid { text-align: right; }
.unpaid .amt { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.unpaid small { display: block; color: var(--muted); font-size: 12.5px; }

.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.controls .grow { flex: 1; }

.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--subtle); border: 1px solid var(--line); border-radius: 999px;
  overflow-x: auto; max-width: 100%; scrollbar-width: none;
}
.seg button {
  height: 30px; padding: 0 12px; border-radius: 999px;
  font-size: 13px; font-weight: 500; color: var(--muted); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.seg .n { font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }

.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search .input { padding-left: 34px; width: 240px; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); cursor: pointer; user-select: none; }

.table { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.row {
  display: grid;
  grid-template-columns: var(--cols);
  gap: 16px; align-items: center;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.1s;
}
.row:first-child { border-top: 0; }
.row:hover { background: var(--subtle); }
.row.sel { background: color-mix(in srgb, var(--primary) 5%, transparent); }
.row.head { cursor: default; padding-top: 10px; padding-bottom: 10px; background: transparent; font-size: 12px; color: var(--faint); font-weight: 500; }
.row.head:hover { background: transparent; }
.table { --cols: minmax(0, 1.3fr) minmax(0, 1.5fr) 120px 150px 96px; }
.table.admin { --cols: 20px minmax(0, 1.3fr) minmax(0, 1.5fr) 120px 150px 96px; }
.cell { min-width: 0; }
.cell b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell small { display: block; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell .none { color: var(--faint); font-weight: 400; }
.cell.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.cell.when { color: var(--muted); font-size: 12.5px; text-align: right; }
.flag { color: var(--s-new) !important; }

.status { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--dot); box-shadow: 0 0 0 3px color-mix(in srgb, var(--dot) 18%, transparent); }
.status.new { --dot: var(--s-new); }
.status.ready { --dot: var(--s-ready); }
.status.with_accountant { --dot: var(--s-with_accountant); }
.status.paid { --dot: var(--s-paid); }

.empty { padding: 64px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-weight: 600; margin-bottom: 4px; }

.bulk {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  padding: 8px 8px 8px 18px; max-width: calc(100vw - 32px);
  background: var(--primary); color: var(--on-primary);
  border-radius: 999px; box-shadow: var(--shadow-lg);
  animation: rise 0.2s ease-out;
}
.bulk b { font-weight: 600; margin-right: 6px; }
.bulk .input { height: 34px; width: 150px; border-radius: 999px; background: transparent; color: var(--on-primary); border-color: color-mix(in srgb, var(--on-primary) 30%, transparent); color-scheme: dark; }
.bulk .btn { height: 34px; background: color-mix(in srgb, var(--on-primary) 12%, transparent); border-color: transparent; color: var(--on-primary); }
.bulk .btn:hover { background: color-mix(in srgb, var(--on-primary) 22%, transparent); }
@media (prefers-color-scheme: dark) { .bulk .input { color-scheme: light; } }
@keyframes rise { from { transform: translate(-50%, 12px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ── Invoice sheet ─────────────────────────────────────────────────── */

.scrim {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(9, 9, 11, 0.4);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade 0.15s ease-out;
}
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 61;
  width: min(1160px, 100vw);
  display: flex; flex-direction: column;
  background: var(--bg); box-shadow: var(--shadow-lg);
  animation: slide 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }

.sheet-head { display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.sheet-head .t { flex: 1; min-width: 0; }
.sheet-head .t small { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.sheet-head .t h2 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sheet-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(360px, 1fr); }
.preview { display: flex; flex-direction: column; min-height: 0; background: var(--subtle); border-right: 1px solid var(--line); }
.preview iframe { flex: 1; width: 100%; border: 0; }
.preview .img { flex: 1; overflow: auto; padding: 20px; }
.preview .img img { display: block; max-width: 100%; margin: 0 auto; border-radius: 8px; box-shadow: var(--shadow); }
.preview .nopreview { flex: 1; display: grid; place-items: center; padding: 32px; text-align: center; color: var(--muted); }
.preview-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--panel); }
.preview-bar .name { flex: 1; min-width: 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-bar .btn { height: 30px; font-size: 12.5px; }

.details { overflow-y: auto; padding: 22px 24px 48px; display: grid; gap: 26px; align-content: start; }
.block { display: grid; gap: 14px; }
.block h3 { font-size: 12px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; }
.by { font-size: 13px; color: var(--muted); margin-top: -6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.amount { display: grid; grid-template-columns: 88px 1fr; gap: 8px; }
.amount input { font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { overflow-wrap: anywhere; white-space: pre-wrap; }
.save-row {
  position: sticky; bottom: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 0; margin: -12px 0; background: var(--bg);
  border-top: 1px solid var(--line);
}
.warn { font-size: 13px; padding: 10px 12px; border-radius: var(--r); color: var(--s-new); background: color-mix(in srgb, var(--s-new) 10%, transparent); }

.tick-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
.tick-row label { font-weight: 500; cursor: pointer; }
.tick-row .input { height: 34px; width: 150px; }
.tick-row .audit { grid-column: 2 / -1; margin-top: -6px; font-size: 12px; color: var(--muted); }
.tick-row .date-ro { color: var(--muted); font-variant-numeric: tabular-nums; }

details.history summary { cursor: pointer; font-size: 12px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; list-style: none; }
details.history summary::-webkit-details-marker { display: none; }
details.history summary::after { content: ' +'; }
details.history[open] summary::after { content: ' −'; }
details.history ol { list-style: none; margin-top: 12px; display: grid; gap: 10px; font-size: 13px; }
details.history li { display: grid; grid-template-columns: 120px 1fr; gap: 12px; }
details.history time { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
details.history .chg { color: var(--muted); font-size: 12px; margin-top: 2px; overflow-wrap: anywhere; }

/* ── Dialog ────────────────────────────────────────────────────────── */

dialog {
  margin: auto; width: min(420px, calc(100vw - 32px));
  padding: 22px; border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--panel); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(9, 9, 11, 0.4); backdrop-filter: blur(3px); }
dialog h2 { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
dialog p { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ── Sign in ───────────────────────────────────────────────────────── */

.signin { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.signin .box { width: 100%; max-width: 380px; text-align: center; }
.signin .mark { width: 44px; height: 44px; border-radius: 12px; margin: 0 auto 22px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-weight: 700; font-size: 20px; }
.signin h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.signin p { color: var(--muted); margin: 6px 0 26px; }
.signin .btn { width: 100%; height: 44px; }
.signin .error { margin-top: 16px; text-align: left; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80;
  padding: 10px 16px; border-radius: 999px;
  background: var(--primary); color: var(--on-primary); font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-lg); animation: rise 0.2s ease-out;
}

/* ── Small screens ─────────────────────────────────────────────────── */

@media (max-width: 860px) {
  .sheet-body { display: block; overflow-y: auto; }
  .preview { height: 62vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .details { overflow: visible; }
}

@media (max-width: 720px) {
  .top { padding: 0 16px; }
  .list { padding: 4px 16px 120px; }
  .controls .grow { display: none; }
  .list-head { margin-bottom: 16px; }
  .unpaid { text-align: left; width: 100%; }
  .seg { width: 100%; }
  .search { flex: 1 1 100%; }
  .search .input { width: 100%; }
  .controls #category { flex: 1; }
  .table, .table.admin { --cols: minmax(0, 1fr) auto; }
  .table.admin .row > :first-child { display: none; }
  .row { padding: 14px 16px; gap: 10px; }
  .row.head { display: none; }
  .row .c-what, .row .c-when { display: none; }
  .row .c-status { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; }
  .row .c-status small { display: inline; }
  .grid2 { grid-template-columns: 1fr; }
  .details { padding: 20px 16px 48px; }
  .kv { grid-template-columns: 110px 1fr; }
  .sheet-head { padding: 12px 16px; }
}
