:root {
  --bg: #f6f7f9; --card: #fff; --line: #dde1e6; --text: #1d2329; --muted: #68717c;
  --accent: #2458c6; --ok: #1f7a3d; --ok-bg: #eaf6ee; --warn: #8a5a00; --warn-bg: #fff6e0;
  --err: #b3261e; --err-bg: #fdecea; --info-bg: #eaf1fd;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 10px; }
main { max-width: 1180px; margin: 0 auto; padding: 20px; }

.top { display: flex; justify-content: space-between; align-items: center; background: #fff; border-bottom: 1px solid var(--line); padding: 0 20px; }
.top nav a { display: inline-block; padding: 14px 12px; text-decoration: none; color: var(--text); border-bottom: 2px solid transparent; }
.top nav a.on { border-color: var(--accent); color: var(--accent); }
.who { display: flex; gap: 12px; align-items: center; color: var(--muted); }
.help-link { display: inline-flex; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--line); align-items: center; justify-content: center; text-decoration: none; }
form.inline { display: inline; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 14px; }
details.card summary { cursor: pointer; }
.hint { color: var(--muted); font-size: 13px; }
.over { color: var(--err); font-weight: 600; }
.box { border-radius: 6px; padding: 10px 14px; margin: 10px 0; }
.box ul { margin: 6px 0; padding-left: 20px; }
.box.error, .flash.error { background: var(--err-bg); color: var(--err); }
.box.warning { background: var(--warn-bg); color: var(--warn); }
.box.ok, .flash.ok { background: var(--ok-bg); color: var(--ok); }
.box.info, .flash.info { background: var(--info-bg); }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.intro { background: var(--info-bg); border-radius: 8px; padding: 14px 18px; margin-bottom: 16px; }
.intro ol { margin: 8px 0 12px; }

label { display: inline-flex; flex-direction: column; gap: 4px; margin: 0 12px 10px 0; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
label.wide { display: flex; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); min-width: 0; }
input.short { width: 90px; } input.tiny { width: 64px; } input.amount { width: 110px; }
textarea { width: 100%; }
.row { display: flex; flex-wrap: wrap; align-items: flex-start; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0 12px; }
.grid label { display: flex; margin-right: 0; }

button, .button { font: inherit; cursor: pointer; border-radius: 6px; padding: 8px 14px; border: 1px solid var(--line); background: #fff; color: var(--text); text-decoration: none; display: inline-block; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.big { padding: 11px 26px; font-size: 16px; }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
.danger { color: var(--err); }
.danger-button { background: var(--err); border-color: var(--err); color: #fff; }
.actions { margin-top: 10px; display: flex; gap: 10px; align-items: center; }

.search { position: relative; }
.search input[type=text] { width: 100%; max-width: 560px; }
.results { position: absolute; z-index: 10; list-style: none; margin: 2px 0 0; padding: 4px 0; background: #fff; border: 1px solid var(--line); border-radius: 6px; max-height: 320px; overflow: auto; min-width: 360px; box-shadow: 0 6px 20px rgba(0,0,0,.08); }
.results li { padding: 6px 12px; cursor: pointer; }
.results li:hover { background: var(--info-bg); }

.types { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.type-block { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.type-block .type-fields { display: none; margin-top: 8px; }
.type-block.active { border-color: var(--accent); }
.type-block.active .type-fields { display: block; }
.items-form { width: 100%; border-collapse: collapse; }
.items-form th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 500; padding: 4px; }
.items-form td { padding: 4px; vertical-align: top; }
.items-form td:first-child { width: 55%; }
.period-cell { white-space: nowrap; }
.period-cell label.check { font-size: 14px; margin: 6px 0 4px; }
.period-fields { font-size: 14px; color: var(--muted); }
.period-fields .hint { white-space: normal; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.presets a { padding: 4px 10px; border: 1px solid var(--line); border-radius: 14px; background: #fff; text-decoration: none; font-size: 13px; }
.presets a.on { border-color: var(--accent); background: var(--info-bg); }
.box.review { background: #fff4e5; color: #7a4a00; }
.review-note { white-space: pre-line; margin: 6px 0; }
.tag.review { background: #fff4e5; color: #8a5a00; }
.items-form .item-name { width: 100%; min-width: 280px; }
.legacy-address { background: #fff; border: 1px dashed var(--line); border-radius: 6px; padding: 8px 12px; margin-bottom: 10px; }

table.list { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { font-size: 13px; color: var(--muted); font-weight: 500; }
table.list tr.inactive td { color: var(--muted); }
.num { text-align: right !important; white-space: nowrap; }
.clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions-cell a { margin-right: 8px; white-space: nowrap; }
.tag { display: inline-block; font-size: 12px; padding: 1px 6px; border-radius: 4px; background: #eef0f3; color: var(--muted); }
.chip { background: var(--info-bg); padding: 4px 8px; border-radius: 12px; color: var(--text); }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 4px; margin-bottom: 10px; }

.doc-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.doc-frame { width: 100%; min-height: 900px; border: 1px solid var(--line); border-radius: 8px; background: #f5f5f5; }
.template-editor { display: grid; grid-template-columns: 1fr 260px; gap: 14px; }
.template-editor textarea { min-height: 560px; font: 13px/1.4 Consolas, monospace; }
.variables { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 640px; overflow: auto; }
.variables h3 { font-size: 13px; color: var(--muted); margin: 8px 0 6px; }
.var { font-size: 12px; padding: 4px 8px; margin: 0 4px 4px 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 16px; display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--text); }
.login { max-width: 360px; margin: 80px auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 28px; }
.login label { display: flex; margin-right: 0; }
.login h1 { font-size: 20px; }
.client-info { margin-top: 8px; }
[hidden] { display: none !important; }
