/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  /* Spacing — 8px base grid */
  --sp-1:  8px;
  --sp-2:  16px;
  --sp-3:  24px;
  --sp-4:  32px;
  --sp-5:  48px;
  --sp-6:  64px;

  /* Border radii */
  --r-sm:  4px;
  --r-md:  8px;
  --r-lg:  12px;

  /* Typography scale */
  --t-xs:   11px;
  --t-sm:   13px;
  --t-base: 15px;
  --t-lg:   18px;
  --t-xl:   24px;
  --t-2xl:  32px;
  --t-3xl:  48px;

  /* Colors */
  --c-bg:        #000000;
  --c-surface:   #0d1f14;
  --c-surface-2: #1F4D2E;
  --c-border:    rgba(201, 162, 39, 0.18);
  --c-border-hi: rgba(201, 162, 39, 0.45);
  --c-accent:    #C9A227;
  --c-accent-hi: #e0b83a;
  --c-accent-lo: rgba(201, 162, 39, 0.10);
  --c-text:      #FFFFFF;
  --c-muted:     rgba(255, 255, 255, 0.45);
  --c-online:    #4ade80;
  --c-offline:   #B22222;
  --c-success:   #4ade80;
  --c-warning:   #C9A227;

  /* Sidebar */
  --sidebar-w: 280px;
  --nav-h:     64px;
  --row-h:     48px;

  /* Transitions */
  --ease: 0.2s ease;
}

/* ============================================================
   RESET
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  outline: none;
}

/* ============================================================
   BASE
   ============================================================ */
body {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  font-size: var(--t-base);
  background-color: var(--c-bg);
  color: var(--c-text);
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { display: none; }

/* ============================================================
   NAV BAR
   ============================================================ */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--nav-h);
  border-bottom: 1px solid var(--c-border);
  background-color: #000000;
  z-index: 900;
  pointer-events: none;
  display: flex;
  align-items: center;
}

/* Hamburger toggle */
.bar {
  pointer-events: auto;
  position: fixed;
  top: calc((var(--nav-h) - var(--row-h)) / 2);
  left: var(--sp-2);
  width: var(--row-h);
  height: var(--row-h);
  background: transparent;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  color: var(--c-text);
  font-size: var(--t-lg);
  cursor: pointer;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--ease), background var(--ease);
}
.bar:hover {
  border-color: var(--c-border-hi);
  background: var(--c-surface);
}

/* Brand logo */
.brand-logo {
  pointer-events: none;
  position: fixed;
  top: calc((var(--nav-h) - 32px) / 2);
  right: var(--sp-3);
  height: 32px;
  width: auto;
  object-fit: contain;
  z-index: 950;
  opacity: 0.9;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background-color: #0d1f14;
  border-right: 1px solid var(--c-border);
  border-radius: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: transform var(--ease);
}

.sidebar.hidden {
  transform: translateX(-100%);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding-top: var(--nav-h);
  padding-bottom: var(--sp-3);
  -webkit-overflow-scrolling: touch;
}

.logo {
  height: var(--row-h);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-2);
  font-size: var(--t-sm);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-muted);
  border-bottom: 1px solid var(--c-border);
}

.items {
  position: relative;
  height: var(--row-h);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-2);
  font-size: var(--t-sm);
  color: var(--c-muted);
  cursor: pointer;
  transition: color var(--ease), background var(--ease);
  user-select: none;
}
.items:hover {
  background: rgba(201, 162, 39, 0.08);
  color: var(--c-text);
}
.items.active {
  color: var(--c-accent);
  background: rgba(201, 162, 39, 0.06);
}
/* Active state: 3px left accent bar */
.items.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: calc((var(--row-h) - 20px) / 2);
  height: 20px;
  width: 3px;
  background: var(--c-accent);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.items span {
  padding-left: var(--sp-1);
}

/* ============================================================
   CONTENT AREA
   ============================================================ */
.content {
  padding-top: var(--nav-h);
  transition: margin-left var(--ease);
}

@media (min-width: 1024px) {
  .content {
    margin-left: var(--sidebar-w);
  }
  .sidebar.hidden ~ .content {
    margin-left: 0;
  }
}

/* ============================================================
   PANEL SECTIONS — shared base
   ============================================================ */
.panel-section {
  min-height: calc(100vh - var(--nav-h));
  padding: var(--sp-3);
}

/* Catch-all for sections not given .panel-section in markup */
#home, #vnc, #files, #gallery,
#textViewer, #camera, #geolocation,
#screenshots, #audio, #activity, #media {
  min-height: calc(100vh - var(--nav-h));
  padding: var(--sp-3);
}

/* ============================================================
   SECTION TOOLBAR (file-controls)
   ============================================================ */
.section-toolbar,
.file-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  align-items: center;
  margin-bottom: var(--sp-2);
}

.section-toolbar input,
.file-controls input {
  flex: 1;
  min-width: 0;
  height: var(--row-h);
  padding: 0 var(--sp-2);
  font-size: var(--t-sm);
  background: #0d1f14;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  color: var(--c-text);
  transition: border-color var(--ease);
}
.section-toolbar input:focus,
.file-controls input:focus {
  border-color: var(--c-accent);
}

/* ============================================================
   BUTTONS
   ============================================================ */
button {
  height: var(--row-h);
  padding: 0 var(--sp-2);
  font-size: var(--t-sm);
  font-family: inherit;
  background: transparent;
  border: 1px solid var(--c-border-hi);
  border-radius: var(--r-sm);
  color: var(--c-text);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
}
button:hover {
  background: rgba(201, 162, 39, 0.10);
  border-color: var(--c-accent);
  color: var(--c-accent-hi);
}
button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* Primary (accent) button */
button.btn-primary {
  background: var(--c-accent);
  border-color: var(--c-accent);
  color: #fff;
}
button.btn-primary:hover {
  background: var(--c-accent-hi);
  border-color: var(--c-accent-hi);
  color: #fff;
}

/* ============================================================
   CARDS — shared
   ============================================================ */
.card {
  background: #0d1f14;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-2);
}

/* ============================================================
   HOME SECTION — bento grid
   ============================================================ */
.home-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--sp-2);
}

/* Device name card — spans 8 cols */
.home-device-card {
  grid-column: span 8;
  background: #0d1f14;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.home-device-card h2 {
  font-size: var(--t-xl);
  font-weight: 700;
  color: var(--c-text);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-wrap: wrap;
}
.home-device-card p {
  font-size: var(--t-sm);
  color: var(--c-muted);
  line-height: 1.6;
}

/* Status badge card — spans 4 cols */
.home-status-card {
  grid-column: span 4;
  background: #1F4D2E;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: var(--sp-2);
}

/* Stat row — 4 equal cards, each 3 cols */
.home-stat-card {
  grid-column: span 3;
  background: #0d1f14;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.home-stat-card .stat-label {
  font-size: var(--t-xs);
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.home-stat-card .stat-value {
  font-size: var(--t-lg);
  font-weight: 600;
  color: var(--c-accent);
}

/* Live status sub-panel — full 12 cols */
.home-live-card {
  grid-column: span 12;
  background: #1F4D2E;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-3);
}
.home-live-card .live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}
.home-live-card .live-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.home-live-card .live-item .live-label {
  font-size: var(--t-xs);
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.home-live-card .live-item strong {
  font-size: var(--t-sm);
  color: var(--c-text);
}

/* Online / offline status indicator */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px var(--sp-1);
  border-radius: var(--r-sm);
  border: 1px solid transparent;
}
.status.online {
  color: var(--c-online);
  background: rgba(34, 211, 238, 0.08);
  border-color: rgba(34, 211, 238, 0.2);
}
.status.online::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-online);
  flex-shrink: 0;
}
.status.offline {
  color: var(--c-offline);
  background: rgba(244, 63, 94, 0.08);
  border-color: rgba(244, 63, 94, 0.2);
}
.status.offline::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-offline);
  flex-shrink: 0;
}

/* ============================================================
   FILE TABLE
   ============================================================ */
.file-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-sm);
  background: #0d1f14;
}
.file-table th {
  height: var(--row-h);
  padding: 0 var(--sp-2);
  text-align: left;
  font-size: var(--t-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--c-muted);
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}
.file-table td {
  height: var(--row-h);
  padding: 0 var(--sp-2);
  border-bottom: 1px solid var(--c-border);
  color: var(--c-text);
  vertical-align: middle;
}
.file-table tr:last-child td {
  border-bottom: none;
}
.file-table tbody tr:hover td {
  background: rgba(201, 162, 39, 0.06);
}

/* ============================================================
   GALLERY / CARD GRID
   ============================================================ */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--sp-2);
}

.gallery-card {
  background: #0d1f14;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  font-size: var(--t-sm);
}
.gallery-card strong {
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--c-text);
  word-break: break-all;
}
.gallery-card span {
  font-size: var(--t-xs);
  color: var(--c-muted);
}
.gallery-card button {
  margin-top: auto;
}

/* Media images inside cards */
.media-img {
  width: 100%;
  height: auto;
  max-height: 280px;
  object-fit: contain;
  border-radius: var(--r-sm);
  display: block;
  cursor: pointer;
}
audio {
  width: 100%;
  height: 32px;
}
video {
  width: 100%;
  border-radius: var(--r-sm);
}

/* ============================================================
   TEXT VIEWER — 2-col split
   ============================================================ */
.text-viewer-split {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-2);
}
@media (min-width: 1024px) {
  .text-viewer-split {
    grid-template-columns: 4fr 8fr;
  }
}
.text-viewer-left {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.text-viewer-left select {
  width: 100%;
  height: var(--row-h);
  padding: 0 var(--sp-1);
  font-size: var(--t-sm);
  font-family: inherit;
  background: #0d1f14;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  color: var(--c-text);
  cursor: pointer;
  transition: border-color var(--ease);
}
.text-viewer-left select:focus {
  border-color: var(--c-accent);
}
.text-viewer-right {
  min-height: 200px;
}

/* ============================================================
   ALERT / TOAST / STATUS MESSAGES
   ============================================================ */
.alert {
  background: #0d1f14;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-2);
  font-size: var(--t-sm);
  color: var(--c-text);
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

/* Floating toast */
.alert-toast {
  position: fixed;
  bottom: var(--sp-3);
  right: var(--sp-3);
  z-index: 99999;
  width: 280px;
  background: #1F4D2E;
  border: 1px solid var(--c-border-hi);
  border-radius: var(--r-md);
  padding: var(--sp-2);
  font-size: var(--t-sm);
  color: var(--c-text);
  animation: toastIn 0.2s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   LOADING OVERLAY
   ============================================================ */
.load {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
}

/* Geometric ring spinner */
.loader {
  width: 40px;
  height: 40px;
  border: 2px solid var(--c-border-hi);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   VNC SECTION
   ============================================================ */
#vnc {
  position: relative;
  padding: 0;
}

.vnc-toolbar {
  position: fixed;
  top: var(--nav-h);
  left: 0;
  right: 0;
  height: var(--sp-5);
  background: #0d1f14;
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 0 var(--sp-2);
  z-index: 800;
}

.vnc-toolbar button {
  height: 32px;
  font-size: var(--t-xs);
  gap: 6px;
}

.vnc-nav-col {
  position: fixed;
  top: 50%;
  right: var(--sp-2);
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  z-index: 800;
  background: #0d1f14;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-1);
}
.vnc-nav-col button {
  width: var(--sp-5);
  height: var(--sp-5);
  padding: 0;
  border-radius: var(--r-sm);
}

.vcontainer {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: var(--sp-5);
  min-height: calc(100vh - var(--nav-h));
}

#video {
  display: block;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  opacity: 0;
  transition: opacity 0.3s ease;
  object-fit: contain;
  position: fixed;
  touch-action: none;
  cursor: crosshair;
}

/* ============================================================
   APP SELECTOR (screenshots filter)
   ============================================================ */
.app-selector {
  background: #0d1f14;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-2);
  margin-bottom: var(--sp-2);
}
.app-list {
  max-height: 320px;
  overflow-y: auto;
  margin-top: var(--sp-1);
}
.app-item {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  height: var(--row-h);
  padding: 0 var(--sp-1);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--ease);
}
.app-item:hover {
  background: rgba(201, 162, 39, 0.08);
}
.app-item input[type="checkbox"] {
  accent-color: var(--c-accent);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.app-item .app-name {
  flex: 1;
  font-size: var(--t-sm);
  color: var(--c-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-item .app-pkg {
  font-size: var(--t-xs);
  color: var(--c-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

/* ============================================================
   ACTIVITY TIMELINE
   ============================================================ */
#activityTimeline {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-2);
}
.activity-card {
  background: #0d1f14;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.activity-card .act-title {
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--c-text);
}
.activity-card .act-duration {
  font-size: var(--t-lg);
  font-weight: 700;
  color: var(--c-accent-hi);
}
.activity-card .act-meta {
  font-size: var(--t-xs);
  color: var(--c-muted);
}

/* ============================================================
   SECTION TITLE
   ============================================================ */
.section-title {
  font-size: var(--t-lg);
  font-weight: 700;
  color: var(--c-text);
  margin-bottom: var(--sp-2);
}

/* ============================================================
   SELECT (generic)
   ============================================================ */
select {
  height: var(--row-h);
  padding: 0 var(--sp-1);
  font-size: var(--t-sm);
  font-family: inherit;
  background: #0d1f14;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  color: var(--c-text);
  cursor: pointer;
  transition: border-color var(--ease);
}
select:focus {
  border-color: var(--c-accent);
}

/* ============================================================
   RESPONSIVE — mobile collapse
   ============================================================ */
@media (max-width: 1023px) {
  .home-grid {
    grid-template-columns: 1fr;
  }
  .home-device-card,
  .home-status-card,
  .home-stat-card,
  .home-live-card {
    grid-column: span 1;
  }
  .home-live-card .live-grid {
    grid-template-columns: 1fr 1fr;
  }
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
  #activityTimeline {
    grid-template-columns: 1fr;
  }
}
