/* Спільний дизайн для всіх сторінок — професійний темний app-shell для медіа-моніторингу
   (IPTV/broadcast processing). Один файл, без Tailwind/React: стек проєкту — Flask+Jinja2,
   тому дизайн-система реалізована на CSS custom properties + BEM-подібних класах. */

:root {
  --bg-app: #f4f5f6;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-hover: #eef0f2;
  --border: #dfe2e6;
  --border-soft: #e8eaed;
  --text: #14171a;
  --text-secondary: #5c6470;
  --text-tertiary: #8a919c;

  --accent: #2f6fe4;
  --accent-fg: #ffffff;
  --ok: #1a7f37;
  --ok-bg: #ddf4e1;
  --warn: #9a6700;
  --warn-bg: #fff1cf;
  --err: #cf222e;
  --err-bg: #ffebe9;
  --neutral: #6b7280;
  --neutral-bg: #eceef0;

  --radius-lg: 10px;
  --radius-md: 8px;
  --radius-sm: 6px;
  --sidebar-w: 208px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-app: #0f1115;
    --bg-surface: #15181d;
    --bg-elevated: #1b1f24;
    --bg-hover: #21252b;
    --border: #262b32;
    --border-soft: #1e2228;
    --text: #e4e6eb;
    --text-secondary: #9aa0a8;
    --text-tertiary: #6b7280;

    --accent: #4c8dff;
    --accent-fg: #ffffff;
    --ok: #3fb950;
    --ok-bg: #0d2818;
    --warn: #d29922;
    --warn-bg: #2b2008;
    --err: #f85149;
    --err-bg: #2c1211;
    --neutral: #8b949e;
    --neutral-bg: #21252b;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg-app);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- App shell: sidebar + content ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  padding: 6px 10px 18px;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.sidebar nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  transition: background 120ms ease, color 120ms ease;
}
.sidebar nav a:hover { background: var(--bg-hover); color: var(--text); }
.sidebar nav a.active { background: var(--bg-hover); color: var(--text); }

.sidebar .foot {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar .foot .status-line {
  font-size: 12px;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
}

.content { flex: 1; min-width: 0; padding: 20px 28px 56px; max-width: 1180px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  gap: 12px;
}
.page-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.page-header .subtitle { color: var(--text-secondary); font-size: 13px; margin-top: 3px; }

/* ---------- KPI cards ---------- */

.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 24px; }
.kpi {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.kpi .kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.kpi .kpi-value.err { color: var(--err); }
.kpi .kpi-label { font-size: 11px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }

/* ---------- Section ---------- */

.section { margin-bottom: 28px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; }
.section-head h2 { font-size: 13px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin: 0; }
.section-head .tools { display: flex; gap: 8px; align-items: center; }

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 500; color: var(--text-secondary); }
.field .unit-input { display: flex; align-items: center; gap: 6px; }
.field .unit-input span { color: var(--text-tertiary); font-size: 13px; }

form.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
form.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input, select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  min-height: 32px;
}
input::placeholder { color: var(--text-tertiary); }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input[type=text].grow, input[type=url].grow { flex: 1; min-width: 180px; }

button {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  min-height: 32px;
  transition: opacity 120ms ease;
}
button:hover { opacity: 0.88; }
button:active { opacity: 0.75; }
button:disabled { opacity: 0.4; cursor: default; }

button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.ghost:hover { background: var(--bg-hover); opacity: 1; }
button.text-btn { background: transparent; color: var(--text-secondary); border: none; padding: 4px 8px; font-weight: 500; min-height: auto; }
button.text-btn:hover { color: var(--text); background: var(--bg-hover); border-radius: var(--radius-sm); }
button.danger-text { color: var(--err); }
button.small { padding: 5px 10px; font-size: 12px; min-height: 28px; }

/* ---------- Status dot + badges ---------- */

.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; flex-shrink: 0; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--err); }
.dot.neutral { background: var(--neutral); }

.status-cell { display: flex; align-items: center; font-size: 12.5px; white-space: nowrap; }
.status-cell.ok { color: var(--ok); }
.status-cell.warn { color: var(--warn); }
.status-cell.err { color: var(--err); }
.status-cell.neutral { color: var(--text-tertiary); }

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}
.badge.done { background: var(--ok-bg); color: var(--ok); }
.badge.error { background: var(--err-bg); color: var(--err); }
.badge.processing, .badge.queued { background: var(--warn-bg); color: var(--warn); }
.badge.cancelled { background: var(--neutral-bg); color: var(--neutral); }

/* ---------- Tables ---------- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 14px; font-size: 13px; vertical-align: middle; }
thead th {
  color: var(--text-tertiary);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
tbody tr { border-bottom: 1px solid var(--border-soft); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

.cell-truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle; color: var(--text-secondary); }
.cell-title { font-weight: 600; }
.cell-sub { color: var(--text-tertiary); font-size: 12px; }
.dt-primary { font-variant-numeric: tabular-nums; }
.dt-secondary { color: var(--text-tertiary); font-size: 12px; font-variant-numeric: tabular-nums; }

.row-actions { display: flex; gap: 4px; align-items: center; justify-content: flex-end; }

/* ---------- Dropdown menu (three-dot actions) ---------- */

.menu-wrap { position: relative; display: inline-block; }
.menu-btn {
  background: transparent; border: 1px solid transparent; color: var(--text-secondary);
  padding: 4px 8px; min-height: auto; font-size: 15px; line-height: 1; border-radius: var(--radius-sm);
}
.menu-btn:hover { background: var(--bg-hover); border-color: var(--border); }
.menu-panel {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 140px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  z-index: 20;
  padding: 4px;
}
.menu-panel.open { display: block; }
.menu-panel button {
  display: block; width: 100%; text-align: left; background: transparent; color: var(--text);
  border: none; padding: 7px 10px; font-size: 13px; font-weight: 400; border-radius: var(--radius-sm); min-height: auto;
}
.menu-panel button:hover { background: var(--bg-hover); opacity: 1; }
.menu-panel button.danger { color: var(--err); }

/* ---------- Dialog / modal ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--bg-elevated);
  color: var(--text);
  width: 420px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.dialog-head { padding: 16px 20px 0; }
.dialog-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.dialog-body { padding: 14px 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog-foot { padding: 12px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Misc ---------- */

.hint { color: var(--text-tertiary); font-size: 12.5px; line-height: 1.5; }
.empty-state { padding: 40px 20px; text-align: center; }
.empty-state .empty-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.empty-state .hint { margin-bottom: 14px; }
mark { background: rgba(76, 141, 255, 0.22); color: inherit; border-radius: 3px; padding: 0 2px; }

/* ---------- Story cards (board page) ---------- */

.story { border-bottom: 1px solid var(--border-soft); padding: 16px 0; }
.story:last-child { border-bottom: none; }
.story h3 { margin: 4px 0 8px; font-size: 15px; font-weight: 600; letter-spacing: -0.005em; }
.story p { margin: 8px 0 0; font-size: 13.5px; line-height: 1.55; color: var(--text); }
.story audio { width: 100%; margin-top: 8px; height: 32px; }
.story video { width: 100%; margin-top: 8px; border-radius: var(--radius-md); display: none; }
.video-status { font-size: 12.5px; color: var(--text-tertiary); margin-top: 6px; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center;
    padding: 10px 14px; gap: 12px; overflow-x: auto; }
  .sidebar .brand { padding: 0; }
  .sidebar nav { flex-direction: row; }
  .sidebar .foot { display: none; }
  .content { padding: 16px 16px 40px; }
  form.row { flex-direction: column; align-items: stretch; }
  form.grid-2 { grid-template-columns: 1fr; }
  input[type=text].grow, input[type=url].grow { min-width: 0; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  .panel table tbody tr { border: 1px solid var(--border); border-radius: var(--radius-md); margin: 10px; padding: 8px 12px; }
  td { padding: 4px 0; border: none; }
  td[data-label]::before { content: attr(data-label) ": "; color: var(--text-tertiary); font-weight: 600; font-size: 11px; }
  .row-actions { justify-content: flex-start; }
}
