/* assets/css/style.css */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f172a;
  --bg2:       #1e293b;
  --bg3:       #334155;
  --surface:   #1e293b;
  --border:    #334155;
  --text:      #f1f5f9;
  --text2:     #94a3b8;
  --primary:   #0ea5e9;
  --primary-d: #0284c7;
  --success:   #22c55e;
  --danger:    #ef4444;
  --warning:   #f59e0b;
  --radius:    10px;
  --sidebar-w: 220px;
  --bottom-nav-h: 64px;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ========================
   SIDEBAR
======================== */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 1.5rem 0;
  z-index: 300;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 0 1.25rem 1.5rem;
  font-size: 17px; font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.sidebar nav { flex: 1; padding: 1rem 0; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 0.75rem 1.25rem;
  color: var(--text2); text-decoration: none;
  font-size: 14px; transition: all 0.15s;
  border-left: 3px solid transparent;
}
.nav-item:hover, .nav-item.active {
  color: var(--text); background: var(--bg3);
  border-left-color: var(--primary);
}
.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text2);
  display: flex; flex-direction: column; gap: 6px;
}
.sidebar-footer a { color: var(--danger); text-decoration: none; font-size: 13px; }

/* Overlay untuk mobile */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 299;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.sidebar-overlay.active {
  opacity: 1;
  pointer-events: all;
}

/* ========================
   TOP BAR (mobile only)
======================== */
.topbar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0;
  height: 56px; z-index: 200;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  align-items: center;
  padding: 0 1rem;
  gap: 12px;
  padding-top: env(safe-area-inset-top);
}
.topbar-title { flex: 1; font-size: 16px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.hamburger {
  width: 44px; height: 44px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 5px;
  cursor: pointer; border-radius: 10px;
  background: transparent; border: none;
  padding: 10px; transition: background 0.15s;
  flex-shrink: 0;
}
.hamburger:active { background: var(--bg3); }
.hamburger span {
  display: block; width: 20px; height: 2px;
  background: var(--text); border-radius: 2px;
  transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center;
}
.sidebar-open .hamburger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.sidebar-open .hamburger span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.sidebar-open .hamburger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ========================
   MAIN CONTENT
======================== */
.main-content {
  margin-left: var(--sidebar-w);
  padding: 2rem;
  min-height: 100vh;
}
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem; gap: 12px; flex-wrap: wrap;
}
.page-header h2 { font-size: 22px; font-weight: 600; }
.page-header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ========================
   NODE CARDS
======================== */
.node-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}
.node-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color 0.2s;
}
.node-card:hover { border-color: var(--primary); }
.node-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 1rem;
}
.node-header h3 { font-size: 16px; font-weight: 600; }
.node-header small { color: var(--text2); font-size: 12px; }
.node-footer {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 1rem; padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text2);
}

.status-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
  margin-top: 4px;
}
.status-online  { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-offline { background: var(--text2); }

.relay-list { display: flex; flex-direction: column; gap: 10px; }
.relay-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg3); border-radius: 8px;
  padding: 0.75rem 0.9rem; min-height: 52px;
}
.relay-label { flex: 1; font-size: 14px; }
.relay-state { font-size: 12px; font-weight: 600; min-width: 28px; text-align: right; }
.state-on  { color: var(--success); }
.state-off { color: var(--text2); }

/* ========================
   TOGGLE SWITCH
======================== */
.switch { position: relative; display: inline-block; width: 48px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 999px; transition: 0.2s;
}
.slider::before {
  content: ''; position: absolute;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--text2); left: 2px; top: 2px;
  transition: 0.2s;
}
input:checked + .slider { background: var(--primary); border-color: var(--primary); }
input:checked + .slider::before { background: #fff; transform: translateX(20px); }

/* ========================
   BUTTONS
======================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0.55rem 1rem; border-radius: 7px;
  font-size: 14px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: 0.15s;
  text-decoration: none; min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); opacity: 0.85; }
.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-d); }
.btn-secondary { background: var(--bg3); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-outline   { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-full { width: 100%; }
.btn-sm   { padding: 0.35rem 0.75rem; font-size: 12px; min-height: 36px; }

/* ========================
   FORMS
======================== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 5px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 0.65rem 0.8rem;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 7px; color: var(--text);
  font-size: 16px; /* 16px penting — cegah auto-zoom di iOS */
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--primary);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.day-checkboxes { display: flex; flex-wrap: wrap; gap: 8px; }
.day-label {
  display: flex; align-items: center; gap: 5px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 12px;
  font-size: 13px; cursor: pointer;
  transition: 0.15s; min-height: 40px;
}
.day-label:has(input:checked) { background: var(--primary); border-color: var(--primary); color: #fff; }
.day-label input { display: none; }

/* ========================
   CARDS
======================== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem;
}
.card h3 { font-size: 16px; font-weight: 600; margin-bottom: 1rem; }

/* ========================
   ALERTS & BADGES
======================== */
.alert {
  padding: 0.75rem 1rem; border-radius: 7px;
  font-size: 14px; margin-bottom: 1rem;
}
.alert-success { background: rgba(34,197,94,0.15); color: #86efac; border: 1px solid rgba(34,197,94,0.3); }
.alert-error   { background: rgba(239,68,68,0.15);  color: #fca5a5; border: 1px solid rgba(239,68,68,0.3); }

.badge {
  display: inline-flex; align-items: center;
  padding: 4px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text2); white-space: nowrap;
}
.badge-success { background: rgba(34,197,94,0.15); color: #86efac; border-color: rgba(34,197,94,0.3); }
.badge-danger  { background: rgba(239,68,68,0.15);  color: #fca5a5; border-color: rgba(239,68,68,0.3); }

/* ========================
   MQTT STATUS
======================== */
.mqtt-status {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 12px; font-size: 12px;
  color: var(--text2); font-weight: 500;
  transition: border-color 0.3s, color 0.3s;
  white-space: nowrap;
}
.mqtt-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}
.mqtt-dot.disconnected { background: var(--danger); }
.mqtt-status:has(.mqtt-dot.disconnected) { border-color: rgba(239,68,68,0.4); color: #fca5a5; }

.mqtt-dot.connecting { background: var(--warning); animation: blink 1s infinite; }
.mqtt-status:has(.mqtt-dot.connecting) { border-color: rgba(245,158,11,0.4); color: #fcd34d; }

.mqtt-dot.connected { background: var(--success); box-shadow: 0 0 6px var(--success); animation: pulse 2s infinite; }
.mqtt-status:has(.mqtt-dot.connected) { border-color: rgba(34,197,94,0.4); color: #86efac; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.2; }
}

/* ========================
   TIMER ROWS
======================== */
.timer-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 0; border-bottom: 1px solid var(--border);
  gap: 12px; min-height: 52px;
}
.timer-row:last-child { border-bottom: none; }
.timer-actions { display: flex; align-items: center; gap: 10px; }
.timer-disabled { opacity: 0.5; }

/* ========================
   MODAL — bottom sheet style
======================== */
.modal {
  position: fixed; inset: 0; z-index: 400;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-box {
  position: relative; z-index: 1;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 1rem 1.5rem 1.5rem;
  width: 100%; max-width: 560px;
  max-height: 85vh; overflow-y: auto;
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
}
.modal-handle {
  width: 40px; height: 4px;
  background: var(--border); border-radius: 2px;
  margin: 0 auto 1rem;
}
.modal-box h3 { margin-bottom: 1rem; font-size: 17px; }
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ========================
   BOTTOM NAVIGATION
======================== */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-inner {
  display: flex; align-items: center; justify-content: space-around;
  height: var(--bottom-nav-h);
}
.bottom-nav-item {
  display: flex; flex-direction: column; align-items: center;
  gap: 3px; padding: 6px 8px; border-radius: 10px;
  color: var(--text2); text-decoration: none;
  font-size: 10px; font-weight: 500;
  transition: all 0.15s; flex: 1; min-height: 44px;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav-item svg {
  width: 22px; height: 22px;
  stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item.active svg { stroke: var(--primary); }
.bottom-nav-item:active { background: var(--bg3); }

/* ========================
   AUTH PAGE
======================== */
.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg); padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
}
.auth-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem;
  width: 100%; max-width: 380px;
}
.auth-logo {
  display: flex; align-items: center; gap: 10px;
  justify-content: center; margin-bottom: 1.5rem;
}
.auth-logo h1 { font-size: 20px; font-weight: 700; }

/* ========================
   MISC
======================== */
.text-muted { color: var(--text2); font-size: 14px; }
.hidden { display: none !important; }
.loading { color: var(--text2); font-size: 14px; padding: 2rem 0; }
pre {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 7px; padding: 1rem; font-size: 12px;
  overflow-x: auto; white-space: pre-wrap; color: #86efac;
  margin-top: 1rem;
}
.result-box { margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.result-box h4 { color: var(--success); margin-bottom: 0.5rem; }

/* ========================
   RESPONSIVE — MOBILE
======================== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
    padding-top: calc(1.5rem + env(safe-area-inset-top));
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { display: block; }
  .topbar { display: flex; }
  .bottom-nav { display: block; }

  .main-content {
    margin-left: 0; padding: 1rem;
    padding-top: calc(56px + env(safe-area-inset-top) + 1rem);
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 1rem);
  }

  .node-grid { grid-template-columns: 1fr; }
  .form-row  { grid-template-columns: 1fr; }
  .page-header h2 { font-size: 18px; }
  #last-update { display: none; }
  .card { padding: 1rem; }
}