:root {
  --brand: #3b82f6;
  --brand-dark: #2563eb;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 12px rgba(15, 23, 42, .06);

  --ok: #10b981;
  --soon: #f59e0b;
  --due: #f97316;
  --overdue: #ef4444;

  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);

  --nav-height: 64px;
  --header-height: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro Text", Roboto, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }

#app { min-height: 100dvh; }

.boot {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  color: var(--text-muted);
}

/* ---------- Identification screen ---------- */
.identify {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px;
  gap: 32px;
  background: linear-gradient(160deg, #eff6ff 0%, #f6f8fb 60%);
}
.identify-emoji { font-size: 72px; }
.identify h1 {
  margin: 0;
  font-size: 28px;
  text-align: center;
}
.identify-sub { color: var(--text-muted); margin: 0; text-align: center; }
.identify-buttons { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.identify-btn {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 20px;
  padding: 20px 28px;
  min-width: 140px;
  font-size: 20px;
  font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .1s ease, border-color .1s ease;
}
.identify-btn:active { transform: scale(.97); }
.identify-btn:hover { border-color: var(--brand); }

/* ---------- Layout ---------- */
.shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: calc(var(--header-height) + var(--safe-top));
}
.app-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}
.back-btn {
  background: none;
  border: none;
  font-size: 22px;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--brand);
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
}
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
}
.user-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }

.main {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 24px);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: var(--safe-bottom);
}
.nav-btn {
  background: none;
  border: none;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text-muted);
  cursor: pointer;
  min-height: var(--nav-height);
  font-size: 11px;
  font-weight: 500;
}
.nav-btn .ico { font-size: 22px; line-height: 1; }
.nav-btn.active { color: var(--brand); }

/* ---------- Rooms grid (dashboard) ---------- */
.rooms-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 600px) {
  .rooms-grid { grid-template-columns: repeat(3, 1fr); }
}
.room-card {
  position: relative;
  background: var(--surface);
  border-radius: 18px;
  padding: 20px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 1px solid var(--border);
  border-left: 6px solid var(--brand);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 110px;
  transition: transform .1s ease;
}
.room-card:active { transform: scale(.98); }
.room-name {
  font-weight: 700;
  font-size: 17px;
  padding-right: 40px;
}
.room-meta {
  color: var(--text-muted);
  font-size: 13px;
}
.room-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 14px;
  display: grid;
  place-items: center;
}
.room-card.has-pending .room-badge { background: var(--overdue); color: white; }
.room-card.has-soon .room-badge { background: var(--due); color: white; }
.room-card.all-ok .room-badge { background: var(--ok); color: white; }

/* ---------- Section title ---------- */
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 24px 0 12px;
}
.section-title:first-child { margin-top: 0; }

/* ---------- Task card ---------- */
.task-list { display: flex; flex-direction: column; gap: 10px; }
.task-card {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  border-left: 6px solid var(--brand);
  padding: 14px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}
.task-card.status-ok       { border-left-color: var(--ok); }
.task-card.status-soon     { border-left-color: var(--soon); }
.task-card.status-due      { border-left-color: var(--due); }
.task-card.status-overdue  { border-left-color: var(--overdue); }
.task-card.status-untracked { border-left-color: var(--text-muted); }
.task-card.status-ok { opacity: .8; }
.task-card.status-untracked { opacity: .85; }

.task-icon {
  font-size: 28px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--surface-soft);
  border-radius: 12px;
}
.task-info { min-width: 0; }
.task-name {
  font-weight: 600;
  font-size: 15px;
  margin: 0 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 12px;
  color: var(--text-muted);
  align-items: center;
}
.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}
.cat-dot { width: 8px; height: 8px; border-radius: 50%; }

.urgency-bar {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
  margin-top: 4px;
}
.urgency-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .3s ease;
}
.task-card.status-ok      .urgency-fill { background: var(--ok); }
.task-card.status-soon    .urgency-fill { background: var(--soon); }
.task-card.status-due     .urgency-fill { background: var(--due); }
.task-card.status-overdue .urgency-fill { background: var(--overdue); }

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.status-badge.status-ok      { background: #d1fae5; color: #065f46; }
.status-badge.status-soon    { background: #fef3c7; color: #92400e; }
.status-badge.status-due     { background: #ffedd5; color: #9a3412; }
.status-badge.status-overdue { background: #fee2e2; color: #991b1b; }
.status-badge.status-untracked { background: var(--surface-soft); color: var(--text-muted); }

.days-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--surface-soft);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.days-chip.status-ok      { color: #065f46; border-color: #a7f3d0; }
.days-chip.status-soon    { color: #92400e; border-color: #fcd34d; }
.days-chip.status-due     { color: #9a3412; border-color: #fdba74; }
.days-chip.status-overdue { color: #991b1b; border-color: #fca5a5; }

.done-btn {
  background: var(--brand);
  color: white;
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
  min-width: 64px;
  box-shadow: 0 2px 6px rgba(59, 130, 246, .3);
}
.done-btn:active { transform: scale(.95); background: var(--brand-dark); }
.done-btn.just-done { background: var(--ok); }

/* ---------- Task detail ---------- */
.task-detail-card {
  background: var(--surface);
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 8px;
}
.task-detail-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}
.task-detail-header h2 {
  margin: 0 0 6px;
  font-size: 20px;
}
.task-detail-icon {
  font-size: 36px;
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  background: var(--surface-soft);
  border-radius: 14px;
  flex-shrink: 0;
}
.task-detail-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}
.task-detail-status .muted { color: var(--text-muted); }
.done-btn-big {
  width: 100%;
  font-size: 16px;
  padding: 16px;
  min-height: 56px;
}

/* ---------- History ---------- */
.history-filter {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 36px;
}
.chip.active { background: var(--brand); border-color: var(--brand); color: white; }

.log-list { display: flex; flex-direction: column; gap: 8px; }
.log-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 12px;
  align-items: center;
}
.log-row.no-icon { grid-template-columns: 1fr auto auto; }
.log-delete { color: var(--text-muted); }
.log-delete:hover { color: var(--overdue); background: #fee2e2; }
.log-icon { font-size: 22px; }
.log-name { font-weight: 600; font-size: 14px; }
.log-meta { font-size: 12px; color: var(--text-muted); }
.log-time { font-size: 12px; color: var(--text-muted); text-align: right; }
.log-who { font-weight: 600; }

/* ---------- Admin lists ---------- */
.admin-list { display: flex; flex-direction: column; gap: 8px; }
.admin-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  align-items: center;
}
.admin-row .icon-cell {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--surface-soft); border-radius: 10px;
  font-size: 20px;
}
.admin-row .main-cell { min-width: 0; }
.admin-row .name { font-weight: 600; }
.admin-row .sub  { font-size: 12px; color: var(--text-muted); }
.icon-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  min-width: 40px;
  min-height: 40px;
  border-radius: 10px;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-soft); color: var(--text); }
.icon-btn.danger:hover { color: var(--overdue); }

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--brand);
  color: white;
  border: none;
  font-size: 28px;
  font-weight: 300;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(59, 130, 246, .4);
  z-index: 9;
  line-height: 1;
}
.fab:active { transform: scale(.95); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 100;
  display: grid;
  place-items: end center;
  animation: fade-in .15s ease;
}
@media (min-width: 600px) {
  .modal-backdrop { place-items: center; }
}
@keyframes fade-in { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(100%); } }

.modal {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow: auto;
  animation: slide-up .2s ease;
}
@media (min-width: 600px) {
  .modal { border-radius: 20px; }
}
.modal h2 { margin: 0 0 16px; font-size: 18px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input, .field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  min-height: 44px;
}
.field input[type="color"] {
  padding: 4px;
  height: 44px;
  width: 80px;
}
.field.hidden { display: none; }
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.btn {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
}
.btn-primary { background: var(--brand); color: white; }
.btn-secondary { background: var(--surface-soft); color: var(--text); }
.btn-danger { background: var(--overdue); color: white; }

.empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}
.empty .big { font-size: 48px; margin-bottom: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 24px);
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 200;
  animation: toast-in .2s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }
