/* ===========================================================================
   Choreo — application design system
   Dark navigation rail + light, airy content. Indigo accent, Inter type.
   =========================================================================== */

:root {
  /* Brand / accent */
  --accent: #6366f1;
  --accent-600: #4f46e5;
  --accent-700: #4338ca;
  --accent-soft: rgba(99, 102, 241, .10);
  --accent-ring: rgba(99, 102, 241, .35);

  /* Content surfaces (light) */
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e8e9ef;
  --border-strong: #d7d9e3;

  /* Text */
  --text: #1b1e2b;
  --text-muted: #6b7180;
  --text-faint: #9aa0ad;

  /* Status */
  --ok: #0fa968;
  --ok-soft: rgba(15, 169, 104, .12);
  --bad: #e5484d;
  --bad-soft: rgba(229, 72, 77, .10);
  --warn: #d9870b;

  /* Navigation rail (dark) */
  --rail-bg: #14161f;
  --rail-bg-2: #1a1d28;
  --rail-border: #262a38;
  --rail-text: #c4c8d4;
  --rail-muted: #7e8499;
  --rail-active: rgba(99, 102, 241, .16);

  /* Shape & depth */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 6px 20px -6px rgba(16, 24, 40, .12), 0 2px 6px -2px rgba(16, 24, 40, .06);
  --shadow-pop: 0 16px 40px -12px rgba(16, 24, 40, .22);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent-600); }

h1, h2, h3 { line-height: 1.25; letter-spacing: -.01em; font-weight: 650; }

::selection { background: var(--accent-ring); }

/* ───────────────────────────── App shell ───────────────────────────────── */

body.has-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 252px;
  min-width: 252px;
  background: linear-gradient(180deg, var(--rail-bg-2), var(--rail-bg));
  border-right: 1px solid var(--rail-border);
  color: var(--rail-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 20px 18px;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: .98rem;
  line-height: 1.2;
  letter-spacing: -.01em;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), #8b5cf6);
  box-shadow: 0 4px 12px -2px var(--accent-ring);
  flex-shrink: 0;
}
.brand-mark svg { width: 19px; height: 19px; display: block; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 12px; }

.nav-section-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--rail-muted);
  font-weight: 600;
  padding: 16px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--rail-text);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 500;
  transition: background .12s, color .12s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .8; }
.nav-item:hover { background: var(--rail-bg-2); color: #fff; }
.nav-item.active { background: var(--rail-active); color: #fff; }
.nav-item.active svg { opacity: 1; color: #a5b4fc; }

.sidebar-footer {
  border-top: 1px solid var(--rail-border);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-chip { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), #8b5cf6);
  color: #fff; font-weight: 650; font-size: .8rem;
}
.user-meta { min-width: 0; line-height: 1.25; }
.user-name { color: #fff; font-size: .85rem; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: var(--rail-muted); font-size: .72rem; text-transform: capitalize; }
.logout-form { display: inline; margin: 0; }
.icon-btn {
  background: none; border: 1px solid transparent; color: var(--rail-muted);
  cursor: pointer; padding: 7px; border-radius: var(--radius-sm); display: grid; place-items: center;
  transition: background .12s, color .12s;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--rail-bg-2); color: #fff; }

.app-main { flex: 1; min-width: 0; }
.content { max-width: 860px; margin: 0 auto; padding: 44px 32px 64px; }

/* ─────────────────────────── Auth (no shell) ───────────────────────────── */

body.auth-body {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 520px at 50% -10%, rgba(99, 102, 241, .10), transparent 70%),
    var(--bg);
}
body.auth-body .content { padding: 0; max-width: 420px; width: 100%; }
.auth-brand {
  display: flex; align-items: center; justify-content: center; gap: 11px;
  margin-bottom: 22px; font-weight: 700; font-size: 1.2rem; color: var(--text);
}

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

.auth-card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}
.auth-card { max-width: 420px; margin: 0 auto; }
.panel { padding: 28px 28px 30px; }

.panel > h1, .auth-card > h1 { font-size: 1.45rem; margin-bottom: 4px; }
.auth-card > h1 { margin-bottom: 14px; }
.panel-sub { color: var(--text-muted); font-size: .92rem; margin-bottom: 20px; }

/* ──────────────────────────── Typography utils ─────────────────────────── */

.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .82rem; }
.nowrap { white-space: nowrap; }
.ok { color: var(--ok); font-weight: 600; }
.bad { color: var(--bad); font-weight: 600; }
.empty { margin-top: 18px; color: var(--text-muted); }

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

.stack { display: flex; flex-direction: column; gap: 16px; margin-top: 18px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; }
.stack label > span { color: var(--text); font-weight: 550; font-size: .85rem; }
.stack label > small { color: var(--text-faint); }

input, select, textarea { font-family: inherit; }

.stack input, .stack select,
.newdance input, .dance-search, .copyfield,
.role-select, .audit-filter select,
.chip-add-form input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: .95rem;
  transition: border-color .12s, box-shadow .12s;
}
.stack input::placeholder, .newdance input::placeholder, .dance-search::placeholder { color: var(--text-faint); }
.stack input:focus, .stack select:focus,
.newdance input:focus, .dance-search:focus,
.role-select:focus, .audit-filter select:focus, .groupadd:focus,
.chip-add-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  font-size: .92rem;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
  transition: background .12s, box-shadow .12s, transform .04s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--accent-600); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
a.btn { display: inline-flex; }
.stack > .btn { width: 100%; padding: 11px 16px; }

.btn-ghost {
  background: var(--surface); color: var(--text); border-color: var(--border-strong);
  box-shadow: none;
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--text-faint); }

/* Quiet text-style action button (delete / revoke / logout etc.) */
.linkbtn {
  background: none; border: none; padding: 4px 6px; cursor: pointer;
  color: var(--text-muted); font-size: .85rem; font-family: inherit; font-weight: 550;
  border-radius: 6px; transition: background .12s, color .12s;
}
.linkbtn:hover { color: var(--text); background: var(--surface-2); }
.linkbtn.danger { color: #c4474b; }
.linkbtn.danger:hover { color: #fff; background: var(--bad); }

.form-error {
  background: var(--bad-soft); border: 1px solid rgba(229, 72, 77, .35);
  color: #b3373b; padding: 10px 12px; border-radius: var(--radius-sm); font-size: .9rem;
}

/* ─────────────────────── Dance browser / lists ─────────────────────────── */

.dances-panel { max-width: 720px; }

.newdance { display: flex; gap: 10px; margin: 18px 0 10px; }
.newdance input { flex: 1; }
.newdance .btn { flex-shrink: 0; }

.dance-search-bar { position: relative; margin: 16px 0 4px; }
.dance-search-bar::before {
  content: ""; position: absolute; left: 13px; top: 50%; width: 16px; height: 16px;
  transform: translateY(-50%); pointer-events: none; opacity: .5;
  background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7180' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
}
.dance-search { padding-left: 38px; }

/* Filter toolbar: a clearly-framed control panel — search + class/event chips */
.browse-toolbar {
  margin: 18px 0 16px;
  padding: 16px 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.browse-toolbar .dance-search-bar { margin: 0; }

.filter-group { display: flex; align-items: flex-start; gap: 12px; }
.filter-group-label {
  flex: 0 0 auto; width: 52px; padding-top: 7px;
  font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); font-weight: 650;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.chip {
  padding: 6px 14px; border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: .85rem; font-weight: 550; font-family: inherit;
  cursor: pointer; white-space: nowrap; transition: all .12s;
}
.chip:hover { border-color: var(--accent); color: var(--accent-600); }
.chip.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 2px 8px -2px var(--accent-ring);
}
.chip.active:hover { color: #fff; }

/* "+ New" chip reveals a small inline create popover */
.chip-add { position: relative; }
.chip-add > summary { list-style: none; display: inline-block; }
.chip-add > summary::-webkit-details-marker { display: none; }
.chip.add { border-style: dashed; color: var(--text-muted); }
.chip.add:hover { color: var(--accent-600); border-color: var(--accent); }
.chip-add[open] > summary .chip.add,
.chip-add[open] > summary.chip.add { color: var(--accent-600); border-color: var(--accent); }
.chip-add-form {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 10;
  display: flex; gap: 6px; padding: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-pop);
}
.chip-add-form input { width: 170px; padding: 8px 10px; font-size: .85rem; }
.btn-sm { padding: 8px 12px; font-size: .82rem; }

.result-count { font-size: .82rem; color: var(--text-muted); font-weight: 550; margin: 4px 0 12px; }

.dance-list { list-style: none; margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.dance-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color .12s, box-shadow .12s, transform .06s;
}
.dance-row:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.dance-open {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px;
  text-decoration: none; color: var(--text);
}
.dance-name { font-weight: 600; font-size: .98rem; }
.dance-open:hover .dance-name { color: var(--accent-600); }
.dance-meta { font-size: .8rem; color: var(--text-muted); }

.crumb { margin-bottom: 12px; font-size: .85rem; }
.crumb a { color: var(--text-muted); text-decoration: none; font-weight: 550; }
.crumb a:hover { color: var(--accent-600); }

/* Class/event chips + assign selector inside a row */
.dance-groups { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: 300px; justify-content: flex-end; }
.groupchip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 6px 3px 10px; border-radius: var(--radius-pill); font-size: .76rem; font-weight: 550;
  border: 1px solid transparent;
}
.groupchip.class { background: rgba(56, 132, 222, .10); color: #2a6fb0; border-color: rgba(56, 132, 222, .22); }
.groupchip.event { background: rgba(217, 135, 11, .12); color: #b5710a; border-color: rgba(217, 135, 11, .25); }
.tagx {
  border: none; background: none; cursor: pointer; padding: 0; line-height: 1;
  color: currentColor; opacity: .55; font-size: 1rem; display: grid; place-items: center;
  width: 16px; height: 16px; border-radius: 50%;
}
.tagx:hover { opacity: 1; background: rgba(0, 0, 0, .08); }
.groupadd {
  padding: 4px 10px; border-radius: var(--radius-pill); font-size: .76rem; font-weight: 550;
  border: 1px dashed var(--border-strong); background: var(--surface); color: var(--text-muted);
  cursor: pointer;
}
.groupadd:hover { border-color: var(--accent); color: var(--accent-600); }

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

.admin-panel { max-width: 920px; }
.audit-panel { max-width: 980px; }
.admin-subhead { font-size: 1.05rem; margin: 28px 0 4px; font-weight: 650; }

.table-wrap {
  margin-top: 16px; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-sm);
}
.admin-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.admin-table th, .admin-table td {
  text-align: left; padding: 12px 16px; vertical-align: middle;
}
.admin-table thead th {
  color: var(--text-muted); font-weight: 600; font-size: .72rem;
  text-transform: uppercase; letter-spacing: .05em;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.admin-table tbody tr { border-bottom: 1px solid var(--border); background: var(--surface); }
.admin-table tbody tr:last-child { border-bottom: none; }
.admin-table tbody tr:hover { background: var(--surface-2); }
.admin-table .row-actions { text-align: right; white-space: nowrap; }
.admin-table .mono { font-size: .8rem; color: var(--text-muted); }

.role-select { width: auto; padding: 6px 10px; font-size: .85rem; }
.role-static { font-size: .88rem; text-transform: capitalize; color: var(--text-muted); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--radius-pill); font-size: .74rem; font-weight: 600;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.open { color: var(--ok); background: var(--ok-soft); border-color: rgba(15, 169, 104, .25); }
.badge.used { color: var(--text-faint); }
.badge.used::before { display: none; }
/* Audit action badge: monospace pill, no status dot */
.audit-table .badge { font-family: var(--mono); font-size: .76rem; font-weight: 550; color: var(--accent-600); background: var(--accent-soft); border-color: rgba(99, 102, 241, .2); }
.audit-table .badge::before { display: none; }

/* Audit viewer */
.audit-filter { margin: 18px 0 4px; max-width: 260px; }
.audit-filter label { display: flex; flex-direction: column; gap: 6px; }
.audit-table td { vertical-align: top; }

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 22px; }
.pager-btn { padding: 8px 14px; font-size: .85rem; }
.pager-btn.disabled {
  opacity: .45; pointer-events: none; background: var(--surface); color: var(--text-faint);
  border: 1px solid var(--border); box-shadow: none;
}

/* Invite result */
.invite-result { margin-top: 18px; }
.invite-link {
  margin-top: 16px; padding: 16px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid rgba(99, 102, 241, .2);
}
.invite-link .copyfield {
  margin-top: 8px; color: var(--accent-700); font-family: var(--mono); font-size: .82rem; cursor: pointer;
}

/* ───────────────────────────── Responsive ──────────────────────────────── */

@media (max-width: 720px) {
  body.has-shell { flex-direction: column; }
  .sidebar {
    width: 100%; min-width: 0; height: auto; position: static; flex-direction: row;
    align-items: center; border-right: none; border-bottom: 1px solid var(--rail-border);
  }
  .sidebar-brand { padding: 14px 16px; }
  .sidebar-nav { display: flex; gap: 2px; padding: 8px; overflow-x: auto; }
  .nav-section-label { display: none; }
  .nav-item span { display: none; }
  .nav-item { padding: 9px; }
  .sidebar-footer { border-top: none; border-left: 1px solid var(--rail-border); }
  .user-meta { display: none; }
  .content { padding: 28px 18px 48px; }
}
