/* ==========================================================================
   Helpdesk — App shell и страница «Входящие»
   Всё собрано из токенов дизайн-системы 1.0. Хардкод-значений нет,
   кроме геометрии раскладки (ширины колонок, брейкпоинты).
   ========================================================================== */

/* Нативные контролы (чекбоксы, скроллбары) должны знать про тёмную тему.
   Кандидат на перенос в design-system/css/tokens.css. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark; } }
input[type="checkbox"] { accent-color: var(--fg-primary); }

/* --- Оболочка приложения ---------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  align-items: start;
}

.app__topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

.app__sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100dvh - var(--topbar-h));
  overflow-y: auto;
  padding-bottom: var(--sp-8);
}

.app__main {
  min-width: 0;
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.app__scrim { display: none; }

/* --- Топбар ------------------------------------------------------------------ */

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--ff-display);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-heading);
  font-size: var(--fs-h4);
  color: var(--fg-primary);
  text-decoration: none;
}
.brand:hover { border-bottom-color: transparent; }
.brand__mark {
  width: 22px; height: 22px;
  background-image: var(--grad-hot);
  flex: none;
}

.topbar__search {
  flex: 1;
  max-width: 460px;
  padding-block: var(--sp-2);
}

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border: var(--bw-hair) solid transparent;
  background: transparent;
  color: var(--fg-secondary);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--bg-muted); color: var(--fg-primary); }
.icon-btn__dot {
  position: absolute;
  top: 4px; right: 4px;
  min-width: 15px; height: 15px;
  padding: 0 3px;
  background: var(--c-red);
  color: var(--c-white);
  border-radius: var(--r-pill);
  font-family: var(--ff-mono);
  font-size: var(--fs-2xs);
  line-height: 15px;
  text-align: center;
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-2) var(--sp-1) var(--sp-1);
  border: var(--bw-hair) solid transparent;
  background: transparent;
  cursor: pointer;
  color: var(--fg-primary);
}
.topbar__user:hover { background: var(--bg-muted); }
.topbar__user-name { font-size: var(--fs-sm); font-weight: var(--fw-medium); }

.nav-toggle { display: none; }

/* --- Сайдбар ----------------------------------------------------------------- */

.side-group { padding: var(--sp-4) 0 var(--sp-2); }
.side-group + .side-group { border-top: var(--bw-hair) solid var(--bd-subtle); }
.side-group__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-3) var(--sp-2);
}
.side-group__add {
  border: 0; background: none; cursor: pointer;
  color: var(--fg-muted); line-height: 0; padding: 2px;
}
.side-group__add:hover { color: var(--fg-accent); }

.nav-item svg { flex: none; color: var(--fg-muted); }
.nav-item--active svg { color: var(--c-red); }
.nav-item__count.is-hot { color: var(--c-red); font-weight: var(--fw-medium); }

.side-foot {
  margin-top: var(--sp-4);
  padding: var(--sp-4) var(--sp-3) 0;
  border-top: var(--bw-hair) solid var(--bd-subtle);
}

/* --- Шапка страницы ---------------------------------------------------------- */

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }
.page-head h1 { margin-bottom: var(--sp-1); }

/* --- Плитки метрик ------------------------------------------------------------ */

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  border: var(--bw-hair) solid var(--bd-default);
  background: var(--bg-surface);
}
.metrics .metric {
  border: 0;
  border-right: var(--bw-hair) solid var(--bd-subtle);
  padding: var(--sp-4) var(--sp-5);
}
.metrics .metric:last-child { border-right: 0; }
.metrics .metric__value { font-size: var(--fs-h1); margin-top: var(--sp-1); }
.metrics .metric--alert .metric__value { color: var(--c-red); }

/* --- Панель фильтров ---------------------------------------------------------- */

.toolbar { border: var(--bw-hair) solid var(--bd-default); background: var(--bg-surface); }
.toolbar__row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  flex-wrap: wrap;
}
.toolbar__row + .toolbar__row { border-top: var(--bw-hair) solid var(--bd-subtle); }
.toolbar__row--chips { gap: var(--sp-2); }
.toolbar .search { border: 0; padding: 0; flex: 1; min-width: 220px; }
.toolbar .search:focus-within { border: 0; }
.spacer { margin-left: auto; }

.ctl-sm { padding: var(--sp-2) var(--sp-3); font-size: var(--fs-sm); width: auto; }
.select.ctl-sm { padding-right: var(--sp-8); }

.viewswitch { display: flex; border: var(--bw-hair) solid var(--bd-default); }
.viewswitch button {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: var(--bg-surface); color: var(--fg-muted); cursor: pointer;
}
.viewswitch button + button { border-left: var(--bw-hair) solid var(--bd-default); }
.viewswitch button[aria-pressed="true"] { background: var(--ctl-solid-bg); color: var(--ctl-solid-fg); }

/* --- Панель массовых действий -------------------------------------------------- */

.bulkbar {
  display: none;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-inverse);
  color: var(--fg-inverse);
  flex-wrap: wrap;
}
.bulkbar.is-visible { display: flex; }
.bulkbar__count { font-family: var(--ff-mono); font-size: var(--fs-sm); }
.bulkbar .btn { border-color: currentColor; color: inherit; }
.bulkbar .btn:hover { background: rgba(127, 127, 127, .25); }

/* --- Таблица тикетов ------------------------------------------------------------ */

.tickets { table-layout: fixed; }
.tickets thead th { padding: var(--sp-3) var(--sp-3); }
.tickets tbody td { padding: var(--sp-3); }
.tickets tbody tr:hover .t-subject { color: var(--fg-accent); }
.tickets tbody tr.is-selected { background: var(--bg-subtle); }
.tickets tbody tr.is-breach td:first-child { box-shadow: inset 3px 0 0 var(--c-red); }
.tickets .table__id { white-space: nowrap; }

/* Колонка темы забирает всё свободное место, остальные фиксированы */
.c-check  { width: 36px; }
.c-star   { width: 30px; }
.c-pri    { width: 104px; }
.c-id     { width: 92px; }
.c-status { width: 128px; }
.c-req    { width: 168px; }
.c-asg    { width: 148px; }
.c-sla    { width: 104px; }
.c-act    { width: 40px; }

.t-subject { color: var(--fg-accent); }
.tickets tbody tr.is-selected { background: var(--bg-subtle); }
.tickets tbody tr.is-breach td:first-child { box-shadow: inset 3px 0 0 var(--c-red); }

.c-check   { width: 36px; }
.c-star    { width: 32px; }
.c-pri     { width: 104px; }
.c-id      { width: 92px; }
.c-status  { width: 132px; }
.c-people  { width: 176px; }
.c-sla     { width: 120px; }
.c-upd     { width: 110px; }
.c-act     { width: 40px; }

.t-subject {
  display: block;
  font-weight: var(--fw-medium);
  color: var(--fg-primary);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.t-subject:hover { color: var(--fg-accent); border-bottom-color: transparent; }
.t-meta {
  display: flex; align-items: center; gap: var(--sp-3);
  margin-top: var(--sp-1);
  font-size: var(--fs-xs); color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  /* обрезка справа выглядит намеренной, а не поломанной */
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
}
.t-meta__item { display: inline-flex; align-items: center; gap: 4px; flex: none; }
.t-meta .tag { flex: none; }

.tag {
  display: inline-flex; align-items: center;
  padding: 1px 6px;
  border: var(--bw-hair) solid var(--bd-default);
  border-radius: var(--r-none);
  font-size: var(--fs-2xs);
  color: var(--fg-secondary);
  white-space: nowrap;
}

.person { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.person__name { font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person__sub  { font-size: var(--fs-2xs); color: var(--fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.assign {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-2);
  border: 1px dashed var(--bd-default);
  background: transparent;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  cursor: pointer;
}
.assign:hover { border-style: solid; border-color: var(--bd-strong); color: var(--fg-primary); }

.sla { font-family: var(--ff-mono); font-size: var(--fs-xs); white-space: nowrap; }
.sla--breach { color: var(--st-danger); font-weight: var(--fw-medium); }

.star { border: 0; background: none; cursor: pointer; color: var(--fg-muted); opacity: .55; line-height: 0; padding: 2px; }
.star:hover { color: var(--c-amber); opacity: 1; }
.star[aria-pressed="true"] { color: var(--c-amber); opacity: 1; }
.star[aria-pressed="true"] svg { fill: currentColor; }

.time { font-family: var(--ff-mono); font-size: var(--fs-xs); color: var(--fg-muted); white-space: nowrap; }

/* --- Подвал списка -------------------------------------------------------------- */

.list-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-4); flex-wrap: wrap;
}

/* --- Пустое состояние ------------------------------------------------------------ */

#empty { display: none; }
#empty.is-visible { display: block; }

/* --- Адаптив ---------------------------------------------------------------------- */

@media (max-width: 1500px) { .hide-xl { display: none; } }
@media (max-width: 1180px) { .hide-lg { display: none; } }
.show-md { display: none; }
@media (max-width: 900px)  {
  .hide-md { display: none; }
  .show-md { display: inline-flex; }
}

@media (max-width: 1080px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .nav-toggle { display: inline-flex; }
  .app__sidebar {
    position: fixed;
    top: var(--topbar-h); left: 0; bottom: 0;
    width: var(--sidebar-w);
    z-index: var(--z-dropdown);
    transform: translateX(-100%);
    transition: transform var(--dur-base) var(--ease);
  }
  .app.is-nav-open .app__sidebar { transform: none; }
  .app.is-nav-open .app__scrim {
    display: block;
    position: fixed; inset: var(--topbar-h) 0 0 0;
    background: var(--bg-overlay);
    z-index: var(--z-overlay);
    z-index: calc(var(--z-dropdown) - 1);
  }
}

@media (max-width: 720px) {
  .app__main { padding: var(--sp-4); }
  .topbar { padding-inline: var(--sp-4); gap: var(--sp-3); }
  .topbar__search { display: none; }
  .page-head__actions .btn span { display: none; }
}
