/* =========================================================================
   BNI Speaker Roster — corporate design system
   Token-driven light/dark theme. Theme is switched via [data-theme] on <html>
   (see the no-flash script and toggle in base.html / app.js). When no explicit
   choice is stored, prefers-color-scheme decides.
   ========================================================================= */

:root {
  /* Brand */
  --brand: #c0202e;
  --brand-strong: #9d1723;
  --brand-soft: #fdecec;
  --brand-contrast: #ffffff;

  /* Accent (slate / corporate blue) */
  --accent: #2f5e8c;
  --accent-strong: #244a6f;

  /* Neutrals — light theme */
  --bg: #eef1f5;
  --bg-grad-1: #eef1f5;
  --bg-grad-2: #e6eaf0;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef2f7;
  --elevated: #ffffff;

  --text: #17202b;
  --text-muted: #5c6b7c;
  --text-faint: #8695a5;

  --line: #e2e8f0;
  --line-strong: #cdd7e3;

  /* States */
  --draft-bg: #fff8e6;
  --draft-border: #f4d98a;
  --draft-text: #8a6100;
  --warn: #c0392b;
  --warn-bg: #fdecec;
  --success: #1f9d6b;

  /* Effects */
  --radius: 14px;
  --radius-sm: 9px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(20, 32, 48, 0.06), 0 1px 3px rgba(20, 32, 48, 0.05);
  --shadow-md: 0 4px 14px rgba(20, 32, 48, 0.08), 0 2px 6px rgba(20, 32, 48, 0.05);
  --shadow-lg: 0 18px 44px rgba(20, 32, 48, 0.14);
  --ring: 0 0 0 3px rgba(47, 94, 140, 0.28);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark theme — explicit choice */
:root[data-theme="dark"] {
  --brand: #f0555c;
  --brand-strong: #f6767c;
  --brand-soft: #35191d;
  --brand-contrast: #1a1113;

  --accent: #6aa5da;
  --accent-strong: #8bbbe6;

  --bg: #0e131a;
  --bg-grad-1: #0e131a;
  --bg-grad-2: #131a24;
  --surface: #171e28;
  --surface-2: #1c242f;
  --surface-3: #222c39;
  --elevated: #1b232e;

  --text: #e7edf4;
  --text-muted: #9fb0c1;
  --text-faint: #74879a;

  --line: #2a333f;
  --line-strong: #37424f;

  --draft-bg: #2c2410;
  --draft-border: #5c4a1a;
  --draft-text: #f2ce7a;
  --warn: #f4837a;
  --warn-bg: #351a1a;
  --success: #46c88f;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55);
  --ring: 0 0 0 3px rgba(106, 165, 218, 0.34);
  color-scheme: dark;
}

/* Dark theme — system preference, when no explicit choice is stored */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #f0555c;
    --brand-strong: #f6767c;
    --brand-soft: #35191d;
    --brand-contrast: #1a1113;

    --accent: #6aa5da;
    --accent-strong: #8bbbe6;

    --bg: #0e131a;
    --bg-grad-1: #0e131a;
    --bg-grad-2: #131a24;
    --surface: #171e28;
    --surface-2: #1c242f;
    --surface-3: #222c39;
    --elevated: #1b232e;

    --text: #e7edf4;
    --text-muted: #9fb0c1;
    --text-faint: #74879a;

    --line: #2a333f;
    --line-strong: #37424f;

    --draft-bg: #2c2410;
    --draft-border: #5c4a1a;
    --draft-text: #f2ce7a;
    --warn: #f4837a;
    --warn-bg: #351a1a;
    --success: #46c88f;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55);
    --ring: 0 0 0 3px rgba(106, 165, 218, 0.34);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--bg-grad-2), transparent 60%),
    linear-gradient(180deg, var(--bg-grad-1), var(--bg-grad-2));
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
  color: var(--text);
}

/* ===================== Top bar ===================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px clamp(16px, 4vw, 44px);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(140%) blur(10px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(160deg, var(--brand), var(--brand-strong));
  color: var(--brand-contrast);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-sm);
  flex: 0 0 auto;
}

.brand-text {
  min-width: 0;
}

.brand-text .eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brand);
}

.brand-text h1 {
  font-size: 19px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.account {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.account .avatar {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.account .admin-chip {
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 11px;
  font-weight: 700;
}

/* ===================== Theme toggle (sun / moon slider) ===================== */

.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0;
  width: 62px;
  height: 32px;
  padding: 3px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  flex: 0 0 auto;
}

.theme-toggle:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.theme-toggle .track-icon {
  flex: 1 1 0;
  display: grid;
  place-items: center;
  color: var(--text-faint);
  transition: color var(--transition);
  z-index: 1;
}

.theme-toggle .track-icon svg {
  width: 15px;
  height: 15px;
  display: block;
}

.theme-toggle .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition);
}

/* Light = knob left, sun lit. Dark = knob right, moon lit. */
:root[data-theme="dark"] .theme-toggle .knob {
  transform: translateX(30px);
}
:root[data-theme="dark"] .theme-toggle .icon-moon {
  color: var(--brand);
}
:root[data-theme="light"] .theme-toggle .icon-sun {
  color: #e8a516;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .knob {
    transform: translateX(30px);
  }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon {
    color: var(--brand);
  }
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .theme-toggle .icon-sun {
    color: #e8a516;
  }
}

/* ===================== Buttons ===================== */

.btn,
button {
  font: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: transform var(--transition), box-shadow var(--transition),
    background var(--transition), border-color var(--transition), color var(--transition);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.btn-primary {
  background: linear-gradient(180deg, var(--brand), var(--brand-strong));
  color: var(--brand-contrast);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  box-shadow: var(--shadow-md);
  filter: brightness(1.04);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--line);
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger {
  background: transparent;
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
}
.btn-danger:hover {
  background: var(--warn-bg);
  border-color: var(--warn);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
  filter: none;
  transform: none;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

/* ===================== Layout ===================== */

main {
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(20px, 3vw, 34px) clamp(16px, 4vw, 44px) 64px;
  display: grid;
  gap: clamp(18px, 2.4vw, 26px);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px clamp(16px, 2.4vw, 24px);
  border-bottom: 1px solid var(--line);
}

.card-head .title-group {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.card-head h2 {
  font-size: 17px;
  font-weight: 700;
}

.card-head .sub {
  font-size: 13px;
  color: var(--text-muted);
}

.section-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand);
  flex: 0 0 auto;
}
.section-icon svg {
  width: 18px;
  height: 18px;
}

.card-body {
  padding: clamp(14px, 2.2vw, 22px);
}
.card-body.flush {
  padding: 0;
}

/* ===================== Stats ===================== */

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(12px, 2vw, 18px);
}

.stat {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.stat .stat-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--surface-3);
  color: var(--accent);
  flex: 0 0 auto;
}
.stat .stat-icon svg {
  width: 22px;
  height: 22px;
}
.stat.accent-brand .stat-icon {
  background: var(--brand-soft);
  color: var(--brand);
}
.stat.accent-warn .stat-icon {
  background: var(--draft-bg);
  color: var(--draft-text);
}

.stat .value {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text);
}
.stat .label {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===================== Notices ===================== */

.notice {
  display: flex;
  gap: 14px;
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.notice.warn {
  border-color: var(--draft-border);
  background: var(--draft-bg);
}
.notice .notice-icon {
  flex: 0 0 auto;
  color: var(--brand);
}
.notice.warn .notice-icon {
  color: var(--draft-text);
}
.notice h2 {
  font-size: 15px;
  margin-bottom: 4px;
}
.notice p {
  margin: 0 0 4px;
  color: var(--text-muted);
  font-size: 14px;
}
.notice code {
  background: var(--surface-3);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 13px;
}

/* ===================== Tables ===================== */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 900px;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.roster-table tbody tr {
  transition: background var(--transition);
}
.roster-table tbody tr:hover {
  background: var(--surface-2);
}

tr.drafted {
  background: var(--draft-bg);
}
tr.drafted:hover {
  background: color-mix(in srgb, var(--draft-bg) 80%, var(--surface-2));
}

.col-handle {
  width: 40px;
  padding-right: 0;
}
.col-actions {
  width: 96px;
  text-align: right;
}

.date-cell {
  min-width: 132px;
}
.date-cell .weekday {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.date-cell .date {
  display: block;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.tag-draft {
  background: var(--draft-bg);
  color: var(--draft-text);
  border: 1px solid var(--draft-border);
}
.warning {
  display: block;
  font-size: 12px;
  color: var(--warn);
  margin-top: 4px;
}

/* Drag handle + drag states */
.drag-handle {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-faint);
  cursor: grab;
  transition: background var(--transition), color var(--transition);
}
.drag-handle:hover {
  background: var(--surface-3);
  color: var(--text);
}
.drag-handle:active {
  cursor: grabbing;
}
.drag-handle svg {
  width: 16px;
  height: 16px;
  pointer-events: none;
}
.drag-handle[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}
/* Row has unsaved edits — dragging is blocked until saved. */
.drag-handle.is-dirty {
  opacity: 0.4;
  cursor: not-allowed;
  color: var(--warn);
}
.drag-handle.is-dirty:hover {
  background: transparent;
}
.tag-unsaved {
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
}

tr.dragging {
  opacity: 0.45;
}
tr.drop-target {
  box-shadow: inset 0 0 0 2px var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

/* ===================== Form controls ===================== */

input[type="text"],
input:not([type]),
textarea,
input[list] {
  width: 100%;
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color var(--transition), box-shadow var(--transition),
    background var(--transition);
}
input:hover,
textarea:hover {
  border-color: var(--accent);
}
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
input::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}
textarea {
  resize: vertical;
  min-height: 40px;
  line-height: 1.4;
}

.speaker-input {
  min-width: 150px;
}
.notes-input {
  min-width: 190px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.check input {
  width: 17px;
  height: 17px;
  accent-color: var(--brand);
  cursor: pointer;
}

/* ===================== Members ===================== */

.member-add {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  padding: 16px;
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.member-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.member-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "name  msp"
    "acts  acts";
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.member-row input[name="name"] {
  grid-area: name;
}
.member-row .check {
  grid-area: msp;
}
.member-row .member-actions {
  grid-area: acts;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.empty {
  color: var(--text-muted);
  font-size: 14px;
  padding: 8px 0;
}

/* Small helper text under drag-enabled table */
.hint {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 12px clamp(16px, 2.4vw, 24px);
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.hint svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

/* Toast for drag feedback */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--surface);
  padding: 11px 18px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===================== Auth / login ===================== */

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  align-items: center;
  display: grid;
  justify-items: center;
  gap: 22px;
  text-align: center;
  width: min(430px, 100%);
  padding: 36px 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
}
.auth-panel.minimal {
  background: transparent;
  border: 0;
  box-shadow: none;
  margin-inline: auto;
}

.auth-topbar {
  position: absolute;
  top: 18px;
  right: 18px;
}

.brand-logo {
  display: block;
  object-fit: contain;
}
.auth-loop-logo {
  aspect-ratio: 5 / 7;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  height: auto;
  max-height: min(60vh, 460px);
  object-fit: cover;
  width: min(320px, 76vw);
}

.auth-brand-copy {
  display: grid;
  gap: 4px;
  justify-items: center;
  text-align: center;
}
.auth-brand-title {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--text);
}
.auth-brand-subtitle {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.auth-actions {
  display: flex;
  justify-content: center;
  margin: 0;
  width: 100%;
}
.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, var(--brand), var(--brand-strong));
  color: var(--brand-contrast);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--shadow-md);
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
}
.primary-action:hover {
  filter: brightness(1.05);
  box-shadow: var(--shadow-lg);
}
.primary-action:active {
  transform: translateY(1px);
}
.auth-user-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 50%;
  position: relative;
}
.auth-user-icon::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 9px;
  width: 10px;
  height: 7px;
  border: 2px solid currentColor;
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
}
.compact-notice {
  width: 100%;
  padding: 12px 14px;
}
.compact-notice p {
  margin: 0;
  font-size: 13px;
}

/* ===================== Responsive ===================== */

@media (max-width: 860px) {
  .stats {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .topbar {
    flex-wrap: wrap;
  }
  .brand-text h1 {
    font-size: 17px;
  }
  .member-add {
    grid-template-columns: 1fr;
  }
  .card-head {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
