:root {
  --bg: #f6f5f2; --surface: #fff; --surface-2: #f0eee9; --text: #1d1c1a; --muted: #6b6862;
  --border: #e2dfd8; --accent: #c2410c; --accent-soft: #fde9dc; --ok: #15803d; --ok-soft: #dcf2e3;
  --warn: #b45309; --warn-soft: #fdf0d5; --bad: #b91c1c; --bad-soft: #fde2e2;
  --radius: 10px; --shadow: 0 1px 2px rgb(0 0 0 / .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514; --surface: #201f1d; --surface-2: #2a2826; --text: #ecebe8; --muted: #a29e97;
    --border: #3a3734; --accent: #fb923c; --accent-soft: #3b2417; --ok: #4ade80; --ok-soft: #173322;
    --warn: #fbbf24; --warn-soft: #3a2d10; --bad: #f87171; --bad-soft: #3d1b1b;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Шапка */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar .inner { max-width: 1400px; margin: 0 auto; padding: .5rem 16px; display: flex; gap: 1rem;
  align-items: center; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); letter-spacing: .02em; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a { color: var(--text); padding: .35rem .6rem; border-radius: 8px; }
.nav a:hover, .nav a.active { background: var(--surface-2); text-decoration: none; }
.badge { display: inline-block; min-width: 1.3em; padding: 0 .4em; border-radius: 999px; font-size: .75rem;
  text-align: center; background: var(--accent); color: #fff; vertical-align: 1px; }
.user { display: flex; gap: .6rem; align-items: center; font-size: .9rem; }

main { max-width: 1400px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

/* Блоки */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: 2fr 1fr; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 1rem; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; }

/* Кнопки и формы */
.btn { display: inline-block; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .45rem .9rem; border-radius: 8px; font: inherit; cursor: pointer; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: .2rem .55rem; font-size: .85rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
form .field, form div:has(> label) { margin-bottom: .75rem; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=password],
input[type=search], input:not([type]), select, textarea {
  width: 100%; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; }
input[type=checkbox] { width: auto; margin-right: .4rem; }
div:has(> input[type=checkbox]) { display: flex; flex-direction: row-reverse; justify-content: flex-end;
  align-items: center; }
div:has(> input[type=checkbox]) label { margin: 0; color: var(--text); font-size: .95rem; }
.helptext { display: block; font-size: .8rem; color: var(--muted); }
.errorlist { color: var(--bad); margin: .2rem 0; padding-left: 1rem; font-size: .85rem; }
.form-cols { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; min-width: 180px; }

/* Таблицы */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
tr.done td { color: var(--muted); text-decoration: line-through; }
td.num, th.num { text-align: right; white-space: nowrap; }

/* Метки */
.tag { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.overdue, .tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.soon, .tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.later, .tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }

/* Сообщения */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { padding: .6rem .9rem; border-radius: 8px; margin-bottom: .5rem; background: var(--ok-soft);
  color: var(--ok); }
.messages li.error { background: var(--bad-soft); color: var(--bad); }
.messages li.warning { background: var(--warn-soft); color: var(--warn); }
.alert { padding: .8rem 1rem; border-radius: 8px; background: var(--warn-soft); color: var(--warn);
  margin-bottom: 1rem; }

/* Канбан */
.board { display: flex; gap: .75rem; overflow-x: auto; padding-bottom: 1rem; align-items: flex-start; }
.column { flex: 0 0 260px; background: var(--surface-2); border-radius: var(--radius); padding: .6rem;
  min-height: 200px; }
.column.drag-over { outline: 2px dashed var(--accent); }
.column h3 { font-size: .85rem; margin: 0 0 .5rem; display: flex; justify-content: space-between; }
.order-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .55rem .6rem;
  margin-bottom: .5rem; cursor: grab; box-shadow: var(--shadow); }
.order-card.dragging { opacity: .5; }
.order-card .client { font-weight: 600; }
.order-card select { margin-top: .4rem; padding: .2rem .3rem; font-size: .8rem; }
.funnel { display: flex; gap: .5rem; flex-wrap: wrap; }
.funnel a { flex: 1 1 110px; background: var(--surface-2); border-radius: 8px; padding: .5rem .6rem; color: var(--text); }
.funnel b { display: block; font-size: 1.3rem; }
.htmx-request.order-card { opacity: .6; }

/* Вход */
.login { max-width: 360px; margin: 10vh auto; }

/* Позиции заказа */
.items { display: grid; gap: .75rem; }
.item { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; background: var(--surface); }
.item.individual { background: var(--surface-2); }
.item-grid { display: grid; gap: 0 .75rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.item-row { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; margin-top: .25rem; }
.item-title { margin-bottom: .5rem; }
.item-delete label { display: inline; color: var(--bad); }
.price-value { font-size: 1.15rem; font-weight: 700; padding: .35rem 0; white-space: nowrap; }
.own-price input { width: 130px; }
.items-total { font-weight: 600; margin: .75rem 0 0; }
details.multi { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); position: relative; }
details.multi summary { padding: .45rem .6rem; cursor: pointer; list-style: none; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
details.multi summary::-webkit-details-marker { display: none; }
details.multi[open] > div, details.multi[open] > ul { position: absolute; z-index: 5; left: 0; right: 0; max-height: 240px;
  overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .4rem .6rem;
  margin: .2rem 0 0; box-shadow: 0 6px 18px rgb(0 0 0 / .15); list-style: none; }
details.multi label { display: block; color: var(--text); font-size: .95rem; margin: .15rem 0; }

/* Калькулятор */
.calc { display: grid; gap: 1rem; grid-template-columns: minmax(280px, 1fr) minmax(260px, 380px); align-items: start; }
@media (max-width: 800px) { .calc { grid-template-columns: 1fr; } }
.calc-result { position: sticky; top: 4.5rem; }
.calc-price { font-size: 2rem; font-weight: 800; }
.calc-total { font-size: 1.2rem; }
.checks label { display: block; color: var(--text); font-size: .95rem; }
table.breakdown td, table.breakdown th { padding: .25rem .5rem; font-size: .9rem; }

.prev-price.differs { color: var(--warn); }
