:root {
  --bg: #121214;
  --surface: #1c1c20;
  --surface-2: #26262b;
  --line: #34343a;
  --text: #f2f1ee;
  --muted: #a3a29c;
  --gold: #cfb87c;
  --gold-ink: #121214;
  --danger: #ff7a6b;
  --ok: #7fd18b;
  --warn: #f2c66d;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(76px + var(--safe-b));
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold); }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: rgba(18, 18, 20, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .2px; }
.brand img { width: 26px; height: 26px; border-radius: 7px; }
.icon-btn { background: none; border: 0; font-size: 22px; padding: 6px 8px; cursor: pointer; color: var(--muted); }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 22px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.card + .card { margin-top: 10px; }
.card.tap { cursor: pointer; }
.card.tap:active { background: var(--surface-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 12px; padding: 10px 14px; cursor: pointer; min-height: 44px;
  text-decoration: none;
}
.btn.primary { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); font-weight: 650; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 14px; }

.dropzone {
  border: 2px dashed var(--line); border-radius: 18px;
  padding: 34px 16px; text-align: center; background: var(--surface);
}
.dropzone.drag { border-color: var(--gold); }
.big-add {
  width: 100%; min-height: 64px; font-size: 18px;
}

label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { background: var(--bg); border: 0; padding: 9px 14px; cursor: pointer; min-height: 40px; }
.seg button.on { background: var(--gold); color: var(--gold-ink); font-weight: 650; }

.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.pill.warn { color: var(--warn); border-color: rgba(242,198,109,.4); }
.pill.ok { color: var(--ok); border-color: rgba(127,209,139,.4); }
.pill.bad { color: var(--danger); border-color: rgba(255,122,107,.4); }
.pill.gold { color: var(--gold); border-color: rgba(207,184,124,.5); }

.amount { font-variant-numeric: tabular-nums; font-weight: 650; }
.line-item { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.line-item:first-child { border-top: 0; }
.line-item .meta { min-width: 0; }
.line-item .meta div { overflow: hidden; text-overflow: ellipsis; }

.preview { width: 100%; max-height: 52vh; object-fit: contain; background: #000; border-radius: 12px; }
.missing { color: var(--warn); font-size: 14px; }

.copy-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; padding: 10px 0; border-top: 1px solid var(--line); }
.copy-row:first-child { border-top: 0; }
.copy-row .k { font-size: 12px; color: var(--muted); }
.copy-row .v { white-space: pre-wrap; word-break: break-word; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(28, 28, 32, 0.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab { position: relative; background: none; border: 0; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 12px; cursor: pointer; }
.tab .tab-ico { font-size: 20px; line-height: 1.2; }
.tab.active { color: var(--gold); }
[hidden] { display: none !important; }
.badge { position: absolute; top: 4px; left: calc(50% + 8px); background: var(--danger); color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(88px + var(--safe-b)); z-index: 10;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; max-width: calc(100% - 32px); box-shadow: 0 8px 30px rgba(0,0,0,.4);
}

.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--gold); }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
