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

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #334155;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --red: #dc2626;
  --red-bg: #450a0a;
  --red-glow: rgba(220, 38, 38, 0.3);
  --green: #22c55e;
  --green-bg: #052e16;
  --blue: #3b82f6;
  --blue-bg: #172554;
  --yellow: #eab308;
  --radius: 12px;
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 100px;
}

header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 16px;
  text-align: center;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header .subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.status-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  font-size: 0.75rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse-dot 2s infinite;
}

.status-dot.offline { background: var(--red); animation: none; }
.status-dot.pending { background: var(--yellow); animation: none; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

section { margin-top: 20px; }

.section-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding: 0 4px;
}

/* Alert banner */
.alert-banner {
  background: var(--red-bg);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 16px;
  animation: alert-pulse 1s ease-in-out infinite;
  display: none;
}

.alert-banner.active { display: block; }

@keyframes alert-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--red-glow); }
  50% { box-shadow: 0 0 20px 4px var(--red-glow); }
}

.alert-banner h2 {
  font-size: 1.1rem;
  color: var(--red);
  margin-bottom: 4px;
}

.alert-banner .cities {
  font-size: 0.9rem;
  line-height: 1.5;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card + .card { margin-top: 8px; }

/* Tunnel link */
.tunnel-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s;
}

.tunnel-link:hover { background: var(--surface-hover); }

.tunnel-link .icon { font-size: 1.2rem; flex-shrink: 0; }

.tunnel-link .url {
  flex: 1;
  font-size: 0.82rem;
  color: var(--blue);
  word-break: break-all;
}

.tunnel-link .arrow {
  font-size: 1.1rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Notification permission */
.notif-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.notif-card .icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.notif-card .info { flex: 1; }

.notif-card .info h3 {
  font-size: 0.9rem;
  font-weight: 600;
}

.notif-card .info p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 10px;
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); }

.btn-red { background: var(--red); color: white; }
.btn-red:hover { background: #b91c1c; }

.btn-blue { background: var(--blue); color: white; }
.btn-blue:hover { background: #2563eb; }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--surface-hover); }

.btn-green { background: var(--green); color: white; }
.btn-green:hover { background: #16a34a; }

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }

.btn-block { width: 100%; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Test alert section */
.test-section {
  display: flex;
  gap: 8px;
}

.test-section .btn { flex: 1; }

/* Area selection */
.area-search {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  margin-bottom: 10px;
  transition: border-color 0.15s;
}

.area-search:focus { border-color: var(--blue); }
.area-search::placeholder { color: var(--text-muted); }

.areas-container {
  max-height: 50vh;
  overflow-y: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

.area-group-title {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-hover);
  padding: 8px 14px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--blue);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.area-group-title:hover { background: var(--surface); }

.area-group-title .toggle-all {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.area-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.4);
  cursor: pointer;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.area-item:hover { background: var(--surface); }
.area-item:last-child { border-bottom: none; }

.area-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
  flex-shrink: 0;
}

.area-item label {
  font-size: 0.85rem;
  cursor: pointer;
  flex: 1;
}

.selected-count {
  font-size: 0.75rem;
  color: var(--blue);
  margin-top: 8px;
  text-align: center;
}

/* History */
.history-item {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(51, 65, 85, 0.4);
  font-size: 0.85rem;
}

.history-item:last-child { border-bottom: none; }

.history-item .time {
  color: var(--text-muted);
  font-size: 0.75rem;
  white-space: nowrap;
  min-width: 50px;
}

.history-item .city { flex: 1; }
.history-item .type {
  font-size: 0.7rem;
  color: var(--red);
  font-weight: 600;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 24px 16px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 0.85rem;
  z-index: 100;
  transition: transform 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show { transform: translateX(-50%) translateY(0); }

/* Scrollbar */
.areas-container::-webkit-scrollbar { width: 4px; }
.areas-container::-webkit-scrollbar-track { background: transparent; }
.areas-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Safe area for iOS */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .container { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
}
