:root {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --line: #dde2e9;
  --line-soft: #eef1f5;
  --text: #1b2430;
  --muted: #6a7683;
  --accent: #2563eb;
  --accent-soft: #eaf0fe;
  --over: #cf2b1f;
  --over-soft: #fdecea;
  --warn: #a8590a;
  --warn-soft: #fdf3e3;
  --ok: #14794a;
  --ok-soft: #e8f6ee;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(24, 39, 60, 0.06), 0 4px 12px rgba(24, 39, 60, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", "Inter", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 24px; line-height: 1.25; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0; letter-spacing: -0.005em; }

.mono { font-family: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.empty { color: var(--muted); font-size: 13px; padding: 12px 0; }
.num { text-align: right; white-space: nowrap; }

/* --- Каркас --- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 60px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; color: inherit; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px; letter-spacing: 0.02em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 650; font-size: 15px; }
.brand-sub { font-size: 11.5px; color: var(--muted); }

.nav { display: flex; gap: 4px; }
.nav a {
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}
.nav a:hover { background: var(--line-soft); color: var(--text); text-decoration: none; }
.nav a.is-active { background: var(--accent-soft); color: var(--accent); }

.whoami { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.whoami select { max-width: 190px; }

.page { max-width: 1440px; margin: 0 auto; padding: 24px; }
.footer {
  max-width: 1440px;
  margin: 0 auto;
  padding: 8px 24px 32px;
  color: var(--muted);
  font-size: 12px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-sub { margin: 0; color: var(--muted); font-size: 13.5px; }
.head-badges { display: flex; gap: 8px; align-items: center; }

.breadcrumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.breadcrumbs a { color: var(--muted); }

/* --- Сообщения --- */

.flash {
  margin: 16px 24px 0;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.flash-static { margin: 0 0 16px; }
.flash-ok { background: var(--ok-soft); border-color: #bfe3cd; color: #0f5c39; }
.flash-err { background: var(--over-soft); border-color: #f4c7c2; color: #8d2117; }

/* --- Кнопки и поля --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #f7f9fc; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1e54cc; }
.btn-danger { background: #fff; border-color: #e9bdb8; color: var(--over); }
.btn-danger:hover { background: var(--over-soft); }
.btn-small { padding: 5px 10px; font-size: 12.5px; }

input, select, textarea {
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  width: 100%;
}
textarea { resize: vertical; min-height: 44px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 550; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }

/* --- Панели --- */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.panel-flat { padding: 0; overflow: hidden; }
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

/* --- Метрики --- */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
}
.stat-value { font-size: 26px; font-weight: 650; line-height: 1.1; letter-spacing: -0.02em; }
.stat-label { font-size: 12.5px; color: var(--muted); }
.stat-over .stat-value { color: var(--over); }
.stat-warn .stat-value { color: var(--warn); }

/* --- Доска --- */

.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 12px; align-items: start; }
.column {
  background: #eaedf2;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 120px;
}
.column-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 2px 4px 10px;
}
.column-count {
  background: #d9dee7;
  color: var(--text);
  border-radius: 20px;
  padding: 0 7px;
  font-size: 11.5px;
}
.column-body { display: flex; flex-direction: column; gap: 8px; }
.column-empty { margin: 4px; font-size: 12.5px; color: #93a0ae; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid #c3ccd8;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.card.is-overdue { border-left-color: var(--over); }
.card.is-done { border-left-color: var(--ok); opacity: 0.85; }
.card-top { display: flex; gap: 8px; justify-content: space-between; align-items: flex-start; }
.card-title { font-size: 13.5px; font-weight: 600; color: var(--text); line-height: 1.35; }
.card-title:hover { color: var(--accent); }
.card-client { font-size: 12.5px; color: var(--muted); }
.card-meta { font-size: 12px; color: var(--muted); }
.card-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--line-soft);
  padding-top: 6px;
  margin-top: 2px;
}
.price { font-size: 13px; font-weight: 650; }

/* --- Чипы и бейджи --- */

.chip {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--line-soft);
  color: #46525f;
  font-size: 11.5px;
  white-space: nowrap;
}
.chip-over { background: var(--over-soft); color: var(--over); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-off { background: var(--line-soft); color: var(--muted); }
.chip-role { text-transform: lowercase; }

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.badge-over { background: var(--over-soft); color: var(--over); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-active { background: #e4f2ff; color: #0b5aa8; }

.status {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  background: var(--line-soft);
  color: var(--muted);
}
.status-active { background: var(--accent-soft); color: var(--accent); }
.status-production { background: #e4f2ff; color: #0b5aa8; }
.status-done { background: var(--ok-soft); color: var(--ok); }
.status-cancelled { background: var(--over-soft); color: var(--over); }
.status-ok { background: var(--ok-soft); color: var(--ok); }
.status-off { background: var(--over-soft); color: var(--over); }

/* --- Таблица --- */

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 650;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fafbfd;
  white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table td:first-child, .table td:last-child { white-space: nowrap; }
.table tbody tr:hover { background: #fafbfd; }
.table tr.row-over { background: #fff9f8; }
.table tr.row-over:hover { background: #fff3f1; }
.table tr.row-muted td { color: #94a0ad; }
.link-strong { font-weight: 600; }
.text-over { color: var(--over); }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab {
  padding: 6px 11px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--muted);
  border: 1px solid transparent;
}
.tab:hover { background: var(--line-soft); text-decoration: none; }
.tab.is-active { background: var(--panel); border-color: var(--line); color: var(--text); font-weight: 550; }

/* --- Карточка заказа --- */

.order-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr); gap: 16px; align-items: start; }

.route { list-style: none; margin: 0; padding: 0; }
.route-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.route-item:last-child { border-bottom: none; padding-bottom: 0; }
.route-item:first-child { padding-top: 0; }
.route-marker {
  flex: 0 0 24px;
  width: 24px; height: 24px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px;
  font-weight: 650;
  background: var(--line-soft);
  color: var(--muted);
  margin-top: 1px;
}
.state-active .route-marker { background: var(--accent); color: #fff; }
.state-done .route-marker { background: var(--ok-soft); color: var(--ok); }
.route-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.route-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.route-title { font-weight: 600; font-size: 14px; }
.state-pending .route-title { color: var(--muted); font-weight: 500; }
.route-result { margin: 0; font-size: 13px; background: #f7f9fb; border-radius: 7px; padding: 7px 10px; }
.inline-form { display: flex; gap: 8px; align-items: flex-start; }
.inline-form textarea { flex: 1; }
.inline-form select { width: auto; min-width: 150px; }

.return-block { margin-top: 2px; }
.return-block summary {
  cursor: pointer;
  font-size: 12.5px;
  color: var(--muted);
  padding: 2px 0;
}
.return-block summary:hover { color: var(--text); }
.return-block .inline-form { margin-top: 8px; flex-wrap: wrap; }

/* --- Журнал --- */

.journal { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.journal-item {
  display: grid;
  grid-template-columns: 118px 130px 160px minmax(0, 1fr);
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line-soft);
  align-items: baseline;
}
.journal-item:last-child { border-bottom: none; }
.journal-time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.journal-actor { font-weight: 550; font-size: 12.5px; }
.journal-type { font-size: 12px; color: var(--muted); }
.journal-msg { min-width: 0; overflow-wrap: anywhere; }
.type-stage_returned { color: var(--warn); }
.type-order_cancelled { color: var(--over); }
.type-stage_done { color: var(--ok); }

/* --- Свойства, цена, адаптер --- */

.props { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 6px 12px; margin: 0; font-size: 13.5px; }
.props dt { color: var(--muted); font-size: 12.5px; }
.props dd { margin: 0; }

.price-block { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.price-big { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; }
.price-source { font-size: 12.5px; color: var(--accent); }

.notice { margin: 0 0 12px; padding: 9px 11px; border-radius: 7px; font-size: 13px; }
.notice-warn { background: var(--warn-soft); color: var(--warn); }

.history { margin-bottom: 12px; font-size: 12.5px; }
.history summary { cursor: pointer; color: var(--muted); }
.history-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.history-list li { display: flex; gap: 8px; flex-wrap: wrap; border-left: 2px solid var(--line); padding-left: 8px; }

.form-compact { display: flex; flex-direction: column; gap: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-actions { display: flex; align-items: center; gap: 14px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line-soft); }

.adapter { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.adapter p { margin: 0; }

.schemes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.schemes li { border-top: 1px solid var(--line-soft); padding-top: 9px; }
.schemes li:first-child { border-top: none; padding-top: 0; }
.scheme-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; font-weight: 550; }
.schemes p { margin: 3px 0 0; }

@media (max-width: 1180px) {
  .board { grid-template-columns: repeat(2, minmax(240px, 1fr)); }
  .order-grid { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 10px; }
  .page { padding: 14px; }
  .flash { margin: 12px 14px 0; }
  .board { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .journal-item { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .table { font-size: 12.5px; }
  .table th, .table td { padding: 8px; }
}
