/* ============================================================
   Totalflix EMBY — tema oscuro
   Paleta: carbón azulado + verde Totalflix; ámbar y rojo para tiempo.
   Display: Archivo · Cuerpo/datos: Inter
   ============================================================ */

* { box-sizing: border-box; }

:root {
  --bg: #0f1419;
  --bg-raised: #151c23;
  --surface: #1a232c;
  --surface-hover: #202b36;
  --line: #263340;
  --line-soft: #1f2933;
  --text: #e9eef3;
  --text-dim: #93a1af;
  --text-faint: #5d6b79;
  --green: #3fd47f;
  --green-deep: #2aa763;
  --green-glow: rgba(63, 212, 127, 0.14);
  --amber: #e8b845;
  --amber-glow: rgba(232, 184, 69, 0.14);
  --red: #f0545c;
  --red-glow: rgba(240, 84, 92, 0.14);
  --font-display: "Archivo", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 10px;
  --sidebar-w: 232px;
}

html { height: 100%; }

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

a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-radius: 4px;
}

code {
  background: var(--bg);
  border: 1px solid var(--line-soft);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--green);
}

.pos { color: var(--green); font-weight: 600; font-variant-numeric: tabular-nums; }
.neg { color: var(--red); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Wordmark ---------- */

.wordmark { display: flex; align-items: baseline; gap: 8px; text-decoration: none; }
.wordmark:hover { text-decoration: none; }
.wordmark-total {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.04em;
  color: var(--text);
}
.wordmark-total em { font-style: normal; color: var(--green); }
.wordmark-emby {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--bg);
  background: var(--green);
  padding: 2px 7px;
  border-radius: 4px;
  transform: translateY(-1px);
}
.wordmark-lg { justify-content: center; margin-bottom: 6px; }
.wordmark-lg .wordmark-total { font-size: 26px; }
.wordmark-lg .wordmark-emby { font-size: 12px; padding: 3px 9px; }

/* ---------- Estructura ---------- */

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

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

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: background 0.15s, color 0.15s;
}
.side-nav a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.side-nav a.is-active {
  background: var(--green-glow);
  color: var(--green);
  border-left-color: var(--green);
  font-weight: 600;
}
.side-nav svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linejoin: round;
  stroke-linecap: round;
  flex-shrink: 0;
}

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.side-user { display: flex; flex-direction: column; padding: 0 12px; }
.side-user-name { font-weight: 600; font-size: 14px; }
.side-user-role {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.page-title {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.01em;
  margin: 0;
}
.credit-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--green-glow);
  color: var(--green);
  font-weight: 700;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(63, 212, 127, 0.25);
}
.credit-chip svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.4; }

.content { padding: 26px 32px 60px; max-width: 1240px; width: 100%; }

/* ---------- Tarjetas de métricas ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card-num {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 800;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.card-label {
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}
.card-accent { border-color: rgba(63, 212, 127, 0.35); background: linear-gradient(160deg, var(--green-glow), var(--surface) 55%); }
.card-accent .card-num { color: var(--green); }
.card-alert { border-color: rgba(240, 84, 92, 0.4); background: linear-gradient(160deg, var(--red-glow), var(--surface) 55%); }
.card-alert .card-num { color: var(--red); }

/* ---------- Paneles y tablas ---------- */

.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
@media (max-width: 900px) { .columns { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  margin-bottom: 18px;
  min-width: 0;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.panel-head h2 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.count {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 1px 8px;
}
.panel-link { font-size: 12.5px; font-weight: 600; }

.table-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: var(--surface-hover); }
th {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
  padding-top: 4px;
}
td { font-size: 13.5px; }
.td-strong { font-weight: 600; }
.td-dim { color: var(--text-dim); }
.td-note {
  display: block;
  font-size: 11.5px;
  font-weight: 400;
  color: var(--text-faint);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.kv th { text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text-dim); width: 130px; }

/* ---------- Medidor de tiempo restante (firma) ---------- */

.th-meter { min-width: 130px; }
.td-meter { min-width: 130px; }
.td-meter { display: table-cell; }
.td-meter .meter { display: inline-block; vertical-align: middle; width: 84px; }
.meter {
  height: 5px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}
.meter span {
  display: block;
  height: 100%;
  border-radius: 999px;
  min-width: 3px;
  transition: width 0.4s ease;
}
.meter-fine span { background: linear-gradient(90deg, var(--green-deep), var(--green)); }
.meter-warm span { background: linear-gradient(90deg, #c79a2e, var(--amber)); }
.meter-hot span { background: linear-gradient(90deg, #c23e45, var(--red)); }
.meter-days {
  display: inline-block;
  vertical-align: middle;
  margin-left: 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* ---------- Badges y chips ---------- */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge-ok { background: var(--green-glow); color: var(--green); }
.badge-warn { background: var(--amber-glow); color: var(--amber); }
.badge-err { background: var(--red-glow); color: var(--red); }

.chip-soft {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 1px 10px;
  font-weight: 700;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Formularios ---------- */

label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin: 14px 0 5px; }

input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 11px;
  width: 100%;
  transition: border-color 0.15s;
}
input::placeholder { color: var(--text-faint); }
input:focus, select:focus { border-color: var(--green-deep); outline: none; }
select { cursor: pointer; }

.form-row { display: flex; gap: 8px; flex-wrap: wrap; }
.form-fields { align-items: flex-end; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { margin: 0; font-size: 11.5px; }
.field.grow { flex: 1; min-width: 180px; }
.field-btn { justify-content: flex-end; }
.duo { display: flex; gap: 6px; }
.duo input { width: 84px; }
.duo select { width: auto; }
.pop-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--green);
  padding-bottom: 2px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 2px;
  max-width: 240px;
}
.form-row input, .form-row select { width: auto; flex: 1; min-width: 130px; }
.form-row input[type="number"] { min-width: 105px; flex: 0 1 130px; }
.form-stack { display: flex; flex-direction: column; gap: 8px; min-width: 210px; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-row input[type="search"] { width: 210px; }
.filter-row select { width: auto; }
.inline { display: inline; }

.hint { color: var(--text-faint); font-size: 12px; margin: 10px 0 0; }
.empty { color: var(--text-dim); padding: 14px 0 4px; margin: 0; }

/* ---------- Botones ---------- */

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-hover);
  color: var(--text);
  padding: 8px 15px;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--green);
  border-color: var(--green);
  color: #08130c;
  font-weight: 700;
}
.btn-primary:hover { background: #55dd8f; border-color: #55dd8f; }
.btn-danger { background: transparent; border-color: rgba(240, 84, 92, 0.4); color: var(--red); }
.btn-danger:hover { background: var(--red-glow); border-color: var(--red); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); border-color: var(--line); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; margin-top: 18px; }

/* ---------- Acciones por fila (popovers <details>) ---------- */

.actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.actions details { position: relative; }
.actions summary {
  cursor: pointer;
  list-style: none;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12.5px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.actions summary::-webkit-details-marker { display: none; }
.actions summary:hover { color: var(--text); background: var(--surface-hover); }
.actions details[open] summary { color: var(--green); background: var(--green-glow); }
.actions details[open] > *:not(summary) {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

/* ---------- Flash ---------- */

.flash {
  padding: 11px 16px;
  border-radius: 8px;
  margin-bottom: 18px;
  font-weight: 500;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.flash-ok { background: var(--green-glow); color: var(--green); border-color: rgba(63, 212, 127, 0.25); }
.flash-error { background: var(--red-glow); color: var(--red); border-color: rgba(240, 84, 92, 0.3); }

/* ---------- Login ---------- */

.login-page { background: var(--bg); }
.login-stage {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 20px;
}
.login-glow {
  position: absolute;
  width: 640px;
  height: 640px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(63, 212, 127, 0.09) 0%, transparent 62%);
  pointer-events: none;
}
.login-box {
  position: relative;
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  padding: 38px 34px;
  width: 372px;
  max-width: 100%;
}
.login-box-center { text-align: center; }
.login-hint { color: var(--text-dim); font-size: 13px; text-align: center; margin: 4px 0 20px; }
.error-code {
  font-family: var(--font-display);
  font-size: 56px;
  font-weight: 800;
  color: var(--green);
  line-height: 1.1;
}

/* ---------- Vista de cliente ---------- */

.client-hero {
  display: flex;
  gap: 24px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 26px 28px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.client-days {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  border: 3px solid var(--green);
  background: var(--green-glow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.client-days.is-warn { border-color: var(--amber); background: var(--amber-glow); }
.client-days.is-warn .client-days-num { color: var(--amber); }
.client-days.is-expired { border-color: var(--red); background: var(--red-glow); }
.client-days.is-expired .client-days-num { color: var(--red); }
.client-days-num {
  font-family: var(--font-display);
  font-size: 42px;
  font-weight: 800;
  color: var(--green);
  line-height: 1;
}
.client-days-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-top: 5px;
}
.client-summary { flex: 1; min-width: 240px; }
.client-summary h2 {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  margin: 0 0 12px;
}
.client-summary .meter { max-width: 320px; margin-bottom: 10px; height: 6px; }
.client-line { color: var(--text-dim); margin: 0 0 12px; }
.client-line strong { color: var(--text); }
.client-hero .flash { margin: 0; }

/* ---------- Modal de bienvenida ---------- */

dialog.modal {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px 26px;
  width: 440px;
  max-width: calc(100vw - 40px);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}
dialog.modal::backdrop { background: rgba(8, 12, 16, 0.72); }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.modal-head h3 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  margin: 0;
}
.modal-sub { color: var(--text-dim); font-size: 13px; margin: 4px 0 12px; }
.welcome-text {
  font-family: var(--font-body);
  font-size: 13.5px;
  line-height: 1.65;
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 14px 16px;
  margin: 0 0 16px;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: all;
}
.modal-actions { display: flex; gap: 8px; }

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

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--line-soft);
    flex-wrap: wrap;
  }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .side-nav a { border-left: none; padding: 7px 10px; }
  .side-foot { margin-top: 0; margin-left: auto; flex-direction: row; align-items: center; }
  .side-user { padding: 0; }
  .side-user-role { display: none; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .actions details[open] > *:not(summary) { right: auto; left: 0; }
}

/* ---------- Movimiento reducido ---------- */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
