/* TechDesk — Dashboard главного инженера.
   Приоритет: читаемость на большом мониторе в кабинете, минимум украшений. */

:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --border: #d9e0e8;
  --border-strong: #c2ccd8;
  --text: #16202b;
  --text-dim: #5c6b7a;
  --text-faint: #8b98a6;
  --accent: #0d6efd;
  --accent-dark: #0a58ca;

  --crit: #d92d20;
  --high: #ea7317;
  --med: #d9a406;
  --low: #12805c;
  --new: #d92d20;
  --work: #0d6efd;
  --overdue: #b42318;
  --done: #12805c;
  --closed: #475467;
  --alert-bg: #fff1ef;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .12);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1319;
    --surface: #161d26;
    --surface-2: #1c242e;
    --border: #27313d;
    --border-strong: #37434f;
    --text: #e7edf3;
    --text-dim: #a3b1c0;
    --text-faint: #7b8998;
    --shadow: none;
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, .5);
    --alert-bg: #3a1512;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

.hidden { display: none !important; }

/* ------------------------------ Шапка ------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  color: var(--text);
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -.2px;
  white-space: nowrap;
}
.brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--crit);
  box-shadow: 0 0 0 4px rgba(217, 45, 32, .15);
  flex: none;
}
/* Платформа приглушена, модуль — акцент: инженер переключается между
   разделами Digital Plant, а не выбирает между продуктами. */
.brand .platform { font-size: 14px; font-weight: 600; color: var(--text-dim); }
.brand .sep { color: var(--text-faint); font-weight: 400; }
.brand .module { font-size: 17px; font-weight: 700; }

/* Настройки собраны под шестерёнкой: справочники и пользователи нужны
   раз в месяц, а место в шапке — каждый день. */
.menu-wrap { position: relative; }
#menu-btn { font-size: 16px; padding: 4px 9px; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 190px; z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 5px;
  display: flex; flex-direction: column; gap: 2px;
}
.menu a {
  padding: 8px 12px; border-radius: 7px;
  color: var(--text); font-weight: 500; font-size: 14px;
  white-space: nowrap;
}
.menu a:hover { background: var(--surface-2); }
.menu a.active { background: var(--accent); color: #fff; }

.live {
  /* Первый элемент правой группы — он и отжимает её к правому краю
     (раньше это делала строка поиска, которая переехала в фильтры) */
  margin-left: auto;
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--text-dim);
  white-space: nowrap;
}
.live i {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--done); display: inline-block;
  animation: pulse 2s infinite;
}
.live.off i { background: var(--text-faint); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .25 } }

.who { display: flex; align-items: center; gap: 10px; font-size: 14px; white-space: nowrap; }
.who b { font-weight: 600; }
.who small { color: var(--text-faint); display: block; font-size: 12px; line-height: 1.1; }

/* ------------------------------ Кнопки ------------------------------ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 500;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--crit); border-color: var(--crit); background: transparent; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-dim); }
.btn.ghost:hover { background: var(--surface-2); }
/* Браузер запретил звук — состояние должно бросаться в глаза,
   иначе тишину примут за неисправность системы. */
.btn.blocked {
  border-color: var(--crit);
  color: var(--crit);
  font-weight: 600;
  animation: alertPulse 1.6s ease-in-out infinite;
}
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ------------------------------ Каркас ------------------------------ */
main { padding: 12px 24px 60px; max-width: 1800px; margin: 0 auto; }

.section-title {
  display: flex; align-items: baseline; gap: 12px;
  margin: 0 0 12px;
  font-size: 15px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .6px;
}
.section-title span { color: var(--text-faint); font-weight: 400; text-transform: none; letter-spacing: 0; }

/* ------------------------------ Фильтры ------------------------------ */
/* Одна строка вместо двух: слева управление фильтром, справа счётчик.
   Отдельный заголовок «Лента проблем» ничего не сообщал — под ним и так лента. */
.filter-bar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 6px; flex-wrap: wrap;
}
.filter-bar .search { flex: 0 1 340px; min-width: 190px; position: relative; }
.filter-bar .search input {
  width: 100%;
  padding: 6px 11px 6px 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
}
.filter-bar .search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.filter-bar .search::before {
  content: "🔎";
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  font-size: 12px; opacity: .6; pointer-events: none;
}

.filter-bar .count {
  margin-left: auto; font-size: 13px; color: var(--text-faint);
  white-space: nowrap;
}
.filter-bar .active { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filter-bar .active i {
  font-style: normal; font-size: 12px;
  padding: 2px 9px; border-radius: 999px;
  background: var(--accent); color: #fff;
}
.filter-bar .active.none { color: var(--text-faint); font-size: 13px; }

.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 16px;
}
.filters select, .filters input[type="date"] {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  max-width: 200px;
}
.filters .sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }
.filters label { font-size: 13px; color: var(--text-faint); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  cursor: pointer; font-size: 13px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ------------------------------ Лента ------------------------------ */
/* Карточка — три строки: шапка, описание, служебные данные. Плотность
   важнее украшений: на мониторе инженера должно помещаться максимум заявок. */
.feed { display: grid; gap: 4px; }

.card {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border-strong);
  border-radius: 7px;
  padding: 5px 11px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.card:hover { background: var(--surface-2); border-color: var(--border-strong); }
.card .body { flex: 1; min-width: 0; }

.thumb {
  flex: none; width: 40px; height: 40px; border-radius: 5px;
  object-fit: cover; background: var(--surface-2);
  border: 1px solid var(--border);
}
img.thumb { cursor: zoom-in; }
img.thumb:hover { border-color: var(--accent); }
.card.sev-critical { border-left-color: var(--crit); }
.card.sev-high { border-left-color: var(--high); }
.card.sev-medium { border-left-color: var(--med); }
.card.sev-low { border-left-color: var(--low); }
.card.alert {
  border-left-color: var(--crit);
  animation: alertPulse 1.1s ease-in-out infinite;
}
@keyframes alertPulse {
  0%, 100% { background: var(--surface); box-shadow: var(--shadow); }
  50% {
    background: var(--alert-bg);
    box-shadow: 0 0 0 3px rgba(217, 45, 32, .55), 0 0 26px rgba(217, 45, 32, .3);
  }
}
/* Отдельной метки «НОВАЯ» нет: рядом уже стоит бейдж статуса, а факт
   «инженер ещё не открывал» показывает сама пульсация. */

.card .line {
  display: flex; align-items: baseline; gap: 8px;
  min-width: 0;
}
/* Вторая строка: описание тянется, служебные данные прижаты вправо
   и отдаются первыми, когда ширины не хватает. */
.card .line.low { align-items: baseline; margin-top: 1px; }
.card .line.low .desc { flex: 1 1 auto; min-width: 0; }
.card .line.low .meta { flex: 0 1 auto; text-align: right; }
.card .num {
  font-family: var(--mono); font-weight: 700; font-size: 12px;
  white-space: nowrap; flex: none;
}
.card .equip {
  font-weight: 600; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 30%;
}
/* Ответственный прижат вправо и уступает место остальному при нехватке ширины */
.card .who {
  margin-left: auto; font-size: 12px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card .desc {
  font-size: 13px; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card .meta {
  font-size: 11px; color: var(--text-faint); line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  white-space: nowrap; flex: none;
}
.badge.overdue { background: #fee4e2; border-color: #fda29b; color: #912018; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge.overdue { background: #3b1512; border-color: #7a271a; color: #fda29b; }
}

.card-del {
  flex: none; width: 20px; height: 18px; padding: 0; align-self: center;
  border: 1px solid transparent; border-radius: 6px;
  background: transparent; color: transparent;
  cursor: pointer; font-size: 12px; line-height: 1;
}
.card:hover .card-del { color: var(--text-faint); }
.card-del:hover { background: var(--crit); border-color: var(--crit); color: #fff; }

.empty {
  text-align: center; padding: 60px 20px; color: var(--text-faint);
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
}

.load-more { display: flex; justify-content: center; margin-top: 16px; }

/* ------------------------------ Карточка проблемы ------------------------------ */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 20px; align-items: start; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.panel h3 {
  margin: 0 0 12px; font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .7px; color: var(--text-dim);
}
.detail-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.detail-head .num { font-family: var(--mono); font-size: 24px; font-weight: 700; }
.detail-head .equip { font-size: 22px; font-weight: 600; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px 20px; }
.info-grid .k { font-size: 12px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .5px; }
.info-grid .v { font-weight: 500; margin-top: 2px; overflow-wrap: anywhere; }

.problem-text { font-size: 17px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.media-grid img, .media-grid video {
  width: 100%; height: 150px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--border); background: #000; cursor: pointer;
}
.media-grid a.doc {
  display: flex; align-items: center; justify-content: center; height: 150px;
  border: 1px dashed var(--border-strong); border-radius: 8px; font-size: 13px; padding: 8px; text-align: center;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 5px; }
.field select, .field input, .field textarea {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
}
.field textarea { min-height: 78px; resize: vertical; }
.field .row { display: flex; gap: 8px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative; padding: 0 0 16px 22px;
  border-left: 2px solid var(--border); margin-left: 5px;
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: 4px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border-strong);
}
.timeline li.hl::before { border-color: var(--accent); background: var(--accent); }
.timeline .t { font-size: 12px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.timeline .a { font-weight: 600; font-size: 14px; }
.timeline .d { font-size: 13px; color: var(--text-dim); overflow-wrap: anywhere; }

/* ------------------------------ Таблицы (справочники/люди) ------------------------------ */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-faint); padding: 8px 10px; border-bottom: 1px solid var(--border);
  font-weight: 600;
}
table.grid td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid tr.off td { opacity: .45; }
table.grid input, table.grid select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); width: 100%; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button {
  padding: 8px 16px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer;
}
.tabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ------------------------------ Логин ------------------------------ */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 30px 28px; box-shadow: var(--shadow-lg);
}
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login p.sub { margin: 0 0 22px; color: var(--text-dim); font-size: 14px; }
.login .err { color: var(--crit); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ------------------------------ Выбор должности ------------------------------ */
.role-picker { position: relative; }
.rp-btn {
  width: 100%; text-align: left;
  padding: 6px 9px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rp-btn:hover { border-color: var(--border-strong); }
.rp-btn::after { content: " ▾"; color: var(--text-faint); }
.rp-menu {
  position: absolute; z-index: 60; top: calc(100% + 4px); left: 0;
  min-width: 250px; max-height: 320px; overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px;
  box-shadow: var(--shadow-lg); padding: 4px;
}
.rp-item { display: flex; align-items: center; border-radius: 6px; }
.rp-item:hover { background: var(--surface-2); }
.rp-name { flex: 1; padding: 7px 10px; cursor: pointer; font-size: 14px; }
.rp-del {
  flex: none; width: 24px; height: 24px; margin-right: 4px; padding: 0;
  border: 1px solid transparent; border-radius: 6px;
  background: transparent; color: var(--text-faint);
  cursor: pointer; font-size: 12px; line-height: 1;
}
.rp-del:hover { background: var(--crit); border-color: var(--crit); color: #fff; }
.rp-new {
  width: 100%; text-align: left; margin-top: 4px;
  padding: 8px 10px; border: 0; border-top: 1px solid var(--border);
  border-radius: 0 0 6px 6px;
  background: transparent; color: var(--accent);
  cursor: pointer; font-size: 14px; font-weight: 500;
}
.rp-new:hover { background: var(--surface-2); }

/* ------------------------------ Модальное окно ------------------------------ */
.modal-back {
  position: fixed; inset: 0; z-index: 95;
  background: rgba(16, 24, 40, .5);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-lg);
  padding: 22px 24px;
}
.modal h3 { margin: 0 0 4px; font-size: 18px; }
.modal p.hint { margin: 0 0 18px; color: var(--text-dim); font-size: 13px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.modal .err { color: var(--crit); font-size: 13px; min-height: 18px; margin-top: 6px; }

/* ------------------------------ Уведомления ------------------------------ */
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 90; display: grid; gap: 10px; max-width: 380px; }
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--crit);
  border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow-lg);
  cursor: pointer; animation: slidein .25s ease-out;
}
.toast b { display: block; font-size: 14px; }
.toast small { color: var(--text-dim); }
@keyframes slidein { from { transform: translateX(30px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ------------------------------ Модальное окно медиа ------------------------------ */
#lightbox {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .88);
  display: grid; place-items: center; z-index: 100; padding: 30px;
}
#lightbox img, #lightbox video { max-width: 100%; max-height: 90vh; border-radius: 8px; }

/* ------------------------------ Адаптив (ноутбук) ------------------------------ */
@media (max-width: 1200px) {
  .detail { grid-template-columns: 1fr; }
  .topbar { gap: 12px; padding: 0 14px; }
}
@media (max-width: 820px) {
  main { padding: 14px 12px 40px; }
  .nav a { padding: 7px 10px; font-size: 14px; }
  .who small { display: none; }
}
