/* =============================================
   STREAMING PANEL - Design System
   Dark Mode · Responsive · Modern UI
   ============================================= */

:root {
  --bg-base:       #0a0c10;
  --bg-surface:    #12151c;
  --bg-raised:     #1a1e28;
  --bg-hover:      #222736;
  --border:        #2a2f3d;
  --text-primary:  #e8eaf0;
  --text-secondary:#8b92a8;
  --text-muted:    #565d72;
  --accent:        #4f8ef7;
  --accent-hover:  #6ba3ff;
  --accent-dim:    rgba(79,142,247,.15);
  --green:         #34c77b;
  --green-dim:     rgba(52,199,123,.15);
  --red:           #f25c5c;
  --red-dim:       rgba(242,92,92,.15);
  --yellow:        #f5a623;
  --yellow-dim:    rgba(245,166,35,.15);
  --purple:        #9d6ef9;
  --purple-dim:    rgba(157,110,249,.15);
  --sidebar-w:     220px;
  --topbar-h:      60px;
  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 4px 24px rgba(0,0,0,.45);
  --transition:    .18s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Layout wrapper ── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ─────────────────────── SIDEBAR ─────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}
.sidebar-logo img {
  width: 32px; height: 32px; object-fit: contain; border-radius: 6px;
}
.sidebar-logo span {
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--text-primary);
  line-height: 1.2;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.nav-section {
  padding: 10px 18px 4px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: .88rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all var(--transition);
}
.nav-link svg { flex-shrink: 0; opacity: .7; }
.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-left-color: var(--border);
}
.nav-link:hover svg { opacity: 1; }
.nav-link.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-left-color: var(--accent);
}
.nav-link.active svg { opacity: 1; }

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .82rem;
}
.sidebar-avatar {
  width: 32px; height: 32px;
  background: var(--accent-dim);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: .8rem;
  color: var(--accent);
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-weight: 600; color: var(--text-primary); truncate: ellipsis; }
.sidebar-user-role { font-size: .72rem; color: var(--text-muted); }

/* ─────────────────────── TOPBAR (mobile) ─────────────────────── */
.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  position: sticky; top: 0; z-index: 90;
}
.topbar-logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: .9rem; color: var(--text-primary);
  text-decoration: none;
}
.topbar-logo img { width: 28px; height: 28px; object-fit: contain; border-radius: 5px; }
.menu-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary); padding: 6px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center;
}
.menu-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* overlay */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 99;
}

/* ─────────────────────── MAIN CONTENT ─────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
}

.page-header {
  margin-bottom: 24px;
}
.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}
.page-subtitle {
  font-size: .85rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ─────────────────────── CARDS ─────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-title {
  font-size: .95rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
  display: flex; align-items: center; gap: 8px;
}
.card-title svg { color: var(--accent); }

/* ─────────────────────── STAT CARDS ─────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.stat-value {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}
.stat-sub {
  font-size: .78rem;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* ─────────────────────── PROGRESS BAR ─────────────────────── */
.progress-wrap { margin-top: 10px; }
.progress-bar {
  height: 6px;
  background: var(--bg-raised);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width .4s ease;
}
.progress-fill.green { background: var(--green); }
.progress-fill.red   { background: var(--red);   }
.progress-fill.yellow{ background: var(--yellow); }

/* ─────────────────────── BADGES ─────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .03em;
}
.badge-green  { background: var(--green-dim);  color: var(--green);  }
.badge-red    { background: var(--red-dim);    color: var(--red);    }
.badge-yellow { background: var(--yellow-dim); color: var(--yellow); }
.badge-blue   { background: var(--accent-dim); color: var(--accent); }
.badge-purple { background: var(--purple-dim); color: var(--purple); }
.badge-dot::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ─────────────────────── BUTTONS ─────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary  { background: var(--accent);    color: #fff; }
.btn-primary:hover  { background: var(--accent-hover); }

.btn-success  { background: var(--green);     color: #fff; }
.btn-success:hover  { filter: brightness(1.1); }

.btn-danger   { background: var(--red);       color: #fff; }
.btn-danger:hover   { filter: brightness(1.1); }

.btn-warning  { background: var(--yellow);    color: #111; }
.btn-warning:hover  { filter: brightness(1.1); }

.btn-ghost {
  background: var(--bg-raised);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm { padding: 6px 12px; font-size: .78rem; }
.btn-lg { padding: 12px 24px; font-size: .95rem; }
.btn-full { width: 100%; }

/* ─────────────────────── FORMS ─────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: .02em;
}
.form-control {
  width: 100%;
  padding: 10px 13px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: .87rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.form-control::placeholder { color: var(--text-muted); }

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b92a8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
}

.form-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.form-row .form-group { flex: 1; min-width: 140px; }

/* ─────────────────────── TABLES ─────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .84rem;
}
.data-table thead th {
  background: var(--bg-raised);
  color: var(--text-muted);
  font-size: .73rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg-hover); }
.data-table td.primary { color: var(--text-primary); font-weight: 500; }
.data-table td.mono { font-family: 'JetBrains Mono', 'Fira Mono', monospace; font-size: .8rem; }

/* ─────────────────────── ALERTS ─────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  margin-bottom: 18px;
  display: flex; align-items: flex-start; gap: 10px;
}
.alert-success { background: var(--green-dim); color: var(--green); border: 1px solid rgba(52,199,123,.3); }
.alert-error   { background: var(--red-dim);   color: var(--red);   border: 1px solid rgba(242,92,92,.3);  }
.alert-info    { background: var(--accent-dim); color: var(--accent);border: 1px solid rgba(79,142,247,.3); }
.alert-warning { background: var(--yellow-dim); color: var(--yellow);border: 1px solid rgba(245,166,35,.3); }

/* ─────────────────────── DIVIDER ─────────────────────── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* ─────────────────────── UTILITIES ─────────────────────── */
.flex   { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 18px; }
.mb-1 { margin-bottom: 6px; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 18px; }
.text-sm { font-size: .8rem; }
.text-xs { font-size: .72rem; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--green); }
.text-danger  { color: var(--red); }
.text-accent  { color: var(--accent); }
.font-mono { font-family: 'JetBrains Mono','Fira Mono',monospace; font-size: .82rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rounded { border-radius: var(--radius); }
.w-full { width: 100%; }

/* ─────────────────────── RESPONSIVE ─────────────────────── */

/* page-wrap: the actual content area inside main-content */
.page-wrap {
  padding: 28px 28px 48px;
}

/* Desktop: hide topbar */
.topbar { display: none; }

@media (max-width: 768px) {
  /* Show topbar, hide sidebar by default */
  .topbar {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 90;
  }

  .sidebar {
    transform: translateX(-100%);
    z-index: 101;
    top: 0; /* covers topbar when open — intentional */
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0,0,0,.6);
  }
  .sidebar-overlay.open {
    display: block;
  }

  .main-content {
    margin-left: 0;
    padding: 0; /* padding handled by page-wrap + topbar */
  }

  .page-wrap {
    padding: 18px 14px 40px;
  }

  /* Video: full width on mobile regardless of inline max-width */
  .video-container,
  .offline-screen {
    max-width: 100% !important;
  }

  /* Stats grid: 2 cols on tablet, 1 on small */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* Admin / generic card grids */
  .card-grid-auto {
    grid-template-columns: 1fr !important;
  }
}

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

  .page-title { font-size: 1.15rem; }

  /* Tables: allow horizontal scroll, freeze first column */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Stack form rows */
  .form-row { flex-direction: column; }
  .form-row .form-group { min-width: 0; }

  /* Clip editor: stack vertically */
  .clip-editor {
    flex-direction: column;
    align-items: stretch;
  }
  .timecode-input { width: 100% !important; }

  /* Page header: stack title and badge/button */
  .page-header.flex {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  /* Stream controls: full width buttons */
  .stream-controls { flex-direction: column; }
  .stream-controls form,
  .stream-controls .btn { width: 100%; }
  .stream-controls .btn { justify-content: center; }

  /* Recording status */
  .recording-status { flex-wrap: wrap; }

  /* Usuarios table: hide created_at and ID on tiny screens */
  .data-table .col-hide-xs { display: none; }

  /* Reduce font in tables */
  .data-table thead th,
  .data-table tbody td { padding: 9px 10px; font-size: .8rem; }

  /* Inline table forms: stack */
  .data-table td > div[style*="flex-direction:column"] {
    gap: 6px;
  }
}

/* Desktop: restore padding from page-wrap, not main-content directly */
@media (min-width: 769px) {
  .main-content {
    padding: 0;
  }
  .page-wrap {
    padding: 28px 28px 48px;
  }
}

/* ─────────────────────── INLINE FORMS IN TABLES ─────────────────────── */
.table-form { display: inline; }
.table-form .form-control {
  width: auto;
  padding: 5px 8px;
  font-size: .78rem;
}

/* ─────────────────────── VIDEO PLAYER ─────────────────────── */
.video-container {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16/9;
}
.video-container video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.offline-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  border-radius: var(--radius);
  aspect-ratio: 16/9;
  text-align: center;
  gap: 16px;
}
.offline-screen img {
  max-width: 200px;
  width: 45%;
  opacity: .85;
}
.offline-screen p {
  color: var(--text-muted);
  font-size: .95rem;
}

/* ─────────────────────── RECORDING CARD STATUS ─────────────────────── */
.recording-status {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
}
.recording-status.active {
  background: var(--red-dim);
  border: 1px solid rgba(242,92,92,.3);
}
.recording-status.idle {
  background: var(--green-dim);
  border: 1px solid rgba(52,199,123,.3);
}
.rec-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--red);
  animation: pulse 1.2s infinite;
}
.recording-status.idle .rec-dot {
  background: var(--green);
  animation: none;
}
@keyframes pulse {
  0%,100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .4; transform: scale(.85); }
}

/* ─────────────────────── STREAM CONTROL BUTTONS ─────────────────────── */
.stream-controls {
  display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px;
}

/* ─────────────────────── CLIP EDITOR ─────────────────────── */
.clip-editor {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-top: 14px;
}
.clip-editor .form-group { margin-bottom: 0; }
.timecode-input { width: 100px !important; font-family: monospace; }
