:root {
  --rosewater: #f5e0dc; --flamingo: #f2cdcd; --pink: #f5c2e7; --mauve: #cba6f7;
  --red: #f38ba8; --maroon: #eba0ac; --peach: #fab387; --yellow: #f9e2af;
  --green: #a6e3a1; --teal: #94e2d5; --sky: #89dceb; --sapphire: #74c7ec;
  --blue: #89b4fa; --lavender: #b4befe; --text: #cdd6f4; --subtext1: #bac2de;
  --subtext0: #a6adc8; --overlay2: #9399b2; --overlay1: #7f849c; --overlay0: #6c7086;
  --surface2: #585b70; --surface1: #45475a; --surface0: #313244;
  --base: #1e1e2e; --mantle: #181825; --crust: #11111b;
  --accent: var(--pink);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--base);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  font-size: 14px;
}

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--mantle);
  border-right: 1px solid var(--surface0);
  position: fixed;
  transition: transform 0.22s ease;
  top: 0; left: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 50;
}

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

.sidebar-brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--pink);
  letter-spacing: -0.01em;
}

.sidebar-brand small { color: var(--subtext0); font-size: 0.7rem; }

nav { padding: 0.75rem 0; flex: 1; overflow-y: auto; }

.nav-section {
  padding: 0.6rem 1.25rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--overlay0);
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 0.45rem 1.25rem;
  color: var(--subtext0);
  text-decoration: none;
  font-size: 0.8125rem;
  border-left: 2px solid transparent;
  transition: all 0.12s;
  gap: 0.5rem;
}

.nav-item:hover { color: var(--text); background: rgba(49,50,68,0.6); }
.nav-item.active { color: var(--pink); border-left-color: var(--pink); background: rgba(245,194,231,0.08); }

.sidebar-footer {
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--surface0);
  font-size: 0.75rem;
}

.sidebar-footer .username { color: var(--subtext1); font-weight: 500; margin-bottom: 0.25rem; }
.sidebar-footer .role-badge {
  display: inline-block;
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  background: rgba(245,194,231,0.15);
  color: var(--pink);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.signout { color: var(--subtext0); text-decoration: none; font-size: 0.75rem; }
.signout:hover { color: var(--red); }

/* ── Main ── */
.main { margin-left: 220px; flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  background: var(--mantle);
  border-bottom: 1px solid var(--surface0);
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-title { font-size: 1rem; font-weight: 600; color: var(--text); }
.topbar-actions { display: flex; gap: 0.5rem; align-items: center; }

.content { padding: 1.5rem; flex: 1; }

/* ── Alerts ── */
.alert {
  padding: 0.625rem 0.875rem;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  margin-bottom: 1rem;
  border: 1px solid;
}
.alert-success { background: rgba(166,227,161,0.12); border-color: var(--green); color: var(--green); }
.alert-error   { background: rgba(243,139,168,0.12); border-color: var(--red);   color: var(--red);   }
.alert-info    { background: rgba(137,180,250,0.12); border-color: var(--blue);  color: var(--blue);  }

/* ── Cards / Stats ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.875rem; margin-bottom: 1.5rem; }

.stat-card {
  background: var(--mantle);
  border: 1px solid var(--surface0);
  border-radius: 0.5rem;
  padding: 1rem 1.125rem;
}
.stat-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--subtext0); font-weight: 600; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--pink); margin-top: 0.2rem; line-height: 1; }
.stat-value.green { color: var(--green); }
.stat-value.yellow { color: var(--yellow); }
.stat-value.red { color: var(--red); }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
  flex-wrap: wrap;
}
.toolbar-left { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.search-box {
  padding: 0.375rem 0.625rem;
  background: var(--surface0);
  border: 1px solid var(--surface1);
  border-radius: 0.375rem;
  color: var(--text);
  font-size: 0.8125rem;
  width: 200px;
  outline: none;
  transition: border-color 0.12s;
}
.search-box:focus { border-color: var(--pink); }
.search-box::placeholder { color: var(--overlay0); }

.filter-select {
  padding: 0.375rem 0.625rem;
  background: var(--surface0);
  border: 1px solid var(--surface1);
  border-radius: 0.375rem;
  color: var(--text);
  font-size: 0.8125rem;
  outline: none;
  cursor: pointer;
}
.filter-select:focus { border-color: var(--pink); }
.filter-select option { background: var(--surface0); }

/* ── Attention grid (dashboard) ── */
.attention-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: start; }

/* ── Table ── */
.table-wrap {
  border: 1px solid var(--surface0);
  border-radius: 0.5rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

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

thead { background: var(--surface0); }

th {
  padding: 0.625rem 0.875rem;
  text-align: left;
  font-weight: 600;
  color: var(--subtext1);
  white-space: nowrap;
  border-bottom: 1px solid var(--surface1);
}

th a {
  color: var(--subtext1);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
th a:hover { color: var(--pink); }
th.sort-active a { color: var(--pink); }

td {
  padding: 0.5rem 0.875rem;
  vertical-align: middle;
  border-bottom: 1px solid rgba(49,50,68,0.8);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(49,50,68,0.4); }
.table-striped tbody tr:nth-child(even) td { background: rgba(49,50,68,0.25); }
.table-striped tbody tr:nth-child(even):hover td { background: rgba(49,50,68,0.4); }

/* Grouped table: each tbody is one group, its first row carrying the rowspan
   cells that span the group. Rows within a group are divided faintly; the group
   boundary gets a full-strength line that also runs under the rowspan cells, so
   those cells visibly reach across every row they span. */
.table-grouped td { border-bottom: 1px solid rgba(49,50,68,0.35); }
.table-grouped tbody tr:last-child td,
.table-grouped tbody td[rowspan] { border-bottom: 1px solid var(--surface1); }
.table-grouped tbody:last-child tr:last-child td,
.table-grouped tbody:last-child td[rowspan] { border-bottom: none; }
.table-grouped td[rowspan] { border-right: 1px solid rgba(49,50,68,0.35); }
.table-grouped td[rowspan]:last-child { border-right: none; border-left: 1px solid rgba(49,50,68,0.35); }
.table-grouped tbody:nth-of-type(even) td { background: rgba(49,50,68,0.25); }
.table-grouped tbody.editing td { background: rgba(245,194,231,0.06); }
.table-grouped tbody:hover td { background: rgba(49,50,68,0.4); }

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

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge-green   { background: rgba(166,227,161,0.18); color: var(--green);  }
.badge-red     { background: rgba(243,139,168,0.18); color: var(--red);    }
.badge-yellow  { background: rgba(249,226,175,0.18); color: var(--yellow); }
.badge-blue    { background: rgba(137,180,250,0.18); color: var(--blue);   }
.badge-pink    { background: rgba(245,194,231,0.18); color: var(--pink);   }
.badge-peach   { background: rgba(250,179,135,0.18); color: var(--peach);  }
.badge-mauve   { background: rgba(203,166,247,0.18); color: var(--mauve);  }
.badge-overlay { background: rgba(108,112,134,0.18); color: var(--overlay1); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.375rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all 0.12s;
  line-height: 1.2;
  white-space: nowrap;
}
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }

.btn-primary { background: var(--pink); color: var(--crust); border-color: var(--pink); }
.btn-primary:hover { background: var(--flamingo); border-color: var(--flamingo); }

.btn-secondary { background: var(--surface1); color: var(--text); border-color: var(--surface1); }
.btn-secondary:hover { background: var(--surface2); }

.btn-ghost { background: transparent; color: var(--subtext1); border-color: var(--surface1); }
.btn-ghost:hover { background: var(--surface0); color: var(--text); }

.btn-danger { background: transparent; color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: rgba(243,139,168,0.15); }

.btn-success { background: var(--green); color: var(--crust); border-color: var(--green); }
.btn-success:hover { background: var(--teal); }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }

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

label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--subtext1);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type=text], input[type=password], input[type=date], input[type=time],
input[type=number], input[type=email], select, textarea {
  padding: 0.5rem 0.625rem;
  background: var(--surface0);
  border: 1px solid var(--surface1);
  border-radius: 0.375rem;
  color: var(--text);
  font-size: 0.8125rem;
  outline: none;
  transition: border-color 0.12s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 2px rgba(245,194,231,0.12);
}
select option { background: var(--surface0); }
textarea { resize: vertical; min-height: 80px; }

/* Table inline edit inputs */
.edit-input {
  padding: 0.25rem 0.4rem;
  background: var(--surface0);
  border: 1px solid var(--surface1);
  border-radius: 0.25rem;
  color: var(--text);
  font-size: 0.8rem;
  outline: none;
  width: 100%;
  min-width: 70px;
}
.edit-input:focus { border-color: var(--pink); }
.edit-input option { background: var(--surface0); }

/* ── Login ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--crust);
}
.login-card {
  background: var(--mantle);
  border: 1px solid var(--surface0);
  border-radius: 0.75rem;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}
.login-card h1 { font-size: 1.4rem; font-weight: 700; color: var(--pink); margin-bottom: 0.25rem; }
.login-card .subtitle { color: var(--subtext0); font-size: 0.8125rem; margin-bottom: 1.75rem; }

/* ── Pagination ── */
.pagination { display: flex; gap: 0.375rem; align-items: center; justify-content: center; padding: 1rem 0; }
.page-link {
  padding: 0.3rem 0.6rem;
  border-radius: 0.25rem;
  font-size: 0.8rem;
  color: var(--subtext1);
  text-decoration: none;
  border: 1px solid var(--surface1);
  transition: all 0.12s;
}
.page-link:hover { border-color: var(--pink); color: var(--pink); }
.page-link.active { background: var(--pink); color: var(--crust); border-color: var(--pink); font-weight: 600; }
.page-ellipsis { color: var(--overlay0); padding: 0.3rem 0.4rem; font-size: 0.8rem; }

/* ── Audit log ── */
.audit-action-create { color: var(--green); }
.audit-action-update { color: var(--yellow); }
.audit-action-delete { color: var(--red); }

/* ── Card ── */
.card {
  background: var(--mantle);
  border: 1px solid var(--surface0);
  border-radius: 0.5rem;
  padding: 1.25rem;
}
.card-title { font-size: 0.8125rem; font-weight: 600; color: var(--subtext1); margin-bottom: 0.875rem; text-transform: uppercase; letter-spacing: 0.04em; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--mantle); }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--overlay0); }

/* ── Dialog / Modal ── */
dialog {
  background: var(--mantle);
  border: 1px solid var(--surface1);
  border-radius: 0.75rem;
  padding: 1.5rem;
  max-width: 420px;
  width: 90%;
  color: var(--text);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  margin: auto;
}
dialog::backdrop {
  background: rgba(17,17,27,0.75);
  backdrop-filter: blur(2px);
}
.modal-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1rem;
}
.modal-body { display: flex; flex-direction: column; gap: .5rem; font-size: .8125rem; color: var(--subtext1); }
.modal-body strong { color: var(--text); }
.modal-footer { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; }

/* ── HTMX indicators ── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
.htmx-request.htmx-indicator { display: inline; }

/* ── Hamburger / mobile nav ── */
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: 0.25rem;
  flex-shrink: 0;
  line-height: 0;
}
.hamburger:hover { color: var(--pink); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 45;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main { margin-left: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .hamburger { display: flex; align-items: center; }
  .topbar { gap: 0.75rem; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .attention-grid { grid-template-columns: 1fr; }
  .hide-mobile { display: none !important; }
}

/* ── Rabbit photos (issue #23) ── */
.rabbit-photo-frame {
  width: 140px; height: 140px;
  border-radius: .5rem;
  overflow: hidden;
  background: var(--surface0);
  border: 1px solid var(--surface1);
  display: flex; align-items: center; justify-content: center;
}
.rabbit-photo-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rabbit-photo-placeholder { font-size: 2.5rem; color: var(--overlay0); }
.rabbit-thumb {
  width: 32px; height: 32px;
  border-radius: .375rem;
  object-fit: cover;
  border: 1px solid var(--surface1);
  vertical-align: middle;
  margin-right: .5rem;
}
.rabbit-thumb-placeholder {
  width: 32px; height: 32px;
  border-radius: .375rem;
  background: var(--surface0);
  border: 1px solid var(--surface1);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .95rem;
  vertical-align: middle;
  margin-right: .5rem;
}
