:root {
  --bg: #f4f6f8; --card: #fff; --ink: #1c2733; --muted: #66758a; --line: #dfe5ec;
  --brand: #0f6e84; --brand-ink: #fff; --brand-soft: #e3f2f5; --ok: #1d7a46; --warn: #b26a00; --bad: #b3261e;
  --side: #14303b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", "Heebo", Arial, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* layout */
.shell { display: flex; min-height: 100vh; }
.side { width: 210px; background: var(--side); color: #cfe0e6; padding: 18px 12px; flex-shrink: 0; display: flex; flex-direction: column; gap: 4px; }
.side .logo { color: #fff; font-weight: 700; font-size: 17px; padding: 4px 10px 16px; }
.side a { color: inherit; padding: 9px 12px; border-radius: 8px; display: block; }
.side a:hover { background: rgba(255,255,255,.08); }
.side a.on { background: var(--brand); color: #fff; }
.side .sp { flex: 1; }
.main { flex: 1; padding: 24px 28px 60px; min-width: 0; max-width: 1200px; }
.bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.bar h1 { margin: 0; flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat .val { font-size: 22px; font-weight: 700; margin-top: 4px; }
.pos { color: var(--ok); } .neg { color: var(--bad); }

/* controls */
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; display: inline-block; }
button:hover, .btn:hover { border-color: var(--brand); }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; color: var(--brand); padding: 2px 4px; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input[type=checkbox] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.f { margin-bottom: 12px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a, .tabs button { padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line); background: #fff; color: var(--ink); }
.tabs .on { background: var(--brand); color: #fff; border-color: var(--brand); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.filters > * { width: auto; }

/* tables */
.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: right; font-size: 13px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--brand-soft); }
td.n, th.n { text-align: left; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
.pill { font-size: 12px; padding: 2px 9px; border-radius: 99px; background: #eef1f4; color: var(--muted); white-space: nowrap; }
.pill.ok { background: #e1f4e8; color: var(--ok); } .pill.warn { background: #fdf0d9; color: var(--warn); } .pill.bad { background: #fde5e3; color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.note { background: #fdf6e3; border: 1px solid #ecd9a0; border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }

/* doc form */
.items input { padding: 6px 8px; }
.items td { padding: 4px; border: 0; }
.items .c-qty { width: 90px; } .items .c-price { width: 130px; } .items .c-tot { width: 120px; text-align: left; padding-top: 10px; } .items .c-x { width: 36px; }
.totals { margin-inline-start: auto; width: 300px; max-width: 100%; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .big { font-size: 18px; font-weight: 700; border-top: 2px solid var(--line); margin-top: 4px; padding-top: 8px; }

/* chart */
.chart { display: flex; align-items: flex-end; gap: 8px; height: 170px; padding-top: 10px; }
.chart .m { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.chart .bars { display: flex; align-items: flex-end; gap: 2px; height: 100%; width: 100%; justify-content: center; }
.chart .b { width: 42%; max-width: 18px; border-radius: 3px 3px 0 0; min-height: 1px; }
.chart .b.i { background: var(--brand); } .chart .b.e { background: #e0a23a; }
.chart .l { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: 5px; }

/* paper */
.paper { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 38px 42px; max-width: 800px; margin: 0 auto; box-shadow: 0 2px 10px rgba(0,0,0,.05); }
.paper .head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--ink); padding-bottom: 14px; margin-bottom: 18px; }
.paper .head img { max-height: 80px; max-width: 200px; }
.paper .biz { font-size: 20px; font-weight: 700; }
.paper .title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 16px; }
.paper .title b { font-size: 21px; }
.paper .copy { border: 1px solid var(--ink); padding: 1px 10px; border-radius: 4px; font-size: 13px; margin-inline-start: 10px; }
.paper .to { margin-bottom: 16px; }
.paper table th { background: #f1f4f7; color: var(--ink); }
.paper .foot { margin-top: 26px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); white-space: pre-wrap; }
.paper .cancelled { color: var(--bad); border: 2px solid var(--bad); display: inline-block; padding: 2px 14px; font-weight: 700; transform: rotate(-4deg); }
.pre { white-space: pre-wrap; }

/* login */
.login { max-width: 380px; margin: 9vh auto; padding: 0 16px; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; margin: 6px 0; }

/* modal + toast */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(640px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); color: var(--ink); }
dialog::backdrop { background: rgba(20,30,40,.45); }
dialog form { padding: 20px 22px; }
dialog .actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 14px; }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 99; max-width: 90vw; }
#toast.on { opacity: 1; }
#toast.bad { background: var(--bad); }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .side { width: auto; flex-direction: row; flex-wrap: wrap; padding: 8px; }
  .side .logo, .side .sp { display: none; }
  .side a { padding: 7px 10px; }
  .main { padding: 16px 14px 60px; }
  .paper { padding: 20px 16px; }
}
@media print {
  body { background: #fff; }
  .side, .noprint, #toast { display: none !important; }
  .main { padding: 0; max-width: none; }
  .paper { border: 0; box-shadow: none; max-width: none; padding: 0; }
  @page { size: A4; margin: 16mm 14mm; }
}
