:root {
  --bg: #1B2430;
  --surface: #232E3D;
  --surface-raised: #2B3747;
  --border: #38455A;
  --text: #EDEAE2;
  --text-muted: #9AA5B1;
  --brass: #C9A24B;
  --brass-dim: #8F7638;
  --open: #C1543B;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
}

h1, h2 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
}

.view { min-height: 100vh; }

#loading-screen:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-mark svg { animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .loading-mark svg { animation: none; }
}

/* --- Login --- */
#login-view:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px;
  text-align: center;
}

.login-mark { margin-bottom: 8px; }

.login-card h1 { font-size: 1.6rem; margin-bottom: 4px; }

.login-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 24px;
}

.login-card label {
  display: block;
  text-align: left;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

input, select {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
}

button {
  font-family: var(--font-body);
  font-weight: 600;
  cursor: pointer;
}

.login-card button[type="submit"] {
  width: 100%;
  padding: 12px;
  margin-top: 8px;
  background: var(--brass);
  color: #1B2430;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
}

.error {
  color: var(--open);
  font-size: 0.85rem;
  margin-top: 14px;
}

/* --- Main --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 8px;
}

.topbar h1 { font-size: 1.4rem; }

.link-btn {
  background: none;
  border: none;
  color: var(--brass);
  font-size: 0.9rem;
  padding: 4px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.whoami {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.whoami .role-pill {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--brass);
  font-size: 0.7rem;
  text-transform: capitalize;
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
}

.checkbox-label input { width: auto; margin-top: 0; }

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  font-size: 0.7rem;
  text-transform: capitalize;
  margin-left: 8px;
}

.inactive-tag {
  color: var(--open);
  font-size: 0.75rem;
  margin-left: 6px;
}

.door-actions-content { padding: 24px; }

.door-actions-content h2 { font-size: 1.2rem; margin-bottom: 4px; }

.door-actions-status {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0 0 18px;
}

.door-actions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.door-action-btn {
  text-align: left;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font-body);
}

.door-action-btn:not(:disabled):hover { border-color: var(--brass); }

.door-action-btn.unconfirmed {
  opacity: 0.5;
  cursor: not-allowed;
}

.unconfirmed-tag {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  max-width: 420px;
}

.settings-card label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.settings-card .dialog-actions { margin-top: 4px; }

.notify-feedback {
  margin: 12px 0 0;
  font-size: 0.85rem;
}

.notify-feedback.success { color: var(--brass); }
.notify-feedback.error { color: var(--open); }

.banner {
  margin: 0 20px 16px;
  padding: 12px 14px;
  background: #3A2E1A;
  border: 1px solid var(--brass-dim);
  border-radius: 8px;
  color: var(--brass);
  font-size: 0.85rem;
}

.push-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 20px 16px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.install-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 100;
  max-width: 420px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.install-mark { flex-shrink: 0; }

.install-text { flex: 1; min-width: 0; }

#install-title {
  font-weight: 600;
  font-size: 0.9rem;
}

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

.install-banner .link-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  background: var(--brass);
  color: #1B2430;
  border-radius: 6px;
  font-weight: 600;
}

.install-dismiss {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  line-height: 1;
  padding: 4px;
  cursor: pointer;
}

@media (max-width: 420px) {
  .install-banner { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
}

main {
  padding: 0 20px 40px;
  max-width: 640px;
  margin: 0 auto;
}

section { margin-top: 28px; }

section h2 {
  font-size: 1.1rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 12px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* --- Doors --- */
.doors-list { display: flex; flex-direction: column; gap: 10px; }

.door-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brass);
  border-radius: 10px;
  padding: 16px 18px;
  transition: border-left-color 0.2s;
}

.door-panel.is-open { border-left-color: var(--open); }

.door-name { font-weight: 600; font-size: 1.05rem; }

.door-status {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.door-panel.is-open .door-status { color: var(--open); }

.door-raw-state {
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.6;
  margin-top: 2px;
}

.toggle-btn {
  padding: 10px 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 0.9rem;
  min-width: 96px;
}

.door-panel.is-open .toggle-btn {
  background: var(--brass);
  color: #1B2430;
  border-color: var(--brass);
}

/* --- Schedules --- */
.schedules-list { display: flex; flex-direction: column; gap: 8px; }

.schedule-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.9rem;
}

.schedule-row .schedule-meta { color: var(--text-muted); font-size: 0.8rem; margin-top: 2px; }

.schedule-row .remove-btn {
  background: none;
  border: none;
  color: var(--open);
  font-size: 0.85rem;
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-style: italic;
}

/* --- Dialog --- */
dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: 90%;
  max-width: 400px;
}

dialog::backdrop { background: rgba(0,0,0,0.6); }

#schedule-form { padding: 24px; }

#schedule-form h2 { margin-bottom: 18px; font-size: 1.2rem; }

#schedule-form label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

fieldset {
  border: none;
  padding: 0;
  margin: 0 0 14px;
}

fieldset legend {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0;
  margin-bottom: 6px;
}

.days-row { display: flex; gap: 6px; flex-wrap: wrap; }

.day-chip {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}

.day-chip.selected {
  background: var(--brass);
  color: #1B2430;
  border-color: var(--brass);
}

.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.dialog-actions button { flex: 1; padding: 10px; border-radius: 8px; border: none; }

.dialog-actions button[type="submit"] { background: var(--brass); color: #1B2430; }

.secondary-btn { background: var(--surface-raised) !important; color: var(--text) !important; border: 1px solid var(--border) !important; }

@media (max-width: 420px) {
  .door-panel { flex-direction: column; align-items: flex-start; gap: 12px; }
  .toggle-btn { width: 100%; }
}
