:root {
  --sea-deep: #103b52;
  --sea-mid: #2f6690;
  --sea-light: #6fa8c9;
  --sky: #eaf4f6;
  --sand: #faf6ee;
  --sun: #e8a13b;
  --ink: #142330;
  --ink-soft: #5b6b76;
  --line: #dce6e8;
  --ok: #3f8f5f;
  --alarm-red: #c0392b;
  --alarm-red-dark: #8f2418;
  --radius: 16px;
  --card: 255, 255, 255;
  --card-tint: rgba(var(--card), 0.6);
  --card-border: rgba(255, 255, 255, 0.5);
  font-size: 16px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  position: relative;
}

/* Blurred photo background, fixed behind all content */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("images/bg-beach.png");
  background-size: cover;
  background-position: center;
  filter: blur(6px);
  transform: scale(1.1); /* hide blurred edges */
  z-index: -2;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(250, 246, 238, 0.5); /* sand tint for text contrast */
  z-index: -1;
}

.glass {
  background: var(--card-tint);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--card-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  height: 30px;
  width: auto;
  display: block;
}

.brand-logo-lg {
  height: 56px;
  width: auto;
  display: block;
  margin: 0 auto 18px;
}

@media (min-width: 768px) {
  .brand-logo {
    height: 46px;
  }
  .brand-logo-lg {
    height: 84px;
  }
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--sea-deep);
  cursor: pointer;
  padding: 8px;
  border-radius: 10px;
  font-size: 1.1rem;
}
.icon-btn:hover { background: var(--sky); }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 80px;
}

.greeting {
  color: var(--ink-soft);
  font-size: 0.95rem;
  margin: 4px 0 2px;
}
.greeting strong {
  display: block;
  font-size: 1.6rem;
  color: var(--sea-deep);
  margin-top: 2px;
}

.category-card {
  background: var(--card-tint);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  margin-top: 22px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(16, 59, 82, 0.08);
}

.category-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px 8px;
  font-weight: 700;
  color: var(--sea-deep);
}

.category-title .tile {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--sky);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sea-mid);
}

.device-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

.device-row .tile {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--sky);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sea-mid);
  flex-shrink: 0;
}

.device-meta { flex: 1; min-width: 0; }
.device-name { font-weight: 600; font-size: 1rem; }
.device-desc { color: var(--ink-soft); font-size: 0.82rem; margin-top: 1px; }

.device-value {
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--sea-deep);
  white-space: nowrap;
}

.action-btn {
  border: none;
  background: var(--sea-mid);
  color: #fff;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: transform 0.08s ease, background 0.15s ease;
  white-space: nowrap;
}
.action-btn:active { transform: scale(0.96); }
.action-btn.pending { background: var(--ink-soft); pointer-events: none; }
.action-btn.done { background: var(--ok); }

.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--card-tint);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 20px;
  padding: 32px 26px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 30px rgba(16, 59, 82, 0.16);
  border: 1px solid var(--card-border);
}

.login-card h1 {
  font-size: 1.3rem;
  color: var(--sea-deep);
  margin: 4px 0 22px;
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-bottom: 6px;
  font-weight: 600;
}
.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 1rem;
  background: var(--sand);
}
.field input:focus {
  outline: 2px solid var(--sea-light);
  outline-offset: 1px;
}

.primary-btn {
  width: 100%;
  padding: 13px;
  background: var(--sea-deep);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}
.primary-btn:hover { background: var(--sea-mid); }

.error-msg {
  color: #b3392c;
  font-size: 0.85rem;
  margin-top: 10px;
  min-height: 1em;
}

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  padding: 60px 20px;
}

/* --- Admin --- */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--card-tint);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  padding: 4px;
  border-radius: 14px;
  margin-bottom: 20px;
}
.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px;
  border-radius: 10px;
  font-weight: 600;
  color: var(--sea-deep);
  cursor: pointer;
}
.tab-btn.active { background: rgba(255,255,255,0.85); box-shadow: 0 1px 2px rgba(16,59,82,0.1); }

.admin-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 26px 0 10px;
}
.admin-section-title h2 { font-size: 1.05rem; color: var(--sea-deep); margin: 0; }

.ghost-btn {
  border: 1px solid var(--sea-mid);
  color: var(--sea-mid);
  background: #fff;
  border-radius: 10px;
  padding: 7px 14px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.ghost-btn:hover { background: var(--sky); }

.list-row {
  background: var(--card-tint);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.list-row .info { flex: 1; min-width: 0; }
.list-row .title { font-weight: 700; font-size: 0.95rem; }
.list-row .sub { color: var(--ink-soft); font-size: 0.78rem; font-family: ui-monospace, monospace; margin-top: 2px; word-break: break-all; }
.list-row .row-actions { display: flex; gap: 4px; }
.icon-mini {
  border: none; background: var(--sky); color: var(--sea-deep);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 0.85rem;
}
.icon-mini.danger { background: #fbe6e2; color: #b3392c; }

dialog {
  border: none;
  border-radius: 18px;
  padding: 0;
  width: min(420px, 92vw);
}
dialog::backdrop { background: rgba(16, 35, 48, 0.45); }
.dialog-body { padding: 22px; }
.dialog-body h3 { margin-top: 0; color: var(--sea-deep); }
.dialog-actions { display: flex; gap: 10px; margin-top: 18px; }
.dialog-actions .primary-btn, .dialog-actions .ghost-btn { flex: 1; }

.checkbox-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0;
}

.toast {
  position: fixed;
  bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 10px;
  font-size: 0.9rem; opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 50;
}
.toast.show { opacity: 1; }

/* --- Critical alarm overlay --- */
.alarm-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--alarm-red);
  animation: alarm-flash 1s step-start infinite;
}

@keyframes alarm-flash {
  0%, 49% { background: var(--alarm-red); }
  50%, 100% { background: var(--alarm-red-dark); }
}

.alarm-card {
  background: #fff;
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.alarm-icon {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 10px;
}

.alarm-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--alarm-red);
  margin-bottom: 10px;
}

.alarm-body {
  color: var(--ink);
  font-size: 1.05rem;
  margin-bottom: 24px;
}

.alarm-dismiss-btn {
  width: 100%;
  padding: 14px;
  background: var(--alarm-red);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
}
.alarm-dismiss-btn:hover { background: var(--alarm-red-dark); }
