/* Base UI kit: reset, shell, controls, dialogs. Board-specific rules live in
   board.css. No CSS framework - the swimlane layout would fight one. */

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.3; text-wrap: balance; }
p { margin: 0 0 0.75rem; text-wrap: pretty; }
a { color: var(--mms-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

::selection { background: var(--mms-primary-ring); }

:focus-visible {
  outline: 2px solid var(--mms-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Motion is a courtesy, never a toll. Anyone who asks the OS for less gets a
   still interface that still works - state changes land instantly. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── App shell ───────────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: var(--mms-primary);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
}

.nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-inline-start: 0.5rem;
}
.nav a {
  padding: 0.4rem 0.75rem;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
}
.nav a:hover { background: var(--surface-sunken); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--mms-primary-soft); color: var(--mms-primary-strong); }

.header-end { margin-inline-start: auto; display: flex; align-items: center; gap: 0.4rem; }

.page { padding: 1rem; }
.page-narrow { max-width: 880px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }

.page-head {
  display: flex; align-items: center; gap: 0.75rem;
  flex-wrap: wrap; margin-bottom: 1rem;
}
.page-head h1 { font-size: 1.25rem; }
.page-head .spacer { margin-inline-start: auto; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    background var(--dur-fast) var(--ease-out-quart),
    border-color var(--dur-fast) var(--ease-out-quart),
    color var(--dur-fast) var(--ease-out-quart),
    transform var(--dur-tap) var(--ease-out-quart);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-sunken); text-decoration: none; }
/* Press reads as the button taking the weight, not as a bounce. */
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--mms-primary);
  border-color: var(--mms-primary);
  color: var(--on-primary);
}
.btn-primary:hover { background: var(--mms-primary-strong); border-color: var(--mms-primary-strong); }

.btn-danger { color: var(--mms-danger); border-color: var(--border); }
.btn-danger:hover { background: var(--mms-danger-soft); }

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

.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.82rem; border-radius: var(--r-sm); }
.btn-icon { padding: 0.45rem; width: 34px; height: 34px; }
.btn-block { width: 100%; }

.icon { width: 18px; height: 18px; flex: none; stroke-width: 1.9; }
.btn-sm .icon { width: 15px; height: 15px; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.field { margin-bottom: 0.9rem; }
.field > label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-2);
}

.input, .select, .textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
}
.input, .select, .textarea {
  transition:
    border-color var(--dur-fast) var(--ease-out-quart),
    box-shadow var(--dur-fast) var(--ease-out-quart);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--mms-primary);
  box-shadow: 0 0 0 3px var(--mms-primary-ring);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.textarea { resize: vertical; min-height: 80px; }
/* A real chevron. The two-gradient triangle trick renders as a pair of stray
   pixels at this size and reads like a font-fallback glyph. */
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23636a7d' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 0.6rem center;
  background-size: 14px 14px;
  padding-inline-start: 2rem;
}
[data-theme="dark"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23878fa2' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
.hint { font-size: 0.8rem; color: var(--text-3); margin-top: 0.25rem; }

/* ── Chips, badges, avatars ──────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.12rem 0.5rem;
  border-radius: var(--r-full);
  font-size: 0.74rem;
  font-weight: 500;
  line-height: 1.7;
  background: var(--surface-sunken);
  color: var(--text-2);
  border: 1px solid transparent;
  white-space: nowrap;
}
.chip-late { background: var(--mms-danger-soft); color: var(--mms-danger); }
.chip-warn { background: var(--mms-warn-soft); color: #8a6300; }
[data-theme="dark"] .chip-warn { color: var(--mms-warn); }
.chip-date { background: var(--surface-sunken); color: var(--text-2); }
.chip-count { background: var(--mms-primary-soft); color: var(--mms-primary-strong); }

.avatar {
  width: 28px; height: 28px;
  border-radius: var(--r-full);
  display: grid; place-items: center;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  flex: none;
  letter-spacing: 0.02em;
}
.avatar-sm { width: 22px; height: 22px; font-size: 0.62rem; }
.avatar-lg { width: 38px; height: 38px; font-size: 0.85rem; }
.avatar-stack { display: flex; }
.avatar-stack .avatar + .avatar { margin-inline-start: -8px; border: 2px solid var(--surface); }

/* ── Cards & tables ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 1rem; }

.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td {
  padding: 0.6rem 0.75rem;
  text-align: start;
  border-bottom: 1px solid var(--border);
}
.table th { color: var(--text-2); font-weight: 500; font-size: 0.82rem; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

/* ── Flash messages & toasts ─────────────────────────────────────────────── */
.flash-stack {
  position: fixed;
  inset-block-start: calc(var(--header-h) + 0.6rem);
  inset-inline-end: 1rem;
  z-index: 90;
  display: flex; flex-direction: column; gap: 0.5rem;
  max-width: min(380px, calc(100vw - 2rem));
}
/* Status is carried by a dot and a tinted full border. A thick coloured bar
   down one edge is the single most recognisable machine-made tell; the dot
   reads the same at a glance and doesn't lopside the card. */
.flash {
  --flash-accent: var(--mms-primary);
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--flash-accent) 32%, var(--border));
  box-shadow: var(--shadow-md);
  font-size: 0.9rem;
  animation: flash-in var(--dur-base) var(--ease-out-quart);
}
.flash::before {
  content: '';
  inline-size: 8px;
  block-size: 8px;
  border-radius: 50%;
  background: var(--flash-accent);
  flex: none;
}
.flash-error { --flash-accent: var(--mms-danger); }
.flash-success { --flash-accent: var(--mms-success); }
.flash-info { --flash-accent: var(--mms-primary); }

@keyframes flash-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
}

/* ── Dialogs (native <dialog>) ───────────────────────────────────────────── */
dialog {
  border: none;
  padding: 0;
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  max-width: min(720px, calc(100vw - 2rem));
  width: 100%;
  max-height: min(86vh, 900px);
}
dialog::backdrop { background: rgba(10, 12, 20, 0.55); backdrop-filter: blur(3px); }

dialog[open] { animation: dialog-in var(--dur-base) var(--ease-out-quint); }
dialog[open]::backdrop { animation: backdrop-in var(--dur-base) var(--ease-out-quart); }

/* Closing is driven from JS: <dialog>.close() is instant, so the class buys
   the exit its frames. Exits run shorter than entrances - leaving should feel
   like getting out of the way. */
dialog.closing { animation: dialog-out calc(var(--dur-base) * 0.75) var(--ease-out-quart) forwards; }
dialog.closing::backdrop { animation: backdrop-out calc(var(--dur-base) * 0.75) var(--ease-out-quart) forwards; }

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
}
@keyframes dialog-out {
  to { opacity: 0; transform: translateY(6px) scale(0.99); }
}
@keyframes backdrop-in { from { opacity: 0; } }
@keyframes backdrop-out { to { opacity: 0; } }

.dialog-head {
  display: flex; align-items: flex-start; gap: 0.6rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
}
.dialog-body { padding: 1rem; overflow-y: auto; }
.dialog-foot {
  display: flex; gap: 0.5rem; justify-content: flex-end;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* ── Auth pages ──────────────────────────────────────────────────────────── */
/* Flat. The soft brand-tinted glow behind a centred login card is the stock
   look; a sign-in screen has one job and gains nothing from atmosphere. */
.auth-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: 1.75rem;
}
.auth-card h1 { font-size: 1.3rem; margin-bottom: 0.25rem; font-family: var(--font-display); }
.auth-card .sub { color: var(--text-2); font-size: 0.9rem; margin-bottom: 1.25rem; }
.auth-brand {
  display: flex; align-items: center; gap: 0.6rem;
  margin-bottom: 1.25rem;
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.small { font-size: 0.83rem; }
.strong { font-weight: 600; }
.row { display: flex; align-items: center; gap: 0.5rem; }
.row-wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-3);
  font-size: 0.9rem;
}

.error-page { display: grid; place-items: center; min-height: 70vh; text-align: center; }
.error-page .code { font-size: 3rem; font-weight: 700; color: var(--mms-primary); }

/* ── User menu ───────────────────────────────────────────────────────────── */
.user-menu { position: relative; }
.user-menu > summary {
  list-style: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 2px;
  border-radius: var(--r-full);
}
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover { background: var(--surface-sunken); }

.user-menu-panel {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 8px);
  width: 240px;
  z-index: 60;
  padding: 0.35rem;
  box-shadow: var(--shadow-md);
}
.user-menu-head { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); margin-bottom: 0.3rem; }
.user-menu-item {
  display: flex; align-items: center; gap: 0.5rem;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: 0.88rem;
  font-family: inherit;
  text-align: start;
  cursor: pointer;
}
.user-menu-item:hover { background: var(--surface-sunken); color: var(--text); text-decoration: none; }

/* ── Filters bar ─────────────────────────────────────────────────────────── */
.filters {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.filters .select { width: auto; min-width: 130px; padding-block: 0.4rem; font-size: 0.85rem; }
.filters-search { position: relative; display: flex; align-items: center; }
.filters-search .icon {
  position: absolute;
  inset-inline-start: 0.55rem;
  color: var(--text-3);
  pointer-events: none;
}
.filters-search .input {
  width: 210px;
  padding-block: 0.4rem;
  padding-inline-start: 2rem;
  font-size: 0.85rem;
}
.filter-toggle {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-size: 0.85rem;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  background: var(--surface);
}
.filter-toggle input { display: none; }
.filter-toggle.on { border-color: var(--mms-danger); color: var(--mms-danger); background: var(--mms-danger-soft); }

/* ── Bulk task push (team page) ──────────────────────────────────────────── */
.scope-choice { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.scope-option {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
  transition:
    border-color var(--dur-fast) var(--ease-out-quart),
    background var(--dur-fast) var(--ease-out-quart),
    color var(--dur-fast) var(--ease-out-quart);
}
.scope-option:has(input:checked) {
  border-color: var(--mms-primary);
  background: var(--mms-primary-soft);
  color: var(--mms-primary-strong);
}

/* The board picker only exists when you ask for specific boards. CSS :has()
   keeps this a plain form - no script to keep in sync with the markup. */
.push-targets { display: none; margin-top: 0.6rem; }
.push-form:has(#scope-some:checked) .push-targets { display: block; }
.push-targets .chip { cursor: pointer; padding: 0.3rem 0.6rem; }
.push-targets .chip:has(input:checked) {
  background: var(--mms-primary-soft);
  color: var(--mms-primary-strong);
}

/* Toast dismissal, driven by a class instead of inline styles so the timing
   lives with the rest of the motion. */
.flash.leaving {
  animation: flash-out calc(var(--dur-base) * 0.75) var(--ease-out-quart) forwards;
}
@keyframes flash-out {
  to { opacity: 0; transform: translateY(-6px) scale(0.98); }
}

/* Fingers are not cursors. On touch, small controls keep their drawn size but
   grow an invisible 44px hit area, which is the part that actually matters. */
@media (pointer: coarse) {
  .btn-icon,
  .task-check,
  .lane-switch button,
  .col-collapse,
  .lane-collapse {
    position: relative;
  }
  .btn-icon::after,
  .task-check::after,
  .lane-switch button::after,
  .col-collapse::after,
  .lane-collapse::after {
    content: '';
    position: absolute;
    inset: 50% auto auto 50%;
    translate: -50% -50%;
    min-inline-size: 44px;
    min-block-size: 44px;
    inline-size: 100%;
    block-size: 100%;
  }
}

@media (max-width: 720px) {
  .app-header { padding: 0 0.6rem; gap: 0.4rem; }
  .brand span { display: none; }
  .nav a { padding: 0.4rem 0.55rem; font-size: 0.86rem; }
  .page { padding: 0.6rem; }
}
