:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #1d2330; --muted: #667085; --line: #e3e6eb;
  --accent: #1f6feb; --accent-ink: #fff; --accent-soft: #e8f0fe;
  --ok: #1a7f37; --ok-soft: #e6f4ea; --warn: #b35900; --warn-soft: #fff1e0;
  --bad: #c62828; --bad-soft: #fdecea; --wr: #6f42c1; --wr-soft: #f1ebfb;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }

/* top bar */
.topbar { background: #14213d; color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar .in { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 4px; min-height: 52px; flex-wrap: wrap; }
.topbar a { color: #dfe6f3; padding: 8px 10px; border-radius: 6px; }
.topbar a:hover, .topbar a.on { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.topbar .brand { font-weight: 700; color: #fff; margin-right: 12px; }
.topbar .sp { flex: 1; }
.topbar form { margin: 0; }
.topbar .lookup input { width: 150px; padding: 6px 8px; border-radius: 6px; border: 0; }
.bell { position: relative; }
.bell .n { position: absolute; top: 0; right: 0; background: var(--bad); color: #fff; font-size: 11px; border-radius: 9px; padding: 0 5px; line-height: 16px; }
.menu-toggle { display: none; background: none; border: 0; color: #fff; font-size: 22px; padding: 6px 10px; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.panel > h2:first-child { margin-top: 0; }
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.cols > * { min-width: 0; }

/* alerts */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; border: 1px solid; }
.alert.ok { background: var(--ok-soft); border-color: #b7dfc2; color: #12522a; }
.alert.err { background: var(--bad-soft); border-color: #f3b8b3; color: #8a1c1c; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* tables */
.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: #fafbfc; white-space: nowrap; }
tr.overdue td { background: #fff7f5; }
td.num, th.num { text-align: right; white-space: nowrap; }
table.kv th { width: 38%; background: none; white-space: normal; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-main { background: var(--accent-soft); color: #1550b8; }
.b-branch { background: #eef0f3; color: #3d4656; }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-wr { background: var(--wr-soft); color: var(--wr); }
.b-done { background: var(--ok-soft); color: var(--ok); }
.b-cancel { background: #f0f0f0; color: #777; text-decoration: line-through; }
.tag { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; background: #eef0f3; color: #3d4656; }
.tag.urgent { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.due { font-size: 12px; color: var(--muted); white-space: nowrap; }
.due.over { color: var(--bad); font-weight: 600; }

/* forms */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
label .muted { font-weight: 400; }
input[type=text], input[type=number], input[type=date], input[type=datetime-local], input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cfd4dc; border-radius: 6px; font: inherit; background: #fff; color: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
input[type=file] { font-size: 13px; max-width: 100%; }
.field { margin-bottom: 12px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 12px; }
.check { display: flex; gap: 6px; align-items: center; font-weight: 400; }
.check input { width: auto; }
.err-text { color: var(--bad); font-size: 12px; margin-top: 2px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px; border: 1px solid #cfd4dc; background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: #f3f5f8; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #195ccc; }
.btn.danger { color: var(--bad); border-color: #f0b4ae; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .6; cursor: wait; }

/* action panel */
.actions { display: flex; flex-direction: column; gap: 8px; }
.action { border: 1px solid var(--line); border-radius: var(--radius); }
.action > summary { list-style: none; cursor: pointer; padding: 10px 12px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.action > summary::-webkit-details-marker { display: none; }
.action > summary::after { content: "▾"; color: var(--muted); }
.action[open] > summary { border-bottom: 1px solid var(--line); background: #fafbfc; }
.action[open] > summary::after { content: "▴"; }
.action .body { padding: 12px; }
.action.primary > summary { color: #1550b8; }
.action.danger > summary { color: var(--bad); }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--line); position: relative; margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline li.plain::before { background: #c4cad4; }

/* gallery */
.gallery { display: flex; flex-wrap: wrap; gap: 8px; }
.gallery a { display: block; width: 96px; text-align: center; font-size: 11px; color: var(--muted); }
.gallery img { width: 96px; height: 96px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
.gallery .file { width: 96px; height: 96px; border-radius: 6px; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--muted); background: #fafbfc; }

/* lines editor */
.lines td { padding: 4px; }
.lines input, .lines select { padding: 6px; }
.lines .w-qty { width: 90px; } .lines .w-unit { width: 70px; } .lines .w-money { width: 120px; } .lines .w-vat { width: 64px; }

.stat { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat .box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .v { font-size: 22px; font-weight: 700; }

.pager { display: flex; gap: 4px; margin-top: 12px; flex-wrap: wrap; }
.pager a, .pager span { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.pager .on { background: var(--accent); color: #fff; border-color: var(--accent); }

.login { max-width: 360px; margin: 10vh auto; }

@media (max-width: 900px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
  .cols .side { order: -1; }
}
@media (max-width: 760px) {
  .menu-toggle { display: block; }
  .topbar .nav { display: none; width: 100%; flex-direction: column; padding-bottom: 8px; }
  .topbar .nav.open { display: flex; }
  .topbar .sp { display: none; }
  .wrap { padding: 12px; }
  .panel { padding: 12px; }
  table.cards thead { display: none; }
  table.cards tr { display: block; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; background: #fff; }
  table.cards td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 10px; }
  table.cards td::before { content: attr(data-l); color: var(--muted); font-size: 12px; }
}
@media print {
  .topbar, .no-print { display: none !important; }
  body { background: #fff; }
  .panel { border: 0; box-shadow: none; padding: 0; }
}
