:root {
  --navy: #10243e;
  --navy-light: #1c3a5e;
  --teal: #1f8a70;
  --teal-dark: #16664f;
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #dfe4ea;
  --text: #1e2733;
  --text-muted: #5c6b7a;
  --danger: #b3261e;
  --danger-bg: #fbe9e7;
  --success: #16664f;
  --success-bg: #e6f4ef;
  --info-bg: #e9eef5;
  --overlay: rgba(10, 18, 30, 0.5);
  --state-hover: rgba(16, 36, 62, 0.06);
  --state-press: rgba(16, 36, 62, 0.1);

  /* M3-style shape scale */
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 20px;
  --radius-xl: 28px;

  /* M3-style elevation */
  --elevation-1: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --elevation-2: 0 2px 6px rgba(16, 24, 40, 0.12);
  --elevation-3: 0 6px 18px rgba(16, 24, 40, 0.2);

  /* M3-style motion */
  --motion-standard: cubic-bezier(0.2, 0, 0, 1);
  --motion-emphasized: cubic-bezier(0.3, 0, 0.1, 1);
  --dur-s: 120ms;
  --dur-m: 220ms;
  --dur-l: 320ms;
}

[data-theme="dark"] {
  --navy: #0c1a2c;
  --navy-light: #16273f;
  --teal: #26a184;
  --teal-dark: #1f8a70;
  --bg: #10151d;
  --card: #1a212c;
  --border: #2b3444;
  --text: #e6ebf1;
  --text-muted: #94a3b8;
  --danger: #f2887e;
  --danger-bg: #3a1e1c;
  --success: #6fd4ae;
  --success-bg: #17332a;
  --info-bg: #1c2a3d;
  --overlay: rgba(0, 0, 0, 0.65);
  --state-hover: rgba(255, 255, 255, 0.06);
  --state-press: rgba(255, 255, 255, 0.1);
  --elevation-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --elevation-2: 0 2px 8px rgba(0, 0, 0, 0.45);
  --elevation-3: 0 8px 22px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes dialogIn {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes rippleAnim {
  from { transform: scale(0); opacity: 0.35; }
  to { transform: scale(1); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background var(--dur-m) var(--motion-standard), color var(--dur-m) var(--motion-standard);
}

/* ---------- Ripple (shared) ---------- */

.ripple-surface { position: relative; overflow: hidden; }
.ripple-dot {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  transform: scale(0);
  animation: rippleAnim 480ms var(--motion-standard);
  pointer-events: none;
}

/* ---------- Top bar ---------- */

.topbar {
  background: var(--navy);
  color: #fff;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--elevation-2);
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: 0.2px;
  white-space: nowrap;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.15rem;
  line-height: 1;
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background var(--dur-s) var(--motion-standard), transform var(--dur-s) var(--motion-standard);
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.icon-btn:active { transform: scale(0.9); }

/* ---------- Nav drawer ---------- */

.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 30;
  opacity: 0;
  transition: opacity var(--dur-m) var(--motion-standard);
}
.nav-overlay.open { display: block; opacity: 1; }

.nav-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 260px;
  max-width: 82vw;
  background: var(--card);
  z-index: 31;
  transform: translateX(-100%);
  transition: transform var(--dur-m) var(--motion-emphasized);
  display: flex;
  flex-direction: column;
  padding: 8px;
  overflow-y: auto;
  box-shadow: var(--elevation-3);
  border-radius: 0 var(--radius-l) var(--radius-l) 0;
}
.nav-drawer.open { transform: translateX(0); }

.nav-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 14px;
  font-weight: 700;
  color: var(--text);
}
.nav-drawer-header button {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 50%;
}
.nav-drawer-header button:hover { background: var(--state-hover); }

.nav-drawer a {
  display: block;
  padding: 11px 14px;
  border-radius: var(--radius-l);
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  margin-bottom: 2px;
  transition: background var(--dur-s) var(--motion-standard);
}
.nav-drawer a:hover { background: var(--state-hover); }
.nav-drawer a.active { background: var(--info-bg); color: var(--navy); font-weight: 600; }
[data-theme="dark"] .nav-drawer a.active { color: #fff; }

.nav-drawer-divider { height: 1px; background: var(--border); margin: 8px 4px; }

/* ---------- Layout ---------- */

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 100px;
  animation: fadeIn var(--dur-l) var(--motion-standard);
}

h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.2px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
.subtitle { color: var(--text-muted); margin: 0 0 24px; font-size: 0.92rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--elevation-1);
  animation: fadeSlideUp var(--dur-m) var(--motion-standard) backwards;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.stat { text-align: left; }
.stat .label { color: var(--text-muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.4px; }
.stat .value { font-size: 1.6rem; font-weight: 700; color: var(--navy); margin-top: 4px; }
[data-theme="dark"] .stat .value { color: #fff; }

/* ---------- Tables ---------- */

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  margin: 0 -4px;
  padding: 0 4px;
  position: relative;
}
.table-scroll::-webkit-scrollbar { height: 7px; }
.table-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.table-scroll::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.table-scroll.has-scroll {
  box-shadow: inset -14px 0 10px -12px rgba(16, 24, 40, 0.18);
}
.table-scroll.has-scroll.at-end {
  box-shadow: inset 14px 0 10px -12px rgba(16, 24, 40, 0.18);
}
.table-scroll.has-scroll.at-middle {
  box-shadow: inset 14px 0 10px -12px rgba(16, 24, 40, 0.18), inset -14px 0 10px -12px rgba(16, 24, 40, 0.18);
}

table { width: 100%; min-width: max-content; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }
.amount { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  background: var(--teal);
  color: #fff;
  border: none;
  margin: 0;
  padding: 10px 20px;
  border-radius: var(--radius-l);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
  transition: background var(--dur-s) var(--motion-standard), transform var(--dur-s) var(--motion-standard), box-shadow var(--dur-s) var(--motion-standard);
}
.btn:hover { background: var(--teal-dark); box-shadow: var(--elevation-1); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.6; cursor: default; transform: none; }

.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.btn-secondary { background: var(--navy-light); }
.btn-secondary:hover { background: var(--navy); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); padding: 5px 12px; font-size: 0.82rem; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-small { padding: 5px 12px; font-size: 0.82rem; }

/* ---------- Forms ---------- */

form .field { margin-bottom: 14px; }
label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  transition: border-color var(--dur-s) var(--motion-standard), box-shadow var(--dur-s) var(--motion-standard);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(31, 138, 112, 0.18);
}
textarea { resize: vertical; min-height: 60px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.errors { color: var(--danger); font-size: 0.8rem; margin-top: 4px; }

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ---------- Notices (persistent banners) ---------- */

.notice {
  padding: 12px 16px;
  border-radius: var(--radius-m);
  margin-bottom: 14px;
  font-size: 0.9rem;
  animation: fadeSlideUp var(--dur-m) var(--motion-standard);
}
.notice-success { background: var(--success-bg); color: var(--success); }
.notice-error { background: var(--danger-bg); color: var(--danger); }
.notice-info { background: var(--info-bg); color: var(--navy); }
[data-theme="dark"] .notice-info { color: var(--text); }

/* ---------- Toasts (one-off action feedback) ---------- */

.toast-stack {
  position: fixed;
  top: 66px;
  right: 12px;
  left: 12px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  align-items: flex-end;
}
.toast {
  pointer-events: auto;
  max-width: 380px;
  padding: 12px 16px;
  border-radius: var(--radius-m);
  font-size: 0.9rem;
  box-shadow: var(--elevation-3);
  opacity: 1;
  transform: translateY(0);
  transition: opacity var(--dur-m) var(--motion-standard), transform var(--dur-m) var(--motion-standard);
  cursor: pointer;
  animation: toastIn var(--dur-m) var(--motion-emphasized);
}
.toast-hide { opacity: 0; transform: translateY(-8px); }
.toast-success { background: var(--success-bg); color: var(--success); }
.toast-error { background: var(--danger-bg); color: var(--danger); }
.toast-info { background: var(--info-bg); color: var(--navy); }
[data-theme="dark"] .toast-info { color: var(--text); }

/* ---------- Tabs / rows / badges ---------- */

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
  padding: 7px 14px;
  border-radius: var(--radius-l);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: background var(--dur-s) var(--motion-standard), color var(--dur-s) var(--motion-standard), border-color var(--dur-s) var(--motion-standard);
}
.tabs a:hover { background: var(--state-hover); }
.tabs a.active { background: var(--navy); color: #fff; border-color: var(--navy); }

.row-actions { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; }
.muted-note { color: var(--text-muted); font-size: 0.85rem; }
.badge { display: inline-block; padding: 3px 10px; border-radius: var(--radius-l); font-size: 0.75rem; }
.badge-admin { background: var(--info-bg); color: var(--navy); }
[data-theme="dark"] .badge-admin { color: var(--text); }
.badge-disabled { background: var(--danger-bg); color: var(--danger); }
.badge-active { background: var(--success-bg); color: var(--success); }

/* ---------- Collapsible sections (dashboard recent activity) ---------- */

details.card { padding: 0; }
details.card summary {
  list-style: none;
  cursor: pointer;
  position: relative;
  padding: 16px 44px 16px 20px;
  font-weight: 600;
  font-size: 1.05rem;
  border-radius: var(--radius-l);
  transition: background var(--dur-s) var(--motion-standard);
}
details.card summary:hover { background: var(--state-hover); }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::marker { content: ""; }
details.card summary::after {
  content: "▾";
  color: var(--text-muted);
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  transition: transform var(--dur-m) var(--motion-standard);
}
details.card[open] summary::after { transform: translateY(-50%) rotate(180deg); }
details.card .details-body { padding: 0 20px 18px; animation: fadeSlideUp var(--dur-m) var(--motion-standard); }

/* ---------- Floating quick-add ---------- */

.fab-wrap { position: fixed; right: 18px; bottom: 18px; z-index: 25; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.fab {
  width: 56px; height: 56px; border-radius: var(--radius-l);
  background: var(--teal); color: #fff; border: none;
  font-size: 1.8rem; line-height: 1; cursor: pointer;
  box-shadow: var(--elevation-3);
  transition: transform var(--dur-m) var(--motion-emphasized), background var(--dur-s) var(--motion-standard), border-radius var(--dur-m) var(--motion-standard);
}
.fab:hover { background: var(--teal-dark); }
.fab:active { transform: scale(0.94); }
.fab-wrap.open .fab { transform: rotate(45deg); border-radius: 50%; }
.fab-menu {
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  opacity: 0; pointer-events: none; transform: translateY(10px) scale(0.9);
  transform-origin: bottom right;
  transition: opacity var(--dur-m) var(--motion-emphasized), transform var(--dur-m) var(--motion-emphasized);
}
.fab-wrap.open .fab-menu { opacity: 1; pointer-events: auto; transform: translateY(0) scale(1); }
.fab-item {
  background: var(--navy); color: #fff; text-decoration: none;
  padding: 10px 18px; border-radius: var(--radius-l); font-size: 0.88rem;
  white-space: nowrap; box-shadow: var(--elevation-2);
  transition: background var(--dur-s) var(--motion-standard), transform var(--dur-s) var(--motion-standard);
}
.fab-item:hover { background: var(--navy-light); transform: translateX(-2px); }

/* ---------- Confirm modal ---------- */

.confirm-overlay {
  display: none;
  position: fixed; inset: 0; background: var(--overlay);
  z-index: 60; align-items: center; justify-content: center; padding: 20px;
  opacity: 0;
  transition: opacity var(--dur-s) var(--motion-standard);
}
.confirm-overlay.open { display: flex; opacity: 1; }
.confirm-box {
  background: var(--card); border-radius: var(--radius-xl); padding: 24px;
  max-width: 360px; width: 100%; box-shadow: var(--elevation-3);
  animation: dialogIn var(--dur-m) var(--motion-emphasized);
}
.confirm-box p { margin: 0 0 18px; color: var(--text); font-size: 0.95rem; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }
