/* Портал агентства — стили. Без сборки, без фреймворков. */
:root {
  --paper: #f2f4f7;
  --surface: #ffffff;
  --ink: #18202e;
  --ink-2: #566175;
  --ink-3: #8a94a6;
  --line: #dde2ea;
  --line-2: #eceff4;
  --accent: #2448e0;
  --accent-ink: #ffffff;
  --accent-soft: #e8edff;
  --red: #e0402b;
  --amber: #e89a0c;
  --green: #1f9560;
  --gray: #9aa3b2;
  --violet: #7a4fd6;
  --panel: #18202e;
  --panel-ink: #e9edf4;
  --radius: 10px;
  --radius-sm: 6px;
  --font-ui: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Unbounded", "Manrope", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--font-ui);
  font-feature-settings: "tnum" 1;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }

/* ---------- лампы статуса ---------- */
.lamp {
  --c: var(--gray);
  display: inline-block;
  flex: none;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 20%, transparent);
}
.l-new .lamp       { --c: var(--red); animation: blink 1.1s steps(2, jump-none) infinite; }
.l-in_progress .lamp { --c: var(--amber); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 25%, transparent), 0 0 12px var(--c); }
.l-paused .lamp    { --c: var(--gray); }
.l-on_hold .lamp   { --c: var(--violet); }
.l-done .lamp      { --c: var(--green); }
@keyframes blink { 0% { opacity: 1; } 100% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .l-new .lamp { animation: none; } }

.lamp-chip { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #1b3ac4; }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.warn { border-color: var(--violet); color: var(--violet); }
.btn.danger, .btn.ghost.danger { color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.icon-btn { width: 36px; height: 36px; border: 0; border-radius: var(--radius-sm); background: transparent; cursor: pointer; font-size: 18px; color: var(--ink-2); }
.icon-btn:hover { background: var(--line-2); }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
input[type=text], input[type=email], input[type=tel], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; min-height: 38px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
textarea { resize: vertical; min-height: 72px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- экран входа ---------- */
.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
}
.auth-panel {
  background: var(--panel); color: var(--panel-ink);
  padding: 48px clamp(24px, 6vw, 80px);
  display: flex; flex-direction: column; justify-content: space-between; gap: 48px;
}
.wordmark { font-family: var(--font-display); font-weight: 700; font-size: 22px; letter-spacing: .02em; }
.wordmark small { display: block; font-family: var(--font-ui); font-weight: 500; font-size: 13px; letter-spacing: 0; color: #9aa6ba; }
.auth-headline { font-family: var(--font-display); font-weight: 600; font-size: clamp(30px, 4.2vw, 52px); line-height: 1.08; max-width: 12ch; }
.tally { display: grid; gap: 14px; margin: 0; padding: 0; list-style: none; max-width: 420px; }
.tally li { display: grid; grid-template-columns: 18px 1fr; align-items: center; gap: 14px; padding-bottom: 14px; border-bottom: 1px solid #2c3648; }
.tally li:last-child { border-bottom: 0; }
.tally .lamp { width: 14px; height: 14px; }
.tally b { display: block; font-weight: 700; }
.tally span { color: #9aa6ba; font-size: 14px; }
.auth-form { display: grid; place-items: center; padding: 48px 24px; }
.auth-card { width: min(380px, 100%); display: grid; gap: 20px; }
.auth-card h1 { font-family: var(--font-display); font-weight: 600; font-size: 24px; }
.google-btn { min-height: 48px; width: 100%; font-size: 15px; }
.google-btn svg { width: 18px; height: 18px; }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--line-2); font-size: 14px; }
.notice.error { background: #fdecea; color: #9b2414; }
@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-panel { padding: 32px 20px; gap: 28px; }
  .auth-headline { font-size: 30px; }
}

/* ---------- каркас приложения ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 0 clamp(16px, 3vw, 32px); height: 60px;
  background: var(--panel); color: var(--panel-ink);
}
.topbar .wordmark { font-size: 17px; }
.topbar .who { margin-left: auto; text-align: right; font-size: 13px; line-height: 1.3; }
.topbar .who b { display: block; font-weight: 600; }
.topbar .who span { color: #9aa6ba; }
.topbar .btn { background: transparent; color: var(--panel-ink); border-color: #3a465c; min-height: 34px; }
.tabs { display: flex; gap: 4px; margin-left: 24px; overflow-x: auto; }
.tabs button {
  height: 60px; padding: 0 14px; border: 0; background: none; color: #9aa6ba; font-weight: 600; cursor: pointer;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs button[aria-selected=true] { color: #fff; border-bottom-color: var(--amber); }

.page { max-width: 1320px; margin: 0 auto; padding: 28px clamp(16px, 3vw, 32px) 64px; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; gap: 16px; margin-bottom: 20px; }
.page-head h1 { font-family: var(--font-display); font-weight: 600; font-size: 26px; }
.page-head .spacer { flex: 1; }

/* сводка */
.counters { display: flex; flex-wrap: wrap; gap: 0; margin-bottom: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.counter { flex: 1 1 140px; padding: 16px 20px; border-right: 1px solid var(--line-2); }
.counter:last-child { border-right: 0; }
.counter b { display: block; font-family: var(--font-display); font-weight: 600; font-size: 28px; line-height: 1.1; }
.counter span { font-size: 13px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.counter.alert b { color: var(--red); }

/* фильтры */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.filters select, .filters input { width: auto; min-width: 160px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 8px 14px; font-weight: 600; cursor: pointer; color: var(--ink-2); }
.seg button[aria-pressed=true] { background: var(--ink); color: #fff; }

/* ---------- таблицы ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line-2); }
th { font-size: 12.5px; font-weight: 600; color: var(--ink-2); background: #f8f9fb; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: #f7f9fd; }
tr.is-overdue td:first-child { box-shadow: inset 3px 0 0 var(--red); }
.task-cell b { display: block; font-weight: 700; }
.task-cell span { font-size: 12.5px; color: var(--ink-3); }
.num { font-family: var(--font-display); font-weight: 500; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.timer { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 48px 20px; text-align: center; color: var(--ink-2); }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

.prio { font-size: 13px; font-weight: 600; white-space: nowrap; }
.prio-1 { color: var(--ink-3); }
.prio-2 { color: var(--ink-2); }
.prio-3 { color: #b4560a; }
.prio-4 { color: var(--red); }

.bar { position: relative; height: 6px; border-radius: 3px; background: var(--line-2); overflow: hidden; min-width: 90px; }
.bar > span { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 3px; transition: width .4s; }
.bar.time > span { background: var(--ink-3); }
.bar.time.late > span { background: var(--red); }
.bar-cell { display: grid; gap: 6px; min-width: 120px; }
.bar-cell small { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.bar-cell small.late { color: var(--red); font-weight: 600; }

/* карточный вид таблиц на телефоне */
@media (max-width: 760px) {
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .table-cards td { border: 0; padding: 4px 0; display: flex; gap: 12px; justify-content: space-between; align-items: center; }
  .table-cards td[data-label]::before { content: attr(data-label); font-size: 12.5px; color: var(--ink-3); flex: none; }
  .table-cards td.task-cell { display: block; }
  .table-cards .bar-cell { flex: 1; max-width: 60%; }
  .tabs { margin-left: 0; }
  .topbar .who { display: none; }
}

/* ---------- панель задачи ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgb(24 32 46 / .35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41;
  width: min(760px, 100%); background: var(--surface); overflow-y: auto;
  box-shadow: -12px 0 40px rgb(24 32 46 / .18);
}
.drawer-enter { transition: transform .22s ease-out; }
.drawer-enter-start { transform: translateX(40px); }
.drawer-enter-end { transform: none; }
@media (prefers-reduced-motion: reduce) { .drawer-enter { transition: none; } }
.drawer-inner { padding: 24px clamp(16px, 3vw, 32px) 48px; display: grid; gap: 26px; }
.drawer-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; }
.drawer-head h2 { font-family: var(--font-display); font-weight: 600; font-size: 22px; margin: 4px 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip { padding: 3px 10px; border-radius: 999px; background: var(--line-2); font-size: 13px; font-weight: 600; }
.chip.danger { background: #fdecea; color: #b42318; }
.hold-banner { padding: 12px 14px; border-radius: var(--radius-sm); background: #f1ebfc; color: #4d2a95; font-weight: 600; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin: 0; }
.facts dt { font-size: 12.5px; color: var(--ink-3); }
.facts dd { margin: 2px 0 0; font-weight: 600; }

.meters { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.meter-top { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-size: 14px; color: var(--ink-2); }
.meter-top strong { color: var(--ink); }
.meter .bar { height: 10px; border-radius: 5px; }
@media (max-width: 560px) { .meters { grid-template-columns: 1fr; } }

.controls { display: grid; gap: 14px; padding: 18px; border-radius: var(--radius); background: var(--panel); color: var(--panel-ink); }
.timer-big { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; }
.timer-big .timer-value { font-family: var(--font-display); font-weight: 600; font-size: 34px; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.timer-big .timer-label { color: #b3bdcd; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.controls .btn:not(.primary):not(.success) { background: transparent; color: var(--panel-ink); border-color: #3a465c; }
.controls .btn.warn { color: #c3a6f5; border-color: #6c50a6; }
.controls .btn.danger { color: #ff8b7a; }
.controls select { width: auto; background: #222c3d; border-color: #3a465c; color: var(--panel-ink); }
.admin-row { padding-top: 12px; border-top: 1px solid #2c3648; }

.drawer section h3 { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
.stages { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); }
.stages li { display: grid; grid-template-columns: 14px 1fr auto 96px; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line-2); }
.stages li:last-child { border-bottom: 0; }
.stage-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--gray); }
.st-done .stage-dot { background: var(--green); border-color: var(--green); }
.st-current { background: #fff8e8; }
.st-current .stage-dot { background: var(--amber); border-color: var(--amber); }
.st-current .stage-name { font-weight: 700; }
.st-pending .stage-name { color: var(--ink-2); }
.stage-weight { font-size: 12.5px; color: var(--ink-3); }
.stage-time { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.desc { margin: 0; white-space: pre-wrap; }

.comment-form { display: grid; gap: 10px; margin-bottom: 14px; }
.comment-form-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; }
.file-pick { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 14px; border: 1px dashed var(--ink-3); border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; color: var(--ink-2); max-width: 100%; }
.file-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.comments td { vertical-align: top; font-size: 14px; }
.comment-body { margin: 0; white-space: pre-wrap; word-break: break-word; }
.file-link { margin-top: 6px; padding: 0; border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; text-align: left; word-break: break-all; }
.row-actions { white-space: nowrap; }
.row-actions button { border: 0; background: none; color: var(--ink-2); cursor: pointer; padding: 2px 4px; font-size: 13px; }
.row-actions button:hover { color: var(--ink); text-decoration: underline; }
.cbadge, .status-select { font-size: 13px; font-weight: 600; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.status-select { width: auto; min-height: 30px; padding: 2px 8px; }
.cs-open { background: #fdecea; color: #b42318; }
.cs-in_work { background: #fff3d6; color: #8a5a00; }
.cs-resolved { background: #e3f4ea; color: #146c43; }

/* ---------- модальные окна ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgb(24 32 46 / .45); display: grid; place-items: center; padding: 16px; }
.modal { width: min(600px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border-radius: var(--radius); padding: 24px; display: grid; gap: 16px; }
.modal h2 { font-family: var(--font-display); font-weight: 600; font-size: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- дашборд ---------- */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; margin-bottom: 20px; }
@media (max-width: 1000px) { .dash-grid { grid-template-columns: 1fr; } }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.box h2 { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.chart { display: grid; grid-template-columns: repeat(14, 1fr); gap: 6px; align-items: end; height: 170px; }
.chart-col { display: grid; grid-template-rows: 1fr auto; height: 100%; gap: 6px; text-align: center; }
.chart-bars { display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.chart-bars i { display: block; width: 40%; max-width: 12px; border-radius: 2px 2px 0 0; min-height: 2px; }
.chart-bars .c-done { background: var(--green); }
.chart-bars .c-created { background: #c7d0de; }
.chart-col small { font-size: 11px; color: var(--ink-3); }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); margin-top: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.kv { display: grid; gap: 10px; margin: 0; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line-2); }
.kv div:last-child { border-bottom: 0; padding-bottom: 0; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 700; }

/* ---------- уведомление ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: var(--radius-sm);
  background: var(--ink); color: #fff; font-weight: 600; box-shadow: 0 8px 24px rgb(24 32 46 / .25);
}
.toast.error { background: #9b2414; }
.loading { min-height: 100vh; display: grid; place-items: center; color: var(--ink-2); }
.live-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: #9aa6ba; }
.live-dot i { width: 7px; height: 7px; border-radius: 50%; background: var(--gray); }
.live-dot.on i { background: var(--green); }

/* ---------- метка роли ---------- */
.role-tag {
  display: inline-flex; align-items: center; gap: 8px;
  margin-bottom: 16px; padding: 6px 14px 6px 12px;
  border-radius: 999px; color: #fff; font-weight: 700; font-size: 14px;
}
.role-tag i { width: 8px; height: 8px; border-radius: 50%; background: #fff; }
.role-client   { background: #1d7fe0; }
.role-operator { background: #1f9560; }
.role-super    { background: #f5b301; }
.topbar.role-bar-client   { box-shadow: inset 0 -3px 0 #1d7fe0; }
.topbar.role-bar-operator { box-shadow: inset 0 -3px 0 #1f9560; }
.topbar.role-bar-super    { box-shadow: inset 0 -3px 0 #5b6578; }
