/* ===============================
   GLOBAL VARIABLES
================================ */
:root {
  --header-h: 64px;
}

/* ========== RESET & BASE ========== */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Arial, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
}

h1 { margin: 0; font-size: 1.25rem; }
p  { margin: 0 0 10px; line-height: 1.55; }

/* ========== HEADER ========== */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: var(--header-h);

  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;

  background: #111827;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 18px;
  line-height: 1.25;
  word-break: break-word;
}

.actions { display: flex; gap: 12px; align-items: center; }
.admin   { margin-left: 12px; }
.admin-actions { display: flex; gap: 8px; margin-top: 8px; }

/* Toggle sidebar (mobile) */
.sidebar-toggle {
  display: none;
  appearance: none;
  border: 1px solid #334155;
  background: #0b1220;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

/* ========== APP GRID ========== */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - var(--header-h));
}

/* ========== SIDEBAR DESKTOP ========== */
.sidebar {
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;

  background: #0b1220;
  border-right: 1px solid #1f2937;
}

/* Nav */
.nav {
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 4px;
}

.nav-section {
  margin: 12px 8px 6px;
  font-size: 0.75rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.nav-link {
  padding: 10px 12px;
  border-radius: 8px;
  color: #e2e8f0;
  text-decoration: none;
  border: 1px solid transparent;
}

.nav-link:hover {
  background: #0f172a;
  border-color: #1f2937;
}

.nav-link.active {
  background: #111827;
  border-color: #334155;
  color: #facc15;
  font-weight: 600;
}

/* ========== MAIN CONTENT ========== */
main {
  padding: 16px 18px;
}

/* ========== GRID DEVICES ========== */
#devices {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 16px;
}

/* ========== DEVICE CARD ========== */
.device-card {
  border: 1px solid #334155;
  border-radius: 8px;
  background: #111827;
  padding: 10px;
}

/* Chart */
.chart-container {
  position: relative;
  width: 100%;
  height: 300px;
}

/* Titles */
h3.device-title {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: #facc15;
}

h4.device-title {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: #ffffff;
}

/* ========== USER META ========== */
.user-meta {
  margin-top: 8px;
  padding: 8px;
  border-top: 1px dashed #334155;
}

.user-meta-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(60px, 1fr));
  gap: 8px;
}

/* ========== FOOTER ========== */
footer {
  padding: 14px 20px;
  color: #94a3b8;
  text-align: center;
  border-top: 1px solid #1f2937;
}

/* ===============================
   RESPONSIVE
================================ */

/* Tablet */
@media (max-width: 992px) {
  .app { grid-template-columns: 220px 1fr; }
  #devices { grid-template-columns: repeat(2, 1fr); }
}

/* ===============================
   MOBILE FIX (SIDEBAR TIDAK KETUTUP HEADER)
================================ */
@media (max-width: 768px) {
  .header-title {gap: 18px;}
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 60;

    top: calc(
      var(--header-h) + env(safe-area-inset-top)
    );

    left: 0;
    width: 260px;
    height: calc(
      100vh - var(--header-h) - env(safe-area-inset-top)
    );

    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 8px 0 24px rgba(0,0,0,.35);
  }

  .app.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }

  body.no-scroll {
    overflow: hidden;
  }

  #devices {
    grid-template-columns: 1fr;
  }

  main {
    padding: 14px;
  }
}

/* ===============================
   PRINT / PDF MODE
================================ */
@media print {

  header,
  footer,
  .sidebar,
  .sidebar-toggle,
  .actions,
  .pagination,
  button {
    display: none !important;
  }

  body {
    background: #fff !important;
    color: #000 !important;
  }

  .app {
    display: block !important;
  }

  #devices {
    display: block !important;
  }

  .device-card {
    page-break-after: always;
    border: none;
    box-shadow: none;
  }
}

/* ========== NN THINKING CANVAS ========== */
#nnThinking {
  border-radius: 6px;
  background: rgba(79,195,247,0.08);
}
