/* style.css — mobile-optimized refresh */
:root {
  --bg: #0b0e14;
  --bg-rgb: 11, 14, 20;
  --panel: #11151c;
  --panel-2: #151a22;
  --text: #e6eaf2;
  --text-dim: #a6b0c0;
  --primary: #4f7cff;
  --primary-600: #3c66e6;
  --success: #2ecc71;
  --warning: #f39c12;
  --danger: #e74c3c;
  --border: #222a36;
  --muted: #1a2130;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
  --radius: 12px;

  --page-padding: clamp(12px, 4vw, 32px);
  --card-gap: clamp(12px, 3vw, 24px);
  --card-padding: clamp(16px, 3vw, 24px);
  --topbar-gap: clamp(8px, 2.4vw, 16px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html, body {
  height: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 72px;
}
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: clamp(15px, 1.6vw, 17px);
  line-height: 1.5;
  color: var(--text);
  background: linear-gradient(180deg, #0b0e14 0%, #0d121a 60%, #0b0e14 100%);
}

#app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100svh;
  background: transparent;
}

.sidebar {
  background: linear-gradient(180deg, #0e131b, #0b0f16);
  border-right: 1px solid var(--border);
  padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.brand-logo-img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 4px;
}
.brand-title {
  font-weight: 700;
  letter-spacing: 0.3px;
}

.nav-link {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  margin: 6px 0;
  transition: all .15s ease;
  min-height: 44px;
}
.nav-link:hover { background: var(--panel-2); border-color: var(--border); }
.nav-link.active {
  background: var(--panel);
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary) inset;
}

.sidebar-footer {
  position: sticky;
  bottom: 0;
  padding: 16px 0 0;
  margin-top: 24px;
  color: var(--text-dim);
  font-size: 12px;
  background: linear-gradient(180deg, transparent, var(--panel) 40%);
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--topbar-gap);
  padding: clamp(10px, 2.5vw, 18px) clamp(14px, 4vw, 28px);
  background: rgba(var(--bg-rgb), 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 15;
}
#menu-toggle {
  border: none;
  background: var(--panel-2);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  min-width: 44px;
  min-height: 44px;
}
.spacer {
  flex: 1;
  min-width: 24px;
}
.status { color: var(--text-dim); }
.auth {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.userbox {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 12px;
}

.view {
  padding: var(--page-padding);
  display: grid;
  gap: var(--card-gap);
}

/* Cards / layout */
.card {
  background: linear-gradient(180deg, #0f141d 0%, #0b1017 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--card-padding);
  min-width: 0;
}
.card h2,
.card h3 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: clamp(1rem, 2vw, 1.25rem);
}
.grid {
  display: grid;
  gap: var(--card-gap);
}
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-1 { grid-template-columns: 1fr; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.section-title h2 {
  margin: 0;
  font-size: clamp(1rem, 2vw, 1.2rem);
}
.muted { color: var(--text-dim); }

/* Buttons */
button,
.btn {
  background: var(--primary);
  border: 1px solid var(--primary-600);
  color: white;
  padding: 10px 20px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  transition: transform .05s ease, filter .2s;
  min-height: 44px;
}
button:hover,
.btn:hover { filter: brightness(1.05); }
button:active,
.btn:active { transform: translateY(1px); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.icon-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(13px, 1.4vw, 14px);
}
.table th,
.table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 6px;
}
.table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  position: relative;
}
.table th:hover { color: var(--text); }
.table th.sortable::after {
  content: '⇅';
  margin-left: 4px;
  opacity: 0.3;
}
.table th.sort-asc::after { content: '↑'; opacity: 1; }
.table th.sort-desc::after { content: '↓'; opacity: 1; }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}
.pagination-info {
  color: var(--text-dim);
  font-size: 14px;
}
.pagination-controls {
  display: flex;
  gap: 8px;
}

/* Forms */
.form-row {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}
.form-row .full { grid-column: 1 / -1; }
.input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 12px;
  width: 100%;
}
label {
  font-size: 12px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
}
.modal-backdrop[hidden] { display: none; }
.modal-backdrop:not([hidden]) {
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal {
  width: min(720px, 96vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: clamp(12px, 3vw, 20px);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.modal-body {
  padding: 16px 0;
  display: grid;
  gap: 14px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 8px;
  flex-wrap: wrap;
}

/* Toast */
.toast {
  position: fixed;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 50;
}

/* Expandable rows */
.expand-row td {
  padding: 16px;
  background: var(--panel-2);
  border-top: 1px solid var(--border);
}

/* Video / media helpers */
.responsive-media {
  width: 100%;
  max-width: 100%;
  border-radius: calc(var(--radius) - 4px);
}
.video-panel video {
  width: 100%;
  max-height: min(50vh, 420px);
  object-fit: contain;
  background: #000;
}

/* Responsive breakpoints */
@media (max-width: 1200px) {
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
  #app { grid-template-columns: 220px 1fr; }
  .grid.cols-2,
  .grid.cols-3 { grid-template-columns: 1fr; }
  .col-span-2 { grid-column: span 1 !important; }
  .video-panel video { max-height: 45vh; }
}
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: -280px;
    width: min(260px, 82vw);
    height: 100vh;
    transition: left .3s ease;
    z-index: 20;
    box-shadow: 2px 0 18px rgba(0,0,0,0.5);
  }
  .sidebar.open { left: 0; }
  .main {
    margin-left: 0;
    min-height: 100vh;
  }
  .view {
    padding: clamp(14px, 4vw, 24px);
  }
  .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar {
    justify-content: space-between;
    padding-block: 14px;
  }
  .spacer { flex-basis: 100%; order: 99; }
  .status { width: 100%; order: 100; }
  .auth { width: 100%; justify-content: flex-start; }
  .card { padding: clamp(14px, 5vw, 20px); }
  .section-title,
  .pagination {
    flex-direction: column;
    align-items: flex-start;
  }
  .video-panel video { max-height: 40vh; }
}
@media (max-width: 480px) {
  body { font-size: 16px; }
  .topbar { padding-inline: clamp(12px, 6vw, 20px); }
  .topbar > * { flex: 1 1 100%; }
  .pagination-controls {
    width: 100%;
    justify-content: space-between;
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Light theme overrides */
body.light {
  --bg: #f8f9fc;
  --bg-rgb: 248, 249, 252;
  --panel: #ffffff;
  --panel-2: #f0f4f8;
  --text: #1a2130;
  --text-dim: #5a6a80;
  --primary: #4f7cff;
  --primary-600: #3c66e6;
  --success: #2ecc71;
  --warning: #f39c12;
  --danger: #e74c3c;
  --border: #d0d8e0;
  --muted: #e8eff8;
  --shadow: 0 10px 30px rgba(0,0,0,0.1);

  background: linear-gradient(180deg, #f8f9fc 0%, #f0f4f8 60%, #f8f9fc 100%);
}
body.light .sidebar {
  background: linear-gradient(180deg, #ffffff, #f8f9fc);
}
body.light .topbar {
  background: rgba(255,255,255,0.85);
}
body.light .card {
  background: linear-gradient(180deg, #ffffff 0%, #f8f9fc 100%);
}
body.light .nav-link:hover,
body.light .userbox,
body.light .icon-btn { background: #f0f4f8; }
body.light .btn-ghost { color: #1a2130; }
body.light .input { background: #ffffff; }
body.light .modal-backdrop { background: rgba(0,0,0,0.3); }
body.light .toast { background: #ffffff; }