/* Раскладка панели. Цвета и шрифты берутся только из theme.css. */

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-weight: var(--weight-text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-weight: var(--weight-heading); line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 34px; }
h2 { font-size: 19px; }
a { color: inherit; }
.muted { color: var(--text-muted); }
.ico { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: var(--tap); padding: 0 24px;
  border: 0; border-radius: var(--radius); cursor: pointer;
  font: inherit; font-weight: var(--weight-heading); font-size: 16px;
  background: var(--accent); color: #fff; text-decoration: none;
  transition: background .15s, transform .1s;
}
.btn:hover { background: var(--accent-strong); }
.btn:active { transform: scale(.98); }
.btn:focus-visible, .nav a:focus-visible, .dock a:focus-visible, input:focus-visible, .ticket:focus-visible, .icon-btn:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 3px;
}
.btn-block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Вход ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-side {
  background: var(--rail); color: var(--text-on-rail);
  padding: 56px; display: flex; flex-direction: column; justify-content: space-between; gap: 40px; overflow: hidden;
}
.login-side .mark { display: flex; align-items: center; gap: 12px; font-weight: var(--weight-heading); font-size: 20px; }
.login-side .mark .ico { width: 30px; height: 30px; stroke: var(--accent); }
.login-side .slogan { font-size: 46px; font-weight: var(--weight-heading); line-height: 1.1; max-width: 13ch; letter-spacing: -0.02em; }
.login-side .rail-preview { display: flex; gap: 14px; transform: rotate(-4deg) translateX(-12px); }
.login-side .rail-preview .ticket { width: 190px; min-height: 130px; }
.login-main { display: grid; place-items: center; padding: 32px; }
.login { width: 100%; max-width: 380px; }
.login h1 { font-size: 30px; margin-bottom: 6px; }
.login .lead { color: var(--text-muted); margin: 0 0 28px; }
.field { display: grid; gap: 8px; margin-bottom: 18px; }
.field label { font-weight: var(--weight-heading); font-size: 15px; }
.field input {
  min-height: var(--tap); padding: 0 18px; font: inherit;
  border: 1.5px solid var(--line); border-radius: var(--radius-small); background: var(--surface); color: var(--text);
  transition: border-color .15s;
}
.field input:focus { border-color: var(--accent); outline: none; }
.alert { border-radius: var(--radius-small); padding: 12px 16px; margin-bottom: 18px; }
.alert-danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Оболочка: плавающее меню + контент ---------- */
.shell { display: grid; grid-template-columns: 272px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 16px; height: calc(100vh - 32px); margin: 16px 0 16px 16px;
  background: var(--surface-glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 22px 14px 14px; display: flex; flex-direction: column; gap: 4px;
}
.sidebar .mark { display: flex; align-items: center; gap: 10px; font-weight: var(--weight-heading); font-size: 18px; padding: 4px 12px 22px; }
.sidebar .mark .ico { stroke: var(--accent); width: 26px; height: 26px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 12px;
  border-radius: var(--radius-small); text-decoration: none; color: var(--text-muted);
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: var(--weight-heading); }
.nav-group { color: var(--text-muted); font-size: 13px; padding: 18px 12px 6px; }
.sidebar .spacer { flex: 1; }
.me { display: flex; align-items: center; gap: 10px; padding: 12px 4px 0 8px; border-top: 1px solid var(--line); margin-top: 8px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: var(--rail); color: var(--text-on-rail);
  font-weight: var(--weight-heading); text-transform: uppercase;
}
.me .who { flex: 1; min-width: 0; line-height: 1.25; }
.me .who small { color: var(--text-muted); }
.me form, .mobile-top form { margin: 0; }
.icon-btn {
  width: 44px; height: 44px; border-radius: var(--radius-small); border: 0; background: transparent;
  color: var(--text-muted); cursor: pointer; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }

.main { padding: 40px 44px 56px; max-width: 1240px; width: 100%; min-width: 0; }
.page-head { margin-bottom: 26px; }
.page-head p { margin: 8px 0 0; color: var(--text-muted); max-width: 60ch; }
.mobile-top { display: none; }

/* ---------- Чековая лента: главный акцент панели ---------- */
.rail {
  position: relative; background: var(--rail); color: var(--text-on-rail);
  border-radius: var(--radius-lg); padding: 24px 26px 30px; overflow: hidden;
}
.rail-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 18px; }
.rail-head h2 { color: var(--text-on-rail); }
.rail-head span { color: rgba(250, 246, 240, .6); font-size: 14px; }
.rail-track { display: flex; gap: 16px; overflow-x: auto; padding: 6px 2px 10px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.ticket {
  position: relative; flex: none; width: 270px; min-height: 176px; scroll-snap-align: start;
  background: var(--ticket); color: var(--text); text-decoration: none;
  border-radius: var(--radius) var(--radius) 0 0; padding: 18px 20px 30px;
  display: flex; flex-direction: column; gap: 10px;
  /* зубчатый отрывной край снизу */
  -webkit-mask: radial-gradient(circle 7px at 50% 100%, transparent 98%, #000) 0 0 / 22px 100% repeat-x;
          mask: radial-gradient(circle 7px at 50% 100%, transparent 98%, #000) 0 0 / 22px 100% repeat-x;
  transition: transform .2s;
}
a.ticket:hover { transform: translateY(-4px) rotate(-.6deg); }
.ticket-top { display: flex; justify-content: space-between; align-items: center; color: var(--text-muted); font-size: 13px; }
.ticket-ico { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.ticket h3 { font-size: 19px; }
.ticket p { margin: 0; color: var(--text-muted); font-size: 14px; }
.ticket-new { background: transparent; color: var(--text-on-rail); border: 1.5px dashed rgba(250, 246, 240, .35); border-radius: var(--radius); -webkit-mask: none; mask: none; }
.ticket-new .ticket-ico { background: rgba(250, 246, 240, .1); color: var(--text-on-rail); }
.ticket-new p, .ticket-new .ticket-top { color: rgba(250, 246, 240, .6); }

@media (prefers-reduced-motion: no-preference) {
  .rail-track .ticket { animation: ticket-in .5s cubic-bezier(.2, .8, .2, 1) both; }
  .rail-track .ticket:nth-child(2) { animation-delay: .08s; }
  .rail-track .ticket:nth-child(3) { animation-delay: .16s; }
  .rail-track .ticket:nth-child(4) { animation-delay: .24s; }
  @keyframes ticket-in { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }
}

/* ---------- Bento-сетка ---------- */
.bento { display: grid; gap: 16px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-4 { grid-column: 1 / -1; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 22px; min-width: 0;
}
.tile-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.section { margin-top: 20px; }
.note { color: var(--text-muted); font-size: 14px; margin: 12px 0 0; }

/* Показатель */
.kpi .label { color: var(--text-muted); font-size: 15px; }
.kpi .value { font-size: 34px; font-weight: var(--weight-number); letter-spacing: -0.02em; line-height: 1.1; margin: 8px 0 14px; font-variant-numeric: tabular-nums; }
.kpi .foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
.spark { width: 96px; height: 34px; overflow: visible; flex: 0 1 96px; min-width: 48px; }
.spark polyline { fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.spark .area { stroke: none; opacity: .16; }
.spark.ok polyline { stroke: var(--ok); } .spark.ok .area { fill: var(--ok); }
.spark.danger polyline { stroke: var(--danger); } .spark.danger .area { fill: var(--danger); }
.chip { display: inline-flex; align-items: center; white-space: nowrap; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: var(--weight-heading); }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn-text); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }

/* График */
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 5; }
.chart .bar { fill: var(--accent-soft); }
.chart .bar-peak { fill: var(--accent); }
.chart .axis { fill: var(--text-muted); font-family: var(--font); font-size: 13px; }
.chart .val { fill: var(--text); font-family: var(--font); font-size: 13px; font-weight: 600; }
.legend { display: flex; gap: 16px; color: var(--text-muted); font-size: 13px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.legend .l-peak { background: var(--accent); }
.legend .l-day { background: var(--accent-soft); }

/* Выводы ИИ */
.ai { background: linear-gradient(180deg, var(--ok-soft), var(--surface) 70%); }
.ai .tile-head .ico { stroke: var(--ok); }
.ai-empty { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 26px 20px; text-align: center; color: var(--text-muted); background: var(--surface); }

/* Таблица мастер-графика: компактная, шапка закреплена */
.table-wrap { max-height: 380px; overflow: auto; border-radius: var(--radius); border: 1px solid var(--line); }
table.compact { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 15px; font-variant-numeric: tabular-nums; }
table.compact th, table.compact td { padding: 9px 14px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.compact th:first-child, table.compact td:first-child { text-align: left; }
table.compact thead th { position: sticky; top: 0; background: var(--bg); z-index: 1; font-weight: var(--weight-heading); color: var(--text-muted); font-size: 14px; }
table.compact tbody tr:last-child td { border-bottom: 0; }
.table-wrap.open { max-height: none; }
table.compact td.wrap, table.compact th.wrap { white-space: pre-line; text-align: left; min-width: 220px; max-width: 460px; }
table.compact td.over { background: var(--danger-soft); color: var(--danger); font-weight: var(--weight-heading); }

/* Нижнее плавающее меню телефона */
.dock { display: none; }

@media (max-width: 1080px) {
  .bento { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  h1 { font-size: 28px; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 14px 16px 120px; }
  .bento { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .tile-head { flex-wrap: wrap; }
  .legend span { white-space: nowrap; }
  table.compact { font-size: 14px; }
  table.compact th, table.compact td { padding: 8px 8px; }
  table.compact thead th { font-size: 13px; white-space: normal; }
  .page-head { margin-bottom: 20px; }
  .mobile-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
  .mobile-top .mark { display: flex; align-items: center; gap: 8px; font-weight: var(--weight-heading); }
  .mobile-top .mark .ico { stroke: var(--accent); }
  .rail { margin: 0 -16px; border-radius: 0; padding: 22px 16px 26px; }
  .ticket { width: 78vw; max-width: 300px; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-side { padding: 28px 22px; gap: 22px; }
  .login-side .slogan { font-size: 32px; }
  .login-side .rail-preview { display: none; }
  .dock {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
    position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 10;
    background: var(--surface-glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
    border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow-float); padding: 6px;
  }
  .dock a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 56px; border-radius: 16px; text-decoration: none; color: var(--text-muted); font-size: 12px;
  }
  .dock a.active { color: var(--accent); background: var(--accent-soft); font-weight: var(--weight-heading); }
}

/* --- Справочники (этап 1.1): формы, подменю, история --- */
.subnav { display: flex; gap: 6px; flex-wrap: wrap; margin: -8px 0 22px; }
.subnav a { padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--text-muted); background: var(--surface); }
.subnav a.active { background: var(--accent-soft); color: var(--accent); font-weight: var(--weight-heading); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.form-grid .wide { grid-column: 1 / -1; }
.field select, .field textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%; box-sizing: border-box;
  border: 1px solid var(--line); border-radius: var(--radius-small); padding: 12px 14px; min-height: var(--tap);
}
.field textarea { min-height: 76px; resize: vertical; }
.field select:focus, .field textarea:focus { border-color: var(--accent); outline: none; }
.field .hint { color: var(--text-muted); font-size: 13px; }
.form-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.row-link { text-decoration: none; font-weight: var(--weight-heading); }
.row-link:hover { color: var(--accent); }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
.dl dt { color: var(--text-muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.hist li { border-left: 3px solid var(--accent-soft); padding: 2px 0 2px 12px; min-width: 0; overflow-wrap: anywhere; }
.hist .when { color: var(--text-muted); font-size: 13px; }
.hist .diff { font-size: 14px; }
.hist .diff del { color: var(--danger); }
.hist .diff ins { color: var(--ok); text-decoration: none; }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
@media (max-width: 760px) { .form-grid { grid-template-columns: 1fr; } }
details > summary { cursor: pointer; color: var(--accent); font-weight: var(--weight-heading); padding: 6px 0; }
tr.muted td { color: var(--text-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
td.check { width: 44px; }
td.check input { width: 22px; height: 22px; accent-color: var(--accent); }

/* Мастер-график: позиции × дни - плотная таблица, первая колонка закреплена при листании */
table.compact.grid th, table.compact.grid td { padding: 6px 7px; font-size: 13px; text-align: center; }
table.compact.grid th:first-child, table.compact.grid td:first-child { position: sticky; left: 0; background: var(--bg); text-align: left; z-index: 2; }
table.compact.grid tfoot th, table.compact.grid tfoot td { border-top: 1px solid var(--line); font-weight: var(--weight-heading); }
.table-wrap.tall { max-height: 720px; }
