:root {
  color-scheme: light;
  --ink: #1f2328;
  --muted: #5d6570;
  --line: #d0d5dc;
  --surface: #ffffff;
  --page: #f4f5f7;
  --header: #a4c2f4;
  --section: #b3cefb;
  --selector: #d3f1db;
  --computed: #e7e8ea;
  --accent: #1a5fb4;
  --series-bar: #2a78d6;
  --series-line: #eb6834;
  font: 13px/1.4 Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--page);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1 { font-size: 16px; margin: 0; }
h2 { font-size: 13px; margin: 18px 0 8px; }
button, .button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface);
  cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .button:hover { border-color: #8f98a5; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { display: grid; gap: 12px; width: min(340px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 24px; }
.login p { margin: 0; color: var(--muted); }
.login label { display: grid; gap: 4px; }
.login input { padding: 7px 8px; border: 1px solid var(--line); border-radius: 4px; }
.login button { background: var(--accent); border-color: var(--accent); color: #fff; padding: 8px; }
.error { color: #a4161a !important; min-height: 1em; }

.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar h1 { margin-right: auto; }
.sync { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 2px; padding: 8px 16px 0; overflow-x: auto; background: var(--surface); border-bottom: 1px solid var(--line); }
.tabs button { border: 1px solid transparent; border-bottom: 0; border-radius: 4px 4px 0 0; background: transparent; white-space: nowrap; }
.tabs button.active { background: var(--header); border-color: var(--line); font-weight: 700; }
.view { padding: 14px 16px 48px; }

.legend-row { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.legend-title { font-weight: 700; background: var(--header); padding: 2px 8px; border: 1px solid #000; }
.chip { padding: 2px 8px; border: 1px solid #000; }
.note-field { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-weight: 700; }
.note-field input { flex: 1; max-width: 640px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 3px; }
.hint { color: var(--muted); margin: 0 0 10px; }

.type-inventory { background: #fe98e8; }
.type-buy { background: #a6e4b7; }
.type-sell { background: #f7b4ae; }
.type-revenue { background: #90d7dd; }
.type-transfer { background: #fde49b; }
.type-asset { background: #00b0f0; }
.type-cinventory { background: #f002bd; }
.type-deposit { background: #7ad693; }

.grid-block { margin-bottom: 8px; }
.grid-scroll { overflow: auto; max-height: calc(100vh - 210px); border: 1px solid #000; background: var(--surface); max-width: 100%; }
table.grid { border-collapse: separate; border-spacing: 0; white-space: nowrap; width: max-content; min-width: 100%; }
.grid th, .grid td { border-right: 1px solid #000; border-bottom: 1px solid #000; padding: 2px 6px; height: 24px; text-align: left; font-weight: 400; }
.grid th { background: var(--header); font-weight: 700; position: sticky; top: 0; z-index: 2; }
.grid .filters th { top: 25px; padding: 1px; font-weight: 400; }
.grid .filters input { width: 100%; min-width: 56px; padding: 1px 4px; border: 1px solid var(--line); background: #fff; }
.grid .no { position: sticky; left: 0; background: var(--surface); z-index: 1; text-align: right; color: var(--muted); }
.grid th.no { background: var(--header); z-index: 3; color: var(--ink); text-align: left; }
.grid td.kind-number, .grid th.kind-number { text-align: right; }
.grid td.computed { background: var(--computed); }
.grid th.computed { background: #c7d0dd; }
.grid td.blocked { background: #000; }
.grid td.below-target { background: #ffc7ce; color: #9c0006; }
.grid td.editable { cursor: cell; }
.grid td.editable:hover { box-shadow: inset 0 0 0 1px var(--accent); }
.grid td.editing { padding: 0; }
.grid td.editing input, .grid td.editing select { width: 100%; min-width: 96px; height: 23px; border: 0; outline: 2px solid var(--accent); padding: 0 5px; text-align: inherit; background: #fff; }
.clip { display: inline-block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.sheet-main .clip, .sheet-example .clip { max-width: 170px; }
.sheet-accounts .clip, .sheet-hedging .clip { max-width: none; }
.link-cell { display: inline-flex; gap: 6px; align-items: baseline; }
.link-cell a { color: #1155cc; }
.link-cell .clip { max-width: 110px; color: var(--muted); }
.row-actions { width: 28px; padding: 0 !important; text-align: center !important; background: var(--surface) !important; }
.icon { border: 0; background: none; padding: 0 6px; font-size: 15px; color: var(--muted); line-height: 1; }
.icon:hover { color: #a4161a; }
.add-row { margin-top: 6px; }
.empty { text-align: center !important; color: var(--muted); padding: 16px !important; }

.controls { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.field { display: inline-flex; align-items: stretch; }
.field span { background: var(--section); border: 1px solid #000; border-right: 0; padding: 3px 8px; font-weight: 700; }
.field select, .field input { background: var(--selector); border: 1px solid #000; padding: 3px 6px; text-align: center; min-width: 90px; width: 100px; }
.field input { background: #fff; }

.split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
.split.wide-right { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
.split.wide-left { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
table.plain { border-collapse: collapse; background: var(--surface); width: 100%; }
.plain th, .plain td { border: 1px solid #000; padding: 3px 7px; text-align: left; vertical-align: top; }
.plain th { background: var(--section); }
.plain td.num { text-align: right; white-space: nowrap; }
.equation { font-weight: 700; margin: 0 0 8px; }
.history .change { max-width: 460px; overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
textarea { width: 100%; max-width: 1000px; padding: 8px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); }

.chart { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 12px; }
.chart figcaption { font-weight: 700; margin-bottom: 6px; }
.legend { display: flex; gap: 14px; color: var(--muted); margin-bottom: 6px; }
.legend-key { display: inline-block; margin-right: 5px; vertical-align: middle; }
.legend-key.bar { width: 10px; height: 10px; background: var(--series-bar); border-radius: 2px; }
.legend-key.line { width: 14px; height: 2px; background: var(--series-line); }
.plot { position: relative; }
.plot svg { display: block; width: 100%; height: auto; }
.tick { fill: var(--muted); font-size: 11px; }
.grid-line, line.grid { stroke: #eceef1; }
line.axis { stroke: #aab1bb; }
.bar { fill: var(--series-bar); }
.trend { fill: none; stroke: var(--series-line); stroke-width: 2; }
.marker { fill: var(--series-line); stroke: var(--surface); stroke-width: 2; }
.crosshair { stroke: #8f98a5; stroke-dasharray: 3 3; pointer-events: none; }
.tooltip { position: absolute; top: 8px; transform: translateX(10px); background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; pointer-events: none; box-shadow: 0 2px 8px rgba(0, 0, 0, .12); min-width: 170px; }
.tooltip.flip { transform: translateX(calc(-100% - 10px)); }
.tooltip div { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); margin-top: 3px; }
.tooltip b { color: var(--ink); }
.share { display: grid; grid-template-columns: minmax(0, 200px) minmax(40px, 1fr) 62px; gap: 7px 8px; align-items: center; }
.share span:first-child, .share > span:not(.share-track) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-track { display: block; height: 12px; }
.share-track i { display: block; height: 100%; background: var(--series-bar); border-radius: 0 3px 3px 0; }
.share b { text-align: right; font-weight: 400; }

.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: #1f2328; color: #fff; padding: 8px 14px; border-radius: 5px; display: flex; gap: 12px; align-items: center; z-index: 10; max-width: calc(100vw - 32px); }
.toast button { background: none; border: 1px solid #fff; color: #fff; padding: 2px 8px; }

@media (max-width: 860px) {
  .split, .split.wide-left, .split.wide-right, .charts { grid-template-columns: minmax(0, 1fr); }
  .grid-scroll { max-height: calc(100vh - 170px); }
  .topbar h1 { font-size: 14px; width: 100%; }
  .view { padding: 10px 8px 40px; }
}
