/* JFPanel — tema oscuro inspirado en Jellyfin/Plex */
:root {
  --bg: #0d1015;
  --bg-soft: #11151c;
  --panel: #161b23;
  --panel-2: #1c222d;
  --border: #262e3a;
  --text: #e9edf3;
  --muted: #8d97a7;
  --faint: #5c6575;
  --accent-a: #aa5cc3;
  --accent-b: #00a4dc;
  --grad: linear-gradient(135deg, #aa5cc3, #00a4dc);
  --green: #2ecc71;
  --red: #e5544b;
  --yellow: #e7b93c;
  --radius: 14px;
  --sidebar-w: 232px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--accent-b); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 650; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.05rem; letter-spacing: .02em; color: var(--text); }
::selection { background: rgba(0, 164, 220, .35); }
::-webkit-scrollbar { height: 10px; width: 10px; }
::-webkit-scrollbar-thumb { background: #2b3442; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- disposición ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0; z-index: 60;
  transition: transform .25s ease;
}
.main {
  flex: 1; margin-left: var(--sidebar-w);
  display: flex; flex-direction: column; min-width: 0;
}
.content { padding: 1.4rem 1.8rem 3rem; max-width: 1500px; width: 100%; margin: 0 auto; }

.brand {
  display: flex; align-items: center; gap: .65rem;
  padding: 1.1rem 1.2rem .9rem;
  font-size: 1.15rem; font-weight: 700; letter-spacing: .02em;
}
.brand .logo { width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; }
.brand span em { font-style: normal; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

.nav { padding: .4rem .7rem; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: .7rem;
  padding: .55rem .75rem; border-radius: 9px;
  color: var(--muted); font-weight: 500; text-decoration: none;
  position: relative;
}
.nav a svg { width: 19px; height: 19px; flex-shrink: 0; opacity: .85; }
.nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--panel-2); color: var(--text); }
.nav a.active::before {
  content: ""; position: absolute; left: -0.7rem; top: 20%; bottom: 20%;
  width: 3px; border-radius: 3px; background: var(--grad);
}
.sidebar-foot { padding: .9rem 1.2rem; color: var(--faint); font-size: .78rem; border-top: 1px solid var(--border); }

.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .8rem 1.8rem; border-bottom: 1px solid var(--border);
  background: rgba(13, 16, 21, .8); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 50;
}
.topbar h1 { margin: 0; font-size: 1.1rem; flex: 1; }
.hamburger { display: none; background: none; border: 0; color: var(--text); cursor: pointer; padding: .3rem; }
.hamburger svg { width: 24px; height: 24px; }

.status-pill {
  display: inline-flex; align-items: center; gap: .45rem;
  background: var(--panel); border: 1px solid var(--border);
  padding: .3rem .75rem; border-radius: 999px; font-size: .8rem; color: var(--muted);
  white-space: nowrap;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.status-dot.ok { background: var(--green); box-shadow: 0 0 6px rgba(46, 204, 113, .7); }
.status-dot.bad { background: var(--red); box-shadow: 0 0 6px rgba(229, 84, 75, .7); }

.user-chip { display: inline-flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .85rem; }
.user-chip a { color: var(--muted); }
.user-chip a:hover { color: var(--red); text-decoration: none; }

/* ---------- tarjetas y secciones ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.2rem;
}
.card + .card, .section + .section { margin-top: 1.2rem; }
.section-head { display: flex; align-items: baseline; gap: .8rem; margin: 1.6rem 0 .8rem; }
.section-head:first-child { margin-top: 0; }
.section-head h2 { margin: 0; }
.section-head .sub { color: var(--muted); font-size: .82rem; }
.section-head .spacer { flex: 1; }

.grid { display: grid; gap: 1.1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.stat-num { font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .8rem; }

/* ---------- botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: .5rem .95rem; font-size: .88rem; font-weight: 550;
  cursor: pointer; text-decoration: none;
  transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.15); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--grad); border: 0; color: #fff; }
.btn-danger { background: rgba(229, 84, 75, .15); border-color: rgba(229, 84, 75, .4); color: #ff8e87; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn[disabled] { opacity: .5; pointer-events: none; }

label.fld { display: block; margin-bottom: .9rem; }
label.fld span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .3rem; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=url], select, textarea {
  width: 100%; background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: .55rem .75rem; font-size: .9rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-b); }
input[type=checkbox] { accent-color: var(--accent-b); width: 16px; height: 16px; }
.check-row { display: flex; align-items: center; gap: .5rem; margin: .35rem 0; font-size: .88rem; }

/* ---------- tablas ---------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .87rem; min-width: 640px; }
.tbl th, .tbl td { padding: .6rem .8rem; text-align: left; white-space: nowrap; }
.tbl th {
  color: var(--muted); font-weight: 600; font-size: .74rem; text-transform: uppercase;
  letter-spacing: .05em; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel);
}
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl th .arrow { opacity: .9; color: var(--accent-b); }
.tbl tbody tr { border-bottom: 1px solid rgba(38, 46, 58, .55); }
.tbl tbody tr:last-child { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--panel-2); }
.tbl td.trunc { max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }

.pager { display: flex; align-items: center; gap: .7rem; margin-top: .9rem; justify-content: flex-end; font-size: .85rem; color: var(--muted); }

/* ---------- insignias / píldoras ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .72rem; font-weight: 600; padding: .12rem .55rem;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--muted); white-space: nowrap;
}
.badge.green { color: #7ee2a8; border-color: rgba(46, 204, 113, .35); background: rgba(46, 204, 113, .1); }
.badge.red { color: #ff9d96; border-color: rgba(229, 84, 75, .35); background: rgba(229, 84, 75, .1); }
.badge.yellow { color: #f3d183; border-color: rgba(231, 185, 60, .35); background: rgba(231, 185, 60, .1); }
.badge.purple { color: #d3a8e8; border-color: rgba(170, 92, 195, .4); background: rgba(170, 92, 195, .12); }
.badge.blue { color: #7fd4f5; border-color: rgba(0, 164, 220, .4); background: rgba(0, 164, 220, .12); }

/* ---------- sesiones activas ---------- */
.stream-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); gap: 1.1rem; }
.stream-card { display: flex; gap: 1rem; overflow: hidden; }
.stream-card .poster {
  width: 92px; aspect-ratio: 2/3; border-radius: 10px; flex-shrink: 0;
  object-fit: cover; background: var(--panel-2); box-shadow: var(--shadow);
}
.stream-card .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .3rem; }
.stream-card .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stream-card .subtitle { color: var(--muted); font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stream-card .meta { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .15rem; }
.stream-card .who { color: var(--muted); font-size: .82rem; margin-top: auto; padding-top: .4rem; display: flex; flex-wrap: wrap; gap: .3rem .8rem; }
.progress { height: 6px; background: var(--panel-2); border-radius: 4px; overflow: hidden; margin-top: .45rem; }
.progress > div { height: 100%; background: var(--grad); border-radius: 4px; transition: width .6s ease; }
.progress-times { display: flex; justify-content: space-between; color: var(--faint); font-size: .74rem; margin-top: .25rem; font-variant-numeric: tabular-nums; }

.empty {
  color: var(--muted); text-align: center; padding: 2.2rem 1rem;
  border: 1px dashed var(--border); border-radius: var(--radius); font-size: .9rem;
}

/* ---------- fila de pósteres ---------- */
.poster-row { display: flex; gap: .9rem; overflow-x: auto; padding: .3rem .1rem .8rem; scroll-snap-type: x proximity; }
.poster-item { width: 132px; flex-shrink: 0; scroll-snap-align: start; text-decoration: none; color: var(--text); }
.poster-item:hover { text-decoration: none; }
.poster-item img {
  width: 132px; aspect-ratio: 2/3; object-fit: cover;
  border-radius: 10px; background: var(--panel-2);
  transition: transform .18s ease, box-shadow .18s ease; display: block;
}
.poster-item:hover img { transform: translateY(-4px) scale(1.02); box-shadow: 0 10px 26px rgba(0, 0, 0, .5); }
.poster-item .cap { font-size: .8rem; margin-top: .4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.poster-item .sub { font-size: .72rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.poster-fallback {
  width: 132px; aspect-ratio: 2/3; border-radius: 10px;
  background: var(--panel-2); display: flex; align-items: center; justify-content: center;
  color: var(--faint); font-size: 1.8rem; font-weight: 700;
}

/* ---------- listas de ranking ---------- */
.rank-list { display: flex; flex-direction: column; gap: .5rem; margin-top: .5rem; }
.rank-item { display: flex; align-items: center; gap: .7rem; font-size: .87rem; }
.rank-item .pos { color: var(--faint); font-weight: 700; width: 1.1rem; text-align: right; font-variant-numeric: tabular-nums; }
.rank-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-item .val { color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; }
.rank-bar { height: 4px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.rank-bar > div { height: 100%; background: var(--grad); }

/* ---------- avatares ---------- */
.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--panel-2); }
.avatar-fallback {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--grad); color: #fff; font-weight: 700; font-size: 1.05rem;
}
.avatar-fallback.lg, .avatar.lg { width: 72px; height: 72px; font-size: 1.6rem; }

.user-card { display: flex; align-items: center; gap: .9rem; text-decoration: none; color: var(--text); }
.user-card:hover { text-decoration: none; border-color: var(--accent-b); }
.user-card .info { min-width: 0; flex: 1; }
.user-card .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-card .sub { color: var(--muted); font-size: .78rem; }

/* ---------- página de medio ---------- */
.media-hero { display: flex; gap: 1.6rem; align-items: flex-start; }
.media-hero .poster { width: 190px; aspect-ratio: 2/3; object-fit: cover; border-radius: 12px; box-shadow: var(--shadow); background: var(--panel-2); flex-shrink: 0; }
.media-hero .info { flex: 1; min-width: 0; }
.media-hero .chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0; }
.media-hero .overview { color: var(--muted); max-width: 70ch; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .3rem 1.2rem; font-size: .86rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow: hidden; text-overflow: ellipsis; }

/* ---------- gráficas ---------- */
.chart-card { min-height: 300px; display: flex; flex-direction: column; }
.chart-card h2 { font-size: .92rem; margin-bottom: .8rem; }
.chart-box { position: relative; flex: 1; min-height: 240px; }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(5, 8, 12, .72);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 1rem; z-index: 100; backdrop-filter: blur(3px);
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 540px; padding: 1.3rem 1.4rem;
  box-shadow: var(--shadow); max-height: 85vh; overflow-y: auto;
}
.modal h2 { margin-bottom: 1rem; }
.modal .actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }

/* ---------- toast ---------- */
#toasts { position: fixed; bottom: 1.2rem; right: 1.2rem; z-index: 200; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--accent-b);
  padding: .7rem 1rem; border-radius: 10px; font-size: .87rem; box-shadow: var(--shadow);
  animation: slide-in .25s ease; max-width: 340px;
}
.toast.err { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
@keyframes slide-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- login / setup ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .brand { justify-content: center; padding: 0 0 1.4rem; font-size: 1.5rem; }
.auth-card .brand .logo { width: 40px; height: 40px; }
.setup-card { max-width: 560px; }
.steps { display: flex; gap: .5rem; margin-bottom: 1.4rem; }
.steps .step { flex: 1; height: 4px; border-radius: 3px; background: var(--panel-2); }
.steps .step.on { background: var(--grad); }
.form-error { color: #ff9d96; font-size: .85rem; margin-top: .6rem; min-height: 1.2em; }
.form-ok { color: #7ee2a8; font-size: .85rem; margin-top: .6rem; }

/* ---------- ajustes ---------- */
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--border); margin-bottom: 1.3rem; flex-wrap: wrap; }
.tabs button {
  background: none; border: 0; color: var(--muted); padding: .6rem 1rem;
  font-size: .9rem; font-weight: 550; cursor: pointer; border-bottom: 2px solid transparent;
  font-family: inherit;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent-b); }
.notifier-row { display: flex; align-items: center; gap: .8rem; padding: .8rem 0; border-bottom: 1px solid rgba(38, 46, 58, .55); }
.notifier-row:last-child { border-bottom: 0; }
.notifier-row .grow { flex: 1; min-width: 0; }
.notifier-row .name { font-weight: 600; }
.notifier-row .sub { color: var(--muted); font-size: .78rem; }

.filter-bar { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1rem; align-items: end; }
.filter-bar label.fld { margin: 0; flex: 1; min-width: 130px; max-width: 220px; }
.filter-bar label.fld.wide { max-width: 320px; min-width: 200px; }

.sev-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: .4rem; background: var(--faint); }
.sev-dot.Information { background: var(--accent-b); }
.sev-dot.Warning { background: var(--yellow); }
.sev-dot.Error { background: var(--red); }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: .8rem; }
.mt0 { margin-top: 0; } .mt1 { margin-top: .5rem; } .mt2 { margin-top: 1rem; } .mt3 { margin-top: 1.5rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .82em; }
.nowrap { white-space: nowrap; }

/* ---------- adaptable ---------- */
@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open { transform: none; box-shadow: 0 0 60px rgba(0,0,0,.6); }
  .main { margin-left: 0; }
  .hamburger { display: inline-flex; }
  .content { padding: 1rem 1rem 3rem; }
  .topbar { padding: .7rem 1rem; }
  .stream-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .media-hero { flex-direction: column; align-items: center; text-align: center; }
  .media-hero .chips { justify-content: center; }
  .kv { grid-template-columns: 1fr; gap: 0 0; }
  .kv dt { margin-top: .5rem; }
  .filter-bar label.fld, .filter-bar label.fld.wide { max-width: none; min-width: 45%; }
  .status-pill .pill-text { display: none; }
}
#sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 55; }
#sidebar-overlay.show { display: block; }
@media (min-width: 961px) {
  /* al ensanchar la ventana con el menú móvil abierto, el overlay no debe quedarse */
  #sidebar-overlay.show { display: none; }
}

/* ---------- editor de plantillas de notificación ---------- */
.tpl-editor summary {
  cursor: pointer; color: var(--muted); font-size: .85rem; font-weight: 600;
  padding: .4rem 0; user-select: none;
}
.tpl-editor summary:hover { color: var(--text); }
.tpl-editor textarea {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .78rem; line-height: 1.45; min-height: 88px; resize: vertical;
}
.tpl-grid { display: grid; gap: .8rem; margin-top: .5rem; }
.ph-table { width: 100%; border-collapse: collapse; font-size: .76rem; margin-top: .4rem; }
.ph-table td { padding: .18rem .5rem .18rem 0; vertical-align: top; }
.ph-table td:first-child { font-family: ui-monospace, Menlo, Consolas, monospace;
  color: #7fd4f5; white-space: nowrap; }
.ph-table td:last-child { color: var(--muted); }
