/* ===============================
   GLOBAL VARIABLES
================================ */
:root {
  --header-h: 64px;
  /* Soft Industrial Palette */
  --bg-main: #f5f6f7;
  --bg-surface: #ffffff;
  --bg-sidebar: #eef1f4;
  --bg-header: #e5e7eb;

  --text-main: #1f2937;
  --text-muted: #6b7280;

  --border-soft: #d1d5db;

  --accent-primary: #3b82f6;   /* steel blue */
  --accent-secondary: #f59e0b; /* industrial amber */
}

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Arial, sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  line-height: 1.3;
}

h1 { font-size: 1.25rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.0rem; }
h4 { font-size: 0.9rem; }
p  { margin: 0 0 6px; font-size: 0.8rem; line-height: 1.55; }

button {
  appearance: none;
  -webkit-appearance: none;

  background: #58a4fc;
  color: var(--text-main);

  border: 1px solid var(--border-soft);
  border-radius: 50px;

  padding: 6px 10px;
  font-size: 0.85rem;
  cursor: pointer;
}

button:hover {
  background: #e5e7eb;
}

/* ===============================
   FORM ELEMENTS (TEXTBOX, SELECT)
================================ */
input,
textarea,
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;

  width: 100%;
  padding: 6px 8px;

  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1.4;

  color: var(--text-main);
  background: var(--bg-surface);

  border: 1px solid var(--border-soft);
  border-radius: 6px;

  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

/* Focus state */
input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

/* Placeholder */
input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

/* Textarea */
textarea {
  resize: vertical;
  min-height: 70px;
}

/* Disabled */
input:disabled,
textarea:disabled,
select:disabled {
  background: #f3f4f6;
  color: #9ca3af;
  cursor: not-allowed;
}


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

  display: flex;
  align-items: center;
  
  padding: 16px 20px;

  background: var(--bg-header);
  border-bottom: 1px solid var(--border-soft);
}

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

.actions {
  margin-left: auto;
  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;*/
/*  color: #e2e8f0;*/
/*  border-radius: 8px;*/
/*  padding: 8px 12px;*/
/*  cursor: pointer;*/
/*  background: var(--bg-sidebar);*/
/*  border-right: 1px solid var(--border-soft);*/
/*}*/
/* ===============================
   SIDEBAR TOGGLE BUTTON
================================ */
.sidebar-toggle {
  display: none;
  appearance: none;

  background: var(--bg-surface);
  color: var(--accent-primary);

  border: 1px solid var(--border-soft);
  border-radius: 8px;

  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 600;

  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}

/* Hover / active */
.sidebar-toggle:hover {
  background: #eef2ff;
  border-color: var(--accent-primary);
}

.sidebar-toggle:active {
  transform: translateY(1px);
}

/* ========== 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: var(--bg-sidebar);
  border-right: 1px solid var(--border-soft);
}

/* 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;
  color: var(--text-muted);
}

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

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

.nav-link.active {
  /*background: #111827;*/
  /*border-color: #334155;*/
  /*color: #facc15;*/
  font-weight: 600;
  background: #e0e7ff;
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* ========== 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 {
  padding: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

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

/* Titles */
h3.device-title {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--accent-primary);
}

h4.device-title {
  font-size: 0.85rem;
  color: var(--text-main);
}

/* ===============================
   DOWNLOAD LINKS
================================ */
.downloads {
  margin-bottom: 8px;
  font-size: 0.8rem;
}

.downloads a {
  text-decoration: none;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s ease, color 0.15s ease;
}

/* JSON */
.download-json {
  color: #60a5fa; /* blue */
}

.download-json:hover {
  background: rgba(96,165,250,0.15);
}

/* CSV */
.download-csv {
  color: #4ade80; /* green */
}

.download-csv:hover {
  background: rgba(74,222,128,0.15);
}


.prediction-result .best {
  color: var(--accent-secondary);
}

.prediction-result {
  margin-top: 2px;
  padding: 6px;
  font-size: 0.85rem;
  border-top: 1px dashed var(--border-soft);
  color: var(--text-muted);
}

.prediction-result p {
  margin-bottom: 0;   
}


.prediction-result .best {
  color: #3fb7e8;
  font-weight: 600;
}

/* ========== USER META ========== */
.user-meta {
  margin-top: 0px;
  padding: 6px;
  border-top: 1px dashed var(--border-soft);
  color: var(--text-muted);
}

.user-meta-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(60px, 1fr));
  gap: 8px;
  font-size: 0.8rem;
  line-height: 1.55;
}

/* ========== FOOTER ========== */
footer {
  padding: 14px 20px;
  text-align: center;
  background: var(--bg-header);
  color: var(--text-muted);
  border-top: 1px solid var(--border-soft);
}

/* ===============================
   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 {
    position: sticky;
    top: 0;
    z-index: 1000;
  }

  .app {
    grid-template-columns: 1fr;
  }

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

    /* 🔑 KUNCI: mulai tepat setelah header */
    top: 0;
    padding-top: env(safe-area-inset-top);

    width: 260px;
    height: 100vh;

    /* dorong isi sidebar ke bawah header */
    margin-top: var(--real-header-h);

    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 8px 0 24px rgba(0,0,0,.35);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-soft);
  }

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

  .sidebar-toggle {
    display: inline-flex;
  }

  body.no-scroll {
    overflow: hidden;
  }

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

  main {
    padding: 14px;
  }
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;

  margin: 12px;
}

.pagination button {
  padding: 6px 10px;
  border-radius: 25px;
  font-size: 0.85rem;
}

#pageInfo {
  font-size: 0.85rem;
  white-space: nowrap;
}

.device-selector {
  display: flex;
  flex-direction: column;
  gap: 6px;

  padding: 12px;
}

.device-selector label {
  font-size: 0.8rem;
  color: #94a3b8;
}

.device-selector select {
  background: #ffffff;
  color: var(--text-main);
  border: 1px solid var(--border-soft);
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
}


/* ===============================
   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);
}
