:root {
  --accent: #2a6099; --accent-dark: #1f4a78; --ink: #1c2530; --muted: #66717e; --line: #dde2e8;
  --bg: #f4f6f8; --card: #fff; --ok: #1d7a46; --warn: #b26a00; --bad: #b3261e;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* layout */
.side { position: fixed; inset: 0 auto 0 0; width: 200px; background: #17212c; color: #c9d3dd; display: flex; flex-direction: column; padding: 16px 0; overflow-y: auto; }
.side .brand { font-size: 22px; font-weight: 800; color: #fff; padding: 0 18px 14px; letter-spacing: 1px; }
.side a { color: inherit; padding: 7px 18px; display: block; }
.side a:hover { background: #223040; text-decoration: none; }
.side a.on { background: var(--accent); color: #fff; }
.side .sep { border-top: 1px solid #2c3a4a; margin: 8px 0; }
.side .foot { margin-top: auto; padding: 10px 18px 0; font-size: 12px; }
.side .foot a { display: inline; padding: 0; color: #9fb4c9; }
.side .foot button { background: none; border: 0; color: #9fb4c9; padding: 0; cursor: pointer; font: inherit; }
main { margin-left: 200px; padding: 24px 28px 60px; max-width: 1400px; }
main.plain { margin: 8vh auto; max-width: 360px; }
@media (max-width: 800px) {
  .side { position: static; width: auto; flex-direction: row; flex-wrap: wrap; padding: 6px; }
  .side .brand, .side .sep { display: none; }
  .side a { padding: 6px 10px; }
  .side .foot { margin: 0; padding: 6px 10px; }
  main { margin: 0; padding: 14px; }
}

/* blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.head h1 { margin: 0; margin-right: auto; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; background: #e7f4ec; color: var(--ok); border: 1px solid #bfe0cc; }
.flash.error { background: #fbeceb; color: var(--bad); border-color: #f0c4c1; }
.preview { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; margin-bottom: 12px; }
pre.text { white-space: pre-wrap; font: 12px/1.5 ui-monospace, Menlo, monospace; max-height: 420px; overflow: auto; background: var(--bg); padding: 10px; border-radius: 6px; margin: 0; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th.right { text-align: right; }
tbody tr:hover { background: #f8fafc; }
tr:last-child td { border-bottom: 0; }
td.clip { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; }

/* forms */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], input[type=email], input[type=file], select, textarea {
  width: 100%; padding: 6px 8px; border: 1px solid #c5ccd4; border-radius: 6px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0e4; border-color: var(--accent); }
textarea { resize: vertical; min-height: 34px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 12px; }
.fields .wide { grid-column: span 2; }
.fields .full { grid-column: 1 / -1; }
.row { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1 1 110px; }
.row > .fit { flex: 0 0 auto; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); margin: 0; }
.check input { width: auto; }
.btn, button.btn { display: inline-block; padding: 6px 12px; border-radius: 6px; border: 1px solid #c5ccd4; background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #eef2f6; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--bad); border-color: #e3b5b1; }
.btn.small { padding: 2px 8px; font-size: 12px; }
.inline { display: inline; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 5px 12px; border-radius: 16px; color: var(--ink); background: #e6eaef; }
.tabs a.on { background: var(--accent); color: #fff; }
.tabs a:hover { text-decoration: none; }

/* document lines */
.lines input, .lines textarea { border-color: transparent; background: transparent; border-radius: 4px; }
.lines td { padding: 2px 3px; }
.lines input:hover, .lines textarea:hover { border-color: #c5ccd4; background: #fff; }
.lines .q { width: 80px; } .lines .u { width: 70px; } .lines .p { width: 120px; } .lines .a { width: 130px; } .lines .x { width: 30px; }
.lines input.num { text-align: right; }
.totals { margin-left: auto; width: 340px; max-width: 100%; }
.totals td { padding: 4px 8px; }
.totals input { text-align: right; width: 130px; }
.totals .grand td { font-weight: 700; font-size: 16px; border-top: 2px solid var(--ink); }

/* status badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: #e6eaef; color: #44505c; white-space: nowrap; }
.st-sent { background: #fff1d6; color: var(--warn); }
.st-paid, .st-accepted { background: #dff3e6; color: var(--ok); }
.st-refused, .st-cancelled { background: #fbe3e1; color: var(--bad); }
.st-draft { background: #e3ecf7; color: var(--accent-dark); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; border: 1px solid #0002; }
.languages { margin-top: 6px; }
.languages button { background: none; border: 0; padding: 0; margin-right: 8px; cursor: pointer; font: inherit; font-size: 12px; color: #7f97ad; text-decoration: underline; }
