/* ============================================================
   Emby Media Manager v2.2 — style.css
   Design tokens aligned with HOME dashboard
   ============================================================ */

/* ── Tokens ─────────────────────────────────────────────────── */
:root {
  --bg:     #080a0d;
  --card:   #14181f;
  --line:   #2b3038;
  --text:   #f3f4f6;
  --muted:  #9ba4b2;
  --blue:   #56b5ee;
  --green:  #44d07a;
  --amber:  #f0bd56;
  --red:    #ee6b82;
  --card-grad: linear-gradient(135deg, #1c2129, #101319);
  --r-card: 22px;
  --r-sm:   12px;
  --gap:    16px;
  --hdr-h:  68px;
  --pad:    24px;
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
a { text-decoration: none; color: inherit; }
img { display: block; }
button { font-family: inherit; }

/* ── Base ────────────────────────────────────────────────────── */
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

body::before {
  content: '';
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(circle at 40% -5%, rgba(86,181,238,0.04) 0%, transparent 40%),
    radial-gradient(circle at 95% 10%,  rgba(255,255,255,0.01) 0%, transparent 30%);
}

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.10); border-radius: 2px; }

/* ══════════════════════════════════════════════ LOGIN ════════ */
#login-screen {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.login-box {
  background: var(--card-grad);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 40px;
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 24px;
}

.login-logo {
  display: flex; flex-direction: column; gap: 4px;
}

.login-logo svg { color: var(--blue); }

.login-title {
  font-size: 1.3rem; font-weight: 700; color: var(--text);
}

.login-sub {
  font-size: 0.8rem; color: var(--muted);
}

.login-field {
  display: flex; flex-direction: column; gap: 6px;
}

.login-field label {
  font-size: 0.78rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}

.login-field input {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  height: 44px;
  transition: border-color 0.15s;
  font-family: inherit;
}

.login-field input:focus {
  border-color: var(--blue);
  background: rgba(86,181,238,0.04);
}

.login-submit {
  height: 44px;
  background: var(--blue);
  color: #06090d;
  border: none;
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.login-submit:hover  { opacity: 0.88; }
.login-submit:active { transform: scale(0.98); }
.login-submit:disabled { opacity: 0.45; cursor: not-allowed; }

.login-error {
  font-size: 0.82rem; color: var(--red); min-height: 1.2em;
  text-align: center; display: none;
}
.login-error.visible { display: block; }

/* ══════════════════════════════════════════════ APP ══════════ */
#app { position: relative; z-index: 1; display: flex; flex-direction: column; min-height: 100dvh; }
#app[hidden] { display: none; }

/* ── Header ──────────────────────────────────────────────────── */
#hdr {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  height: var(--hdr-h);
  padding: 0 var(--pad);
  background: rgba(8,10,13,0.90);
  backdrop-filter: blur(40px) saturate(130%);
  -webkit-backdrop-filter: blur(40px) saturate(130%);
  border-bottom: 1px solid var(--line);
  gap: 16px;
}

.hdr-brand { display: flex; flex-direction: column; gap: 1px; }

.hdr-title {
  font-size: 1.05rem; font-weight: 700; color: var(--text); white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
}

.hdr-title svg { color: var(--blue); flex-shrink: 0; }

.hdr-sub {
  font-size: 0.72rem; color: var(--muted); white-space: nowrap;
}

.hdr-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.76rem; color: var(--muted);
  flex-shrink: 0;
}

.hdr-status .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-green  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-amber  { background: var(--amber); }
.dot-red    { background: var(--red); }
.dot-muted  { background: var(--muted); }

.hdr-links { display: flex; align-items: center; gap: 4px; }

.hdr-link {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px; border-radius: 8px;
  font-size: 0.78rem; color: var(--muted);
  border: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
}

.hdr-link:hover {
  color: var(--text); background: rgba(255,255,255,0.05);
  border-color: var(--line);
}

.hdr-link svg { flex-shrink: 0; }

.hdr-btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 8px;
  border: none; background: none; cursor: pointer; color: var(--muted);
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.hdr-btn-icon:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.hdr-btn-icon:focus-visible { outline: 1.5px solid var(--blue); outline-offset: 2px; }

/* ── Main grid ───────────────────────────────────────────────── */
#grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--gap);
  padding: var(--pad);
  flex: 1;
}

@media (max-width: 1199px) {
  #grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 699px) {
  #grid { grid-template-columns: minmax(0, 1fr); }
  #hdr { flex-wrap: wrap; height: auto; padding: 12px var(--pad); }
  .hdr-sub { display: none; }
}

/* ── Card ────────────────────────────────────────────────────── */
.panel-card {
  background: var(--card-grad);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: var(--pad);
  cursor: pointer;
  display: flex; flex-direction: column; gap: 16px;
  transition: border-color 0.18s, transform 0.15s;
  text-align: left; font-family: inherit; color: inherit;
  min-width: 0;
  position: relative; overflow: hidden;
}

.panel-card::before {
  content: ''; position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(circle at 50% 0%, rgba(86,181,238,0.06), transparent 60%);
  transition: opacity 0.2s; pointer-events: none; border-radius: inherit;
}

.panel-card:hover { border-color: rgba(86,181,238,0.3); }
.panel-card:hover::before { opacity: 1; }
.panel-card:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

@media (prefers-reduced-motion: no-preference) {
  .panel-card:hover { transform: translateY(-2px); }
}

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

.card-icon {
  width: 40px; height: 40px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(86,181,238,0.08);
  border: 1px solid rgba(86,181,238,0.15);
  border-radius: 11px;
  color: var(--blue);
}

.card-status {
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em;
  padding: 3px 9px; border-radius: 20px;
  text-transform: uppercase;
}

.status-ok     { background: rgba(68,208,122,0.12); color: var(--green); }
.status-warn   { background: rgba(240,189,86,0.12);  color: var(--amber); }
.status-error  { background: rgba(238,107,130,0.12); color: var(--red); }
.status-muted  { background: rgba(155,164,178,0.10); color: var(--muted); }

.card-label {
  font-size: 0.72rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.07em;
}

.card-number {
  font-size: 2.4rem; font-weight: 800; line-height: 1;
  color: var(--text); letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  min-height: 2.4rem;
}

.card-number.loading {
  background: linear-gradient(90deg, var(--line) 25%, rgba(255,255,255,0.05) 50%, var(--line) 75%);
  background-size: 200% 100%;
  border-radius: 8px; color: transparent;
  animation: shimmer 1.4s infinite;
  width: 60%; min-height: 2.4rem;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.card-metrics {
  display: flex; flex-direction: column; gap: 6px; flex: 1;
}

.metric-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}

.metric-label { font-size: 0.73rem; color: var(--muted); white-space: nowrap; }

.metric-value {
  font-size: 0.82rem; font-weight: 600; color: var(--text);
  font-variant-numeric: tabular-nums; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}

.metric-value.ok    { color: var(--green); }
.metric-value.warn  { color: var(--amber); }
.metric-value.error { color: var(--red); }

/* ══════════════════════════════════════════════ DIALOG ═══════ */
dialog {
  position: fixed; inset: 0; margin: auto;
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  background: #0f1318;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  color: var(--text);
  padding: 0; overflow: hidden;
  display: flex; flex-direction: column;
}

dialog::backdrop {
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(4px);
}

.dlg-header {
  display: flex; align-items: center; gap: 12px;
  padding: 20px var(--pad);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.dlg-header-icon {
  width: 36px; height: 36px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(86,181,238,0.08);
  border: 1px solid rgba(86,181,238,0.15);
  border-radius: 10px; color: var(--blue);
}

.dlg-title {
  font-size: 1.05rem; font-weight: 700; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.dlg-close {
  width: 36px; height: 36px; min-width: 36px;
  border: none; background: none; cursor: pointer;
  color: var(--muted); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s; flex-shrink: 0;
}
.dlg-close:hover { color: var(--text); background: rgba(255,255,255,0.07); }
.dlg-close:focus-visible { outline: 1.5px solid var(--blue); outline-offset: 2px; }

.dlg-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px var(--pad);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap; flex-shrink: 0;
}

.dlg-search {
  background: rgba(255,255,255,0.04); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 12px;
  color: var(--text); font-size: 0.85rem; outline: none;
  height: 36px; min-width: 160px; flex: 1;
  font-family: inherit; transition: border-color 0.15s;
}
.dlg-search:focus { border-color: var(--blue); }
.dlg-search::placeholder { color: var(--muted); }

.dlg-filter {
  background: rgba(255,255,255,0.04); border: 1px solid var(--line);
  border-radius: 9px; padding: 0 10px;
  color: var(--text); font-size: 0.82rem; outline: none;
  height: 36px; cursor: pointer; font-family: inherit;
  transition: border-color 0.15s;
}
.dlg-filter:focus { border-color: var(--blue); }

.dlg-action {
  height: 36px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--line); background: rgba(255,255,255,0.04);
  color: var(--text); font-size: 0.82rem; cursor: pointer;
  font-family: inherit; transition: border-color 0.15s, background 0.15s;
  white-space: nowrap;
}
.dlg-action:hover { border-color: rgba(86,181,238,0.3); background: rgba(86,181,238,0.05); }
.dlg-action:focus-visible { outline: 1.5px solid var(--blue); outline-offset: 2px; }
.dlg-action:disabled { opacity: 0.4; cursor: not-allowed; }
.dlg-action.primary { background: var(--blue); color: #06090d; border-color: var(--blue); font-weight: 700; }
.dlg-action.primary:hover { opacity: 0.85; }
.dlg-action.danger  { color: var(--red); border-color: rgba(238,107,130,0.3); }

.dlg-body {
  flex: 1; overflow-y: auto; padding: var(--pad);
  display: flex; flex-direction: column; gap: 8px;
}

/* Table */
.dlg-table { width: 100%; border-collapse: collapse; table-layout: fixed; }

.dlg-table th {
  text-align: left; font-size: 0.7rem; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em;
  padding: 0 12px 10px; border-bottom: 1px solid var(--line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.dlg-table td {
  padding: 10px 12px; border-bottom: 1px solid rgba(43,48,56,0.5);
  font-size: 0.82rem; vertical-align: middle;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.dlg-table tr:last-child td { border-bottom: none; }

.dlg-table tr:hover td { background: rgba(255,255,255,0.025); }

/* State messages */
.state-msg {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 48px 24px; text-align: center; color: var(--muted);
  font-size: 0.88rem;
}

.state-msg svg { opacity: 0.35; }
.state-msg .state-title { font-weight: 600; font-size: 0.95rem; color: var(--text); }
.state-msg .state-sub   { font-size: 0.8rem; }

/* Pill badge */
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 0.7rem;
  font-weight: 700; letter-spacing: 0.03em; white-space: nowrap;
}
.pill-green  { background: rgba(68,208,122,0.12);  color: var(--green); }
.pill-amber  { background: rgba(240,189,86,0.12);   color: var(--amber); }
.pill-red    { background: rgba(238,107,130,0.12);  color: var(--red); }
.pill-blue   { background: rgba(86,181,238,0.12);   color: var(--blue); }
.pill-muted  { background: rgba(155,164,178,0.10);  color: var(--muted); }

/* Storage bar */
.storage-bar {
  width: 100%; height: 6px; border-radius: 3px;
  background: rgba(255,255,255,0.07); overflow: hidden;
}

.storage-bar-fill {
  height: 100%; border-radius: 3px;
  background: var(--blue); transition: width 0.3s ease;
}

.storage-bar-fill.warn  { background: var(--amber); }
.storage-bar-fill.error { background: var(--red); }

/* Queue job row */
.job-row {
  background: rgba(255,255,255,0.02); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 8px;
}

.job-row-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.job-row-title { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: break-word; }
.job-row-meta  { font-size: 0.76rem; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }
.job-row-meta span::before { content: attr(data-label) ': '; }

.job-actions { display: flex; gap: 8px; }

/* Automation log */
.log-entry {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 14px; border-radius: 10px;
  background: rgba(255,255,255,0.02); border: 1px solid var(--line);
}

.log-time { font-size: 0.73rem; color: var(--muted); white-space: nowrap; min-width: 130px; font-variant-numeric: tabular-nums; }
.log-body { font-size: 0.82rem; flex: 1; overflow-wrap: break-word; }

/* Sources health */
.source-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: 12px;
  background: rgba(255,255,255,0.02); border: 1px solid var(--line);
}

.source-icon { flex-shrink: 0; color: var(--muted); }
.source-label { font-weight: 600; flex: 1; }
.source-detail { font-size: 0.78rem; color: var(--muted); }

/* Responsive dialog */
@media (max-width: 699px) {
  dialog {
    width: 100vw; max-height: 100dvh;
    border-radius: var(--r-card) var(--r-card) 0 0;
    position: fixed; top: auto; bottom: 0; left: 0; right: 0;
    margin: 0; transform: none;
  }
  .dlg-toolbar { gap: 6px; }
  .dlg-search { min-width: 120px; }
}

/* Safari: preserve native closed-dialog and hidden states. */
[hidden], dialog:not([open]) { display:none!important; }
#grid { flex:0 0 auto; align-content:start; }
.panel-card { min-height:245px; }
@media(max-width:699px){.panel-card{min-height:220px;}}
