/* ===============================
   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;
  --accent-secondary: #f59e0b;
}

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

html,
body {
  width: 100%;
  overflow-x: hidden;
}

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

img,
canvas,
svg,
video {
  max-width: 100%;
  height: auto;
  display: block;
}

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: 1rem; }
h4 { font-size: 0.9rem; }

p {
  margin: 0 0 6px;
  font-size: 0.8rem;
  line-height: 1.55;
}

/* ===============================
   BUTTON
================================ */
button {
  appearance: none;
  -webkit-appearance: none;

  background: #58a4fc;
  color: white;

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

  padding: 6px 10px;
  font-size: 0.85rem;

  cursor: pointer;

  transition:
    background .15s ease,
    border-color .15s ease,
    transform .1s ease;
}

button:hover {
  color: var(--text-main);
  background: #e5e7eb;
}

button:active {
  transform: translateY(1px);
}

/* ===============================
   FORM ELEMENTS
================================ */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="url"],
textarea,
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;

  width: 100%;
  max-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;
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  margin-right: 0.4rem;
  accent-color: var(--accent-primary);
}

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

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

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

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

/* ===============================
   HEADER
================================ */
header {
  position: sticky;
  top: 0;
  z-index: 1000;

  min-height: var(--header-h);

  display: flex;
  align-items: center;
  flex-wrap: wrap;

  gap: 10px;

  padding: 16px 20px;

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

.header-title {
  display: flex;
  align-items: center;
  gap: 18px;

  flex: 1 1 220px;
  min-width: 0;

  line-height: 1.25;
  word-break: break-word;

  padding-left: 10px;
}

.actions {
  margin-left: auto;

  display: flex;
  flex-wrap: wrap;

  gap: 12px;
  align-items: center;
}

.admin {
  margin-left: 12px;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

/* ===============================
   SIDEBAR TOGGLE BUTTON
================================ */
.sidebar-toggle {
  display: none;

  appearance: none;

  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 2000;

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

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

  width: 43px;
  height: 43px;

  padding: 0;

  font-size: 1rem;
  font-weight: 600;

  cursor: pointer;

  box-shadow: 0 4px 12px rgba(0,0,0,0.15);

  transition:
    background .15s ease,
    border-color .15s ease,
    transform .1s ease;
}

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

.sidebar-toggle:active {
  transform: scale(0.96);
}

/* ===============================
   APP GRID
================================ */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;

  min-height: calc(100vh - var(--header-h));
  min-height: calc(100dvh - var(--header-h));
}

/* ===============================
   SIDEBAR DESKTOP
================================ */
.sidebar {
  position: sticky;
  top: var(--header-h);

  min-height: calc(100vh - var(--header-h));
  min-height: calc(100dvh - var(--header-h));

  overflow-y: auto;

  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-soft);
}

/* ===============================
   NAVIGATION
================================ */
.nav {
  display: flex;
  flex-direction: column;

  padding: 12px;
  gap: 4px;
}

.nav-section {
  margin: 12px 8px 6px;

  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: .06em;

  color: var(--text-muted);
}

.nav-link {
  padding: 10px 12px;

  border-radius: 8px;

  color: var(--text-main);
  text-decoration: none;

  border: 1px solid transparent;

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

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

.nav-link.active {
  font-weight: 600;

  background: #e0e7ff;
  border-color: var(--accent-primary);

  color: var(--accent-primary);
}

/* ===============================
   MAIN CONTENT
================================ */
main {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;

  padding: 16px 18px;
}

/* ===============================
   DEVICES GRID
================================ */
#devices {
  display: grid;

  /* RESPONSIVE FIX */
  /* grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); */
  grid-template-columns: repeat(2, minmax(0, 1fr));

  gap: 16px;
}

/* ===============================
   DEVICE CARD
================================ */
.device-card {
  width: 100%;
  min-width: 0;

  padding: 10px;
  margin-bottom: 16px;

  background: var(--bg-surface);

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

  box-shadow: 0 2px 6px rgba(0,0,0,0.04);

  overflow: hidden;
}

/* ===============================
   CHART
================================ */
.chart-container {
  position: relative;

  width: 100%;
  max-width: 100%;

  height: 300px;
}

/* ===============================
   TITLES
================================ */
h3.device-title {
  margin: 0 0 6px;

  font-size: 0.95rem;
  color: var(--accent-primary);

  word-break: break-word;
}

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

  word-break: break-word;
}

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

.download-json {
  color: #60a5fa;
}

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

.download-csv {
  color: #4ade80;
}

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

/* ===============================
   PREDICTION RESULT
================================ */
.prediction-result {
  margin-top: 2px;
  padding: 6px;

  font-size: 0.85rem;

  border-top: 1px dashed var(--border-soft);

  color: var(--text-main);

  overflow-wrap: break-word;
}

.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;
}

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

/* ===============================
   FOOTER
================================ */
footer {
  padding: 14px 20px;

  text-align: center;

  background: var(--bg-header);

  color: var(--text-muted);

  border-top: 1px solid var(--border-soft);
}

/* ===============================
   TABLET
================================ */
@media (max-width: 992px) {

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

  #devices {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  }

  

}

/* ===============================
   MOBILE
================================ */
@media (max-width: 768px) {

  body.no-scroll {
    overflow: hidden;
  }

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

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

    top: var(--header-h);
    left: 0;

    width: 260px;

    height: calc(100vh - var(--header-h));
    height: calc(100dvh - var(--header-h));

    padding-top: env(safe-area-inset-top);

    margin-top: 0;

    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;
    align-items: center;
    justify-content: center;
  }

  main {
    padding: 14px;
  }

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

  .chart-container {
    height: 220px;
  }

  .user-meta-form {
    grid-template-columns: 1fr;
  }

  .actions {
    width: 100%;
    margin-left: 0;
  }

  button {
    min-height: 42px;
    padding: 10px 14px;
  }

  header {
    padding-left: 60px;
  }

}

/* ===============================
   SMALL MOBILE
================================ */
@media (max-width: 480px) {

  header {
    padding: 12px;
  }

  .header-title {
    gap: 10px;
    padding-left: 0;
  }

  h1 {
    font-size: 1rem;
  }

  h2 {
    font-size: 0.95rem;
  }

  main {
    padding: 10px;
  }

  .device-card {
    padding: 8px;
  }

  .chart-container {
    height: 200px;
  }

}

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

  width: 100%;
  max-width: 100%;
}