/* Detailng CRM — кастомная админка.
   Стиль: тёмный рейл-сайдбар, светлый контент, карточки со скруглениями,
   пастельные бейджи, оранжевый фирменный акцент. */

:root {
  --ink: #101b28;
  --ink-soft: #3d4754;
  --muted: #8a93a2;
  --border: #e7ecf2;
  --bg: #eef3f9;
  --card: #ffffff;
  --accent: #e8820c;
  --accent-soft: #fdf1e0;
  --green: #22a45d;
  --green-soft: #e1f6e8;
  --red: #dc2626;
  --red-soft: #fdecec;
  --blue: #2f7df6;
  --blue-soft: #eaf1fb;
  --amber: #e8a20c;
  --amber-soft: #fdf6de;
  --violet: #8b5cf6;
  --violet-soft: #f1eafe;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(16, 27, 40, .05), 0 8px 24px -12px rgba(16, 27, 40, .12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, 'Segoe UI', Roboto, sans-serif;
  background:
    radial-gradient(1200px 500px at 20% -10%, #dbe9fb 0%, transparent 60%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-size: 14px;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ── Каркас ─────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.rail {
  width: 76px;
  background: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 0;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.rail .logo {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px;
  margin-bottom: 18px;
  letter-spacing: .5px;
}

.rail-btn {
  width: 46px; height: 46px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #8fa0b3;
  transition: background .15s, color .15s;
  position: relative;
}
.rail-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.rail-btn.active { background: var(--accent); color: #fff; }
.rail-btn svg { width: 21px; height: 21px; }

.rail .spacer { flex: 1; }

/* всплывающая подпись */
.rail-btn::after {
  content: attr(data-tip);
  position: absolute;
  left: 58px; top: 50%;
  transform: translateY(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 12px; font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity .15s;
  z-index: 50;
  box-shadow: var(--shadow);
}
.rail-btn:hover::after { opacity: 1; }

.main { flex: 1; min-width: 0; padding: 26px 30px 40px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 22px;
}
.topbar h1 { font-size: 24px; font-weight: 800; }
.topbar .who { display: flex; align-items: center; gap: 10px; }
.topbar .who .meta { text-align: right; }
.topbar .who .name { font-weight: 700; font-size: 13.5px; }
.topbar .who .role { color: var(--muted); font-size: 12px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 800; font-size: 14px;
  flex-shrink: 0;
}

/* ── Карточки и сетки ───────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card, .stack > * + * { margin-top: 16px; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.card-head h2 { font-size: 16.5px; font-weight: 800; }
.card-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 1000px) { .grid.cols-2 { grid-template-columns: 1fr; } }

/* ── Стат-карточки ──────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.stat {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.stat .top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.stat .label { font-weight: 700; font-size: 13.5px; color: var(--ink-soft); }
.stat .value { font-size: 27px; font-weight: 800; letter-spacing: -.5px; }
.stat .foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; min-height: 20px; }

.icon-tile {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; flex-shrink: 0;
}
.icon-tile svg { width: 20px; height: 20px; }
.tone-blue   { background: var(--blue-soft);   color: var(--blue); }
.tone-amber  { background: var(--amber-soft);  color: var(--amber); }
.tone-green  { background: var(--green-soft);  color: var(--green); }
.tone-violet { background: var(--violet-soft); color: var(--violet); }
.tone-red    { background: var(--red-soft);    color: var(--red); }
.tone-accent { background: var(--accent-soft); color: var(--accent); }

.trend {
  font-size: 12px; font-weight: 700;
  padding: 3px 8px; border-radius: 999px;
}
.trend.up { background: var(--green-soft); color: var(--green); }
.trend.down { background: var(--red-soft); color: var(--red); }
.trend.flat { background: var(--blue-soft); color: var(--blue); }
.stat .hint { color: var(--muted); font-size: 12px; }

/* ── Таблицы ────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 12px; font-weight: 700;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; transition: background .12s; }
tbody tr.clickable:hover { background: #f7fafc; }

.cell-main { font-weight: 700; }
.cell-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.num { font-variant-numeric: tabular-nums; }

.entity { display: flex; align-items: center; gap: 11px; }
.entity .avatar { width: 36px; height: 36px; font-size: 12.5px; }

/* ── Бейджи статусов ────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700;
  padding: 4px 11px; border-radius: 999px;
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-reception   { background: var(--blue-soft);   color: var(--blue); }
.st-in_progress { background: var(--amber-soft);  color: #b45309; }
.st-ready       { background: var(--green-soft);  color: var(--green); }
.st-delivered   { background: #eff1f4;            color: #5b6572; }
.ts-assigned    { background: var(--blue-soft);   color: var(--blue); }
.ts-in_progress { background: var(--amber-soft);  color: #b45309; }
.ts-paused      { background: #eff1f4;            color: #5b6572; }
.ts-done        { background: #e0f2fe;            color: #0369a1; }
.ts-accepted    { background: var(--green-soft);  color: var(--green); }
.ts-rework      { background: var(--red-soft);    color: var(--red); }
.badge.overdue  { background: var(--red);         color: #fff; }

/* ── Формы и кнопки ─────────────────────────────── */
.input, select.input, textarea.input {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font: inherit;
  color: var(--ink);
  width: 100%;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label {
  font-size: 11px; font-weight: 700;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: .6px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-weight: 700; font-size: 13.5px;
  background: var(--accent); color: #fff;
  transition: filter .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.05); }
.btn.dark { background: var(--ink); }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--border); }
.btn.danger { background: var(--red); }
.btn.sm { padding: 7px 13px; font-size: 12.5px; border-radius: 10px; }
.btn svg { width: 15px; height: 15px; }

.search-box { position: relative; }
.search-box .input { padding-left: 38px; min-width: 240px; }
.search-box svg {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--muted);
}

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 600; font-size: 13px;
  color: var(--ink-soft);
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row .field { flex: 1; min-width: 130px; }

/* ── Флеш и ошибки ──────────────────────────────── */
.flash {
  background: var(--green-soft); color: var(--green);
  font-weight: 700; font-size: 13.5px;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
}
.errors {
  background: var(--red-soft); color: var(--red);
  font-weight: 600; font-size: 13.5px;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
}
.errors ul { margin-left: 18px; }

/* ── Дашборд: услуги ────────────────────────────── */
.bar-row { display: grid; grid-template-columns: 200px 1fr 90px; gap: 12px; align-items: center; padding: 8px 0; }
.bar-row .name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: #f0f4f9; border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill { background: linear-gradient(90deg, var(--accent), #f5a942); height: 100%; border-radius: 999px; }
.bar-row .val { text-align: right; color: var(--muted); font-size: 12.5px; font-weight: 600; }

/* ── Карточка заказа ────────────────────────────── */
.order-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
}
.order-head .plate { font-size: 24px; font-weight: 800; letter-spacing: 1px; }
.order-head .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 13.5px; }
.kv .k { color: var(--ink-soft); }
.kv .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.kv.total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 11px; }
.kv .v.danger { color: var(--red); }
.kv .v.ok { color: var(--green); }

.photos { display: flex; gap: 10px; flex-wrap: wrap; }
.photo-tile { text-align: center; }
.photo-tile img {
  width: 104px; height: 104px; object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
}
.photo-tile .cap { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-top: 4px; }

.timeline { list-style: none; }
.timeline li { display: flex; gap: 12px; padding: 7px 0; font-size: 13px; }
.timeline .t { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; width: 110px; flex-shrink: 0; }
.timeline .who { color: var(--muted); font-size: 12px; }

.task-block { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; }
.task-block + .task-block { margin-top: 10px; }
.task-block .head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.task-block .title { font-weight: 700; font-size: 14.5px; }
.task-block .sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.task-block .actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.task-block .actions form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.defect { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.defect:last-child { border-bottom: none; }
.defect .kind { font-size: 11px; font-weight: 800; color: var(--accent); text-transform: uppercase; letter-spacing: .5px; }

/* ── Пагинация ──────────────────────────────────── */
.pager { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 14px; }
.pager a, .pager span {
  min-width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 10px;
  border-radius: 10px;
  font-weight: 600; font-size: 13px;
  color: var(--ink-soft);
  border: 1px solid var(--border);
  background: #fff;
}
.pager .current { background: var(--ink); color: #fff; border-color: var(--ink); }
.pager .dots { border: none; background: none; }

/* ── Логин ──────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 34px;
}
.login-card .logo {
  width: 54px; height: 54px; border-radius: 16px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
  margin-bottom: 16px;
}
.login-card .logo svg { width: 26px; height: 26px; }
.login-card h1 { font-size: 23px; font-weight: 800; }
.login-card .sub { color: var(--muted); margin: 4px 0 20px; }
.login-card .field + .field { margin-top: 12px; }
.login-card .btn { width: 100%; margin-top: 18px; padding: 13px; }

/* --- Справочник v2: аккордеон, inline-редактирование, тосты --- */
.toolbar { margin-bottom: 14px; }
.toolbar .js-search { max-width: 340px; }
.cat-add { display: flex; gap: 8px; margin-bottom: 12px; }
.cat-add .input { flex: 1; }
.acc-list, .cat-list { border-top: 1px solid var(--border); }
.acc-item + .acc-item, .cat-list .cat-row { border-top: 1px solid var(--border); }
.cat-view { display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-radius: 10px; }
.cat-view:hover { background: #f7f9fb; }
.cat-view.js-toggle { cursor: pointer; }
.cat-view .name { font-weight: 600; }
.cat-view .muted { color: var(--muted); font-size: 12.5px; }
.cat-view .actions { margin-left: auto; display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.cat-row:hover .actions, .cat-row:focus-within .actions { opacity: 1; }
.icon-btn { border: 1px solid var(--border); background: #fff; border-radius: 8px; width: 28px; height: 28px; cursor: pointer; color: var(--ink); font-size: 13px; line-height: 1; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.chev { transition: transform .15s; font-size: 11px; color: var(--muted); flex: none; }
.acc-item.open > .cat-row .chev { transform: rotate(90deg); }
.acc-body { padding: 2px 0 12px 30px; }
.acc-body .cat-add { margin: 8px 0 0; max-width: 420px; }
.cat-edit { display: flex; gap: 8px; align-items: center; padding: 6px 8px; }
.cat-edit .input { flex: 1; max-width: 320px; }
.dot { width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--border); flex: none; display: inline-block; }
.color-input { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; flex: none; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 50; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 13.5px; box-shadow: 0 8px 24px rgba(16, 27, 40, .25); animation: toast-in .15s ease-out; }
.toast.err { background: var(--red); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
