/* Каркас интерфейса CRM (задача 1.7). Палитра — из макета, согласованного с руководством.
   Шрифты системные: страницы ничего не загружают со сторонних серверов. */
:root {
  --bg: #F2F4F7;
  --panel: #FFFFFF;
  --ink: #141C25;
  --muted: #5A6777;
  --line: #DCE1E8;
  --hover: #EEF2F8;
  --accent: #2347B8;
  --accent-ink: #FFFFFF;
  --accent-soft: #E6EBFA;
  --side: #161D27;
  --side-ink: #CDD5E0;
  --side-muted: #7F8B9B;
  --side-active: #26344D;
  --bad: #B03535;
  --bad-soft: #F8E3E3;
  --shadow: 0 10px 30px rgba(20, 28, 37, .12);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --r: 6px;
  --side-width: 13.5rem;
  --tabbar: 3.75rem;
  --fast: 150ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0D1217;
    --panel: #141B23;
    --ink: #E3E8EE;
    --muted: #98A4B2;
    --line: #27313C;
    --hover: #1B2430;
    --accent: #8AA8FF;
    --accent-ink: #0D1217;
    --accent-soft: #1C2644;
    --side: #090D12;
    --side-active: #1C2840;
    --bad: #F08A8A;
    --bad-soft: #3A1C1C;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip { position: absolute; left: -999px; top: .5rem; z-index: 20; padding: .5rem .75rem; border-radius: var(--r);
        background: var(--accent); color: var(--accent-ink); }
.skip:focus { left: .5rem; }

/* Раскладка: меню слева, шапка и содержимое справа */
.app {
  display: grid;
  grid-template-columns: var(--side-width) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "side top" "side content";
  min-height: 100vh;
  min-height: 100dvh; /* на телефоне — без учёта выезжающих панелей браузера */
}

.side { grid-area: side; background: var(--side); color: var(--side-ink); padding: 1.25rem .75rem; }
.brand { font-weight: 700; letter-spacing: .14em; color: #FFFFFF; padding: 0 .75rem 1.25rem; }
.side ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .125rem; }
.side a {
  display: block; padding: .55rem .75rem; border-radius: var(--r);
  color: var(--side-ink); text-decoration: none; transition: background-color var(--fast), color var(--fast);
}
.side a:hover { background: var(--side-active); color: #FFFFFF; }
.side a[aria-current="page"] { background: var(--side-active); color: #FFFFFF; box-shadow: inset 3px 0 0 var(--accent); }

.top {
  grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 2rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 1.5rem; line-height: 1.2; letter-spacing: -.01em; }
.tools { display: flex; align-items: center; gap: 1rem; color: var(--muted); font-size: .875rem; }
.tools form { margin: 0; }
.today::first-letter { text-transform: uppercase; }
.company { color: var(--ink); font-weight: 600; }
.company select {
  padding: .35rem .5rem; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--panel); font-weight: 600; max-width: 16rem;
}
button.quiet {
  border: 1px solid var(--line); background: transparent; border-radius: var(--r);
  padding: .35rem .75rem; cursor: pointer; transition: background-color var(--fast);
}
button.quiet:hover { background: var(--hover); }

.content { grid-area: content; padding: 2rem; max-width: 72rem; min-width: 0; } /* широкие таблицы прокручиваются внутри */
.placeholder {
  background: var(--panel); border: 1px solid var(--line); border-radius: calc(var(--r) * 2);
  padding: 1.75rem 2rem; box-shadow: var(--shadow); max-width: 44rem;
}
.placeholder .lead { margin: 0 0 .5rem; font-size: 1.125rem; font-weight: 600; }
.placeholder p:last-child { margin-bottom: 0; color: var(--muted); }

/* Разделы с содержимым: панели, таблицы, формы (с задачи 2.7) */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: calc(var(--r) * 2);
  padding: 1.25rem 1.5rem; margin-bottom: 1.25rem;
}
.panel.narrow { max-width: 36rem; box-shadow: var(--shadow); }
.panel h2 { margin: 0; font-size: 1.125rem; line-height: 1.3; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem 1rem; flex-wrap: wrap; }
.panel-head + p { margin: .5rem 0 1rem; max-width: 52rem; }
.muted { color: var(--muted); }
.warn { color: var(--bad); font-size: .875rem; }
.scroll { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
.list th {
  text-align: left; font-size: .8125rem; font-weight: 600; color: var(--muted); padding: .5rem .75rem;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.list td { padding: .625rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.list tbody tr:last-child td { border-bottom: 0; }
.list tbody tr:hover { background: var(--hover); }
.list .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list .actions { text-align: right; white-space: nowrap; }
.list .actions > * + * { margin-left: .75rem; }
.tag {
  display: inline-flex; align-items: center; gap: .25rem; padding: .1rem .55rem; margin: 0 .25rem .25rem 0;
  border-radius: 999px; background: var(--accent-soft); font-size: .875rem;
}
form.inline { display: inline; margin: 0; }
button.link { border: 0; background: none; padding: 0 .15rem; cursor: pointer; color: var(--muted); line-height: 1; }
button.link:hover { color: var(--bad); }
.inline-form summary { cursor: pointer; color: var(--accent); font-size: .875rem; }
.inline-form form { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .4rem; }
.inline-form select, .stack input, .stack select {
  padding: .45rem .6rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel);
}
.stack { display: grid; gap: 1rem; margin-top: 1rem; }
.stack label { display: grid; gap: .3rem; font-size: .875rem; color: var(--muted); }
.stack input, .stack select { font-size: 1rem; color: var(--ink); }
.stack small { font-size: .8125rem; }
.buttons { display: flex; align-items: center; gap: 1rem; }
.button, button.primary, button.danger {
  display: inline-block; padding: .55rem 1rem; border: 0; border-radius: var(--r); cursor: pointer;
  font-weight: 600; text-decoration: none; transition: filter var(--fast);
}
.button.primary, button.primary { background: var(--accent); color: var(--accent-ink); }
button.danger { background: var(--bad); color: var(--panel); }
.button:hover, button.primary:hover, button.danger:hover { filter: brightness(1.08); }
.facts { padding-left: 1.25rem; margin: 1rem 0 1.25rem; }
.facts li + li { margin-top: .4rem; }
.notice {
  margin: 0 0 1rem; padding: .6rem .75rem; border-radius: var(--r); background: var(--accent-soft); max-width: 52rem;
}
.notice.bad { background: var(--bad-soft); color: var(--bad); }
/* График работы: неделя — таблица «день / с / до» (задача 4.1) */
.week th[scope="row"] { color: var(--ink); font-size: 1rem; }
.week td { padding: .375rem .75rem; }
.week input { min-width: 7rem; }
.delete-schedule {
  display: flex; align-items: center; flex-wrap: wrap; gap: .75rem;
  margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--line);
}

/* Телефон: меню — нижняя панель, шапка компактная (НФТ-07) */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "top" "content";
    padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom, 0px));
  }
  .side {
    position: fixed; inset: auto 0 0 0; z-index: 10; padding: .25rem .25rem env(safe-area-inset-bottom, 0px);
    height: calc(var(--tabbar) + env(safe-area-inset-bottom, 0px));
  }
  .brand { display: none; }
  /* шесть разделов РОПа помещаются на экране от 360 px; при большем числе панель прокручивается */
  .side ul { grid-auto-flow: column; grid-auto-columns: minmax(3.4rem, 1fr); overflow-x: auto; height: 100%; }
  .side a { height: 100%; display: grid; place-items: center; padding: 0 .2rem; font-size: .75rem; text-align: center; }
  .side a[aria-current="page"] { box-shadow: inset 0 3px 0 var(--accent); }
  .top { flex-wrap: wrap; padding: .75rem 1rem; gap: .5rem; }
  .top h1 { font-size: 1.25rem; }
  .tools { width: 100%; justify-content: space-between; gap: .5rem; }
  .user, .today { display: none; }
  .company select, button.quiet { min-height: 2.75rem; } /* под палец: не меньше 44 px */
  .content { padding: 1rem; }
  .placeholder, .panel { padding: 1.25rem; }
  .inline-form select, .stack input, .stack select, .button, button.primary, button.danger { min-height: 2.75rem; }
  .week th, .week td { padding-left: .25rem; padding-right: .25rem; }
  .step { white-space: normal; }
  .week input { min-width: 0; width: 100%; }
}

/* Вход */
body.auth { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 1rem; }
.card {
  width: 100%; max-width: 24rem; background: var(--panel); border: 1px solid var(--line);
  border-radius: calc(var(--r) * 2); padding: 2rem; box-shadow: var(--shadow);
}
.card h1 { margin: 0 0 1.25rem; font-size: 1.375rem; line-height: 1.25; }
.card form { display: grid; gap: .875rem; }
.card label { display: grid; gap: .3rem; font-size: .875rem; color: var(--muted); }
.card input {
  padding: .6rem .75rem; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--panel); font-size: 1rem;
}
.card button[type="submit"] {
  padding: .65rem 1rem; border: 0; border-radius: var(--r); cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; transition: filter var(--fast);
}
.card button[type="submit"]:hover { filter: brightness(1.08); }
.card code { word-break: break-all; background: var(--hover); padding: .1rem .3rem; border-radius: 4px; }
.alert { margin: 0 0 1rem; padding: .6rem .75rem; border-radius: var(--r); background: var(--bad-soft); color: var(--bad); }

/* Очередь менеджеров: где менеджер сейчас (задача 4.7) */
.state { white-space: nowrap; }
.state.stopped, .state.away { color: var(--bad); }
.state.off_shift { color: var(--muted); }
.inline-action { margin-top: .25rem; }
.inline-form label { display: inline-flex; align-items: center; gap: .35rem; }
.note { margin: .75rem 0 0; font-size: .875rem; }
.choice { border: 0; padding: 0; margin: 0; display: flex; gap: 1.25rem; }
.choice legend { font-size: .875rem; color: var(--muted); margin-bottom: .3rem; padding: 0; }
.choice label { display: inline-flex; align-items: center; gap: .4rem; color: var(--ink); font-size: 1rem; }
.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.pages { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }

/* Нормативы и просроченные задачи (задача 4.6) */
.with-unit { display: flex; align-items: center; gap: .6rem; }
.with-unit input { width: 7rem; }
.list .overdue { color: var(--bad); white-space: nowrap; }

/* Заявки: следующий шаг и пометки (задача 4.6) */
.step { white-space: nowrap; font-weight: 600; }
.step.no_step_late, .step.step_overdue { color: var(--bad); }
.step.no_step { color: var(--muted); }
.step.today { color: var(--accent); }
.list .num.bad { color: var(--bad); font-weight: 600; }
.choice.column { flex-direction: column; gap: .5rem; }
code.secret {
  font-size: 1.125rem; letter-spacing: .04em; padding: .15rem .4rem; border-radius: 4px; background: var(--hover);
  user-select: all;
}

/* Экран «Сейчас» (задача 4.8) */
.stamp { margin: 0 0 1rem; font-size: .875rem; }
.summary tr.group th { padding-top: 1rem; font-size: .875rem; color: var(--ink); text-align: left; }
.summary tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
.summary small { font-weight: 400; color: var(--muted); }

/* Отчёты (задача 4.9) */
.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .45rem .9rem; border-radius: var(--r); text-decoration: none; color: var(--ink); }
.tabs a[aria-current="page"] { background: var(--accent-soft); font-weight: 600; }
.period { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.period label { display: inline-flex; align-items: center; gap: .4rem; }
.period input { padding: .4rem .5rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
.pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 1.25rem; }
.panel h3 { margin: 1.25rem 0 .5rem; font-size: 1rem; }

/* Клиенты: поиск, карточка, «Давно не покупали» (КЛИ-02…05) */
.search { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: 1rem; }
.search input[type="search"] {
  flex: 1 1 18rem; min-width: 0; padding: .55rem .75rem; font-size: 1rem;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--panel);
}
.period input[type="number"] { width: 6rem; }
.period select { padding: .4rem .5rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
.back { margin: 0 0 .75rem; font-size: .875rem; }
.back a { text-decoration: none; }
.requisites { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 1rem 1.5rem; margin: 1rem 0 0; }
.requisites dt { font-size: .8125rem; color: var(--muted); }
.requisites dd { margin: .15rem 0 0; overflow-wrap: anywhere; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1rem; margin: 0 0 1.25rem; }
.tile {
  display: grid; gap: .2rem; padding: 1rem 1.25rem; background: var(--panel);
  border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: calc(var(--r) * 2);
}
.tile .label { font-size: .8125rem; color: var(--muted); }
.tile .value { font-size: 1.375rem; font-weight: 650; line-height: 1.25; font-variant-numeric: tabular-nums; }
.feed .kind { white-space: nowrap; font-weight: 600; }
.persons td:first-child { font-weight: 600; }
.feed .kind.payment { color: var(--accent); }
.feed .kind.refusal { color: var(--bad); }
.feed .kind.task { color: var(--muted); }
@media (max-width: 768px) {
  .search input[type="search"], .period select, .period input { min-height: 2.75rem; }
}

/* Причины отказа (НАС-03) */
.reasons { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.hidden-reason input[name="name"] { color: var(--muted); }
.reason-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin: 0; }
.reason-row input[name="name"] {
  flex: 1 1 16rem; min-width: 0; padding: .4rem .5rem; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--panel);
}
.reason-row label, .inline-check { display: inline-flex; align-items: center; gap: .35rem; color: var(--ink); }

/* Журнал (ИЗО-06) */
.journal td { font-size: .875rem; }
.journal td:nth-child(4), .journal td:nth-child(5) { overflow-wrap: anywhere; }

/* Задачи (ЗАД-02, ЗАД-03) */
.badge {
  display: inline-grid; place-items: center; min-width: 1.35rem; height: 1.35rem; padding: 0 .35rem; margin-left: .35rem;
  border-radius: 999px; background: var(--bad); color: var(--panel); font-size: .75rem; font-weight: 700;
}
.task-new summary { cursor: pointer; list-style: none; }
.task-new summary::-webkit-details-marker { display: none; }
.task-new summary h2::after { content: " +"; color: var(--accent); }
.task-new[open] summary h2::after { content: ""; }
.tasks { list-style: none; margin: 0 0 1rem; padding: 0; }
.task {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem 1rem;
  padding: .6rem .25rem; border-bottom: 1px solid var(--line);
}
.task:last-child { border-bottom: 0; }
.task-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .6rem; min-width: 0; }
.task .when { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 4.5rem; color: var(--muted); }
.task.overdue .when { color: var(--bad); }
.task.today .when { color: var(--accent); }
.task.done .what { text-decoration: line-through; color: var(--muted); }
.task-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .9rem; font-size: .875rem; }
.inline-done { display: flex; gap: .4rem; margin: 0; }
.inline-done input {
  width: 11rem; padding: .3rem .45rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel);
}
.bad-text { color: var(--bad); }

/* Логистика: запросы цены доставки и доставки в работе (ЛОГ-01…05) */
.delivery-state { font-weight: 600; white-space: nowrap; }
.delivery-state.waiting, .delivery-state.cancelled { color: var(--muted); }
.delivery-state.fresh, .day.today { color: var(--accent); }
.delivery-state.stale, .day.overdue { color: var(--bad); }
.day { font-weight: 600; }
.list .nowrap { white-space: nowrap; }
.tabs .count { color: var(--muted); font-weight: 400; }
.filter { display: flex; gap: .9rem; font-size: .875rem; }
.filter a[aria-current] { color: var(--ink); font-weight: 600; text-decoration: none; }
.totals { display: flex; flex-wrap: wrap; gap: .4rem 1.5rem; margin: 0 0 1rem; }
.deliveries .act { min-width: 14rem; }
.act > * + * { margin-top: .5rem; }
.act form.inline { display: inline-block; margin: 0 .5rem .25rem 0; }
.act input {
  width: 8.5rem; padding: .4rem .5rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel);
}
.act input[name="note"] { width: 12rem; }
.validity { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .35rem; font-size: .875rem; color: var(--muted); }
@media (max-width: 768px) {
  .act input, .act input[name="note"] { width: 100%; min-height: 2.75rem; }
}
