* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body {
  background: #0f172a;
  color: #e5e7eb;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* AUTH OVERLAY */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top, rgba(56, 189, 248, 0.12), transparent 60%),
              radial-gradient(circle at bottom, rgba(34, 197, 94, 0.12), transparent 60%),
              rgba(15, 23, 42, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.auth-card {
  background: #020617;
  border-radius: 1rem;
  padding: 1.75rem 1.5rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.9);
  border: 1px solid #1f2937;
}

.auth-card h1 {
  font-size: 1.4rem;
  margin-bottom: 0.75rem;
  text-align: center;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.auth-form label {
  font-size: 0.85rem;
}

.auth-form input {
  background: #020617;
  border-radius: 0.6rem;
  border: 1px solid #1f2937;
  padding: 0.45rem 0.7rem;
  color: #e5e7eb;
  outline: none;
  font-size: 0.9rem;
}

.auth-form input:focus {
  border-color: #38bdf8;
}

.auth-card .hint {
  margin-top: 0.6rem;
  font-size: 0.75rem;
  color: #9ca3af;
}

/* Top bar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: #020617;
  border-bottom: 1px solid #1f2937;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #38bdf8;
}

.nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.user-info {
  font-size: 0.8rem;
  color: #9ca3af;
  margin-right: 0.75rem;
}

.nav-link {
  border: none;
  background: transparent;
  color: #9ca3af;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s, color 0.2s, transform 0.1s, opacity 0.1s;
}

.nav-link:hover {
  background: #111827;
  transform: translateY(-1px);
}

.nav-link.active {
  background: #38bdf8;
  color: #020617;
}

.nav-logout {
  background: #111827;
  color: #f97316;
}
.nav-logout:hover {
  background: #7c2d12;
  color: #fed7aa;
}

/* Connect button & status */
.connect-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0.5rem;
}

.nav-connect {
  border: 1px solid #1f2937;
}

.nav-connect.connected {
  background: #22c55e;
  color: #020617;
}

.connect-status {
  font-size: 0.75rem;
  color: #f97316;
}
.connect-status.connected {
  color: #22c55e;
}

/* Layout */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 1rem 3rem;
  flex: 1;
}

.section {
  display: none;
  animation: fadeIn 0.25s ease-in-out;
}

.section.active {
  display: block;
}

h1 {
  font-size: 1.6rem;
  margin-bottom: 0.35rem;
}

.subtitle {
  font-size: 0.9rem;
  color: #9ca3af;
  margin-bottom: 1rem;
}

.subtitle.small {
  margin-top: 0.25rem;
  margin-bottom: 0.5rem;
}

/* Cards / grid */
.grid-analog {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.card {
  background: #020617;
  border-radius: 0.9rem;
  padding: 1rem;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.6);
  border: 1px solid #1e293b;
}

.card h2 {
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
  color: #cbd5f5;
}

.value {
  font-size: 1.6rem;
  font-weight: 600;
  margin-top: 0.2rem;
}

/* Bars (for level) */
.bar {
  width: 100%;
  height: 0.45rem;
  background: #111827;
  border-radius: 999px;
  margin-top: 0.5rem;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #22c55e, #eab308);
  transition: width 0.3s ease;
}

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.chart-card {
  background: #020617;
  border-radius: 0.8rem;
  padding: 0.75rem;
  border: 1px solid #1e293b;
}

.chart-card h3 {
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
  color: #d1d5db;
}

.chart-card canvas {
  width: 100%;
  height: 220px;
}

/* Grafik mode controls */
.graph-mode-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-top: 0.4rem;
  margin-bottom: 0.6rem;
  font-size: 0.8rem;
}

.graph-mode-controls label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.recorded-controls {
  display: none; /* akan di-show via JS ketika mode recorded */
  align-items: center;
  gap: 0.4rem;
}

/* Digital */
.digital-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.digital-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #020617;
  border-radius: 999px;
  padding: 0.25rem 0.55rem 0.25rem 0.7rem;
  border: 1px solid #1f2937;
  font-size: 0.8rem;
  gap: 0.35rem;
}

.digital-indicator {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #4b5563;
  box-shadow: 0 0 0 rgba(34, 197, 94, 0);
  transition: background 0.15s, box-shadow 0.15s;
}

.digital-indicator.on {
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.8);
}

.digital-btn {
  border-radius: 999px;
  border: none;
  font-size: 0.75rem;
  padding: 0.15rem 0.6rem;
  cursor: pointer;
  background: #1f2937;
  color: #e5e7eb;
  transition: background 0.15s, transform 0.1s, opacity 0.1s;
  white-space: nowrap;
}

.digital-btn:hover:not(.disabled):not(:disabled) {
  background: #22c55e;
  color: #020617;
  transform: translateY(-1px);
}

.digital-btn.on {
  background: #22c55e;
  color: #020617;
}

.digital-btn.disabled,
.digital-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Status text */
.status-text {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: #9ca3af;
}

/* History */
.history-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}

.history-controls label {
  margin-right: 0.25rem;
}

.history-table-wrapper {
  overflow-x: auto;
  max-height: 380px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.history-table thead {
  position: sticky;
  top: 0;
  background: #020617;
  z-index: 1;
}

.history-table th,
.history-table td {
  border-bottom: 1px solid #1f2937;
  padding: 0.25rem 0.35rem;
  text-align: center;
  white-space: nowrap;
}

/* Inputs & select */
.history-controls select,
.settings-form input[type="number"],
.settings-form input[type="text"],
.graph-mode-controls select,
.graph-mode-controls input[type="number"] {
  background: #020617;
  border: 1px solid #1f2937;
  color: #e5e7eb;
  padding: 0.35rem 0.6rem;
  border-radius: 0.45rem;
  font-size: 0.85rem;
  outline: none;
}

.history-controls select:focus,
.settings-form input:focus,
.graph-mode-controls select:focus,
.graph-mode-controls input:focus {
  border-color: #38bdf8;
}

/* Buttons */
.primary-btn,
.secondary-btn {
  border-radius: 999px;
  padding: 0.4rem 1.1rem;
  font-size: 0.85rem;
  border: none;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, background 0.2s, color 0.2s;
}

.primary-btn {
  background: #38bdf8;
  color: #020617;
  box-shadow: 0 5px 15px rgba(56, 189, 248, 0.5);
}

.primary-btn:hover {
  background: #0ea5e9;
  transform: translateY(-1px);
}

.secondary-btn {
  background: #111827;
  color: #e5e7eb;
  border: 1px solid #1f2937;
}

.secondary-btn:hover {
  background: #1f2937;
}

.secondary-btn.danger {
  border-color: #ef4444;
  color: #fecaca;
}

.secondary-btn.danger:hover {
  background: #7f1d1d;
}

/* Settings */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.settings-form label {
  font-size: 0.85rem;
}

/* Footer */
.footer {
  text-align: center;
  padding: 0.75rem;
  font-size: 0.75rem;
  color: #6b7280;
  border-top: 1px solid #1f2937;
  background: #020617;
}

/* Animation */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive */
@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }
}
