/* KTasks — ported from the legacy stella33-tasks-standalone artifact stylesheet.
 *
 * Every colour/radius/font the legacy file hard-coded is now derived from the
 * ten branding tokens of the /branding.css contract (PLAN §4):
 *
 *   --brand-primary --brand-accent --sidebar-bg --sidebar-text
 *   --page-bg --card-bg --text-main --text-muted --radius --font-family
 *
 * The defaults below reproduce the legacy look exactly. /branding.css is loaded
 * AFTER this file and re-declares the same ten names on a bare `:root`, so an
 * admin's values win by cascade order without touching any rule here.
 *
 * Everything else (surfaces, borders, faint text, sidebar shades, priority
 * chips, avatars) is color-mix()'d off those ten, so a dark token set produces
 * a coherent dark UI and a light one the legacy palette — which is why there is
 * no prefers-color-scheme block any more (see the note in app.js' header).
 */

:root {
  /* ---- the branding contract (defaults = the legacy look) ---- */
  --brand-primary: #94562B;
  --brand-accent: #7C4522;
  --sidebar-bg: #1B2C31;
  --sidebar-text: #D9DED3;
  --page-bg: #F5F4EE;
  --card-bg: #FFFFFF;
  --text-main: #1C2C31;
  --text-muted: #5B6B67;
  --radius: 10px;
  --font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* ---- fixed project palette (server: src/services/constants.js) ---- */
  --project-color-1: #94562B;
  --project-color-2: #4F7350;
  --project-color-3: #4A6FA0;
  --project-color-4: #8C7A3E;
  --project-color-5: #B5502F;
  --project-color-6: #5C7874;
  --project-color-7: #6B5B95;
  --project-color-8: #C77DA0;
  --project-color-9: #3E7C8C;
  --project-color-10: #A68A56;
}

:root {
  /* ---- legacy variables: direct aliases + literal fallbacks ----
     A custom property whose value fails to parse does NOT fall back to an
     earlier declaration (it goes invalid-at-computed-value-time at the point of
     use), so the literals below are the real safety net for browsers without
     color-mix(); the @supports block after this one re-derives them from the
     branding tokens wherever color-mix() is available. */
  --bg: var(--page-bg);
  --surface: var(--card-bg);
  --surface-raised: #FBFAF6;
  --surface-2: #ECEAE0;
  --border: #DAD8CB;
  --border-soft: #E7E5DA;
  --text: var(--text-main);
  --text-faint: #8A9490;

  --accent: var(--brand-primary);
  --accent-hover: var(--brand-accent);
  --accent-soft: #F3E4D6;
  --accent-contrast: #FFF9F3;

  --sidebar-bg-deep: #142327;
  --sidebar-text-muted: #93A29C;
  --sidebar-border: #2B3F44;

  /* Priority / status hues are semantic, not brand — they keep the legacy
     values; only their soft backgrounds follow the card colour. */
  --pri-low: #5C7874;
  --pri-low-bg: #E7ECE9;
  --pri-medium: #8C7A3E;
  --pri-medium-bg: #EFE9D3;
  --pri-high: #B5502F;
  --pri-high-bg: #F6E2D9;
  --status-done: #4F7350;
  --status-done-bg: #E1EADD;
  --status-watch: #4A6FA0;
  --status-watch-bg: #E1E7F0;

  --shadow-sm: 0 1px 2px rgba(20, 25, 20, 0.07);
  --shadow-md: 0 10px 28px rgba(20, 28, 25, 0.10);
  --focus-ring: #5C7874;

  /* 10px → 6 / 10 / 18, the legacy triple, from a single token. */
  --radius-sm: calc(var(--radius) * 0.6);
  --radius-md: var(--radius);
  --radius-lg: calc(var(--radius) * 1.8);

  --avt-1-bg: #F3E4D6; --avt-1-fg: #7C4522;
  --avt-2-bg: #DCE3E2; --avt-2-fg: #20343A;
  --avt-3-bg: #E7ECEA; --avt-3-fg: #4C5D5A;
  --avt-4-bg: #EDEAE0; --avt-4-fg: #6B664F;
  --avt-5-bg: #EFF1E8; --avt-5-fg: #5C6152;
}

/* Everything the legacy stylesheet hard-coded, re-derived from the ten tokens.
   Mixing towards --text-main / --card-bg rather than towards black or white is
   what lets a DARK token set produce a coherent dark UI from the same rules. */
@supports (color: color-mix(in srgb, red 50%, blue)) {
  :root {
    --surface-raised: color-mix(in srgb, var(--card-bg) 94%, var(--text-main));
    --surface-2: color-mix(in srgb, var(--page-bg) 92%, var(--text-main));
    --border: color-mix(in srgb, var(--page-bg) 82%, var(--text-main));
    --border-soft: color-mix(in srgb, var(--page-bg) 89%, var(--text-main));
    --text-faint: color-mix(in srgb, var(--text-muted) 74%, var(--page-bg));

    --accent-soft: color-mix(in srgb, var(--brand-primary) 15%, var(--card-bg));
    --accent-contrast: color-mix(in srgb, var(--card-bg) 92%, var(--brand-primary));

    --sidebar-bg-deep: color-mix(in srgb, var(--sidebar-bg) 84%, #000);
    --sidebar-text-muted: color-mix(in srgb, var(--sidebar-text) 60%, var(--sidebar-bg));
    --sidebar-border: color-mix(in srgb, var(--sidebar-bg) 82%, var(--sidebar-text));

    --pri-low-bg: color-mix(in srgb, var(--pri-low) 16%, var(--card-bg));
    --pri-medium-bg: color-mix(in srgb, var(--pri-medium) 18%, var(--card-bg));
    --pri-high-bg: color-mix(in srgb, var(--pri-high) 16%, var(--card-bg));
    --status-done-bg: color-mix(in srgb, var(--status-done) 16%, var(--card-bg));
    --status-watch-bg: color-mix(in srgb, var(--status-watch) 15%, var(--card-bg));

    --avt-1-bg: color-mix(in srgb, #94562B 18%, var(--card-bg));
    --avt-1-fg: color-mix(in srgb, #7C4522 80%, var(--text-main));
    --avt-2-bg: color-mix(in srgb, #4A6FA0 16%, var(--card-bg));
    --avt-2-fg: color-mix(in srgb, #20343A 80%, var(--text-main));
    --avt-3-bg: color-mix(in srgb, #5C7874 16%, var(--card-bg));
    --avt-3-fg: color-mix(in srgb, #4C5D5A 80%, var(--text-main));
    --avt-4-bg: color-mix(in srgb, #8C7A3E 16%, var(--card-bg));
    --avt-4-fg: color-mix(in srgb, #6B664F 80%, var(--text-main));
    --avt-5-bg: color-mix(in srgb, #6B5B95 15%, var(--card-bg));
    --avt-5-fg: color-mix(in srgb, #5C6152 80%, var(--text-main));
  }
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  /* ARCHITECTURE §5: the sidebar's dark band is painted on <body> as a hard
     gradient stop so it always reaches the bottom of the page, even when the
     flex stretch fails. */
  background: linear-gradient(to right, var(--sidebar-bg) 268px, var(--bg) 268px);
  color: var(--text);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  min-height: 100vh;
}
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
::selection { background: var(--accent-soft); color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- sidebar */
#app { display: flex; width: 100%; min-height: 100vh; }
.sidebar {
  width: 268px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 28px 22px 20px;
  gap: 28px;
  border-right: 1px solid var(--sidebar-border);
  overflow-y: auto;
}
.brand { display: flex; flex-direction: column; gap: 10px; }
.brand .mark-img {
  width: 178px;
  height: auto;
  display: block;
}
.brand .wordmark {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--sidebar-text);
}
.brand .sub {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--sidebar-text-muted);
  font-weight: 600;
}

.sb-block { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.sb-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sidebar-text-muted);
  font-weight: 600;
}
.sb-user-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sb-user-name { font-size: 0.85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-user-mail { font-size: 0.7rem; color: var(--sidebar-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 700; flex-shrink: 0;
}
.avatar.sm { width: 22px; height: 22px; font-size: 0.6rem; }
.avt-1 { background: var(--avt-1-bg); color: var(--avt-1-fg); }
.avt-2 { background: var(--avt-2-bg); color: var(--avt-2-fg); }
.avt-3 { background: var(--avt-3-bg); color: var(--avt-3-fg); }
.avt-4 { background: var(--avt-4-bg); color: var(--avt-4-fg); }
.avt-5 { background: var(--avt-5-bg); color: var(--avt-5-fg); }

select.user-select {
  flex: 1; min-width: 0; width: 100%; max-width: 100%;
  background: var(--sidebar-bg-deep); color: var(--sidebar-text);
  border: 1px solid var(--sidebar-border); border-radius: var(--radius-sm);
  padding: 7px 8px; font-size: 0.85rem; font-weight: 600;
  text-overflow: ellipsis;
}
.sb-new-user { display: none; gap: 6px; min-width: 0; }
.sb-new-user.open { display: flex; }
.sb-new-user input {
  flex: 1; min-width: 0; background: var(--sidebar-bg-deep); color: var(--sidebar-text);
  border: 1px solid var(--sidebar-border); border-radius: var(--radius-sm);
  padding: 7px 8px; font-size: 0.83rem;
}
.sb-new-user input::placeholder { color: var(--sidebar-text-muted); }

.nav-btn {
  display: flex; align-items: center; justify-content: space-between;
  background: none; border: none; color: var(--sidebar-text);
  padding: 8px 10px; border-radius: var(--radius-sm); font-size: 0.88rem; font-weight: 500;
  text-align: left; width: 100%;
}
.nav-btn:hover { background: rgba(255, 255, 255, 0.06); }
.nav-btn.active { background: var(--accent); color: var(--accent-contrast); font-weight: 700; }
.nav-btn .count { font-size: 0.76rem; opacity: 0.85; }
.nav-list { display: flex; flex-direction: column; gap: 3px; }

.chip-list { display: flex; flex-direction: column; gap: 3px; }
.cat-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  background: none; border: none; color: var(--sidebar-text-muted);
  padding: 7px 10px; border-radius: var(--radius-sm); font-size: 0.83rem;
  text-align: left; width: 100%;
}
.cat-chip:hover { background: rgba(255, 255, 255, 0.06); color: var(--sidebar-text); }
.cat-chip.active { background: rgba(255, 255, 255, 0.1); color: var(--sidebar-text); font-weight: 600; }
.cat-chip .cat-chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-chip-row { display: flex; align-items: center; gap: 2px; }
.cat-chip-row .cat-chip { flex: 1; min-width: 0; }
.cat-delete-btn {
  flex-shrink: 0; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: var(--radius-sm); color: var(--sidebar-text-muted);
  font-size: 0.95rem; line-height: 1; opacity: 0.4; transition: opacity 0.12s;
}
.cat-chip-row:hover .cat-delete-btn, .cat-delete-btn:focus-visible { opacity: 1; }
.cat-delete-btn:hover { background: rgba(197, 90, 60, 0.18); color: var(--pri-high); }
.cat-delete-btn.confirm { opacity: 1; background: var(--pri-high); color: #fff; font-weight: 700; }
.cat-delete-btn.confirm:hover { background: var(--pri-high); color: #fff; }
.cat-add-toggle {
  background: none; border: 1px dashed var(--sidebar-border); color: var(--sidebar-text-muted);
  padding: 6px 10px; border-radius: var(--radius-sm); font-size: 0.8rem; text-align: left;
}
.cat-add-toggle:hover { color: var(--sidebar-text); border-color: var(--sidebar-text-muted); }
.cat-add-form { display: none; gap: 6px; min-width: 0; }
.cat-add-form.open { display: flex; }
.cat-add-form input {
  flex: 1; min-width: 0; background: var(--sidebar-bg-deep); color: var(--sidebar-text);
  border: 1px solid var(--sidebar-border); border-radius: var(--radius-sm);
  padding: 6px 8px; font-size: 0.82rem;
}
.cat-add-form input::placeholder { color: var(--sidebar-text-muted); }
.project-add-form.open { flex-direction: column; align-items: stretch; }
.color-swatch-row { display: flex; gap: 7px; flex-wrap: wrap; padding: 2px 0; }
.color-swatch {
  width: 22px; height: 22px; border-radius: 50%; padding: 0; flex-shrink: 0;
  border: none; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.color-swatch.selected { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.95), 0 0 0 4px rgba(0, 0, 0, 0.6); }
.project-visibility-wrap { display: flex; flex-direction: column; gap: 6px; }
.project-visibility-select {
  border: 1px solid rgba(127, 127, 127, 0.4); border-radius: var(--radius-sm);
  background: rgba(127, 127, 127, 0.08); color: inherit; padding: 6px 8px; font-size: 0.82rem;
}
.project-share-checklist {
  display: flex; flex-direction: column; gap: 4px; max-height: 130px; overflow-y: auto;
  padding: 6px 8px; border: 1px solid rgba(127, 127, 127, 0.4); border-radius: var(--radius-sm);
  background: rgba(127, 127, 127, 0.05);
}
.project-share-checklist label { display: flex; align-items: center; gap: 7px; font-size: 0.8rem; cursor: pointer; }
.project-share-checklist-hidden { display: none; }
.picker-list { display: flex; flex-direction: column; gap: 6px; }
.picker-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 0.85rem; text-align: left; color: var(--text);
}
.picker-item:hover { border-color: var(--accent); background: var(--accent-soft); }

.sb-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.select-mode-toggle {
  background: none; border: none; color: var(--sidebar-text-muted); font-size: 0.74rem;
  font-weight: 600; text-decoration: underline; text-underline-offset: 2px; padding: 2px 0;
}
.select-mode-toggle:hover { color: var(--sidebar-text); }
.select-checkbox-wrap { display: flex; align-items: center; flex-shrink: 0; padding: 0 2px; }
.select-checkbox-wrap input { width: 15px; height: 15px; cursor: pointer; }
.complete-btn:hover { background: rgba(79, 115, 80, 0.2); color: var(--status-done); }
.bulk-bar {
  display: flex; align-items: center; gap: 10px; background: var(--accent-soft);
  border: 1px solid var(--accent); border-radius: var(--radius-sm); padding: 8px 12px;
  margin: 0 0 14px 0;
}
.bulk-count { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.sidebar .bulk-bar { margin: 0; }
.sidebar .bulk-count { color: var(--text); }
.selected-row { outline: 2px solid var(--accent); outline-offset: -2px; }
.archive-tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.archive-tab-btn {
  background: var(--surface-2); border: 1px solid var(--border-soft); color: var(--text-faint);
  padding: 7px 14px; border-radius: 999px; font-size: 0.82rem; font-weight: 600;
}
.archive-tab-btn:hover { color: var(--text); }
.archive-tab-btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.project-done-row .card-title { flex: 1; }
.project-done-row .project-dot { flex-shrink: 0; }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 13px; border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 600;
}
.btn:hover { border-color: var(--text-faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: none; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--pri-high); border-color: var(--pri-high-bg); }
.btn.danger:hover { background: var(--pri-high-bg); }
.btn.danger.armed { background: var(--pri-high); border-color: var(--pri-high); color: #fff; }
.btn.small { padding: 5px 9px; font-size: 0.78rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.sidebar .btn.ghost { color: var(--sidebar-text-muted); }
.sidebar .btn.ghost:hover { background: rgba(255, 255, 255, 0.06); color: var(--sidebar-text); }
.sidebar .btn.danger { background: none; border-color: transparent; color: var(--pri-high); }
.sidebar .btn.danger:hover { background: rgba(197, 90, 60, 0.16); }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.sidebar-footer .foot-note { font-size: 0.72rem; color: var(--sidebar-text-muted); }
.mail-toggle {
  display: flex; align-items: center; gap: 8px; font-size: 0.74rem;
  color: var(--sidebar-text-muted); cursor: pointer;
}
.mail-toggle input { flex-shrink: 0; }
.mail-toggle:hover { color: var(--sidebar-text); }

/* ------------------------------------------------------------------- main */
.main { flex: 1; min-width: 0; padding: 34px 42px 60px; display: flex; flex-direction: column; gap: 22px; }
.readonly-banner {
  background: var(--pri-high-bg); color: var(--pri-high); border: 1px solid var(--pri-high-bg);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 0.85rem; font-weight: 600;
}
.main-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.main-header h1 { font-size: 1.5rem; font-weight: 700; }
.main-header .stats { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.stat-chip {
  font-size: 0.78rem; font-weight: 600; color: var(--text-muted);
  background: var(--surface-2); border-radius: 100px; padding: 4px 11px;
  display: flex; align-items: center; gap: 5px;
}
.stat-dot { width: 7px; height: 7px; border-radius: 50%; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search-box {
  display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 100px; padding: 7px 12px; min-width: 0; width: 220px;
}
.search-icon { color: var(--text-faint); flex-shrink: 0; }
.search-input { border: none; background: none; outline: none; font-size: 0.85rem; width: 100%; min-width: 0; color: var(--text); }
.search-input::placeholder { color: var(--text-faint); }
.search-clear {
  flex-shrink: 0; background: none; border: none; color: var(--text-faint); font-size: 1rem;
  line-height: 1; padding: 0 0 0 2px; border-radius: 50%;
}
.search-clear:hover { color: var(--text); }
.saving-pill {
  font-size: 0.76rem; color: var(--text-muted); display: none; align-items: center; gap: 6px;
}
.saving-pill.visible { display: flex; }
.spin {
  width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-chip {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted);
  padding: 5px 12px; border-radius: 100px; font-size: 0.8rem; font-weight: 600;
}
.filter-chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }

.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; align-items: start; }
@media (max-width: 1180px) { .board { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .board { grid-template-columns: 1fr; } }
.col { background: var(--surface-2); border-radius: var(--radius-lg); padding: 14px; display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.col-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 2px 6px; }
.col-head .title { font-size: 0.82rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); display: flex; align-items: center; gap: 7px; }
.col-head .count { font-size: 0.78rem; color: var(--text-faint); }
.col-cards { display: flex; flex-direction: column; gap: 9px; }
.col-empty { color: var(--text-faint); font-size: 0.82rem; padding: 14px 6px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius-md); }
.col-add-btn {
  background: none; border: 1px dashed var(--border); color: var(--text-faint);
  border-radius: var(--radius-md); padding: 9px 10px; font-size: 0.82rem; font-weight: 600; text-align: center; width: 100%;
}
.col-add-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.card {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-md);
  padding: 12px 13px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow-sm);
  text-align: left; width: 100%; cursor: pointer;
}
.card:hover { border-color: var(--text-faint); box-shadow: var(--shadow-md); }
.card:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-top-left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cat-tag { font-size: 0.7rem; font-weight: 600; color: var(--text-muted); background: var(--surface-2); border-radius: 100px; padding: 2px 8px; }
.project-tag { font-size: 0.7rem; font-weight: 700; border-radius: 100px; padding: 2px 8px; }
.project-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.title-dot { width: 12px; height: 12px; margin-right: 9px; vertical-align: middle; }
.watch-tag { font-size: 0.7rem; font-weight: 700; color: var(--status-watch); background: var(--status-watch-bg); border-radius: 100px; padding: 2px 8px; }
.due-urgency-tag { font-size: 0.7rem; font-weight: 700; border-radius: 100px; padding: 2px 8px; }
.due-urgency-tag.soon { color: var(--pri-medium); background: var(--pri-medium-bg); }
.due-urgency-tag.overdue { color: var(--pri-high); background: var(--pri-high-bg); }
.pri-tag { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; border-radius: 100px; padding: 2px 8px; }
.pri-tag.low { background: var(--pri-low-bg); color: var(--pri-low); }
.pri-tag.medium { background: var(--pri-medium-bg); color: var(--pri-medium); }
.pri-tag.high { background: var(--pri-high-bg); color: var(--pri-high); }
.card-title { font-size: 0.92rem; font-weight: 600; line-height: 1.35; }
.card-title.done { text-decoration: line-through; color: var(--text-muted); }
.card-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-meta-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.card-assignee { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--text-muted); }
.comment-badge { display: flex; align-items: center; gap: 3px; font-size: 0.74rem; color: var(--text-faint); flex-shrink: 0; }
.card-due { font-size: 0.75rem; color: var(--text-faint); }
.card-due.overdue { color: var(--pri-high); font-weight: 700; }
.subtask-bar { height: 4px; background: var(--border-soft); border-radius: 4px; overflow: hidden; }
.subtask-bar .fill { height: 100%; background: var(--status-done); }
.subtask-count { font-size: 0.72rem; color: var(--text-faint); }
.status-row { display: flex; gap: 5px; margin-top: 2px; }
.status-btn {
  flex: 1; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 5px 4px; border-radius: var(--radius-sm); border: 1px solid var(--border-soft); background: var(--surface-2);
  color: var(--text-faint);
}
.status-btn.current { background: var(--text); color: var(--surface); border-color: var(--text); }
.status-btn.current.is-done { background: var(--status-done); border-color: var(--status-done); }
.status-btn.current.is-watch { background: var(--status-watch); border-color: var(--status-watch); }
.card-watch-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }

/* ------------------------------------------------------------- login gate */
.gate { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.gate-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 36px 34px; max-width: 400px; width: 100%; box-shadow: var(--shadow-md); display: flex; flex-direction: column; gap: 18px; }
.gate-card .mark-img { width: 168px; height: auto; display: block; }
.gate-card .wordmark { font-size: 1.6rem; font-weight: 700; letter-spacing: 0.02em; }
.gate-card p { color: var(--text-muted); font-size: 0.9rem; }
.gate-users { display: flex; flex-direction: column; gap: 6px; }
.gate-user-btn { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-raised); font-weight: 600; font-size: 0.88rem; justify-content: center; }
.gate-user-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.gate-divider { display: flex; align-items: center; gap: 10px; color: var(--text-faint); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
.gate-divider::before, .gate-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.gate-new { display: flex; gap: 8px; min-width: 0; }
.gate-new input { flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; background: var(--surface); font-size: 0.88rem; }
.gate-form { display: none; flex-direction: column; gap: 8px; }
.gate-form.open { display: flex; }
.gate-form input {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px;
  background: var(--surface); font-size: 0.88rem; width: 100%;
}
.gate-toggle { background: none; border: none; color: var(--text-muted); font-size: 0.78rem; text-decoration: underline; padding: 0; }
.gate-toggle:hover { color: var(--text); }
.gate-error { color: var(--pri-high); font-size: 0.82rem; font-weight: 600; }

/* ------------------------------------------------------- modals and panel */
.backdrop { position: fixed; inset: 0; background: rgba(17, 25, 23, 0.32); z-index: 40; }
.export-modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(560px, 92vw); max-height: 82vh; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md); z-index: 41; display: flex; flex-direction: column;
}
.export-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.export-textarea {
  width: 100%; min-height: 260px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px;
  font-family: 'Courier New', monospace; font-size: 0.76rem; background: var(--surface-2); color: var(--text);
  resize: vertical;
}
.footer-link-btn {
  background: none; border: none; color: var(--sidebar-text-muted); font-size: 0.72rem; text-decoration: underline;
  padding: 0; text-align: left;
}
.footer-link-btn:hover { color: var(--sidebar-text); }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-md);
  z-index: 41; display: flex; flex-direction: column; transform: translateX(0);
}
@media (prefers-reduced-motion: no-preference) {
  .panel { animation: slidein 0.22s ease-out; }
}
@keyframes slidein { from { transform: translateX(100%); } to { transform: translateX(0); } }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border-soft); }
.panel-head h2 { font-size: 1.05rem; font-weight: 700; }
.panel-close { background: none; border: none; color: var(--text-muted); font-size: 1.1rem; padding: 4px 8px; border-radius: var(--radius-sm); }
.panel-close:hover { background: var(--surface-2); }
.panel-body { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.76rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.field input[type="text"], .field input[type="date"], .field input[type="email"],
.field input[type="password"], .field input[type="color"], .field input[type="file"], .field select {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; background: var(--surface); font-size: 0.9rem;
}
.field input[type="color"] { padding: 2px; height: 38px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-btn { flex: 1 1 84px; border: 1px solid var(--border); background: var(--surface); padding: 7px 6px; border-radius: var(--radius-sm); font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.seg-btn.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.seg-btn.pri-active.low { background: var(--pri-low); border-color: var(--pri-low); color: #fff; }
.seg-btn.pri-active.medium { background: var(--pri-medium); border-color: var(--pri-medium); color: #fff; }
.seg-btn.pri-active.high { background: var(--pri-high); border-color: var(--pri-high); color: #fff; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.assignee-checklist {
  display: flex; flex-direction: column; gap: 2px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px; max-height: 168px; overflow-y: auto;
}
.assignee-check-row {
  display: flex; align-items: center; gap: 9px; padding: 6px 7px; border-radius: var(--radius-sm);
  font-size: 0.87rem; cursor: pointer;
}
.assignee-check-row:hover { background: var(--surface-2); }
.assignee-check-row input[type="checkbox"] { flex-shrink: 0; }
.watch-field { gap: 0; }
label.watch-toggle-row {
  display: flex; align-items: center; gap: 9px; padding: 8px 9px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface-2); font-size: 0.83rem; font-weight: 600;
  text-transform: none; letter-spacing: normal; color: var(--text); cursor: pointer;
}
.watch-toggle-row input[type="checkbox"] { flex-shrink: 0; }
.cat-inline-add { display: none; gap: 6px; margin-top: 4px; }
.cat-inline-add.open { display: flex; }
.cat-inline-add input { flex: 1; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 9px; font-size: 0.85rem; }
.project-inline-add.open { flex-direction: column; align-items: stretch; }
.subtask-list { display: flex; flex-direction: column; gap: 6px; }
.subtask-row { display: flex; align-items: center; gap: 8px; }
.subtask-row input[type="text"] { flex: 1; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 6px 9px; font-size: 0.85rem; }
.subtask-row input[type="text"].done-text { text-decoration: line-through; color: var(--text-faint); }
.subtask-remove { background: none; border: none; color: var(--text-faint); font-size: 0.95rem; padding: 4px 6px; border-radius: var(--radius-sm); }
.subtask-remove:hover { background: var(--pri-high-bg); color: var(--pri-high); }
.subtask-add { display: flex; gap: 6px; margin-top: 2px; }
.subtask-add input { flex: 1; border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 6px 9px; font-size: 0.85rem; background: none; }
.panel-foot { border-top: 1px solid var(--border-soft); padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-foot .foot-actions { display: flex; align-items: center; gap: 8px; }
.helper-text { font-size: 0.78rem; color: var(--text-faint); }

.completed-note {
  display: flex; align-items: center; gap: 7px; font-size: 0.82rem; font-weight: 600;
  color: var(--status-done); background: var(--status-done-bg); border-radius: var(--radius-sm); padding: 8px 11px;
}
.join-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 0.82rem; font-weight: 600;
  color: var(--accent-hover); background: var(--accent-soft); border-radius: var(--radius-sm); padding: 8px 11px;
}
.comment-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 4px; }
.comment-row { display: flex; gap: 9px; }
.comment-body { flex: 1; background: var(--surface-2); border-radius: var(--radius-md); padding: 8px 11px; }
.comment-head { display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; }
.comment-author { font-size: 0.8rem; font-weight: 700; }
.comment-time { font-size: 0.7rem; color: var(--text-faint); }
.comment-source { font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--status-watch); background: var(--status-watch-bg); border-radius: 100px; padding: 1px 7px; }
.comment-text { font-size: 0.85rem; color: var(--text); white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.comment-add { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.comment-add textarea {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px;
  font-size: 0.85rem; resize: vertical; min-height: 54px; background: var(--surface);
}
.comment-add-wrap { position: relative; width: 100%; min-width: 0; }
.mention { color: var(--accent); font-weight: 700; }
.mention-menu {
  display: none; flex-direction: column; position: absolute; left: 0; bottom: calc(100% + 6px); width: min(260px, 100%);
  max-height: 180px; overflow-y: auto; background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-md); padding: 5px; gap: 2px; z-index: 20;
}
.mention-menu.open { display: flex; }
.mention-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-sm);
  font-size: 0.83rem; text-align: left; width: 100%; background: none; border: none;
}
.mention-item:hover { background: var(--surface-2); }

/* ---------------------------------------------------------- notifications */
.notif-list { display: flex; flex-direction: column; gap: 8px; }
.notif-row {
  display: flex; align-items: flex-start; gap: 11px; background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius-md); padding: 12px 14px; box-shadow: var(--shadow-sm);
}
.notif-row.unread { border-color: var(--accent); background: var(--accent-soft); }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 8px; flex-shrink: 0; background: transparent; }
.notif-dot.unread { background: var(--accent); }
.notif-body { flex: 1; min-width: 0; }
.notif-text { font-size: 0.86rem; color: var(--text); }
.notif-actor { font-weight: 700; }
.notif-task { font-weight: 600; color: var(--accent-hover); }
.notif-time { font-size: 0.72rem; color: var(--text-faint); margin-top: 3px; }
.notif-actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.badge-unread { background: var(--accent); color: var(--accent-contrast); border-radius: 100px; padding: 1px 7px; }
.nav-btn.active .badge-unread { background: rgba(255, 255, 255, 0.28); color: inherit; }

/* --------------------------------------------------- archive / flat lists */
.done-list { display: flex; flex-direction: column; gap: 8px; }
.done-row {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius-md); padding: 11px 14px; text-align: left; width: 100%; box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.done-row:hover { border-color: var(--text-faint); }
.done-row:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.done-row .card-title { flex: 1; }
.done-row .cat-tag { flex-shrink: 0; }
.done-row .project-tag { flex-shrink: 0; }
.done-row .due-urgency-tag { flex-shrink: 0; }
.done-row .done-when { flex-shrink: 0; font-size: 0.76rem; color: var(--text-faint); width: 160px; text-align: right; }
.archive-meta { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.status-pill {
  flex-shrink: 0; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  border-radius: 100px; padding: 4px 11px; width: 84px; text-align: center;
}
.status-pill-todo { background: var(--surface-2); color: var(--text-faint); }
.status-pill-doing { background: var(--accent-soft); color: var(--accent-hover); }
.status-pill-done { background: var(--status-done-bg); color: var(--status-done); }
.status-pill-watch { background: var(--status-watch-bg); color: var(--status-watch); }

/* ----------------------------------------------------------------- admin */
.admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.admin-section { display: flex; flex-direction: column; gap: 14px; max-width: 860px; }
.admin-card {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-md);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow-sm);
}
.admin-card h2 { font-size: 1rem; font-weight: 700; }
.user-row {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius-md); padding: 10px 14px; box-shadow: var(--shadow-sm);
}
.user-row .grow { flex: 1; min-width: 0; }
.user-row .user-name { font-size: 0.9rem; font-weight: 600; }
.user-row .user-mail { font-size: 0.76rem; color: var(--text-faint); }
.role-pill {
  flex-shrink: 0; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  border-radius: 100px; padding: 4px 11px; background: var(--surface-2); color: var(--text-faint);
}
.role-pill.admin { background: var(--accent-soft); color: var(--accent-hover); }
.logo-preview { max-width: 200px; max-height: 70px; display: block; }
.m365-guide {
  border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  padding: 10px 14px; background: var(--surface-2);
}
.m365-guide summary { cursor: pointer; font-weight: 600; font-size: 0.85rem; }
.m365-guide ol { margin: 10px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.m365-guide li { font-size: 0.82rem; color: var(--text-muted); }
.m365-guide code { font-size: 0.8em; background: var(--surface); border: 1px solid var(--border-soft); border-radius: 4px; padding: 1px 5px; }

/* ---------------------------------------------------------------- toasts */
.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 0.85rem; box-shadow: var(--shadow-md); max-width: 320px;
}
@media (prefers-reduced-motion: no-preference) { .toast { animation: rise 0.18s ease-out; } }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
