/* ---------------------------------------------------------------------------
   Design tokens. Light is the default; dark is switched by data-theme on <html>
   (set before first paint by the inline script in the page head).
   --------------------------------------------------------------------------- */
/* Palette and type follow the community's visual style: Manrope (a free
   geometric sans standing in for TT Norms), dark-grey text on white and pale
   cyan surfaces, navy for navigation, and a blue-to-violet gradient on primary
   actions with pill-shaped buttons. */
:root {
  color-scheme: light;
  font-family: "Manrope Variable", Manrope, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  --bg: #f4f8fb;
  --surface: #ffffff;
  --surface-alt: #f2f8fc;
  --border: #e2eaf2;
  --border-input: #cdd9e5;

  --text: #333333;
  --text-2: #46505f;
  --muted: #6f7a8a;
  --muted-2: #9aa5b4;

  --accent: #2577d3;
  --accent-hover: #1b62b3;
  --accent-bg: #eefafd;
  --accent-ring: rgba(37, 119, 211, 0.18);
  --brand: #621ebb;
  --brand-gradient: linear-gradient(91deg, #2577d3, #621ebb);
  --brand-gradient-hover: linear-gradient(91deg, #1f68bd, #521699);
  --navy: #2c4376;

  --sidebar-bg: #ffffff;
  --sidebar-border: #e6edf4;
  --sidebar-text: #2c4376;
  --sidebar-text-hover: #1b2d55;
  --sidebar-active-bg: #e6f2fc;
  --sidebar-active-text: #1b62b3;
  --sidebar-active-icon: #2577d3;
  --sidebar-brand-text: #2c4376;
  --sidebar-shadow: rgba(44, 67, 118, 0.18);

  --success: #1f8a4c;
  --success-bg: #e3f7ec;
  --warning: #b3620a;
  --warning-bg: #fff3dd;
  --warning-border: #f7c96b;
  --error: #c0392b;
  --error-bg: #fdecea;
  --error-border: #f3b1aa;
  --neutral: #6f7a8a;
  --neutral-bg: #eef2f7;
  --info: #1b62b3;
  --info-bg: #e6f2fc;

  --btn-primary: #2577d3;
  --btn-primary-hover: #1b62b3;
  --btn-secondary: #2c4376;
  --btn-secondary-hover: #22355f;
  --btn-success: #1f8a4c;
  --btn-success-hover: #19713e;
  --btn-danger: #d64536;
  --btn-danger-hover: #b8362a;

  --code-bg: #eef3f8;
  --code-text: #46505f;
  --shadow-sm: 0 1px 2px rgba(44, 67, 118, 0.06);
  --shadow-md: 0 10px 28px rgba(44, 67, 118, 0.14);
  --avatar-bg: #2c4376;
  --msg-mine-bg: #e6f2fc;
  --msg-mine-text: #1b2d55;
  --overlay: rgba(28, 37, 64, 0.5);
  --radius: 12px;
  --radius-sm: 8px;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #151b2c;
  --surface: #1e2640;
  --surface-alt: #262f4b;
  --border: #33405e;
  --border-input: #44526f;

  --text: #e8eef6;
  --text-2: #c8d2e0;
  --muted: #93a0b4;
  --muted-2: #6b788c;

  --accent: #5fa3ea;
  --accent-hover: #86bcf0;
  --accent-bg: rgba(95, 163, 234, 0.14);
  --accent-ring: rgba(95, 163, 234, 0.25);
  --brand: #a98beb;
  --brand-gradient: linear-gradient(91deg, #2577d3, #621ebb);
  --brand-gradient-hover: linear-gradient(91deg, #3c8ae0, #7a3ad0);
  --navy: #c8d2e0;

  --sidebar-bg: #1b2238;
  --sidebar-border: #2a3350;
  --sidebar-text: #a7b4c8;
  --sidebar-text-hover: #e6ecf5;
  --sidebar-active-bg: rgba(37, 119, 211, 0.22);
  --sidebar-active-text: #f0f6ff;
  --sidebar-active-icon: #86bcf0;
  --sidebar-brand-text: #ffffff;
  --sidebar-shadow: rgba(0, 0, 0, 0.4);

  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.14);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.14);
  --warning-border: rgba(251, 191, 36, 0.4);
  --error: #f87171;
  --error-bg: rgba(248, 113, 113, 0.14);
  --error-border: rgba(248, 113, 113, 0.4);
  --neutral: #9aa8bd;
  --neutral-bg: rgba(148, 163, 184, 0.16);
  --info: #86bcf0;
  --info-bg: rgba(95, 163, 234, 0.16);

  --btn-primary: #2577d3;
  --btn-primary-hover: #3c8ae0;
  --btn-secondary: #44526f;
  --btn-secondary-hover: #566585;
  --btn-success: #1f6b3f;
  --btn-success-hover: #23804b;
  --btn-danger: #a13529;
  --btn-danger-hover: #b8402f;

  --code-bg: #141a2b;
  --code-text: #c8d2e0;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.5);
  --avatar-bg: #3d5a9a;
  --msg-mine-bg: rgba(37, 119, 211, 0.24);
  --msg-mine-text: #e6f2fc;
  --overlay: rgba(4, 8, 20, 0.7);
}

/* ---------------------------------------------------------------------------
   Base
   --------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; font-size: 15px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { text-wrap: balance; letter-spacing: -0.01em; font-weight: 600; margin: 0 0 0.5em; line-height: 1.25; color: var(--navy); }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75em; }
p:last-child { margin-bottom: 0; }
code { font-family: ui-monospace, "Cascadia Code", "Fira Code", monospace; font-size: 0.85em; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; color: var(--code-text); }
pre { margin: 0 0 0.75em; background: var(--code-bg); border-radius: 6px; padding: 10px 12px; overflow-x: auto; }
pre code { background: none; padding: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.86em; }
.inline { display: inline; }
.icon { width: 18px; height: 18px; flex-shrink: 0; vertical-align: -0.2em; }
.icon.brand { width: 16px; height: 16px; }
.icon-space { display: inline-block; width: 18px; }
.stack-sm > * + * { margin-top: 8px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }

main { flex: 1; min-width: 0; margin: 28px 0; padding: 0 24px; max-width: 1240px; }
main.wide { max-width: none; }
main.narrow { max-width: 820px; }

/* ---------------------------------------------------------------------------
   Sidebar (desktop: sticky column, collapsible to an icon rail;
   mobile: slide-in drawer opened from a top bar)
   --------------------------------------------------------------------------- */
.sidebar { width: 240px; flex-shrink: 0; background: var(--sidebar-bg); border-right: 1px solid var(--sidebar-border); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.sidebar-head { display: flex; align-items: center; border-bottom: 1px solid var(--sidebar-border); padding-right: 10px; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px; text-decoration: none; flex: 1; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; background: var(--brand-gradient); border-radius: 9px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: #fff; }
.brand-mark .icon { width: 17px; height: 17px; }
.brand-text { font-weight: 700; color: var(--sidebar-brand-text); font-size: 0.95em; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; }
.nav-items { flex: 1; padding: 8px; display: flex; flex-direction: column; gap: 1px; }
.nav-item { position: relative; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 15px; border-radius: 6px; color: var(--sidebar-text); font-size: 0.88em; font-weight: 500; text-decoration: none; transition: background 0.12s, color 0.12s; white-space: nowrap; }
.nav-item > span:first-of-type { overflow: hidden; text-overflow: ellipsis; }
.nav-item:hover { background: var(--sidebar-border); color: var(--sidebar-text-hover); text-decoration: none; }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }
.nav-item.active .nav-icon { color: var(--sidebar-active-icon); }
.nav-icon { width: 18px; height: 18px; }
.nav-divider { height: 1px; background: var(--sidebar-border); margin: 5px 2px; flex-shrink: 0; }
.nav-badge { margin-left: auto; background: #dc2626; color: #fff; border-radius: 9999px; font-size: 0.72em; font-weight: 700; line-height: 1; padding: 3px 6px; min-width: 18px; text-align: center; }
.nav-footer { padding: 10px; border-top: 1px solid var(--sidebar-border); display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.account-menu { position: relative; display: flex; flex: 1; min-width: 0; }
.user-chip { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; border-radius: 6px; margin: -4px; padding: 4px 4px 4px 12px; background: transparent; border: 0; cursor: pointer; font: inherit; text-align: left; white-space: nowrap; color: var(--sidebar-text); }
.user-chip:hover, .user-chip[aria-expanded="true"] { background: var(--sidebar-border); color: var(--sidebar-text-hover); }
.user-name { font-size: 0.86em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.popover { position: fixed; z-index: 60; min-width: 210px; background: var(--sidebar-bg); border: 1px solid var(--sidebar-border); border-radius: var(--radius); box-shadow: 0 8px 24px var(--sidebar-shadow); padding: 4px; display: grid; gap: 2px; }
.popover form { display: flex; }
.popover-item { display: flex; align-items: center; gap: 9px; flex: 1; width: 100%; padding: 8px 10px; border-radius: 6px; color: var(--sidebar-text); font: inherit; font-size: 0.88em; font-weight: 500; text-decoration: none; background: transparent; border: 0; cursor: pointer; text-align: left; white-space: nowrap; }
.popover-item:hover { background: var(--sidebar-border); color: var(--sidebar-text-hover); text-decoration: none; }
.popover-item.is-current { color: var(--sidebar-text-hover); }
.popover-section { border-top: 1px solid var(--sidebar-border); border-bottom: 1px solid var(--sidebar-border); margin: 4px 0; padding: 4px 0; display: grid; gap: 2px; }
.popover-heading { font-size: 0.7em; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted-2); padding: 6px 10px 2px; }
.sidebar-collapse-btn, .icon-btn { background: transparent; border: 0; color: var(--sidebar-text); cursor: pointer; padding: 6px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; position: relative; }
.sidebar-collapse-btn:hover, .icon-btn:hover { background: var(--sidebar-border); color: var(--sidebar-text-hover); }
.collapse-icon { transition: transform 0.18s ease; }
.brand-text, .nav-item > span, .user-name { transition: opacity 0.15s ease, visibility 0.15s; }
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }
.sidebar-close-btn { display: none; position: absolute; top: 14px; right: 10px; background: transparent; border: 0; color: var(--sidebar-text); cursor: pointer; padding: 4px; border-radius: 4px; }
.dot-badge { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: #dc2626; }

@media (min-width: 769px) {
  .sidebar { transition: width 0.18s ease; overflow-x: hidden; }
  html.sidebar-collapsed .sidebar { width: 64px; }
  html.sidebar-collapsed .brand-text, html.sidebar-collapsed .nav-item > span, html.sidebar-collapsed .user-name { opacity: 0; visibility: hidden; }
  html.sidebar-collapsed .nav-item .nav-badge { opacity: 1; visibility: visible; position: absolute; left: 30px; top: 4px; width: 8px; height: 8px; min-width: 0; padding: 0; font-size: 0; }
  html.sidebar-collapsed .brand { display: none; }
  html.sidebar-collapsed .sidebar-head { justify-content: center; padding-right: 0; box-sizing: content-box; min-height: 62px; }
  html.sidebar-collapsed .collapse-icon { transform: rotate(180deg); }
}

@media (max-width: 768px) {
  body { flex-direction: column; }
  .mobile-topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--sidebar-bg); border-bottom: 1px solid var(--sidebar-border); position: sticky; top: 0; z-index: 40; }
  .mobile-topbar-brand { font-weight: 700; color: var(--sidebar-brand-text); font-size: 0.95em; flex: 1; text-decoration: none; }
  .topbar-bell { color: var(--sidebar-text); }
  .sidebar { position: fixed; top: 0; left: 0; width: 260px; max-width: 84vw; height: 100vh; transform: translateX(-100%); transition: transform 0.25s ease; z-index: 50; }
  .sidebar-collapse-btn { display: none; }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3); }
  .sidebar-close-btn { display: flex; }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 45; opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
  main { padding: 0 16px; margin: 16px 0; }
}

/* ---------------------------------------------------------------------------
   Cards, page header, tabs, alerts
   --------------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.card + .card, .card + .grid, .grid + .card { margin-top: 20px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-title h2 { margin: 0; }
.card.danger { border-color: var(--error-border); }
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-2 { display: grid; gap: 20px; grid-template-columns: 2fr 1fr; align-items: start; }
/* Grid cells are spaced by `gap`; the stacked-card margin would push all but the first cell down. */
.grid > .card, .grid-2 > .card { margin-top: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-subtitle { margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; scrollbar-width: none; }
.tab { padding: 9px 14px; color: var(--muted); font-weight: 500; font-size: 0.92em; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 6px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent-hover); border-bottom-color: var(--brand); }
.tab-count { background: var(--neutral-bg); color: var(--muted); border-radius: 9999px; padding: 1px 7px; font-size: 0.8em; font-weight: 600; }
.tab.active .tab-count { background: var(--accent-bg); color: var(--accent-hover); }
.alert { border-radius: var(--radius-sm); padding: 12px 14px; border: 1px solid var(--border); background: var(--surface-alt); margin-bottom: 14px; }
.alert ul { margin: 0; padding-left: 18px; }
.alert-error { background: var(--error-bg); border-color: var(--error-border); color: var(--error); }
.alert-info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.flash { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 18px; border: 1px solid transparent; font-weight: 500; }
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error { background: var(--error-bg); color: var(--error); border-color: var(--error-border); }
.flash-info { background: var(--info-bg); color: var(--info); }
.flash span { flex: 1; }
.flash-close { background: transparent; border: 0; color: inherit; cursor: pointer; padding: 2px; display: flex; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty-icon { width: 36px; height: 36px; color: var(--accent); margin-bottom: 8px; }
.empty-title { font-weight: 600; color: var(--text-2); margin-bottom: 4px; }

/* ---------------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px; border-radius: 9999px; border: 1px solid transparent; background-color: var(--btn-primary); background-image: var(--brand-gradient); color: #fff; font: inherit; font-size: 0.92em; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.3; transition: background 0.12s, border-color 0.12s, color 0.12s; white-space: nowrap; }
.btn:hover { background-color: var(--btn-primary-hover); background-image: var(--brand-gradient-hover); text-decoration: none; }
.btn-secondary, .btn-success, .btn-danger, .btn-outline, .btn-ghost { background-image: none; }
.btn-secondary:hover, .btn-success:hover, .btn-danger:hover, .btn-outline:hover, .btn-ghost:hover { background-image: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary { background: var(--btn-secondary); }
.btn-secondary:hover { background: var(--btn-secondary-hover); }
.btn-success { background: var(--btn-success); }
.btn-success:hover { background: var(--btn-success-hover); }
.btn-danger { background: var(--btn-danger); }
.btn-danger:hover { background: var(--btn-danger-hover); }
.btn-outline { background: var(--surface); color: var(--text-2); border-color: var(--border-input); }
.btn-outline:hover { background: var(--surface-alt); border-color: var(--muted-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--neutral-bg); }
.btn-sm { padding: 5px 12px; font-size: 0.85em; }
.btn-lg { padding: 12px 22px; font-size: 1em; }
.btn-block { width: 100%; }
.btn .icon { width: 16px; height: 16px; }
.btn.is-loading { position: relative; color: transparent; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
.link-btn:hover { text-decoration: underline; }

/* ---------------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------------- */
form.stack { display: grid; gap: 14px; max-width: 640px; }
form.stack.wide { max-width: none; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; align-items: start; }
label { display: grid; gap: 5px; align-content: start; font-weight: 600; font-size: 0.9em; color: var(--text-2); }
.hint { font-weight: 400; font-size: 0.86em; color: var(--muted); line-height: 1.45; }
label.check { grid-template-columns: auto 1fr; align-items: center; column-gap: 8px; row-gap: 3px; font-weight: 500; }
label.check input { margin: 0; }
label.check .hint { grid-column: 2; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: grid; gap: 12px; margin: 0; min-width: 0; }
legend { font-weight: 700; padding: 0 6px; font-size: 0.9em; color: var(--text-2); }
fieldset.plain { border: 0; padding: 0; }
input, select, textarea { font: inherit; color: var(--text); padding: 8px 12px; border: 1px solid var(--border-input); border-radius: var(--radius-sm); background: var(--surface); width: 100%; transition: border-color 0.12s, box-shadow 0.12s; min-width: 0; }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }
input[type="file"] { padding: 6px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
textarea { min-height: 96px; resize: vertical; }
select { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; cursor: pointer; }
.form-actions { display: flex; align-items: center; gap: 12px; border-top: 1px solid var(--border); padding-top: 14px; flex-wrap: wrap; }
.repeat-list { display: grid; gap: 8px; }
.repeat-row { display: grid; grid-template-columns: 140px 1fr 140px auto; gap: 8px; align-items: center; }
.repeat-row.two { grid-template-columns: 160px 1fr auto; }
.radio-group { display: flex; gap: 6px 18px; flex-wrap: wrap; }
label.radio { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.segmented { display: inline-flex; justify-self: start; width: fit-content; background: var(--surface-alt); border: 1px solid var(--border-input); border-radius: 9999px; padding: 3px; gap: 3px; }
.segmented label { position: relative; display: flex; }
.segmented input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.segmented span { padding: 6px 14px; border-radius: 9999px; font-size: 0.9em; font-weight: 500; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

/* Filters above a list */
.filter-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.filter-row label { gap: 4px; min-width: 140px; }
.filter-row label.check { min-width: 0; }
.filter-row .search { flex: 1; min-width: 200px; }
.filter-row .btn { align-self: flex-end; }
.filter-clear { font-size: 0.9em; color: var(--muted); padding: 8px 4px; align-self: flex-end; }

/* ---------------------------------------------------------------------------
   Badges, chips, avatars, lists, tables
   --------------------------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 9999px; font-size: 0.76em; font-weight: 600; white-space: nowrap; background: var(--neutral-bg); color: var(--neutral); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-accent { background: var(--accent-bg); color: var(--accent-hover); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px 3px 7px; border-radius: 9999px; border: 1px solid var(--border); background: var(--surface-alt); color: var(--text-2); font-size: 0.82em; font-weight: 500; white-space: nowrap; }
.chip .icon { width: 14px; height: 14px; color: var(--accent-hover); }
a.chip:hover { border-color: var(--accent); color: var(--accent-hover); text-decoration: none; }
.chip-toggle { cursor: pointer; user-select: none; }
.chip-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip-toggle.is-on { background: var(--accent-bg); border-color: var(--accent); color: var(--accent-hover); }
.chip-toggle:hover { border-color: var(--accent); }
.chip-toggle:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--accent-ring); }
.chips-select { gap: 8px; }
.chips-select .chip { padding: 6px 12px 6px 9px; font-size: 0.88em; position: relative; }
.avatar { border-radius: 50%; background: var(--avatar-bg); color: #fff; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; object-fit: cover; overflow: hidden; }
.avatar-sm { width: 28px; height: 28px; font-size: 0.7em; }
.avatar-md { width: 40px; height: 40px; font-size: 0.9em; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.2em; }
.avatar-xl { width: 96px; height: 96px; font-size: 2em; }
.user-link { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.user-link:hover { text-decoration: none; color: var(--accent-hover); }
.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--border); }
.list-item:first-child { border-top: 0; padding-top: 0; }
.list-item:last-child { padding-bottom: 0; }
.list-item .grow { min-width: 0; }
.list-item-title { font-weight: 600; color: var(--text); }
.list-item-title:hover { color: var(--accent-hover); text-decoration: none; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 0.84em; align-items: center; }
.meta .icon { width: 14px; height: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 0.92em; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 18px; }
.page-link { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 34px; padding: 0 8px; border-radius: 9999px; border: 1px solid var(--border); color: var(--text-2); font-weight: 500; font-size: 0.9em; background: var(--surface); }
.page-link:hover { border-color: var(--accent); color: var(--accent-hover); text-decoration: none; }
.page-current { background: var(--accent); border-color: var(--accent); color: #fff; }
.stat { display: grid; gap: 2px; }
.stat-value { font-size: 1.7em; font-weight: 600; color: var(--navy); letter-spacing: -0.02em; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 0.85em; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; }

/* ---------------------------------------------------------------------------
   Requests
   --------------------------------------------------------------------------- */
.request-list { display: grid; gap: 12px; }
.request-card { display: grid; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm); transition: border-color 0.12s; }
.request-card:hover { border-color: var(--muted-2); }
.request-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.request-card-title { font-size: 1.05em; font-weight: 600; color: var(--text); }
.request-card-title:hover { color: var(--accent-hover); text-decoration: none; }
.request-card-desc { color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.volunteer-list { display: grid; gap: 8px; }
.volunteer-row { display: flex; align-items: center; gap: 10px; }
.volunteer-row .grow { min-width: 0; }
.detail-list { display: grid; gap: 10px; }
.detail-list dt { font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.detail-list dd { margin: 2px 0 0; }
.prose { overflow-wrap: anywhere; }
.prose ul, .prose ol { margin: 0 0 0.75em; padding-left: 22px; }
.prose blockquote { margin: 0 0 0.75em; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.prose a { text-decoration: underline; }

/* Comment / message threads */
.thread { display: grid; gap: 14px; }
.comment { display: flex; gap: 10px; }
.comment-body { flex: 1; min-width: 0; }
.comment-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.comment-head .muted { font-size: 0.82em; }
.comment-text { background: var(--surface-alt); border: 1px solid var(--border); border-radius: 0 14px 14px 14px; padding: 8px 12px; margin-top: 4px; }
.comment-actions { display: flex; gap: 8px; margin-top: 4px; font-size: 0.82em; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.attachment { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); font-size: 0.85em; color: var(--text-2); max-width: 260px; }
.attachment span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment:hover { border-color: var(--accent); text-decoration: none; }
.attachment-image { display: block; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); max-width: 260px; }
.attachment-image img { display: block; max-height: 220px; width: auto; }

/* Composer (comments and chat) */
.composer { display: grid; gap: 8px; }
.composer textarea { min-height: 64px; }
.composer-bar { display: flex; align-items: center; gap: 6px; }
.composer-bar .grow { flex: 1; }
.composer-hint { font-size: 0.8em; color: var(--muted-2); }
.emoji-wrap { position: relative; }
.emoji-panel { position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 30; width: 296px; max-width: calc(100vw - 32px); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-md); padding: 8px; display: grid; gap: 6px; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; max-height: 220px; overflow-y: auto; }
.emoji-grid button { background: transparent; border: 0; font-size: 1.3em; padding: 4px; border-radius: 6px; cursor: pointer; line-height: 1.2; }
.emoji-grid button:hover { background: var(--neutral-bg); }
.emoji-cat { font-size: 0.7em; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); grid-column: 1 / -1; padding: 6px 4px 2px; }
.file-picked { font-size: 0.82em; color: var(--muted); }

/* ---------------------------------------------------------------------------
   Chat
   --------------------------------------------------------------------------- */
.chat-layout { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
.conversation-list { display: flex; flex-direction: column; }
.conversation { display: flex; gap: 10px; align-items: center; padding: 10px 8px; border-radius: 8px; color: var(--text); }
.conversation:hover { background: var(--surface-alt); text-decoration: none; }
.conversation.active { background: var(--accent-bg); }
.conversation .grow { min-width: 0; }
.conversation-name { font-weight: 600; display: flex; align-items: center; gap: 6px; min-width: 0; }
.conversation-name > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-name .icon { width: 14px; height: 14px; color: var(--muted); }
.conversation-preview { color: var(--muted); font-size: 0.85em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation.unread .conversation-name { color: var(--accent-hover); }
.conversation.unread .conversation-preview { color: var(--text); font-weight: 500; }
.chat { display: flex; flex-direction: column; height: calc(100vh - 140px); min-height: 420px; }
.chat-head { display: flex; align-items: center; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding: 4px 2px; }
.msg { display: flex; gap: 8px; max-width: 80%; align-items: flex-end; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-bubble { background: var(--surface-alt); border: 1px solid var(--border); border-radius: 16px 16px 16px 4px; padding: 7px 11px; min-width: 0; }
.msg.mine .msg-bubble { background: var(--msg-mine-bg); color: var(--msg-mine-text); border-color: transparent; border-radius: 16px 16px 4px 16px; }
.msg-meta { font-size: 0.74em; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; }
.msg.mine .msg-meta { justify-content: flex-end; }
.msg-sender { font-size: 0.78em; font-weight: 600; color: var(--accent-hover); margin-bottom: 2px; }
.msg-day { text-align: center; font-size: 0.75em; color: var(--muted); margin: 10px 0 4px; }
.chat-composer { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 6px; }
.load-earlier { text-align: center; }
@media (max-width: 900px) {
  .chat-layout { grid-template-columns: 1fr; }
  .chat-layout.has-open .conversation-panel { display: none; }
  .chat { height: calc(100vh - 150px); }
  .msg { max-width: 92%; }
}

/* ---------------------------------------------------------------------------
   Notifications
   --------------------------------------------------------------------------- */
.notif { display: flex; gap: 12px; align-items: flex-start; padding: 12px 10px; border-radius: 8px; color: var(--text); }
.notif:hover { background: var(--surface-alt); text-decoration: none; }
.notif.unread { background: var(--accent-bg); }
.notif-icon { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-bg); display: flex; align-items: center; justify-content: center; color: var(--accent-hover); flex-shrink: 0; }
.notif-text { flex: 1; min-width: 0; }
.notif-time { font-size: 0.8em; color: var(--muted); white-space: nowrap; }

/* ---------------------------------------------------------------------------
   Profile
   --------------------------------------------------------------------------- */
.profile-head { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.profile-head .grow { min-width: 200px; }
.profile-name { font-size: 1.4em; font-weight: 700; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.contact-list { display: grid; gap: 6px; }
.contact-list a, .contact-list span.item { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); }
.social-links { display: flex; flex-wrap: wrap; gap: 6px; }
.social-links a { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px; color: var(--text-2); font-size: 0.86em; }
.social-links a:hover { border-color: var(--accent); color: var(--accent-hover); text-decoration: none; }
.availability { display: inline-flex; align-items: center; gap: 5px; font-size: 0.82em; font-weight: 600; }
.availability::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); }
.availability.available::before { background: #22c55e; }
.availability.busy::before { background: #f59e0b; }
.availability.away::before { background: #94a3b8; }
.photo-upload { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.person-card { display: flex; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-sm); }
.person-card .grow { min-width: 0; }
.person-card:hover { border-color: var(--muted-2); }
.person-name { font-weight: 600; color: var(--text); font-size: 1.02em; }
.person-name:hover { color: var(--accent-hover); text-decoration: none; }
.people-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.invite-box { display: flex; gap: 8px; align-items: center; }
.invite-box input { font-family: ui-monospace, monospace; font-size: 0.9em; }

/* ---------------------------------------------------------------------------
   Map
   --------------------------------------------------------------------------- */
.map { width: 100%; height: calc(100vh - 200px); min-height: 360px; border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; background: var(--surface-alt); }
.map-mini { height: 260px; }
.map-marker { width: 40px; height: 40px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35); background: var(--avatar-bg); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 0.85em; overflow: hidden; }
.map-marker img { width: 100%; height: 100%; object-fit: cover; }
.map-marker.request { background: var(--brand-gradient); border-radius: 12px; }
.map-marker.request .icon { width: 20px; height: 20px; }
.map-marker.me { border-color: #facc15; }
.leaflet-popup-content { margin: 12px 14px; font: inherit; font-size: 0.9em; }
.leaflet-popup-content-wrapper { border-radius: 8px; }
.map-popup { display: grid; gap: 6px; min-width: 200px; }
.map-popup .chips { gap: 4px; }
.map-popup .chip { font-size: 0.78em; }
.map-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
:root[data-theme="dark"] .leaflet-tile { filter: brightness(0.7) contrast(1.05) saturate(0.85); }
:root[data-theme="dark"] .leaflet-popup-content-wrapper, :root[data-theme="dark"] .leaflet-popup-tip { background: var(--surface); color: var(--text); }
:root[data-theme="dark"] .leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--border); }

/* ---------------------------------------------------------------------------
   Dialog
   --------------------------------------------------------------------------- */
dialog { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); padding: 20px; max-width: 520px; width: calc(100% - 32px); box-shadow: var(--shadow-md); }
dialog::backdrop { background: var(--overlay); }
dialog h2 { margin-bottom: 12px; }

/* ---------------------------------------------------------------------------
   Auth pages
   --------------------------------------------------------------------------- */
.auth-body { display: block; }
.auth-main { max-width: 420px; margin: 60px auto; padding: 0 16px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.3em; margin-bottom: 20px; justify-content: center; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px; box-shadow: var(--shadow-sm); display: grid; gap: 14px; }
.auth-card h1 { margin: 0; font-size: 1.3em; }
.auth-footer { text-align: center; font-size: 0.9em; color: var(--muted); }
.auth-locales { display: flex; justify-content: center; gap: 12px; margin-top: 18px; font-size: 0.85em; flex-wrap: wrap; }
.auth-locales a { color: var(--muted); }
.auth-locales a.is-current { color: var(--text); font-weight: 600; }

/* ---------------------------------------------------------------------------
   htmx and motion
   --------------------------------------------------------------------------- */
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-indicator { display: none; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--accent-ring); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 1.4s !important; } }

@media (max-width: 768px) {
  .grid-2 { grid-template-columns: 1fr; }
  .repeat-row, .repeat-row.two { grid-template-columns: 1fr; }
  .repeat-row > button { justify-self: start; }
  .map { height: calc(100vh - 170px); }
  .card { padding: 16px; }
  table { font-size: 0.85em; }
  th, td { padding: 7px 8px; }
}

/* Per-language editor */
.locale-switch span { position: relative; padding: 6px 12px; font-weight: 600; letter-spacing: 0.04em; }
.locale-dot { position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }
.mobile-only { display: none; }
@media (max-width: 900px) { .mobile-only { display: inline-flex; } }

/* Dashboard: two even columns on desktop */
.grid.grid-dash { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid.grid-dash { grid-template-columns: 1fr; } }
