/* ============================================================
   Garage IoT Monitor — Mobile-first PWA styles
   ============================================================ */

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface-hover: #222240;
  --border: #2a2a4a;
  --text: #e0e0e0;
  --text-muted: #8888aa;
  --primary: #3498db;
  --green: #2ecc71;
  --red: #e74c3c;
  --yellow: #f39c12;
  --orange: #e67e22;
  --gray: #666;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  -webkit-font-smoothing: antialiased;
}

/* Screens */
.screen { max-width: 480px; margin: 0 auto; padding: 0 16px 24px; }

/* Login */
.login-card {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 48px 24px; margin-top: 20vh; text-align: center;
}
.login-card h1 { font-size: 28px; font-weight: 700; }
.login-card p { color: var(--text-muted); }

/* Header */
.app-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; margin-bottom: 12px;
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.header-left { display: flex; align-items: center; gap: 8px; }
.header-left h1 { font-size: 20px; font-weight: 700; }
.header-icon { border-radius: 6px; }
.header-right { display: flex; align-items: center; gap: 12px; }

/* Connection dot */
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-connected { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-disconnected { background: var(--red); }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 12px;
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.card-header h2 { font-size: 15px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }

/* Status card */
.status-card {
  display: flex; align-items: center; gap: 20px; padding: 24px;
}
.status-icon-wrap {
  flex-shrink: 0; width: 100px; height: 100px;
  display: flex; align-items: center; justify-content: center;
}
.status-info { display: flex; flex-direction: column; gap: 4px; }
.state-label { font-size: 28px; font-weight: 800; letter-spacing: 1px; }
.state-closed { color: var(--green); }
.state-open { color: var(--red); }
.state-transit { color: var(--yellow); }
.state-fault { color: var(--orange); }
.state-unknown { color: var(--gray); }
.meta { font-size: 13px; color: var(--text-muted); }
.fault-banner {
  background: rgba(230, 126, 34, 0.15); color: var(--orange);
  padding: 6px 10px; border-radius: 6px; font-size: 12px; font-weight: 600;
  margin-top: 4px;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border: none; border-radius: 8px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #2980b9; }
.btn-secondary { background: var(--surface-hover); color: var(--text); border: 1px solid var(--border); }
.btn-toggle {
  width: 100%; padding: 16px;
  background: linear-gradient(135deg, #2c3e50, #34495e);
  color: #fff; font-size: 17px; border-radius: 12px;
}
.btn-toggle:hover { background: linear-gradient(135deg, #34495e, #3d566e); }
.btn-toggle:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-toggle:disabled:active { transform: none; }
.btn-icon {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 6px; border-radius: 6px;
}
.btn-icon:hover { color: var(--text); background: var(--surface-hover); }

/* Activity feed */
.activity-card { padding-bottom: 12px; }
.activity-scroll {
  max-height: 360px; overflow-y: auto; margin: 0 -20px; padding: 0 20px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.activity-scroll::-webkit-scrollbar { width: 6px; }
.activity-scroll::-webkit-scrollbar-track { background: transparent; }
.activity-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.activity-feed { list-style: none; }
.activity-feed li {
  padding: 10px 0; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 14px;
}
.activity-feed li:last-child { border-bottom: none; }
.activity-empty { color: var(--text-muted); justify-content: center; }
.activity-day-header {
  display: block; padding: 8px 0 4px; font-size: 11px; font-weight: 700;
  color: var(--primary); text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: var(--surface); z-index: 1;
}
.activity-text { flex: 1; }
.activity-time { color: var(--text-muted); font-size: 12px; white-space: nowrap; margin-left: 12px; }
.activity-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-right: 10px;
}
.activity-dot-open { background: var(--red); }
.activity-dot-closed { background: var(--green); }
.activity-dot-transit { background: var(--yellow); }
.activity-dot-fault { background: var(--orange); }
.activity-dot-command { background: var(--primary); }

/* Debug log */
.debug-section summary { cursor: pointer; list-style: none; }
.debug-section summary::-webkit-details-marker { display: none; }
.debug-section[open] .debug-log { max-height: 300px; overflow-y: auto; }
.badge {
  background: var(--surface-hover); color: var(--text-muted);
  padding: 2px 8px; border-radius: 10px; font-size: 12px;
}
.debug-log { list-style: none; }
.debug-log li {
  padding: 6px 0; border-bottom: 1px solid var(--border);
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 11px;
  color: var(--text-muted); word-break: break-all;
}

/* Confirm dialog */
.confirm-dialog {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; max-width: 320px; width: 90%;
}
.confirm-dialog::backdrop { background: rgba(0,0,0,0.6); }
.dialog-content p { margin-bottom: 20px; font-size: 15px; }
.dialog-actions { display: flex; gap: 10px; }
.dialog-actions .btn { flex: 1; }

/* Responsive — slightly wider on tablets */
@media (min-width: 600px) {
  .screen { max-width: 540px; }
  .status-card { padding: 32px; }
}

/* Settings toggle */
.setting-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 14px; cursor: pointer; position: relative;
  padding: 4px 0; user-select: none;
}
.setting-row input[type="checkbox"] { display: none; }
.toggle-switch {
  width: 44px; height: 24px; background: var(--border); border-radius: 12px;
  position: relative; transition: background 0.2s; flex-shrink: 0; margin-left: 12px;
}
.toggle-switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; background: #fff; border-radius: 50%;
  transition: transform 0.2s;
}
.setting-row input:checked + .toggle-switch { background: var(--primary); }
.setting-row input:checked + .toggle-switch::after { transform: translateX(20px); }

/* Admin panel */
.admin-section summary { cursor: pointer; list-style: none; }
.admin-section summary::-webkit-details-marker { display: none; }
.admin-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.user-list { list-style: none; }
.user-list li {
  padding: 10px 0; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; font-size: 13px;
}
.user-list li:last-child { border-bottom: none; }
.user-info { flex: 1; }
.user-name { font-weight: 600; display: block; }
.user-email { color: var(--text-muted); font-size: 12px; }
.user-status { font-size: 11px; padding: 2px 8px; border-radius: 8px; margin-left: 8px; }
.user-status-active { background: rgba(46,204,113,0.15); color: var(--green); }
.user-status-disabled { background: rgba(231,76,60,0.15); color: var(--red); }
.user-actions { display: flex; gap: 6px; }
.user-actions button { font-size: 11px; padding: 4px 10px; }
.form-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; }
.form-input {
  padding: 8px 12px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px;
}
