/* ============================================================
   Merlin's Keeper — App Stylesheet
   Dark theme, mobile-first, no external dependencies
   ============================================================ */

/* ── Custom Properties ─────────────────────────────────────── */

:root {
  --bg:          #0d1117;
  --bg2:         #161b22;
  --bg3:         #21262d;
  --border:      #30363d;
  --border2:     #3d444e;
  --text:        #f0f6fc;
  --text2:       #9198a1;
  --text3:       #656d76;
  --accent:      #3fb950;
  --accent-d:    #2ea043;
  --accent-hl:   #56d364;
  --blue:        #58a6ff;
  --blue-d:      #388bfd;
  --warn:        #d29922;
  --danger:      #f85149;
  --danger-d:    #da3633;
  --online:      #3fb950;
  --offline:     #8b949e;
  --temp-color:  #ff8c42;
  --humid-color: #4ecdc4;
  --sidebar-w:   220px;
  --topbar-h:    52px;
  --radius:      8px;
  --radius-sm:   5px;
  --shadow:      0 4px 16px rgba(0,0,0,.4);
  --transition:  150ms ease;
}

/* ── Reset ──────────────────────────────────────────────────── */

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

html { font-size: 15px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .15em .4em;
  font-size: .875em;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

img { max-width: 100%; }

/* ── Layout — App Shell ─────────────────────────────────────── */

.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────── */

.sidebar {
  grid-row: 1 / -1;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 1rem 1rem .75rem;
  border-bottom: 1px solid var(--border);
}

.brand-link {
  display: flex;
  align-items: center;
  gap: .5rem;
  text-decoration: none;
  color: var(--text);
}

.brand-icon { flex-shrink: 0; }

.brand-text {
  font-weight: 700;
  font-size: .9rem;
  color: var(--text);
}

.nav-list {
  list-style: none;
  padding: .5rem 0;
  flex: 1;
}

.nav-item { margin: .15rem .5rem; }

.nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
  color: var(--text2);
  text-decoration: none;
  font-size: .9rem;
  transition: background var(--transition), color var(--transition);
}

.nav-link:hover { background: var(--bg3); color: var(--text); text-decoration: none; }
.nav-item.active .nav-link { background: var(--bg3); color: var(--accent); }

.nav-icon { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-footer {
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .5rem;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-d);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.user-info { overflow: hidden; }

.user-name {
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  font-size: .72rem;
  color: var(--text3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer-links {
  display: flex;
  justify-content: space-between;
  margin-top: .35rem;
}

.footer-link {
  font-size: .8rem;
  color: var(--text3);
  padding: .3rem .4rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
  text-decoration: none;
}

.footer-link:hover { color: var(--text); text-decoration: none; }
.footer-link.active { color: var(--accent); }
.footer-link.danger:hover { color: var(--danger); }

/* ── Topbar (mobile) ────────────────────────────────────────── */

.topbar {
  display: none;
  grid-column: 2;
  align-items: center;
  gap: .75rem;
  padding: 0 1rem;
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text2);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.hamburger svg { width: 20px; height: 20px; }

.topbar-title {
  flex: 1;
  font-weight: 600;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-logout { font-size: .8rem; color: var(--text3); white-space: nowrap; }
.topbar-logout:hover { color: var(--danger); }

/* ── Main Content ───────────────────────────────────────────── */

.main-content {
  grid-column: 2;
  padding: 1.5rem 2rem;
  max-width: 1200px;
  width: 100%;
}

/* ── Flash Bar ──────────────────────────────────────────────── */

.flash-bar {
  grid-column: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.5rem;
  font-size: .9rem;
  font-weight: 500;
}

.flash-success { background: rgba(63,185,80,.15); border-bottom: 1px solid rgba(63,185,80,.3); color: var(--accent-hl); }
.flash-error   { background: rgba(248,81,73,.12); border-bottom: 1px solid rgba(248,81,73,.25); color: #ff8177; }
.flash-info    { background: rgba(88,166,255,.1);  border-bottom: 1px solid rgba(88,166,255,.2);  color: var(--blue); }

.flash-close {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  font-size: 1.2rem;
  line-height: 1;
  padding: 0 .25rem;
  opacity: .7;
}

/* ── Page Header ────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: .75rem;
}

.page-back {
  display: flex;
  flex-direction: column;
  gap: .15rem;
}

.back-link {
  font-size: .8rem;
  color: var(--text2);
}

.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.page-actions { display: flex; gap: .5rem; align-items: center; }

/* ── Section ────────────────────────────────────────────────── */

.section { margin-bottom: 2rem; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: .5rem;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .75rem;
}

/* ── Buttons ────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { text-decoration: none; }

.btn-primary  { background: var(--accent-d); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hl); border-color: var(--accent-hl); }

.btn-outline  { background: transparent; color: var(--text); border-color: var(--border2); }
.btn-outline:hover { background: var(--bg3); border-color: var(--border2); }

.btn-danger   { background: var(--danger-d); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #e7443f; }

.btn-sm  { padding: .3rem .7rem; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Cards ──────────────────────────────────────────────────── */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.card-link {
  display: block;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  text-decoration: none;
  color: var(--text);
}

.card-link:hover {
  border-color: var(--border2);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
}

.card-header {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  margin-bottom: .75rem;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.card-name {
  font-weight: 700;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Status indicators ──────────────────────────────────────── */

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.online  { background: var(--online); box-shadow: 0 0 0 3px rgba(63,185,80,.2); }
.status-dot.offline { background: var(--offline); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}

.status-pill.online  { background: rgba(63,185,80,.15);  color: var(--accent-hl); }
.status-pill.offline { background: rgba(139,148,158,.1);  color: var(--offline); }

.status-pill.online::before  { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--online); }
.status-pill.offline::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--offline); }

/* ── Readings ───────────────────────────────────────────────── */

.readings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: .5rem;
  margin-bottom: .5rem;
}

.reading-cell {
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: .5rem;
}

.reading-label {
  font-size: .7rem;
  color: var(--text3);
  display: block;
  margin-bottom: .2rem;
}

.reading-values { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

.reading-temp  { color: var(--temp-color); font-weight: 700; font-size: .9rem; }
.reading-humid { color: var(--humid-color); font-weight: 700; font-size: .9rem; }
.reading-temp.alert, .reading-humid.alert { color: var(--danger); }

.readings-mini {
  display: flex;
  gap: .75rem;
  font-weight: 700;
  font-size: .85rem;
  margin-top: .5rem;
}

.readings-strip {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: .5rem;
}

.readings-strip.compact .reading-block { min-width: 100px; }

.reading-block {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  min-width: 120px;
}

.reading-block-label {
  font-size: .75rem;
  color: var(--text3);
  margin-bottom: .5rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.reading-block-values { display: flex; gap: .75rem; flex-wrap: wrap; }

.reading-value { display: flex; flex-direction: column; align-items: center; gap: .1rem; }

.rv-number {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -.02em;
}

.rv-unit { font-size: .65rem; color: var(--text3); text-transform: uppercase; }

.reading-value.temp .rv-number  { color: var(--temp-color); }
.reading-value.humid .rv-number { color: var(--humid-color); }
.reading-value.temp.alert .rv-number, .reading-value.humid.alert .rv-number { color: var(--danger); }

/* ── Line states (MKST) ─────────────────────────────────────── */

.line-states {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}

.line-state {
  padding: .2rem .5rem;
  border-radius: var(--radius-sm);
  font-size: .75rem;
  font-weight: 600;
}

.line-state.on  { background: rgba(63,185,80,.15); color: var(--accent-hl); }
.line-state.off { background: var(--bg); color: var(--text3); }

/* ── Meta strip ─────────────────────────────────────────────── */

.meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 2rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  font-size: .85rem;
  color: var(--text2);
  margin-bottom: 1.5rem;
}

/* ── Badges ─────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: .15rem .6rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text2);
}

.device-type-badge {
  font-size: .7rem;
  color: var(--text3);
}

/* ── Tables ─────────────────────────────────────────────────── */

.table-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.table th {
  background: var(--bg3);
  color: var(--text3);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .6rem 1rem;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: .65rem 1rem;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

.table tr:hover td { background: var(--bg3); }
.table-link { color: var(--text); font-weight: 600; }
.table-link:hover { color: var(--blue); text-decoration: none; }
.text-muted { color: var(--text3); }

/* ── Charts ─────────────────────────────────────────────────── */

.chart-container {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  height: 220px;
}

.chart-container canvas { max-height: 100%; }

.range-tabs {
  display: flex;
  gap: .25rem;
}

.range-tab {
  padding: .3rem .7rem;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  font-weight: 600;
  color: var(--text2);
  background: var(--bg3);
  border: 1px solid var(--border);
  transition: background var(--transition), color var(--transition);
}

.range-tab:hover { background: var(--border); color: var(--text); text-decoration: none; }
.range-tab.active { background: var(--accent-d); color: #fff; border-color: var(--accent); }

/* ── Forms ──────────────────────────────────────────────────── */

.form { display: flex; flex-direction: column; gap: 1rem; }

.form-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.form-page { max-width: 640px; }

.form-group { display: flex; flex-direction: column; gap: .35rem; flex: 1; }

.form-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }

.form-row-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

.form-label { font-size: .85rem; font-weight: 600; color: var(--text2); }

.form-input, .form-select, .form-textarea {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .9rem;
  padding: .55rem .75rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(88,166,255,.15);
}

.form-textarea { resize: vertical; line-height: 1.5; }

.form-hint { font-size: .78rem; color: var(--text3); }

.form-actions { display: flex; gap: .75rem; justify-content: flex-end; margin-top: .5rem; }

.required { color: var(--danger); }

.form-inline { display: block; }
.form-inline .form-group { margin-bottom: 1rem; }

/* ── Event log ──────────────────────────────────────────────── */

.event-form { margin-bottom: 1.5rem; }

.event-top-row {
  display: flex;
  align-items: flex-end;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: .75rem;
}

.event-type-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: 0;
  flex: 1;
}

.event-date-group { flex-shrink: 0; margin-bottom: 0; }

.event-type-btn { cursor: pointer; }

.event-type-btn input { display: none; }

.event-type-btn span {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .35rem .8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border2);
  font-size: .85rem;
  background: var(--bg3);
  color: var(--text2);
  transition: border-color var(--transition), background var(--transition), color var(--transition);
  user-select: none;
}

.event-type-btn input:checked + span {
  border-color: var(--accent);
  background: rgba(63,185,80,.1);
  color: var(--accent-hl);
}

.event-list { list-style: none; display: flex; flex-direction: column; gap: .5rem; }

.event-item {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .65rem .9rem;
}

.event-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: .05rem; }

.event-body { flex: 1; display: flex; flex-direction: column; gap: .1rem; }

.event-type { font-weight: 600; font-size: .875rem; }

.event-data { font-size: .85rem; color: var(--text2); }

.event-time { font-size: .78rem; color: var(--text3); white-space: nowrap; margin-top: .1rem; }

.event-actions { display: flex; gap: .5rem; margin-top: .2rem; }
.event-actions a, .link-btn {
  font-size: .72rem;
  color: var(--text3);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  font-family: inherit;
}
.event-actions a:hover { color: var(--blue); }
.link-btn.danger:hover { color: var(--danger); }

/* ── Detail grid ────────────────────────────────────────────── */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.detail-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.detail-card-title {
  font-size: .9rem;
  font-weight: 700;
  color: var(--text2);
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.detail-card-link { font-size: .8rem; font-weight: 400; }

.detail-list { display: grid; grid-template-columns: auto 1fr; gap: .3rem .75rem; font-size: .875rem; }
.detail-list dt { color: var(--text3); font-weight: 600; }
.detail-list dd { color: var(--text); }
.notes-text { white-space: pre-wrap; word-break: break-word; }

/* ── Empty state ────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  max-width: 480px;
  margin: 0 auto;
}

.empty-icon {
  width: 80px;
  height: 80px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
  color: var(--text3);
}

.empty-icon svg { width: 40px; height: 40px; }

.empty-state h2 { font-size: 1.2rem; margin-bottom: .5rem; }

.empty-state p { color: var(--text2); font-size: .9rem; margin-bottom: 1.25rem; }

.empty-user-id { margin-top: 1.5rem; }

/* ── UID display ────────────────────────────────────────────── */

.uid-section {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin-top: 2rem;
  padding: .75rem 1rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .85rem;
}

.uid-label { color: var(--text3); }

.uid-code {
  font-size: .85rem;
  letter-spacing: .05em;
}

.empty-user-id .label {
  display: block;
  font-size: .8rem;
  color: var(--text3);
  margin-bottom: .35rem;
}

/* ── Danger zone ────────────────────────────────────────────── */

.danger-zone {
  border: 1px solid rgba(248,81,73,.3);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  background: rgba(248,81,73,.04);
}

.danger-title { color: var(--danger); }

/* ── Hint box ───────────────────────────────────────────────── */

.hint-box {
  background: rgba(88,166,255,.06);
  border: 1px solid rgba(88,166,255,.2);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  font-size: .875rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.hint-box p { color: var(--text2); }

/* ── Card footer / misc ─────────────────────────────────────── */

.card-footer { margin-top: .5rem; }
.last-seen { font-size: .75rem; color: var(--text3); }
.no-data   { font-size: .85rem; color: var(--text3); padding: .5rem 0; }
.animal-species { font-size: .8rem; color: var(--text2); margin-bottom: .35rem; }

/* ── Alert section ──────────────────────────────────────────── */

.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  margin-bottom: 1rem;
}

.alert-error   { background: rgba(248,81,73,.12); color: #ff8177; border: 1px solid rgba(248,81,73,.25); }
.alert-success { background: rgba(63,185,80,.1);  color: var(--accent-hl); border: 1px solid rgba(63,185,80,.25); }
.alert-info    { background: rgba(88,166,255,.08); color: var(--blue); border: 1px solid rgba(88,166,255,.2); }

/* ── Error page ─────────────────────────────────────────────── */

.error-page {
  text-align: center;
  padding: 5rem 2rem;
}

.error-code  { font-size: 5rem; font-weight: 900; color: var(--border2); line-height: 1; }
.error-title { font-size: 1.5rem; margin: 1rem 0 .5rem; }
.error-msg   { color: var(--text2); margin-bottom: 1.5rem; }

/* ── Guest layout ───────────────────────────────────────────── */

.guest-body {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.guest-wrap {
  width: 100%;
  max-width: 420px;
}

.guest-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.brand-logo {
  display: flex;
  justify-content: center;
  margin-bottom: .75rem;
}

.brand-name {
  font-size: 1.4rem;
  font-weight: 800;
}

.brand-sub {
  font-size: .85rem;
  color: var(--text3);
}

.guest-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
}

.guest-card-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
}

.guest-link {
  text-align: center;
  font-size: .85rem;
  color: var(--text3);
  margin-top: 1rem;
}

.guest-sub {
  font-size: .875rem;
  color: var(--text2);
  margin-bottom: 1.25rem;
}

/* Email verification banner */

.verify-notice {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1.5rem;
  background: rgba(88,166,255,.08);
  border-bottom: 1px solid rgba(88,166,255,.2);
  color: var(--blue);
  font-size: .85rem;
}

.verify-resend-btn {
  background: none;
  border: 1px solid rgba(88,166,255,.35);
  border-radius: var(--radius-sm);
  color: var(--blue);
  font-size: .8rem;
  padding: .2rem .6rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition);
}
.verify-resend-btn:hover { background: rgba(88,166,255,.1); }

/* ── Mobile ─────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .app-body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100%;
    width: var(--sidebar-w);
    z-index: 100;
    transition: left .2s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open { left: 0; }

  .topbar { display: flex; grid-column: 1; }

  .main-content { grid-column: 1; padding: 1rem; }

  .flash-bar { grid-column: 1; }

  .form-row-4 { grid-template-columns: repeat(2, 1fr); }

  .chart-container { height: 180px; }
}

@media (max-width: 480px) {
  .form-row { grid-template-columns: 1fr; }
  .form-row-4 { grid-template-columns: 1fr 1fr; }
  .page-title { font-size: 1.15rem; }
}

/* ── Calendar ───────────────────────────────────────────────── */

.cal-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1.5rem;
  align-items: start;
}

.cal-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.cal-month-title { font-weight: 700; font-size: 1rem; }

.cal-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.2rem;
  text-decoration: none;
  transition: background var(--transition);
}

.cal-nav-btn:hover { background: var(--border); text-decoration: none; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.cal-header-cell {
  padding: .5rem 0;
  text-align: center;
  font-size: .72rem;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}

.cal-day {
  min-height: 72px;
  padding: .35rem .4rem;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

.cal-day:nth-child(7n) { border-right: none; }
.cal-day:hover { background: var(--bg3); }
.cal-day.selected { background: rgba(88,166,255,.08); border-color: var(--blue); }
.cal-day.empty { cursor: default; background: transparent; }
.cal-day.today { background: rgba(63,185,80,.05); }

.cal-day-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text2);
}

.today-num { background: var(--accent); color: #fff; }

.cal-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 3px;
}

.cal-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.cal-dot-more { font-size: .65rem; color: var(--text3); line-height: 7px; }

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1.25rem;
  padding: .65rem 1rem;
  border-top: 1px solid var(--border);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .75rem;
  color: var(--text2);
}

.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* Day panel */

.day-panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  opacity: 0;
  transform: translateX(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}

.day-panel.open { opacity: 1; transform: translateX(0); pointer-events: all; }

.day-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.day-panel-title { font-size: .9rem; font-weight: 700; }

.day-panel-close {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 .2rem;
}

.day-panel-close:hover { color: var(--text); }

.day-event-list {
  list-style: none;
  padding: .5rem 0;
  max-height: 500px;
  overflow-y: auto;
}

.day-empty { padding: 1rem; font-size: .85rem; color: var(--text3); text-align: center; }

.day-event-item {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--border);
}

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

.day-event-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: .35rem;
}

.day-event-body { flex: 1; display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.day-event-animal { font-weight: 700; font-size: .85rem; color: var(--text); text-decoration: none; }
.day-event-animal:hover { color: var(--blue); }
.day-event-type { font-size: .75rem; color: var(--text2); }
.day-event-data { font-size: .8rem; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day-event-time { font-size: .72rem; color: var(--text3); white-space: nowrap; flex-shrink: 0; }

.day-event-actions { display: flex; gap: .35rem; margin-top: .3rem; }

.day-event-actions a,
.day-event-actions button {
  font-size: .72rem;
  padding: .15rem .45rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text2);
}

.day-event-actions .del-btn { color: var(--danger); border-color: rgba(248,81,73,.3); }
.day-event-actions a:hover { color: var(--blue); text-decoration: none; }
.day-event-actions .del-btn:hover { background: rgba(248,81,73,.1); }

@media (max-width: 900px) {
  .cal-layout { grid-template-columns: 1fr; }
  .day-panel { transform: none; }
  .cal-day { min-height: 52px; }
}

/* ── Profile ─────────────────────────────────────────────────── */

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.5rem;
}

.profile-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.profile-card-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.25rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}

.profile-hint {
  font-size: .85rem;
  color: var(--text2);
  margin-bottom: 1rem;
  line-height: 1.5;
}

.uid-display {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  margin-bottom: 1rem;
}

.uid-code-lg {
  font-size: .95rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--accent-hl);
  letter-spacing: .05em;
  flex: 1;
  word-break: break-all;
}

.profile-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.5rem;
  font-size: .8rem;
  color: var(--text3);
}

/* ── Toggle switch ──────────────────────────────────────────── */

.toggle-label {
  display: flex;
  align-items: center;
  gap: .65rem;
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="checkbox"] { display: none; }

.toggle-track {
  width: 40px;
  height: 22px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 11px;
  flex-shrink: 0;
  position: relative;
  transition: background var(--transition), border-color var(--transition);
}

.toggle-track::after {
  content: '';
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text3);
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform var(--transition), background var(--transition);
}

.toggle-label input:checked + .toggle-track {
  background: var(--accent-d);
  border-color: var(--accent);
}

.toggle-label input:checked + .toggle-track::after {
  transform: translateX(18px);
  background: #fff;
}

.toggle-text { font-size: .875rem; color: var(--text); }

/* ── Care Repository ─────────────────────────────────────────── */

.care-disclaimer {
  background: rgba(210,153,34,.08);
  border: 1px solid rgba(210,153,34,.25);
  border-radius: var(--radius-sm);
  color: var(--warn);
  font-size: .8rem;
  padding: .6rem 1rem;
  margin-bottom: 1.25rem;
}

.care-search-form {
  display: flex;
  gap: .5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.care-search-form .form-input { flex: 1; min-width: 200px; }

.care-list { display: flex; flex-direction: column; gap: 0; }

.care-letter-group { margin-bottom: 1rem; }

.care-letter {
  font-size: .75rem;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: .3rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: .25rem;
}

.care-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .65rem .75rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  transition: background var(--transition);
}

.care-item:hover { background: var(--bg2); text-decoration: none; }

.care-item-main { display: flex; flex-direction: column; gap: .1rem; }

.care-item-title { font-weight: 600; font-size: .9rem; }

.care-item-species { font-size: .8rem; color: var(--text3); }
.care-item-species em { font-style: italic; }

.care-item-author { font-size: .78rem; color: var(--text3); white-space: nowrap; }

/* Article view */

.care-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.5rem;
  font-size: .85rem;
  color: var(--text2);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-bottom: 1rem;
}

.care-content {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  line-height: 1.8;
  font-size: .95rem;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 1rem;
}

.care-textarea { font-family: inherit; line-height: 1.7; }

.care-status-banner {
  padding: .65rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  margin-bottom: 1rem;
  border: 1px solid;
}

.care-status-banner.warn   { background: rgba(210,153,34,.08); border-color: rgba(210,153,34,.25); color: var(--warn); }
.care-status-banner.danger { background: rgba(248,81,73,.08);  border-color: rgba(248,81,73,.25);  color: var(--danger); }
.care-status-banner.ok     { background: rgba(63,185,80,.08);  border-color: rgba(63,185,80,.25);  color: var(--accent-hl); }

/* Status pills */
.care-status-pill {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  background: var(--bg3);
  color: var(--text2);
}
.care-status-pill.warn   { background: rgba(210,153,34,.1);  color: var(--warn); }
.care-status-pill.ok     { background: rgba(63,185,80,.1);   color: var(--accent-hl); }
.care-status-pill.danger { background: rgba(248,81,73,.1);   color: var(--danger); }

/* Moderation */
.mod-list { display: flex; flex-direction: column; gap: 1rem; }

.mod-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.mod-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}

.mod-title:hover { color: var(--blue); }

.mod-species { font-size: .8rem; color: var(--text3); margin-top: .15rem; }

.mod-meta { font-size: .78rem; color: var(--text3); margin-top: .25rem; }

.mod-preview {
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: .75rem;
  font-size: .85rem;
  color: var(--text2);
  line-height: 1.6;
  margin: .75rem 0;
  white-space: pre-wrap;
}

.mod-actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }

.reject-form { display: flex; align-items: center; gap: .5rem; flex: 1; }

.mod-reject-input { flex: 1; min-width: 160px; }

.table-actions { white-space: nowrap; }

/* ── Public footer ───────────────────────────────────────────── */

.pub-footer {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  margin-top: 3rem;
}

.pub-footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: .8rem;
  color: var(--text3);
}

.pub-footer-links { display: flex; gap: 1rem; flex-wrap: wrap; }
.pub-footer-links a { color: var(--text3); text-decoration: none; }
.pub-footer-links a:hover { color: var(--text2); }

/* ── About page ──────────────────────────────────────────────── */

.about-intro {
  font-size: 1rem;
  color: var(--text2);
  line-height: 1.8;
  max-width: 760px;
  margin-bottom: 2rem;
}

.about-devices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin-bottom: .5rem;
}

.about-device-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.about-device-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-hl);
  margin-bottom: .5rem;
}

.about-device-desc {
  font-size: .875rem;
  color: var(--text2);
  line-height: 1.6;
  margin-bottom: .75rem;
}

.about-device-specs {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}

.about-device-specs li {
  font-size: .82rem;
  color: var(--text3);
  padding-left: 1rem;
  position: relative;
}

.about-device-specs li::before {
  content: '·';
  position: absolute;
  left: 0;
  color: var(--accent);
}

.about-features {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.about-feature-item {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.about-feature-icon { font-size: 1.4rem; flex-shrink: 0; margin-top: .1rem; }

.about-feature-item strong { display: block; color: var(--text); margin-bottom: .2rem; font-size: .95rem; }
.about-feature-item p { font-size: .875rem; color: var(--text2); line-height: 1.6; margin: 0; }

.about-cta {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* ── Contact page ────────────────────────────────────────────── */

.contact-wrap {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 768px) { .contact-wrap { grid-template-columns: 1fr; } }

.contact-info {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.contact-info p {
  font-size: .875rem;
  color: var(--text2);
  line-height: 1.6;
  margin-bottom: 1rem;
}

.contact-detail-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  font-size: .875rem;
  color: var(--text2);
}

.contact-detail-list a { color: var(--blue); }

.contact-form { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }

/* ── Policy pages ────────────────────────────────────────────── */

.policy-wrap { max-width: 760px; }
.policy-updated { font-size: .82rem; color: var(--text3); margin-bottom: 2rem; }

.policy-section {
  margin-bottom: 2rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}
.policy-section:last-child { border-bottom: none; }

.policy-section h2 {
  font-size: 1.05rem; font-weight: 700; color: var(--text);
  margin-bottom: .75rem;
}
.policy-section h3 {
  font-size: .9rem; font-weight: 700; color: var(--text2);
  margin: 1rem 0 .4rem;
}
.policy-section p { font-size: .9rem; color: var(--text2); line-height: 1.8; margin-bottom: .6rem; }
.policy-section ul { padding-left: 1.25rem; margin-bottom: .6rem; }
.policy-section li { font-size: .9rem; color: var(--text2); line-height: 1.8; }

.cookie-table-wrap { overflow-x: auto; margin: .75rem 0; }
.cookie-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.cookie-table th {
  background: var(--bg3); color: var(--text3); font-size: .7rem;
  text-transform: uppercase; letter-spacing: .05em;
  padding: .5rem .75rem; text-align: left;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.cookie-table td {
  padding: .65rem .75rem; color: var(--text2); line-height: 1.6;
  border-bottom: 1px solid var(--border); vertical-align: top;
}
.cookie-table tr:last-child td { border-bottom: none; }

/* ── App footer (authenticated layout) ───────────────────────── */

.app-footer {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem 2rem;
  font-size: .78rem;
  color: var(--text3);
  border-top: 1px solid var(--border);
  margin-top: auto;
}
.app-footer a { color: var(--text3); text-decoration: none; }
.app-footer a:hover { color: var(--text2); }

/* ── Delete account page ─────────────────────────────────────── */

.delete-account-wrap { max-width: 640px; }

.delete-account-warning {
  background: rgba(248,81,73,.06);
  border: 1px solid rgba(248,81,73,.25);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}
.delete-account-warning h2 { font-size: .95rem; color: var(--danger); margin-bottom: .75rem; }
.delete-account-warning p { font-size: .875rem; color: var(--text2); line-height: 1.7; margin-bottom: .5rem; }
.delete-account-warning ul { padding-left: 1.25rem; margin-bottom: .5rem; }
.delete-account-warning li { font-size: .875rem; color: var(--text2); line-height: 1.7; }

.delete-account-form { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }

/* ── Species Repository ──────────────────────────────────────── */

/* Filter bar */
.species-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  margin-bottom: 1.25rem;
}
.species-search { flex: 1; min-width: 200px; max-width: 300px; }
.species-filter-pills { display: flex; flex-wrap: wrap; gap: .35rem; }
.species-cat-count {
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.15); border-radius: 10px;
  font-size: .65rem; min-width: 16px; height: 16px; padding: 0 .3rem; margin-left: .2rem;
}

/* Card grid */
.species-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.species-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.species-card:hover { border-color: var(--border2); box-shadow: var(--shadow); text-decoration: none; color: var(--text); }

.species-card-img {
  width: 100%; height: 160px;
  background: var(--bg3);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.species-card-img img { width: 100%; height: 100%; object-fit: cover; }
.species-img-placeholder { font-size: 3rem; opacity: .3; }

.species-card-body { padding: .85rem 1rem; display: flex; flex-direction: column; gap: .3rem; flex: 1; }

.species-card-badges { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .1rem; }

.species-cat-badge {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text3);
  background: var(--bg3); border-radius: 4px; padding: .1rem .4rem;
}

.species-diff-badge {
  font-size: .68rem; font-weight: 700;
  border-radius: 4px; padding: .1rem .45rem;
}
.diff-beginner     { background: rgba(63,185,80,.15);  color: var(--accent-hl); }
.diff-intermediate { background: rgba(210,153,34,.15); color: var(--warn); }
.diff-advanced     { background: rgba(248,81,73,.12);  color: var(--danger); }

.species-card-name  { font-weight: 700; font-size: .95rem; }
.species-card-latin { font-size: .8rem; color: var(--text3); font-style: italic; }
.species-card-desc  { font-size: .82rem; color: var(--text2); line-height: 1.5; }
.species-card-temps { font-size: .78rem; color: var(--text3); margin-top: auto; padding-top: .35rem; }

/* Detail page */
.species-detail-wrap {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 900px) { .species-detail-wrap { grid-template-columns: 1fr; } }

.species-detail-aside { display: flex; flex-direction: column; gap: 1rem; }

.species-detail-img-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.species-detail-img { width: 100%; display: block; max-height: 260px; object-fit: cover; }

.species-key-facts {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.species-badges-row { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .25rem; }
.species-latin-name { font-style: italic; font-size: .9rem; color: var(--text3); }

.species-fact-row { display: flex; flex-direction: column; gap: .1rem; border-top: 1px solid var(--border); padding-top: .4rem; }
.species-fact-label { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text3); }
.species-fact-val { font-size: .875rem; color: var(--text); }
.species-wiki-link { font-size: .82rem; color: var(--blue); margin-top: .25rem; }

.species-description {
  font-size: .95rem; color: var(--text2); line-height: 1.8;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.25rem;
}

.species-care-sections { display: flex; flex-direction: column; gap: 1rem; margin-top: 1.25rem; }

.species-care-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.species-care-title { font-size: .9rem; font-weight: 700; margin-bottom: .5rem; }
.species-care-body  { font-size: .875rem; color: var(--text2); line-height: 1.7; white-space: pre-wrap; }

.species-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: .75rem;
}
.species-gallery-item { display: flex; flex-direction: column; gap: .3rem; }
.species-gallery-img { width: 100%; height: 140px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); display: block; }
.species-gallery-caption { font-size: .75rem; color: var(--text3); }

/* Admin species form */
.species-form-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.species-form-heading {
  font-size: .95rem; font-weight: 700; color: var(--text);
  margin-bottom: 1rem; padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}
.species-current-img { margin-bottom: .75rem; }

.species-admin-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}
.species-admin-gallery-item { display: flex; flex-direction: column; gap: .3rem; }

/* ── Device CSV export ───────────────────────────────────────── */

.section-header-right { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.export-wrap          { display: flex; align-items: center; gap: .35rem; }

/* ── Audit log ───────────────────────────────────────────────── */

.audit-action-label { font-size: .82rem; white-space: nowrap; }

/* ── Contact message cards ───────────────────────────────────── */

.contact-msg-list { display: flex; flex-direction: column; gap: 1rem; }

.contact-msg-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  border-left: 3px solid transparent;
}

.contact-msg-card.is-unread { border-left-color: var(--blue); }
.contact-msg-card.is-read   { opacity: .75; }

.contact-msg-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .75rem;
  flex-wrap: wrap;
}

.contact-msg-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem 1rem; }

.contact-msg-name  { font-weight: 700; font-size: .95rem; }
.contact-msg-email { font-size: .85rem; color: var(--blue); }
.contact-msg-time  { font-size: .78rem; }

.contact-msg-body {
  font-size: .9rem;
  color: var(--text2);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  margin-bottom: .75rem;
}

.contact-msg-reply { display: flex; gap: .5rem; }

/* ── Alert type pills ────────────────────────────────────────── */

.alert-type-pill {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .15rem .55rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  background: var(--bg3);
  color: var(--text2);
}

.alert-type-danger { background: rgba(248,81,73,.12);  color: var(--danger); }
.alert-type-warn   { background: rgba(210,153,34,.12); color: var(--warn); }
.alert-type-blue   { background: rgba(88,166,255,.12); color: var(--blue); }

/* ── In Memoriam ─────────────────────────────────────────────── */

.memoriam-intro {
  color: var(--text2);
  font-size: .95rem;
  margin-bottom: 1.5rem;
  font-style: italic;
}

.memoriam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

.memoriam-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.memoriam-photo-wrap {
  width: 100%;
  height: 200px;
  background: var(--bg3);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.memoriam-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: grayscale(30%);
  opacity: .9;
}

.memoriam-no-photo { background: var(--bg3); }
.memoriam-photo-placeholder { font-size: 3.5rem; opacity: .3; }

.memoriam-body { padding: 1.1rem 1.25rem 1.25rem; display: flex; flex-direction: column; gap: .5rem; flex: 1; }

.memoriam-name { font-size: 1.2rem; font-weight: 700; color: var(--text); }

.memoriam-species { font-size: .875rem; color: var(--text2); }
.memoriam-morph   { color: var(--text3); }

.memoriam-dates {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem;
  font-size: .82rem;
  color: var(--text3);
}

.memoriam-date-sep { opacity: .5; }

.memoriam-age {
  background: var(--bg3);
  border-radius: 20px;
  padding: .1rem .55rem;
  font-size: .75rem;
  color: var(--text3);
}

.memoriam-note {
  font-size: .875rem;
  color: var(--text2);
  font-style: italic;
  line-height: 1.6;
  margin-top: .25rem;
  padding-top: .5rem;
  border-top: 1px solid var(--border);
}

.memoriam-profile-link {
  font-size: .8rem;
  color: var(--blue);
  margin-top: auto;
  padding-top: .5rem;
  text-decoration: none;
}
.memoriam-profile-link:hover { text-decoration: underline; }

/* Memorial banner on animal detail page */

.memoriam-banner {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  background: rgba(120,80,180,.1);
  border: 1px solid rgba(120,80,180,.3);
  border-radius: var(--radius);
  padding: .9rem 1.1rem;
  margin-bottom: 1.5rem;
  color: #c9a0e8;
  font-size: .9rem;
}

.memoriam-banner-icon { font-size: 1.4rem; flex-shrink: 0; }
.memoriam-banner-note { margin-top: .35rem; font-style: italic; color: #b08ad0; font-size: .85rem; }

/* Record Death form */

.record-death-section {
  border: 1px solid rgba(120,80,180,.25);
  border-radius: var(--radius);
  padding: 1.25rem;
  background: rgba(120,80,180,.04);
}

.record-death-hint {
  font-size: .875rem;
  color: var(--text2);
  margin-bottom: 1rem;
}

.record-death-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: .75rem;
}

.record-death-row .form-group { min-width: 160px; margin-bottom: 0; }

.btn-memoriam {
  background: rgba(120,80,180,.2);
  border: 1px solid rgba(120,80,180,.4);
  color: #c9a0e8;
  border-radius: var(--radius-sm);
  padding: .55rem 1.1rem;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}
.btn-memoriam:hover { background: rgba(120,80,180,.35); border-color: rgba(120,80,180,.6); }

/* ── Admin ───────────────────────────────────────────────────── */

.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  text-align: center;
}

.stat-card.stat-warn { border-color: rgba(210,153,34,.4); background: rgba(210,153,34,.06); }

.stat-value { font-size: 2rem; font-weight: 800; color: var(--text); line-height: 1; margin-bottom: .3rem; }
.stat-label { font-size: .75rem; color: var(--text3); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }

.admin-alert {
  background: rgba(210,153,34,.1);
  border: 1px solid rgba(210,153,34,.3);
  color: var(--warn);
  border-radius: var(--radius-sm);
  padding: .6rem 1rem;
  font-size: .875rem;
  margin-bottom: .75rem;
}

.admin-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 900px) { .admin-two-col { grid-template-columns: 1fr; } }

.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}

.admin-table th {
  background: var(--bg3);
  color: var(--text3);
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: .5rem .75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.admin-table td {
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: rgba(255,255,255,.02); }
.admin-table tr.row-warn td { background: rgba(210,153,34,.05); }

.text-dim  { color: var(--text3); }
.text-ok   { color: var(--accent-hl); }
.text-warn { color: var(--warn); }

.role-pill {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
}
.role-pill.role-admin     { background: rgba(88,166,255,.15); color: var(--blue); }
.role-pill.role-moderator { background: rgba(63,185,80,.12);  color: var(--accent-hl); }
.role-pill.role-user      { background: var(--bg3); color: var(--text2); }

.admin-role-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .8rem;
  padding: .25rem .5rem;
  cursor: pointer;
}

.section-link { font-size: .8rem; color: var(--blue); font-weight: 400; margin-left: .5rem; }

.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--warn);
  color: #000;
  font-size: .65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 .35rem;
  margin-left: .3rem;
  vertical-align: middle;
}

/* Log viewer */

.log-wrap {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem 0;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: .72rem;
  max-height: 400px;
  overflow-y: auto;
}

.log-full { max-height: none; }

.log-line {
  padding: .2rem .75rem;
  line-height: 1.5;
  border-left: 2px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text3);
}

.log-line:hover { white-space: normal; word-break: break-all; background: rgba(255,255,255,.03); }

.log-line.log-5xx { border-left-color: var(--danger); color: #ff8177; background: rgba(248,81,73,.05); }
.log-line.log-4xx { border-left-color: var(--warn); color: var(--warn); }
.log-line.log-3xx { border-left-color: var(--blue); color: var(--text2); }
.log-line.log-2xx { color: var(--text3); }

.log-status { font-weight: 700; margin-right: .5rem; min-width: 2.5rem; display: inline-block; }
.log-status-log-5xx { color: var(--danger); }
.log-status-log-4xx { color: var(--warn); }
.log-status-log-3xx { color: var(--blue); }
.log-status-log-2xx { color: var(--text3); }
.log-method { font-weight: 600; color: var(--accent-hl); margin-right: .4rem; min-width: 2.5rem; display: inline-block; }
.log-path   { color: var(--text); margin-right: .75rem; }
.log-ip     { margin-right: .5rem; }
.log-time   { }

.log-filters { display: flex; gap: .35rem; }

/* ── Animal event images ─────────────────────────────────────── */

.event-image-wrap { margin-top: .5rem; display: flex; flex-direction: column; gap: .35rem; }

.event-image-thumb {
  max-width: 100%;
  max-height: 260px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
  object-fit: contain;
  background: var(--bg3);
}

.visibility-btn {
  font-size: .72rem;
  color: var(--text3);
}
.visibility-btn:hover { color: var(--blue); }

/* ── Animal reading cell (dashboard) ────────────────────────── */

.reading-cell-animal { display: flex; flex-direction: column; gap: .15rem; grid-column: 1 / -1; }

.reading-animal-name {
  font-weight: 700;
  font-size: .9rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reading-animal-species {
  font-size: .7rem;
  color: var(--text3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Event-actions alignment fix ────────────────────────────── */

.event-actions { align-items: center; }
.event-actions form { display: contents; }

/* ── Topbar brand logo (mobile) ──────────────────────────────── */

.topbar-brand { display: flex; align-items: center; flex-shrink: 0; }
.topbar-brand:hover { opacity: .85; text-decoration: none; }

/* ── Public layout ───────────────────────────────────────────── */

.public-body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.pub-header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.pub-header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.pub-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  text-decoration: none;
  color: var(--text);
}
.pub-brand:hover { text-decoration: none; color: var(--text); }

.pub-brand-text { font-weight: 700; font-size: .95rem; }

.pub-nav { display: flex; align-items: center; gap: .75rem; }

.pub-nav-link {
  font-size: .875rem;
  color: var(--text2);
  text-decoration: none;
  padding: .35rem .6rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.pub-nav-link:hover { color: var(--text); background: var(--bg3); text-decoration: none; }

.pub-main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ── Landing page ────────────────────────────────────────────── */

.landing-hero {
  text-align: center;
  padding: 4rem 1rem 3rem;
  max-width: 680px;
  margin: 0 auto;
}

.landing-badge {
  display: inline-block;
  background: rgba(63,185,80,.12);
  border: 1px solid rgba(63,185,80,.3);
  color: var(--accent-hl);
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: .3rem .9rem;
  border-radius: 20px;
  margin-bottom: 1.25rem;
}

.landing-title {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 1.1rem;
}

.landing-desc {
  font-size: 1.05rem;
  color: var(--text2);
  line-height: 1.7;
  margin-bottom: 2rem;
}

.landing-actions {
  display: flex;
  gap: .75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.landing-features {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin: 2rem 0;
}

.landing-feature-wide { grid-column: 1 / -1; }

.landing-feature {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  text-align: center;
}

.landing-feature-icon { font-size: 2rem; margin-bottom: .75rem; }

.landing-feature-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .4rem;
}

.landing-feature-text { font-size: .85rem; color: var(--text2); line-height: 1.6; }

.landing-care-cta {
  text-align: center;
  padding: 2.5rem 1rem;
  border-top: 1px solid var(--border);
  margin-top: 1.5rem;
}

.landing-care-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: .5rem;
}

.landing-care-text { color: var(--text2); font-size: .9rem; margin-bottom: 1rem; }

@media (max-width: 600px) {
  .landing-title { font-size: 1.7rem; }
}

/* ── Dashboard — nested animals ──────────────────────────────── */

.device-card-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.device-card-wrap:hover { border-color: var(--border2); box-shadow: var(--shadow); }

.device-card-wrap.in-alert {
  background: rgba(248,81,73,.08);
  border-color: rgba(248,81,73,.5);
}
.device-card-wrap.in-alert:hover {
  border-color: rgba(248,81,73,.75);
  box-shadow: 0 4px 16px rgba(248,81,73,.15);
}
.device-card-wrap.in-alert .device-card-header:hover {
  background: rgba(248,81,73,.05);
}

.device-card-header {
  display: block;
  padding: 1rem;
  text-decoration: none;
  color: var(--text);
  transition: background var(--transition);
}

.device-card-header:hover { background: rgba(255,255,255,.02); text-decoration: none; color: var(--text); }

.device-nested-animals {
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: .5rem .75rem .75rem;
}

.nested-animals-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text3);
  margin-bottom: .4rem;
}

.nested-animal-card {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  padding: .45rem .6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg2);
  text-decoration: none;
  color: var(--text);
  margin-top: .35rem;
  transition: border-color var(--transition), background var(--transition);
}

.nested-animal-card:hover { border-color: var(--accent-d); background: rgba(63,185,80,.05); text-decoration: none; }

.nested-animal-name { font-size: .85rem; font-weight: 600; }
.nested-animal-species { font-size: .75rem; color: var(--text3); }

/* ── Device page — linked animals ────────────────────────────── */

.linked-animals-list { display: flex; flex-direction: column; gap: .5rem; }

.linked-animal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color var(--transition), background var(--transition);
}

.linked-animal-row:hover { border-color: var(--accent-d); background: rgba(63,185,80,.05); text-decoration: none; }

.linked-animal-info { display: flex; flex-direction: column; gap: .1rem; }
.linked-animal-name { font-weight: 600; font-size: .9rem; }
.linked-animal-species { font-size: .8rem; color: var(--text3); }
.linked-animal-arrow { color: var(--text3); font-size: .9rem; }

/* ── Calendar filters ────────────────────────────────────────── */

.cal-filters {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: .75rem;
  padding: .15rem 0;
}

.cal-filter-group { display: flex; align-items: center; gap: .5rem; }

.cal-filter-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text3);
  white-space: nowrap;
}

.cal-filter-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .8rem;
  padding: .3rem .6rem;
  cursor: pointer;
}

.filter-type-btns { display: flex; gap: .35rem; flex-wrap: wrap; }

.filter-type-btn {
  font-size: .8rem;
  padding: .3rem .75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text2);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
}

.filter-type-btn:hover { background: var(--border); color: var(--text); text-decoration: none; }

.filter-type-btn.active {
  background: var(--accent-d);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ── Calendar month picker ───────────────────────────────────── */

.cal-month-picker-wrap { position: relative; }

.cal-month-title {
  font-weight: 700;
  font-size: 1rem;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: .25rem .5rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  display: flex;
  align-items: center;
  gap: .3rem;
}

.cal-month-title::after {
  content: '▾';
  font-size: .65rem;
  color: var(--text3);
}

.cal-month-title:hover { background: var(--bg3); }

.month-picker-popup {
  position: absolute;
  top: calc(100% + .4rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 220px;
  padding: .75rem;
  z-index: 100;
  display: none;
}

.month-picker-popup.open { display: block; }

.picker-year-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .6rem;
}

.picker-year-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  width: 28px;
  height: 28px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.picker-year-btn:hover { background: var(--border); }

.picker-year-label { font-weight: 700; font-size: .95rem; }

.picker-month-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .3rem;
}

.picker-month-btn {
  background: var(--bg3);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text2);
  cursor: pointer;
  font-size: .8rem;
  padding: .4rem 0;
  text-align: center;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.picker-month-btn:hover { background: var(--border); color: var(--text); }
.picker-month-btn.current { border-color: var(--accent); color: var(--accent-hl); font-weight: 600; }

/* ── Calendar right panel — always visible ───────────────────── */

.day-panel {
  opacity: 1;
  transform: none;
  pointer-events: all;
}

.panel-back-btn {
  font-size: .78rem;
  color: var(--blue);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
  align-self: flex-start;
}
.panel-back-btn:hover { text-decoration: underline; }

.day-panel-header { flex-direction: column; align-items: flex-start; gap: .2rem; }

.summary-date-group { list-style: none; }

.summary-date-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text3);
  padding: .5rem 1rem .2rem;
  border-top: 1px solid var(--border);
}

.summary-date-group:first-child .summary-date-label { border-top: none; }

.summary-day-events { list-style: none; }
