/* === Base === */
:root {
  --bg: #0b0d12;
  --bg-elev: #12151c;
  --bg-elev-2: #161a23;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #e6e8ef;
  --text-dim: #a5abbd;
  --text-mute: #7a8194;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --accent-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;
  --shadow-card: 0 8px 30px rgba(0, 0, 0, 0.25);
  --shadow-primary: 0 6px 20px rgba(99, 102, 241, 0.35);
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  --bg: #f6f7fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #f1f3f9;
  --border: rgba(15, 18, 30, 0.08);
  --border-strong: rgba(15, 18, 30, 0.14);
  --text: #0f1220;
  --text-dim: #4a5067;
  --text-mute: #6b7388;
  --shadow-card: 0 8px 30px rgba(15, 18, 30, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

:root[data-theme="light"] {
  color-scheme: light;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -200px, rgba(99, 102, 241, 0.18), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  margin: 0;
  min-width: 320px;
  text-rendering: geometricPrecision;
}

:root[data-theme="light"] body {
  background:
    radial-gradient(1200px 600px at 50% -200px, rgba(99, 102, 241, 0.1), transparent 60%),
    var(--bg);
}

::selection {
  background: rgba(99, 102, 241, 0.35);
  color: #fff;
}

::-webkit-scrollbar {
  height: 10px;
  width: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-mute);
}

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select,
summary {
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.2s ease;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.35);
  outline: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.shell {
  margin: 0 auto;
  max-width: 1520px;
  min-height: 100vh;
  padding: 24px;
}

/* === Header === */
.topbar {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-bottom: 20px;
  padding: 0 0 18px;
}

.eyebrow {
  color: var(--text-mute);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 1;
  margin-bottom: 8px;
  text-transform: uppercase;
}

h1 {
  color: var(--text);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.top-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  min-width: 0;
}

.nav-link,
.theme-toggle {
  align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-dim);
  display: inline-flex;
  font-size: 13px;
  font-weight: 500;
  height: 36px;
  justify-content: center;
  line-height: 1;
  min-height: 36px;
  padding: 0 14px;
  text-decoration: none;
  white-space: nowrap;
}

.nav-link:hover,
.theme-toggle:hover {
  border-color: var(--border-strong);
  color: var(--text);
  transform: translateY(-1px);
}

.nav-link[href$="analytics.html"] {
  background: var(--accent-grad);
  border-color: transparent;
  box-shadow: var(--shadow-primary);
  color: #fff;
}

/* === Grouped topbar menu (import/export/sync) === */
.nav-menu {
  position: relative;
}

.nav-menu__panel {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  display: grid;
  gap: 2px;
  min-width: 220px;
  padding: 6px;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
}

.nav-menu__panel[hidden] {
  display: none;
}

.nav-menu__item {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  font: 500 13px/1 var(--font-sans);
  gap: 8px;
  padding: 9px 10px;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  width: 100%;
}

.nav-menu__item:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}

.nav-menu__item svg,
.nav-menu__item i {
  color: inherit;
  flex: 0 0 auto;
  height: 14px;
  stroke-width: 2;
  width: 14px;
}

[data-nav-menu-trigger][aria-expanded="true"] {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.35);
  color: var(--text);
}

.yard-toggle {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  font-size: 12px;
  font-weight: 600;
  gap: 6px;
  height: 36px;
  letter-spacing: 0.02em;
  line-height: 1;
  padding: 0 4px;
  white-space: nowrap;
}

.yard-toggle:hover {
  color: var(--text);
}

.yard-toggle input {
  accent-color: var(--success);
  appearance: none;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  display: grid;
  height: 16px;
  margin: 0;
  place-content: center;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  width: 16px;
}

.yard-toggle input::before {
  border-bottom: 2px solid #fff;
  border-right: 2px solid #fff;
  content: "";
  height: 8px;
  opacity: 0;
  transform: rotate(45deg) translate(-1px, -1px) scale(0.8);
  transition: opacity 0.15s ease, transform 0.15s ease;
  width: 4px;
}

.yard-toggle input:checked {
  background: var(--success);
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.14);
}

.yard-toggle input:checked::before {
  opacity: 1;
  transform: rotate(45deg) translate(-1px, -1px) scale(1);
}

.account-overlay {
  align-items: center;
  background: rgba(5, 8, 16, 0.62);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 9999;
}

.account-dialog {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  color: var(--text);
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 18px;
  width: min(440px, 100%);
}

.account-dialog__head {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.account-dialog__head strong {
  display: block;
  font-size: 18px;
}

.account-dialog__head span,
.account-form span,
.account-dialog__message {
  color: var(--text-dim);
  font-size: 12px;
}

.account-dialog__close {
  align-items: center;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  height: 32px;
  justify-content: center;
  width: 32px;
}

.account-form {
  border-top: 1px solid var(--border);
  display: grid;
  gap: 10px;
  padding-top: 14px;
}

.account-form label {
  display: grid;
  gap: 6px;
}

.account-form input {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  min-height: 38px;
  padding: 8px 10px;
}

.account-dialog__message {
  min-height: 18px;
}

.account-dialog__message--error {
  color: var(--danger);
}

.account-dialog__logout {
  justify-self: start;
}

.theme-toggle {
  padding: 0;
  width: 36px;
}

.theme-icon {
  fill: none;
  height: 17px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 17px;
}

.theme-icon-sun {
  display: none;
}

:root[data-theme="light"] .theme-icon-moon {
  display: none;
}

:root[data-theme="light"] .theme-icon-sun {
  display: block;
}

.nav-link.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.export-progress {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin: 0 0 20px;
  padding: 14px 16px;
}

.export-progress-head {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.export-progress-head strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.export-progress-head span {
  color: var(--text-mute);
  font-size: 12px;
}

.export-progress-track {
  background: var(--bg-elev-2);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.export-progress-bar {
  background: var(--accent-grad);
  border-radius: inherit;
  height: 100%;
  transition: width 0.3s ease;
  width: 0;
}

.export-history {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin: 0 0 20px;
  padding: 12px 16px;
}

.export-history__head,
.export-history__item {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.export-history__head strong {
  color: var(--text);
  font-size: 13px;
}

.export-history__actions {
  align-items: center;
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}

.icon-button {
  align-items: center;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  flex-shrink: 0;
  height: 32px;
  justify-content: center;
  padding: 0;
  width: 32px;
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.icon-button i,
.icon-button svg {
  height: 16px;
  pointer-events: none;
  width: 16px;
}

.icon-button--danger:hover {
  border-color: var(--ruby);
  color: var(--ruby);
}

.export-history__item strong .icon-button {
  margin-left: 8px;
  vertical-align: middle;
}

.export-history__list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.export-history__item {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.export-history__meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.export-history__name {
  color: var(--text);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.export-history__time,
.export-history__empty {
  color: var(--text-mute);
  font-size: 12px;
}

.export-history__status--error { color: var(--ruby); }

/* === User administration === */
.admin-workspace {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin: 0 0 20px;
  padding: 20px;
}

.admin-workspace[hidden] {
  display: none;
}

.admin-workspace__head,
.admin-users-table__head,
.admin-users-table__row,
.admin-users-table__actions {
  align-items: center;
  display: flex;
  gap: 12px;
}

.admin-workspace__head,
.admin-users-table__head {
  justify-content: space-between;
}

.admin-workspace h2,
.admin-users-table__head h3 {
  color: var(--text);
  margin: 0;
}

.admin-workspace h2 {
  font-size: 20px;
}

.admin-users-table__head {
  margin-top: 20px;
}

.admin-users-table__head h3 {
  font-size: 16px;
}

.admin-create-user-form {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(150px, 1fr) minmax(170px, 1fr) minmax(180px, 1fr) auto;
  margin-top: 18px;
}

.admin-create-user-form label {
  display: grid;
  gap: 7px;
}

.admin-create-user-form label > span {
  color: var(--text-mute);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.admin-create-user-form input,
.admin-create-user-form select,
.admin-users-table input,
.admin-users-table select {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  min-height: 38px;
  padding: 0 10px;
}

.admin-workspace__message {
  color: var(--emerald);
  display: block;
  font-size: 13px;
  min-height: 18px;
  padding-top: 12px;
}

.admin-workspace__message--error { color: var(--ruby); }

.admin-users-table {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.admin-users-table__row {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) minmax(150px, 0.8fr) minmax(180px, 1.1fr) minmax(160px, 1fr) minmax(280px, 1.8fr);
  padding: 10px;
}

.admin-users-table__login {
  color: var(--text);
  overflow-wrap: anywhere;
}

.admin-users-table__complexes {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.admin-users-table__complexes span {
  color: var(--text-mute);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}

.admin-users-table__complexes select {
  min-width: 0;
  width: 100%;
}

.admin-users-table__complexes .nav-link {
  justify-content: center;
  min-height: 38px;
  width: 100%;
}

.complex-picker-overlay {
  align-items: center;
  background: rgba(3, 7, 18, .76);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 120;
}

.complex-picker {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .45);
  display: grid;
  gap: 18px;
  max-height: min(760px, calc(100dvh - 40px));
  max-width: 920px;
  overflow: auto;
  padding: 20px;
  width: min(920px, 100%);
}

.complex-picker__head,
.complex-picker__actions {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.complex-picker__head > div { display: grid; gap: 4px; }
.complex-picker__head strong { font-size: 18px; }
.complex-picker__head span,
.complex-picker__column p,
.complex-picker__empty { color: var(--text-mute); font-size: 13px; margin: 0; }

.complex-picker__columns {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.complex-picker__column {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  display: grid;
  gap: 8px;
  min-height: 270px;
  padding: 14px;
  transition: border-color .15s ease, background .15s ease;
}

.complex-picker__column.is-drop-target {
  background: rgba(16, 185, 129, .08);
  border-color: var(--success);
}

.complex-picker__column h3 { font-size: 15px; margin: 0; }

.complex-picker__list {
  align-content: start;
  display: grid;
  gap: 8px;
}

.complex-picker__item {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: grab;
  font: inherit;
  min-height: 40px;
  padding: 9px 11px;
  text-align: left;
}

.complex-picker__item:hover { border-color: var(--accent); color: var(--accent); }
.complex-picker__item.is-dragging { opacity: .45; }

@media (max-width: 640px) {
  .complex-picker-overlay { align-items: end; padding: 0; }
  .complex-picker { border-bottom: 0; max-height: 90dvh; padding: 16px; }
  .complex-picker__columns { grid-template-columns: 1fr; }
  .complex-picker__column { min-height: 190px; }
}

.admin-users-table__actions {
  justify-content: flex-end;
}

.admin-users-table__actions input { min-width: 0; width: 100%; }

.admin-users-table__loading {
  color: var(--text-mute);
  font-size: 13px;
  padding: 12px 0;
}

@media (max-width: 900px) {
  .admin-create-user-form,
  .admin-users-table__row {
    grid-template-columns: 1fr 1fr;
  }

  .admin-create-user-form .btn,
  .admin-users-table__complexes,
  .admin-users-table__actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .admin-workspace { padding: 16px; }
  .admin-create-user-form,
  .admin-users-table__row { grid-template-columns: 1fr; }
  .admin-users-table__actions { grid-column: auto; }
}

/* === Filters === */
.toolbar,
.metrics,
.workspace {
  width: 100%;
}

.toolbar {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  padding: 16px;
}

.filters {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  min-width: 0;
}

.filters label,
label {
  min-width: 0;
}

label span {
  color: var(--text-mute);
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
  margin-bottom: 8px;
  text-transform: uppercase;
}

input,
select {
  appearance: none;
  background-color: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  height: 38px;
  min-height: 38px;
  padding: 0 12px;
  width: 100%;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%23A5ABBD' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right 10px center;
  background-repeat: no-repeat;
  padding-right: 34px;
}

:root[data-theme="light"] select {
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%236B7388' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

input::placeholder {
  color: var(--text-mute);
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
  outline: none;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  filter: invert(1) opacity(0.65);
}

:root[data-theme="light"] input[type="date"]::-webkit-calendar-picker-indicator {
  filter: none;
  opacity: 0.65;
}

.status-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-group label,
.toggle {
  align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  min-height: 36px;
  padding: 0 10px;
  white-space: nowrap;
}

.status-group label:has(input:checked),
.toggle:has(input:checked) {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.32);
  color: var(--text);
}

.status-group input,
.toggle input {
  height: 16px;
  min-height: 0;
  width: 16px;
}

/* === KPI === */
.metrics {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 20px;
}

.analytics-metrics {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.metric {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  padding: 18px 20px;
  position: relative;
}

.metric::before {
  background: var(--accent-grad);
  content: "";
  height: 2px;
  left: 0;
  opacity: 0.9;
  position: absolute;
  right: 0;
  top: 0;
}

.metric:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

.metric span {
  color: var(--text-mute);
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  line-height: 1;
  margin-bottom: 10px;
  text-transform: uppercase;
}

.metric strong {
  color: var(--text);
  display: block;
  font-family: var(--font-mono);
  font-size: 40px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
}

.metric:nth-child(4) strong,
.metric.danger strong {
  color: var(--warning);
}

/* === Sidebar === */
.workspace {
  align-items: start;
  display: grid;
  gap: 20px;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar,
.feed {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.panel,
.feed {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.panel {
  padding: 16px;
  position: sticky;
  top: 16px;
}

.panel-head,
.feed-head {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.panel h2,
.feed h2 {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
}

.bars,
.theme-list {
  display: grid;
  gap: 0;
  margin-top: 12px;
}

.theme-item {
  align-items: center;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  display: flex;
  font-size: 13px;
  font-weight: 500;
  gap: 12px;
  justify-content: space-between;
  line-height: 1.35;
  padding: 10px;
}

.theme-item:first-child {
  border-top: 0;
}

.theme-item:hover {
  background: rgba(99, 102, 241, 0.08);
  border-radius: var(--radius-sm);
  box-shadow: inset 2px 0 0 var(--accent);
}

.theme-item span:first-child {
  min-width: 0;
}

.theme-item strong,
.bar-row strong {
  background: var(--bg-elev-2);
  border-radius: 6px;
  color: var(--text);
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  min-width: 28px;
  padding: 2px 8px;
  text-align: center;
}

.bar-row {
  display: grid;
  gap: 8px;
}

.bar-row header {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.bar-track {
  background: var(--bg-elev-2);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.bar-fill {
  background: var(--accent-grad);
  height: 100%;
}

.bar-fill-warn {
  background: linear-gradient(135deg, var(--warning), var(--danger));
}

/* === Feed === */
.feed {
  overflow: hidden;
  padding: 0;
}

.feed-head {
  border-bottom: 1px solid var(--border);
  padding: 18px 20px;
}

.feed h2 {
  font-size: 18px;
  font-weight: 600;
}

#loadedAt,
.analytics-table-panel #loadedAt {
  color: var(--text-mute);
  font-size: 12px;
  margin-top: 4px;
}

.feed-head select {
  max-width: 190px;
}

.message-list {
  display: grid;
}

.empty,
.error,
.loading {
  color: var(--text-mute);
  padding: 24px;
}

.error {
  color: var(--danger);
}

/* === Card === */
.message {
  background: var(--bg-elev);
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 280px);
  padding: 18px 20px;
  position: relative;
}

.message + .message {
  border-top: 1px solid var(--border);
}

.message:hover {
  box-shadow: var(--shadow-card);
}

.message-overdue {
  box-shadow: inset 3px 0 0 var(--warning);
}

.message-main {
  min-width: 0;
}

.message-top {
  align-items: center;
  display: flex;
  margin-bottom: 6px;
}

.message-top__documents,
.message-top__statuses {
  align-items: center;
  display: flex;
  gap: 12px;
  min-width: 0;
}

.message-top__statuses {
  margin-left: auto;
}

.message-id {
  color: var(--text-mute);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.message-id:hover {
  color: var(--text);
}

.status {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: 999px;
  color: var(--warning);
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  padding: 4px 10px;
  white-space: nowrap;
}

.message h3 {
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.32;
  margin: 6px 0;
}

.message-text {
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
}

.message-meta {
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  font-size: 12px;
  font-weight: 500;
  gap: 8px;
  margin-top: 14px;
}

.message-meta span {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  line-height: 1;
  padding: 4px 10px;
}

.mobile-assign {
  align-items: center;
  column-gap: 12px;
  display: grid;
  grid-template-columns: max-content minmax(180px, 230px) max-content minmax(0, 1fr);
  margin-top: 10px;
  row-gap: 8px;
}

.mobile-assign label {
  align-items: center;
  display: contents;
  gap: 8px;
}

.mobile-assign label > span {
  color: var(--text-mute);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}

.mobile-assign-select {
  height: 30px;
  min-height: 30px;
  min-width: 0;
  padding: 0 28px 0 8px;
  width: auto;
}

.mobile-assign-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mobile-assign-action {
  align-items: center;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  gap: 6px;
  justify-content: center;
  min-height: 34px;
  padding: 7px 11px;
  width: auto;
}

.mobile-assign-action:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.mobile-assign-action svg,
.mobile-assign-action i {
  height: 14px;
  width: 14px;
}

@media (max-width: 900px) {
  .mobile-assign {
    grid-template-columns: max-content minmax(160px, 1fr);
  }

  .mobile-assign-actions {
    grid-column: 1 / -1;
  }
}

.photos {
  align-content: start;
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.photos img,
.comment-photos img,
.linked-photos img {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: zoom-in;
  object-fit: cover;
  transition: transform 0.2s ease, box-shadow 0.15s ease;
}

.photos img {
  aspect-ratio: 1.35 / 1;
  height: 92px;
  width: 100%;
}

.photos:has(img:only-child) img {
  height: 200px;
}

.photos img:hover,
.comment-photos img:hover,
.linked-photos img:hover {
  transform: scale(1.03);
}

.comments {
  grid-column: 1 / -1;
}

.comment-box,
.linked-box {
  background: transparent;
  border: 0;
  border-top: 1px solid var(--border);
  margin-top: 14px;
  padding: 14px 0 0;
}

.linked-comments .comment-box {
  margin-top: 6px;
  padding-top: 10px;
}

.comment-box summary,
.linked-box summary {
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  list-style: none;
}

.comment-box summary:hover,
.linked-box summary:hover {
  color: var(--text);
}

.comment {
  border-top: 1px solid var(--border);
  margin-top: 12px;
  padding-top: 12px;
}

.comment-meta,
.comment-deadline {
  color: var(--text-mute);
  font-size: 12px;
  margin-bottom: 8px;
}

.comment-deadline {
  color: var(--warning);
  font-weight: 600;
}

.comment p,
.linked-message p {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.55;
}

.comment-photos,
.linked-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.comment-photos img,
.linked-photos img {
  aspect-ratio: 4 / 3;
  height: 54px;
  width: 78px;
}

.linked-message {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding: 14px;
}

.linked-message a {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

/* === Analytics / Tables === */
.analytics-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 20px;
}

.analytics-table-panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}

.table-wrap {
  margin-top: 14px;
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 760px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--bg-elev-2);
  color: var(--text-mute);
  font-size: 12px;
  font-weight: 600;
}

.compact-list {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.compact-group {
  border-top: 1px solid var(--border);
  display: grid;
  gap: 8px;
  padding-top: 12px;
}

.compact-group:first-child {
  border-top: 0;
  padding-top: 0;
}

.compact-group header {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.compact-group header span,
.compact-item span,
.compact-item small {
  color: var(--text-mute);
}

.compact-group header strong {
  color: var(--text);
}

.compact-item {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  display: grid;
  gap: 4px;
  padding: 10px;
  text-decoration: none;
}

.compact-item:hover {
  border-color: var(--border-strong);
}

.compact-empty {
  padding: 8px 0;
}

/* === Dialog === */
.photo-dialog {
  background: transparent;
  border: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  max-height: 90vh;
  max-width: min(980px, 92vw);
  padding: 0;
}

.photo-dialog::backdrop {
  background: rgba(5, 7, 12, 0.82);
}

.photo-dialog img {
  border-radius: var(--radius-lg);
  display: block;
  max-height: 90vh;
  max-width: 92vw;
}

.photo-dialog[open] {
  display: grid;
  place-items: center;
}

.dialog-close,
.dialog-nav,
.photo-counter {
  background: rgba(5, 7, 12, 0.74);
  color: #fff;
}

.dialog-close {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  cursor: pointer;
  height: 36px;
  min-height: 36px;
  padding: 0;
  position: absolute;
  right: 10px;
  top: 10px;
  width: 36px;
}

.dialog-nav {
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  font-size: 42px;
  height: 54px;
  justify-content: center;
  line-height: 1;
  min-height: 54px;
  padding: 0 0 4px;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 54px;
}

.dialog-nav-prev {
  left: 12px;
}

.dialog-nav-next {
  right: 12px;
}

.photo-counter {
  border-radius: 999px;
  bottom: 12px;
  font-size: 13px;
  font-weight: 700;
  left: 50%;
  padding: 7px 12px;
  position: absolute;
  transform: translateX(-50%);
}

.photo-compare-dialog {
  background: var(--bg-elev);
  border: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  max-height: 90vh;
  max-width: min(1100px, 94vw);
  padding: 0;
}

.photo-compare-dialog::backdrop {
  background: rgba(5, 7, 12, 0.82);
}

.photo-compare-dialog[open] {
  display: grid;
  place-items: center;
}

.photo-compare-body {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-height: 90vh;
  overflow: auto;
  padding: 48px 64px;
}

.photo-compare-pane {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.photo-compare-pane figcaption {
  color: var(--text-mute);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: center;
  text-transform: uppercase;
}

.photo-compare-pane img {
  border-radius: var(--radius-md);
  display: block;
  margin: 0 auto;
  max-height: 68vh;
  object-fit: contain;
  width: 100%;
}

.photo-compare-pane--empty {
  align-items: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-mute);
  display: flex;
  font-size: 13px;
  justify-content: center;
  min-height: 220px;
  text-align: center;
}

.photo-compare-empty {
  color: var(--text-mute);
  padding: 48px;
  text-align: center;
}

@media (max-width: 720px) {
  .photo-compare-body {
    grid-template-columns: 1fr;
    padding: 40px 20px;
  }
}

/* === Responsive === */
@media (max-width: 1280px) {
  .filters {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .analytics-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1024px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .panel {
    position: static;
  }

  .sidebar {
    order: -1;
  }

  .analytics-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .shell {
    padding: 16px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .nav-link {
    flex: 1 1 calc(50% - 8px);
  }

  .theme-toggle {
    flex: 0 0 36px;
  }

  .filters,
  .analytics-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .message {
    grid-template-columns: 1fr;
  }

  .photos {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .photos img,
  .photos:has(img:only-child) img {
    height: auto;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 24px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric {
    padding: 16px;
  }

  .metric strong {
    font-size: 34px;
  }

  .photos {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* === Light theme === */
:root[data-theme="light"] .nav-link[href$="analytics.html"] {
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.25);
}

:root[data-theme="light"] .message:hover {
  box-shadow: 0 8px 30px rgba(15, 18, 30, 0.12);
}

/* === Polish v2 === */
/* Sidebar */
.panel-head {
  margin-bottom: 14px;
  padding-top: 4px;
}

.panel-head h2 {
  align-items: center;
  display: inline-flex;
  gap: 8px;
}

.panel-head h2 svg,
.panel-head h2 i {
  color: var(--accent);
  height: 16px;
  width: 16px;
}

.theme-list::before {
  color: var(--text-mute);
  content: "Категории заявок";
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.theme-item {
  overflow: hidden;
  transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.2s ease;
}

.theme-item:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

:root[data-theme="light"] .theme-item:nth-child(even) {
  background: rgba(15, 18, 30, 0.025);
}

.theme-item span:first-child {
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  display: -webkit-box;
  line-height: 1.35;
  overflow: hidden;
  white-space: normal;
}

.theme-item:hover {
  transform: translateX(2px);
}

/* Header icons */
.nav-link {
  gap: 8px;
}

.nav-link svg,
.nav-link i,
.theme-toggle svg,
.theme-toggle i {
  color: inherit;
  flex: 0 0 auto;
  height: 14px;
  stroke-width: 2;
  width: 14px;
}

.nav-link[href$="analytics.html"] svg,
.nav-link[href$="analytics.html"] i {
  color: #fff;
}

/* KPI deltas */
.kpi-card[data-delta]::after {
  align-items: center;
  background-color: rgba(16, 185, 129, 0.1);
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='10' viewBox='0 0 10 10' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2 8L8 2M8 2H3.5M8 2V6.5' stroke='%2310B981' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: 6px center;
  background-repeat: no-repeat;
  background-size: 10px;
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 999px;
  color: var(--success);
  content: attr(data-delta) " за 24ч";
  display: inline-flex;
  font: 500 12px/1 var(--font-sans);
  gap: 4px;
  margin-top: 8px;
  padding: 3px 8px 3px 20px;
}

.kpi-card[data-trend="down"]::after {
  background-color: rgba(239, 68, 68, 0.1);
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='10' viewBox='0 0 10 10' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2 2L8 8M8 8H3.5M8 8V3.5' stroke='%23EF4444' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  border-color: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.kpi-card[data-trend="flat"]::after {
  background-color: rgba(255, 255, 255, 0.05);
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='10' viewBox='0 0 10 10' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2 5H8M8 5L5.5 2.5M8 5L5.5 7.5' stroke='%237A8194' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  border-color: var(--border);
  color: var(--text-mute);
}

.kpi-card:nth-child(1) { transition-delay: 0ms; }
.kpi-card:nth-child(2) { transition-delay: 60ms; }
.kpi-card:nth-child(3) { transition-delay: 120ms; }
.kpi-card:nth-child(4) { transition-delay: 180ms; }
.kpi-card:nth-child(5) { transition-delay: 240ms; }
.kpi-card:nth-child(6) { transition-delay: 300ms; }

/* Request id copy */
.req-id {
  align-items: center;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font: 600 13px/1 var(--font-mono);
  gap: 6px;
  min-height: 0;
  padding: 3px 8px;
  position: relative;
}

.req-id:hover {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

.req-id svg,
.req-id i {
  height: 12px;
  opacity: 0.6;
  width: 12px;
}

.req-id:hover svg,
.req-id:hover i {
  opacity: 1;
}

.req-id__tip {
  animation: reqTip 1.2s ease forwards;
  background: var(--accent);
  border-radius: 6px;
  color: #fff;
  font: 600 11px/1 var(--font-sans);
  left: 50%;
  padding: 4px 8px;
  pointer-events: none;
  position: absolute;
  top: -28px;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 3;
}

@keyframes reqTip {
  0% { opacity: 0; transform: translate(-50%, 4px); }
  15%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -4px); }
}

/* Related portals */
.related {
  background: transparent;
  border: 0;
  border-top: 1px solid var(--border);
  margin-top: 14px;
  padding: 14px 0 0;
}

.related__summary {
  align-items: center;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  font-size: 13px;
  font-weight: 600;
  gap: 8px;
  list-style: none;
  padding: 10px 12px;
}

.related__summary::-webkit-details-marker {
  display: none;
}

.related__summary:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.related__summary svg,
.related__summary i {
  color: var(--text-mute);
  height: 14px;
  transition: transform 0.2s ease;
  width: 14px;
}

.related[open] .related__summary svg,
.related[open] .related__summary i {
  transform: rotate(90deg);
}

.related .linked-message {
  margin-top: 10px;
}

/* Reveal */
.reveal {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.5s ease, transform 0.5s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.reveal.is-visible {
  opacity: 1;
  transform: none;
}

/* Empty state */
.empty-state {
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  margin: 20px;
  padding: 60px 20px;
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-state svg,
.empty-state i {
  color: var(--text-mute);
  height: 40px;
  margin-bottom: 12px;
  width: 40px;
}

.empty-state h3 {
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  margin: 0 0 6px;
}

.empty-state p {
  color: var(--text-mute);
  font-size: 14px;
  font-weight: 400;
  margin: 0 0 16px;
}

.btn--ghost {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-dim);
  cursor: pointer;
  font-weight: 500;
  min-height: 36px;
  padding: 8px 16px;
}

.btn--ghost:hover {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

/* Light polish */
:root[data-theme="light"] .req-id {
  border-color: var(--border-strong);
}

:root[data-theme="light"] .kpi-card[data-trend="flat"]::after {
  background-color: rgba(15, 18, 30, 0.04);
}

/* === Polish v3: export primary === */
@keyframes pulseHint {
  0%,
  100% {
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  }

  50% {
    box-shadow: 0 6px 28px rgba(16, 185, 129, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  }
}

.btn--accent {
  animation: pulseHint 2.4s ease-in-out 2;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border: 1px solid rgba(16, 185, 129, 0.45);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  color: #fff;
  font-weight: 600;
  position: relative;
}

.btn--accent:hover {
  border-color: rgba(16, 185, 129, 0.65);
  box-shadow: 0 8px 26px rgba(16, 185, 129, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  color: #fff;
  transform: translateY(-1px);
}

.btn--accent:active {
  transform: translateY(0);
}

.btn--accent i,
.btn--accent svg {
  color: #fff;
}

:root[data-theme="light"] .btn--accent {
  border-color: rgba(5, 150, 105, 0.55);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.25);
}

/* === Manual update button === */
.btn--ruby {
  background: linear-gradient(135deg, #e11d48 0%, #9f1239 100%);
  border: 1px solid rgba(225, 29, 72, 0.55);
  box-shadow: 0 6px 20px rgba(225, 29, 72, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.14);
  color: #fff;
  font-weight: 600;
}

.btn--ruby:hover {
  border-color: rgba(244, 63, 94, 0.72);
  box-shadow: 0 8px 26px rgba(225, 29, 72, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  color: #fff;
}

.btn--ruby i,
.btn--ruby svg {
  color: #fff;
}

.btn--ruby.is-updating,
.btn--ruby:disabled {
  cursor: wait;
  opacity: 0.82;
  pointer-events: none;
}

.btn--ruby.is-updating svg,
.btn--ruby.is-updating i {
  animation: updateSpin 1s linear infinite;
}

@keyframes updateSpin {
  to {
    transform: rotate(360deg);
  }
}

:root[data-theme="light"] .btn--ruby {
  border-color: rgba(190, 18, 60, 0.58);
  box-shadow: 0 6px 18px rgba(225, 29, 72, 0.22);
}

/* === Polish v4.1: dual date pickers === */
.filter-field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.filter-field__label {
  color: var(--text-mute);
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

.date-input {
  align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  height: 40px;
  padding: 0 36px;
  position: relative;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.date-input:hover {
  border-color: var(--border-strong);
}

.date-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

.date-input__icon {
  color: var(--text-mute);
  height: 16px;
  left: 12px;
  pointer-events: none;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
}

.date-input__field {
  background: transparent;
  border: 0;
  caret-color: transparent;
  color: var(--text);
  cursor: pointer;
  flex: 1;
  font: 500 13px/1 var(--font-sans);
  height: 100%;
  min-height: 0;
  outline: 0;
  padding: 0;
  user-select: none;
}

.date-input__field:focus {
  border: 0;
  box-shadow: none;
}

.date-input__field::placeholder {
  color: var(--text-mute);
}

.date-input__field::selection {
  background: transparent;
}

.date-input__clear {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--text-mute);
  cursor: pointer;
  display: inline-flex;
  height: 22px;
  justify-content: center;
  min-height: 0;
  padding: 0;
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  transition: background 0.15s, color 0.15s;
  width: 22px;
}

.date-input__clear:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}

.date-input__clear i,
.date-input__clear svg {
  height: 14px;
  width: 14px;
}

.flatpickr-calendar {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  font-family: var(--font-sans);
}

.flatpickr-months .flatpickr-month,
.flatpickr-current-month,
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year,
.flatpickr-weekday {
  color: var(--text);
  fill: var(--text);
}

.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month .numInputWrapper,
.flatpickr-current-month input.cur-year {
  background: transparent;
  background-image: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  height: auto;
  min-height: 0;
  padding: 0;
  width: auto;
}

.flatpickr-current-month .flatpickr-monthDropdown-months {
  appearance: none;
  padding-right: 0;
}

.flatpickr-current-month input.cur-year {
  font: inherit;
  text-align: left;
  width: 4.5ch;
}

.flatpickr-current-month .cur-month {
  font-weight: 500;
  margin-left: 0;
}

.flatpickr-current-month .numInputWrapper span {
  display: none;
}

.flatpickr-calendar select,
.flatpickr-calendar input {
  appearance: none;
  background: transparent;
  background-image: none;
  border: 0;
  box-shadow: none;
  min-height: 0;
  padding: 0;
}

.flatpickr-calendar input::-webkit-outer-spin-button,
.flatpickr-calendar input::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

.flatpickr-day {
  border-radius: 8px;
  color: var(--text-dim);
}

.flatpickr-day:hover {
  background: var(--bg-elev-2);
  border-color: transparent;
}

.flatpickr-day.today {
  border-color: var(--accent);
  color: var(--text);
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.flatpickr-day.flatpickr-disabled,
.flatpickr-day.prevMonthDay,
.flatpickr-day.nextMonthDay {
  color: var(--text-mute);
  opacity: 0.5;
}

.flatpickr-time input,
.flatpickr-time .flatpickr-am-pm {
  color: var(--text);
}

.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
  color: var(--text-mute);
  fill: var(--text-mute);
}

.flatpickr-months .flatpickr-prev-month:hover,
.flatpickr-months .flatpickr-next-month:hover {
  color: var(--text);
  fill: var(--text);
}

:root[data-theme="light"] .flatpickr-calendar {
  background: #fff;
  box-shadow: 0 20px 50px rgba(15, 18, 30, 0.15);
}

:root[data-theme="light"] .flatpickr-day {
  color: var(--text);
}

.fp-presets {
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
}

.fp-presets button {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  flex: 1 1 auto;
  font: 500 12px/1 var(--font-sans);
  min-height: 0;
  padding: 6px 10px;
  transition: all 0.15s;
}

.fp-presets button:hover {
  background: var(--bg-elev-2);
  border-color: var(--accent);
  color: var(--accent);
}

/* === Status: in-progress (blue) === */
.status-badge--in-progress,
.badge[data-status="in-progress"] {
  color: #7dd3fc;
  background: rgba(14, 165, 233, 0.12);
  border: 1px solid rgba(14, 165, 233, 0.35);
}

:root[data-theme="light"] .status-badge--in-progress,
:root[data-theme="light"] .badge[data-status="in-progress"] {
  color: #0369a1;
  background: rgba(14, 165, 233, 0.1);
  border-color: rgba(14, 165, 233, 0.45);
}

/* === Status: resolved / actions taken (green) === */
.status-badge--resolved {
  color: #6ee7b7;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
}

:root[data-theme="light"] .status-badge--resolved {
  color: #047857;
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.4);
}

/* === Status: problem not confirmed (neutral) === */
.status-badge--not-found {
  color: #94a3b8;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.32);
}

:root[data-theme="light"] .status-badge--not-found {
  color: #475569;
  background: rgba(100, 116, 139, 0.1);
  border-color: rgba(100, 116, 139, 0.35);
}

/* === Status: resident refutation (red) === */
.status-badge--refutation {
  color: #f87171;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.46);
}

:root[data-theme="light"] .status-badge--refutation {
  color: #b91c1c;
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.4);
}

/* === Mobile app / PWA === */
.filter-toggle {
  align-items: center;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  cursor: pointer;
  display: none;
  font: 600 14px/1 var(--font-sans);
  gap: 8px;
  height: 42px;
  justify-content: center;
  padding: 0 14px;
  width: 100%;
}

.filter-toggle svg,
.filter-toggle i {
  height: 16px;
  width: 16px;
}

.filter-toggle:hover {
  border-color: var(--border-strong);
}

.filter-toggle[aria-expanded="true"] {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.35);
  color: var(--text);
}

.filter-toggle__count {
  align-items: center;
  background: var(--accent-grad);
  border-radius: 999px;
  color: #fff;
  display: inline-flex;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  height: 18px;
  justify-content: center;
  line-height: 1;
  min-width: 18px;
  padding: 0 5px;
}

.filter-toggle__count[hidden] {
  display: none;
}

.mobile-tabbar {
  display: none;
}

.mobile-tabbar__item {
  align-items: center;
  background: transparent;
  border: 0;
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  font: 700 10px/1.1 var(--font-sans);
  gap: 5px;
  justify-content: center;
  min-width: 0;
  padding: 8px 4px;
  text-decoration: none;
}

.mobile-tabbar__item:hover,
.mobile-tabbar__item:focus-visible {
  color: var(--text);
}

.mobile-tabbar__item svg,
.mobile-tabbar__item i {
  height: 18px;
  width: 18px;
}

@media (display-mode: standalone) {
  .shell {
    padding-top: max(18px, env(safe-area-inset-top));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 768px) {
  body {
    min-width: 0;
    overflow-x: hidden;
  }

  .shell {
    padding: 12px 12px calc(86px + env(safe-area-inset-bottom));
  }

  .topbar {
    backdrop-filter: blur(14px);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 30;
    padding: 14px;
  }

  .eyebrow {
    font-size: 10px;
  }

  h1 {
    font-size: 23px;
    line-height: 1.12;
  }

  .top-actions {
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 40px;
  }

  .top-actions #exportPhotoLink,
  .top-actions .nav-menu,
  .top-actions #manualUpdateButton,
  .top-actions a[href="/analytics.html"],
  .top-actions #accountButton {
    display: none;
  }

  .nav-link,
  .theme-toggle {
    min-width: 0;
  }

  .nav-link {
    flex: none;
    font-size: 12px;
    height: 40px;
    justify-content: center;
    padding: 0 10px;
  }

  .theme-toggle {
    height: 40px;
    width: 100%;
  }

  .yard-toggle {
    justify-content: center;
    min-width: 0;
    overflow: hidden;
  }

  .yard-toggle span {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-tabbar {
    backdrop-filter: blur(18px);
    background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
    border: 1px solid var(--border-strong);
    border-radius: 18px 18px 0 0;
    bottom: 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.28);
    display: grid;
    gap: 0;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
    left: 0;
    padding: 6px max(6px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-right));
    position: fixed;
    right: 0;
    z-index: 60;
  }

  .toolbar {
    padding: 10px;
  }

  .filter-toggle {
    display: inline-flex;
  }

  .toolbar:not(.is-open) .filters {
    display: none;
  }

  .toolbar.is-open .filters {
    margin-top: 12px;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .filters label,
  .filter-field {
    width: 100%;
  }

  select,
  input,
  .date-input {
    min-height: 44px;
  }

  .metrics {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-left: 0;
    margin-right: 0;
    overflow: visible;
    padding: 0;
    scroll-snap-type: none;
  }

  .metric {
    flex: none;
    min-height: 94px;
    padding: 13px 14px;
    scroll-snap-align: none;
  }

  .metric span {
    font-size: 10px;
    letter-spacing: 0.08em;
    margin-bottom: 8px;
    white-space: nowrap;
  }

  .metric strong {
    font-size: 28px;
  }

  .kpi-card[data-delta]::after {
    font-size: 10px;
    margin-top: 7px;
    max-width: 100%;
    padding: 3px 7px 3px 18px;
    white-space: nowrap;
  }

  .workspace {
    gap: 14px;
  }

  .sidebar {
    order: 2;
  }

  .feed {
    order: 1;
  }

  .feed-head {
    align-items: stretch;
    gap: 12px;
  }

  .feed-head select {
    max-width: none;
    width: 100%;
  }

  .message {
    border-radius: var(--radius-lg);
    gap: 14px;
    padding: 16px;
  }

  .message-top {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .message-top__statuses {
    margin-left: 0;
  }

  .status {
    align-self: flex-start;
  }

  .message h3 {
    font-size: 15px;
  }

  .message-text {
    font-size: 13px;
  }

  .message-meta {
    gap: 6px;
  }

  .message-meta span {
    max-width: 100%;
  }

  .photos {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .photos img,
  .photos:has(img:only-child) img {
    aspect-ratio: 4 / 3;
    height: auto;
    min-height: 112px;
  }

  .photo-dialog {
    background: rgba(5, 7, 12, 0.94);
    border-radius: 0;
    box-shadow: none;
    height: 100dvh;
    margin: 0;
    max-height: none;
    max-width: none;
    padding: max(18px, env(safe-area-inset-top)) 12px max(44px, env(safe-area-inset-bottom));
    width: 100vw;
  }

  .photo-dialog::backdrop {
    background: rgba(5, 7, 12, 0.96);
  }

  .photo-dialog img {
    border-radius: 14px;
    height: auto;
    max-height: calc(100dvh - 118px);
    max-width: calc(100vw - 24px);
    object-fit: contain;
    width: auto;
  }

  .dialog-close {
    right: max(12px, env(safe-area-inset-right));
    top: max(12px, env(safe-area-inset-top));
  }

  .dialog-nav {
    background: rgba(5, 7, 12, 0.68);
    height: 46px;
    min-height: 46px;
    width: 46px;
  }

  .dialog-nav-prev {
    left: 10px;
  }

  .dialog-nav-next {
    right: 10px;
  }

  .photo-counter {
    bottom: max(14px, env(safe-area-inset-bottom));
  }
}

@media (min-width: 1180px) and (max-width: 1400px) {
  .topbar {
    gap: 12px;
  }

  h1 {
    font-size: 24px;
  }

  .top-actions {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .nav-link,
  .theme-toggle {
    font-size: 12px;
    padding: 0 10px;
  }

  .yard-toggle {
    font-size: 11px;
    gap: 4px;
  }
}

@media (max-width: 420px) {
  .yard-toggle {
    font-size: 11px;
    gap: 5px;
    padding: 0 2px;
  }

  .metric {
    min-height: 88px;
    padding: 12px;
  }

  .metric strong {
    font-size: 26px;
  }
}

/* === Background: Moscow map === */
body {
  position: relative;
  isolation: isolate;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: url("assets/moscow-map-dark.svg");
  background-repeat: no-repeat;
  background-position: center center;
  background-size: min(1100px, 90vmin);
  opacity: 0.07;
  filter: blur(0.3px);
  transition: opacity 0.3s ease, background-image 0.3s ease;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background:
    radial-gradient(
      circle at 50% 50%,
      rgba(99, 102, 241, 0.1) 0%,
      rgba(99, 102, 241, 0) 55%
    );
  transition: background 0.3s ease;
}

:root[data-theme="light"] body::before {
  background-image: url("assets/moscow-map-light.svg");
  opacity: 0.06;
}

:root[data-theme="light"] body::after {
  background:
    radial-gradient(
      circle at 50% 50%,
      rgba(30, 58, 138, 0.06) 0%,
      rgba(30, 58, 138, 0) 60%
    );
}

@media (max-width: 640px) {
  body::before {
    background-attachment: scroll;
    background-size: 120vmin;
    opacity: 0.05;
  }

  body::after {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  body::before,
  body::after {
    transition: none;
  }
}

/* === Deadline history === */
.deadline-history {
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev-2);
}

.deadline-history__title {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.deadline-history__row {
  padding: 8px 0;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.45;
  border-top: 1px solid var(--border);
}

.deadline-history__row:first-of-type {
  border-top: 0;
  padding-top: 0;
}

/* Active state for mobile tabbar (home tab) */
.mobile-tabbar__item.is-active,
.mobile-tabbar__item.is-active i {
  color: var(--accent);
}

.card-pdf-link {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: var(--text-mute);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
}

.card-txt-link {
  display: inline-grid;
  width: 42px;
  height: 34px;
  place-items: center;
  color: var(--text-mute);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}

.card-txt-link:hover {
  color: var(--text);
  border-color: var(--accent);
}

.card-pdf-link:hover {
  color: var(--text);
  border-color: var(--accent);
}

.card-pdf-link img {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  object-fit: cover;
}
