:root {
  --bg: #E9EDF1;
  --paper: #FFFFFF;
  --ink: #1B2430;
  --muted: #637081;
  --line: #D6DDE5;
  --accent: #0E7A4F;
  --accent-ink: #FFFFFF;
  --due: #B4441C;
  --void: #8A93A0;
  --tape: #FFFFFF;
  --shadow: 0 1px 0 rgba(27, 36, 48, .06), 0 8px 24px -12px rgba(27, 36, 48, .25);
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161B; --paper: #1B2129; --ink: #E7ECF1; --muted: #93A0AF; --line: #2C3540;
    --accent: #3FBF86; --accent-ink: #0B1F16; --due: #F08A5D; --void: #6B7684; --tape: #20262F;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 var(--sans); font-variant-numeric: tabular-nums;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { max-width: 720px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px 0; }

header.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
header.top h1 { font-size: 26px; line-height: 1.15; margin: 0; font-weight: 700; letter-spacing: -.3px; }
header.top .sub { color: var(--muted); font-size: 14px; }

h2 { font-size: 17px; margin: 28px 0 10px; font-weight: 600; }

/* --- кассовая лента: главный элемент --- */
.tape {
  position: relative; background: var(--tape); padding: 22px 22px 30px; margin: 0 2px 8px;
  box-shadow: var(--shadow); font-family: var(--mono);
  -webkit-mask: radial-gradient(circle at 6px 100%, transparent 6px, #000 6.5px) 0 0 / 12px 100% repeat-x,
                linear-gradient(#000, #000) 0 0 / 100% calc(100% - 6px) no-repeat;
          mask: radial-gradient(circle at 6px 100%, transparent 6px, #000 6.5px) 0 0 / 12px 100% repeat-x,
                linear-gradient(#000, #000) 0 0 / 100% calc(100% - 6px) no-repeat;
}
.tape .period { display: flex; justify-content: space-between; align-items: center; font-size: 14px; color: var(--muted); }
.tape .period button { border: 0; background: none; padding: 6px 10px; cursor: pointer; color: var(--ink); font-size: 18px; border-radius: 8px; }
.tape .period button:hover { background: var(--bg); }
.tape .period strong { color: var(--ink); font-weight: 600; text-transform: none; }
.tape .income { display: flex; flex-direction: column; align-items: flex-start; margin-top: 14px; padding-bottom: 12px; border-bottom: 1px dashed var(--muted); }
.tape .income .label { font-size: 15px; color: var(--muted); }
.tape .income .value { font-size: 38px; font-weight: 700; letter-spacing: -1px; line-height: 1.15; color: var(--ink); overflow-wrap: anywhere; }
.tape .income .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.tape .rows { margin-top: 12px; }
.tape .row { display: flex; align-items: baseline; gap: 8px; font-size: 15px; padding: 3px 0; }
.tape .row::after { content: ""; order: 1; flex: 1; border-bottom: 1px dotted var(--line); transform: translateY(-4px); }
.tape .row span:last-child { order: 2; }
.tape .row.minus span:last-child::before { content: "− "; }
.tape .total { border-top: 1px dashed var(--muted); margin-top: 12px; padding-top: 12px; display: flex; justify-content: space-between; align-items: baseline; }
.tape .total .label { font-size: 15px; }
.tape .total .value { font-size: 22px; font-weight: 600; letter-spacing: -.5px; color: var(--accent); }
.tape .total .value.neg { color: var(--due); }
.tape .foot { font-size: 12px; color: var(--muted); margin-top: 6px; text-align: right; }

.period-kind { display: flex; gap: 6px; margin: 0 0 12px; }

/* --- списки --- */
.list { background: var(--paper); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; cursor: pointer; background: none; width: 100%; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.item:last-child { border-bottom: 0; }
.item:hover { background: color-mix(in srgb, var(--bg) 50%, transparent); }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amount { font-weight: 600; white-space: nowrap; }
.item.void .title, .item.void .amount { color: var(--void); text-decoration: line-through; }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); }
.empty .btn { margin-top: 12px; }

.status { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; border: 1px solid currentColor; }
.status.new, .status.sent { color: var(--due); }
.status.paid { color: var(--accent); }
.status.cancelled { color: var(--void); }

/* --- столбики по статьям --- */
.bars { background: var(--paper); border-radius: 14px; box-shadow: var(--shadow); padding: 8px 16px; }
.bar { padding: 8px 0; }
.bar .lbl { display: flex; justify-content: space-between; font-size: 14px; gap: 12px; }
.bar .track { height: 6px; background: var(--bg); border-radius: 3px; margin-top: 5px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--ink); opacity: .75; border-radius: 3px; }

.year { background: var(--paper); border-radius: 14px; box-shadow: var(--shadow); padding: 14px 12px 8px; }
.year svg { width: 100%; height: 150px; display: block; }
.year .legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); padding: 4px 4px 0; }
.year .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

table.clients { width: 100%; border-collapse: collapse; font-size: 14px; }
table.clients th { text-align: right; font-weight: 500; color: var(--muted); font-size: 12px; padding: 10px 6px 6px; }
table.clients th:first-child, table.clients td:first-child { text-align: left; padding-left: 16px; }
table.clients td { text-align: right; padding: 9px 6px; border-top: 1px solid var(--line); white-space: nowrap; }
table.clients td:last-child, table.clients th:last-child { padding-right: 16px; }
table.clients td:first-child { white-space: normal; }
.wrap-x { overflow-x: auto; }

/* --- кнопки и поля --- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--paper); border-radius: 12px; padding: 10px 14px; cursor: pointer; font-weight: 500; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--due); }
.btn.block { width: 100%; padding: 13px; }
.btn:disabled { opacity: .5; cursor: progress; }
.chip { border: 1px solid var(--line); background: var(--paper); border-radius: 99px; padding: 6px 12px; cursor: pointer; font-size: 14px; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 0; }
.actions .btn { flex-direction: column; padding: 12px 6px; font-size: 14px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

label.f { display: block; margin: 0 0 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; }
select { max-width: 100%; text-overflow: ellipsis; }
textarea { min-height: 70px; resize: vertical; }
input.big { font-size: 28px; font-weight: 600; padding: 10px 12px; }
input.bad { border-color: var(--due); box-shadow: 0 0 0 1px var(--due); outline-color: var(--due); }
/* minmax(0,…): длинное название клиента в select не распирает колонку на телефоне */
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.hint { font-size: 13px; color: var(--muted); margin: -4px 0 12px; }
label.f .hint { margin: 6px 0 0; }

.itemrow { display: grid; grid-template-columns: 1fr 64px 120px 36px; gap: 6px; margin-bottom: 10px; }
@media (max-width: 560px) {
  /* на телефоне: название на всю ширину, ниже количество × цена */
  .itemrow { grid-template-columns: 70px 1fr 36px; padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
  .itemrow > input:first-child { grid-column: 1 / -1; }
}
.itemrow button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 20px; }
.itemrow-head { display: grid; grid-template-columns: 1fr 64px 110px 36px; gap: 6px; font-size: 12px; color: var(--muted); }

.card { background: var(--paper); border-radius: 14px; box-shadow: var(--shadow); padding: 16px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.big-sum { font-size: 34px; font-weight: 700; letter-spacing: -.6px; margin: 4px 0 8px; }

.banner { background: var(--paper); border-left: 3px solid var(--due); padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; box-shadow: var(--shadow); font-size: 15px; }
.banner a { font-weight: 600; }

/* --- нижняя панель --- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs[hidden] { display: none; }
#tabs a { flex: 1; max-width: 140px; height: var(--tabs-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--muted); font-size: 11px; }
#tabs a.on { color: var(--accent); }
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }

/* --- нижний лист --- */
dialog#sheet { border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px; max-height: 92vh; background: var(--paper); color: var(--ink); border-radius: 18px 18px 0 0; box-shadow: 0 -10px 40px rgba(0, 0, 0, .3); }
dialog#sheet::backdrop { background: rgba(10, 14, 20, .45); }
dialog#sheet[open] { animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
.sheet-inner { padding: 10px 18px calc(22px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 92vh; }
.sheet-inner .grab { width: 40px; height: 4px; background: var(--line); border-radius: 2px; margin: 0 auto 12px; }
.sheet-inner h3 { margin: 0 0 14px; font-size: 20px; }
@media (min-width: 700px) {
  dialog#sheet { margin: auto; border-radius: 18px; }
}

/* тост переносится внутрь открытого листа (top layer), поэтому по центру через left/right + margin, без translateX */
#toast { position: fixed; left: 16px; right: 16px; width: fit-content; max-width: 560px; margin: 0 auto; bottom: calc(var(--tabs-h) + 18px + env(safe-area-inset-bottom)); transform: translateY(20px); background: var(--ink); color: var(--paper); padding: 11px 16px; border-radius: 12px; font-size: 15px; line-height: 1.4; white-space: pre-line; overflow-wrap: anywhere; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; }
#toast.show { opacity: 1; transform: none; }
#toast.err { background: var(--due); color: #fff; }

.login { max-width: 360px; margin: 18vh auto 0; }
.login h1 { font-size: 30px; margin: 0 0 4px; }
.login p { color: var(--muted); margin: 0 0 20px; }

.seg { display: flex; background: var(--paper); border-radius: 10px; padding: 3px; box-shadow: var(--shadow); margin-bottom: 14px; }
.seg button { flex: 1 1 auto; text-align: center; border: 0; background: none; padding: 7px 8px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* --- эргономика --- */
.btn.hero { font-size: 17px; padding: 16px; border-radius: 14px; margin: 0 0 8px; box-shadow: var(--shadow); }
.actions.two { grid-template-columns: 1fr 1fr; margin: 0 0 16px; }
.actions.two .btn { flex-direction: row; padding: 12px; font-size: 15px; }
.btn.primary-outline { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.linklike { display: inline; text-align: left; border: 0; background: none; padding: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; }

.alert { display: flex; flex-direction: column; gap: 2px; background: var(--paper); border-left: 3px solid var(--accent); padding: 12px 14px; border-radius: 10px; margin: 0 0 12px; box-shadow: var(--shadow); color: var(--ink); text-decoration: none; font-size: 15px; }
.alert span { color: var(--muted); font-size: 14px; }
.alert.due { border-left-color: var(--due); }
.alert.due b { color: var(--due); }
.status.overdue { color: #fff; background: var(--due); border-color: var(--due); }

.onboarding { margin-bottom: 14px; }
.steps { margin: 10px 0 0; padding-left: 22px; }
.steps li { padding: 6px 0; }
.steps li a, .steps li .linklike { font-weight: 600; }
.steps li.done { color: var(--muted); text-decoration: line-through; }
.steps li.done::marker { content: "✓  "; color: var(--accent); }

.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: -4px -18px 14px; padding: 0 18px 4px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chips.scroll .chip { white-space: nowrap; }
.flabel { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.more-opts { margin: 4px 0 14px; }
.more-opts summary { cursor: pointer; color: var(--accent); font-size: 15px; padding: 6px 0; }
.more-opts[open] summary { margin-bottom: 10px; }

.limit .lbl { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.limit .track { height: 8px; background: var(--bg); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.limit .fill { height: 100%; background: var(--accent); border-radius: 4px; }
.limit .fill.warn { background: var(--due); }

input.search { margin: 0 0 10px; }
.item[hidden] { display: none; }

.receipt-done { text-align: center; padding: 6px 0 16px; }
.receipt-done .big-sum { color: var(--accent); }
.receipt-done a { display: inline-block; margin-top: 8px; }

.login .hero { margin-bottom: 14px; }
.seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; } .seg button { white-space: nowrap; }

/* Блокировка: пока приложение не на экране, содержимое скрыто */
body.veiled #app, body.veiled #tabs, body.veiled dialog { visibility: hidden; }
