/* =========================================================================
   TeamAltarra — stylesheet
   Sections: tokens, reset, auth screens, shell, components, responsive
   ========================================================================= */

/* --- design tokens ------------------------------------------------------ */
:root {
    /* Native controls (select, date picker, scrollbars) follow the app theme,
       not the operating system, so a selected <option> stays readable. */
    color-scheme: light;
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #fafbfc;
    --surface-3: #f0f2f5;
    --border: #e3e6ea;
    --border-strong: #d2d7de;
    --text: #14181f;
    --text-muted: #646d7c;
    --text-faint: #8b93a1;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #e8efff;
    --success: #128a5b;
    --success-soft: #e2f6ee;
    --warning: #b4720a;
    --warning-soft: #fdf1dc;
    --danger: #cf2f3f;
    --danger-soft: #fdeaec;
    --info: #6d4aff;
    --info-soft: #efeaff;
    --code-keyword: #7c3aed;
    --code-string: #0f766e;
    --code-number: #b45309;
    --code-comment: #78828f;
    --code-function: #1d4ed8;
    --code-type: #0e7490;
    --code-attr: #b91c8f;
    --code-builtin: #9333ea;
    --shadow-sm: 0 1px 2px rgba(19, 25, 38, .06);
    --shadow: 0 6px 18px rgba(19, 25, 38, .08);
    --shadow-lg: 0 18px 50px rgba(19, 25, 38, .18);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --sidebar-width: 256px;
    --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --mono: "JetBrains Mono", "Cascadia Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0d1015;
    --surface: #151a21;
    --surface-2: #1a2028;
    --surface-3: #20272f;
    --border: #262e38;
    --border-strong: #333d49;
    --text: #e7eaf0;
    --text-muted: #9aa4b4;
    --text-faint: #79838f;
    --primary: #5b8cff;
    --primary-hover: #7ba3ff;
    --primary-soft: #1b2a4d;
    --success: #35c58b;
    --success-soft: #14342a;
    --warning: #e0a54a;
    --warning-soft: #3a2c14;
    --danger: #ff7b88;
    --danger-soft: #3c1d22;
    --info: #a58cff;
    --info-soft: #2a2350;
    --code-keyword: #c4b5fd;
    --code-string: #86efac;
    --code-number: #fcd34d;
    --code-comment: #77828f;
    --code-function: #93c5fd;
    --code-type: #67e8f9;
    --code-attr: #f9a8d4;
    --code-builtin: #d8b4fe;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 8px 24px rgba(0, 0, 0, .45);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
}

/* --- reset ------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

::selection { background: var(--primary); color: #fff; }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* thin scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border: 3px solid transparent;
    background-clip: content-box;
    border-radius: 999px;
}

/* --- boot & auth screens ----------------------------------------------- */
.boot {
    position: fixed;
    inset: 0;
    display: grid;
    place-content: center;
    gap: 18px;
    justify-items: center;
    background: var(--bg);
    z-index: 40;
}
.boot__logo { font-weight: 700; letter-spacing: -.02em; font-size: 1.6rem; }
.boot__spinner {
    width: 28px; height: 28px;
    border: 3px solid var(--border-strong);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(900px 500px at 15% -10%, var(--primary-soft), transparent),
        radial-gradient(700px 500px at 110% 20%, var(--info-soft), transparent),
        var(--bg);
}
.auth__card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 28px;
    animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.auth__brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.auth__mark {
    width: 34px; height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--info));
    color: #fff;
    display: grid; place-items: center;
    font-weight: 700;
}
.auth__links { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; font-size: .9rem; }
.auth__hint {
    background: var(--surface-3);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: .82rem;
    color: var(--text-muted);
    margin-top: 14px;
    word-break: break-all;
}

/* --- application shell ------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 30;
}
.sidebar__head { display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px; }
.sidebar__mark {
    width: 32px; height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), var(--info));
    color: #fff;
    display: grid; place-items: center;
    font-weight: 700;
    flex: 0 0 auto;
}
.sidebar__name { font-weight: 650; letter-spacing: -.01em; }
.sidebar__tag { font-size: .72rem; color: var(--text-faint); }
.sidebar__nav { padding: 6px 10px 16px; overflow-y: auto; flex: 1; }
.sidebar__group {
    margin: 14px 8px 6px;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-faint);
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
    cursor: pointer;
    border: 0;
    background: transparent;
    width: 100%;
    text-align: left;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-item.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item svg { width: 18px; height: 18px; flex: 0 0 auto; }
.nav-item__badge {
    margin-left: auto;
    background: var(--surface-3);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 1px 8px;
    font-size: .74rem;
    font-weight: 600;
}
.nav-item.is-active .nav-item__badge { background: var(--primary); color: #fff; }

.sidebar__foot { border-top: 1px solid var(--border); padding: 12px; }
.sidebar__theme {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-bottom: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-muted);
    font: inherit;
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.sidebar__theme:hover { background: var(--surface-3); color: var(--text); border-color: var(--border-strong); }
.sidebar__theme svg { width: 16px; height: 16px; flex: 0 0 auto; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip__logout { margin-left: auto; flex: 0 0 auto; }
.avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: grid; place-items: center;
    font-weight: 650;
    font-size: .78rem;
    flex: 0 0 auto;
    overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar--sm { width: 26px; height: 26px; font-size: .7rem; }
.avatar--lg { width: 96px; height: 96px; font-size: 1.6rem; }
.avatar-upload { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.avatar-upload__actions { display: flex; flex-direction: column; gap: 8px; min-width: 180px; }
.user-chip__meta { min-width: 0; flex: 1; }
.user-chip__name { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip__role { font-size: .76rem; color: var(--text-faint); }

.shell__main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 22px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.topbar__titles { min-width: 0; }
.topbar__subtitle { margin: 0; font-size: .82rem; color: var(--text-muted); }
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.view { padding: 22px; width: 100%; max-width: 1240px; margin: 0 auto; flex: 1; }

.scrim { position: fixed; inset: 0; background: rgba(9, 12, 18, .5); z-index: 25; }

/* --- layout helpers ---------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    /* Flush content (lists, tables) paints a hover background that would square
       off the rounded corners; clipping keeps the card radius intact. */
    overflow: hidden;
}
.card__head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.card__head h2, .card__head h3 { margin: 0; }
.card__body { padding: 16px; }
.card__body--flush { padding: 0; }
.card__actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.grid { display: grid; gap: 16px; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid--sidebar { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.spacer { flex: 1; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: .84rem; }
.tiny { font-size: .76rem; }
.mono { font-family: var(--mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mb-0 { margin-bottom: 0; }

/* --- buttons & form controls ------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-weight: 550;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s ease, border-color .15s ease, transform .05s ease;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-3); color: var(--text); }
.btn--block { width: 100%; }
.btn--sm { padding: 5px 10px; font-size: .84rem; }
.btn--icon { padding: 7px; }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

.burger, .burger::before, .burger::after {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
}
.burger { position: relative; }
.burger::before, .burger::after { position: absolute; content: ""; }
.burger::before { top: -6px; }
.burger::after { top: 6px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field__label { font-size: .82rem; font-weight: 600; color: var(--text-muted); }
.field__hint { font-size: .76rem; color: var(--text-faint); }
.field__error { font-size: .78rem; color: var(--danger); }

.input, .select, .textarea {
    width: 100%;
    padding: 9px 11px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    transition: border-color .15s ease, box-shadow .15s ease;
}

/*.select {*/
/*    padding: 0;*/
/*    border: none;*/
/*}*/

/*.ts-control, .ts-wrapper.single.input-active .ts-control {*/
/*    height: 38px;*/
/*}*/
/* Dropdown options are painted by the browser: state the colours explicitly so
   the selected row is readable in both themes. */
.select option, .select optgroup {
    background-color: var(--surface);
    color: var(--text);
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.tag-editor { position: relative; width: 100%; }
.tag-editor__box {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-height: 42px;
    padding: 5px 8px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: text;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.tag-editor__box:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    padding: 2px 6px 2px 9px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
    line-height: 1.4;
    background: var(--primary-soft);
    color: var(--primary);
    border: 1px solid color-mix(in srgb, var(--primary) 24%, transparent);
}
.tag-chip__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-chip__remove {
    display: inline-grid;
    place-items: center;
    width: 16px;
    height: 16px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font-size: .95rem;
    line-height: 1;
    cursor: pointer;
    opacity: .75;
}
.tag-chip__remove:hover {
    opacity: 1;
    background: color-mix(in srgb, var(--primary) 18%, transparent);
}
.tag-editor__input {
    flex: 1 1 110px;
    min-width: 80px;
    border: 0;
    outline: 0;
    padding: 3px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: .92rem;
    line-height: 1.45;
}
.tag-editor__input::placeholder { color: var(--text-faint); }
.tag-editor__dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 80;
    max-height: 200px;
    overflow-y: auto;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}
.tag-editor__option {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 7px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: .86rem;
    text-align: left;
    cursor: pointer;
}
.tag-editor__option:hover,
.tag-editor__option.is-active {
    background: var(--primary-soft);
    color: var(--primary);
}
.textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
/* Markdown editor: monospace (JetBrains Mono first, see --mono) keeps the
   source aligned with the rendered preview. */
.editor .textarea {
    font-family: var(--mono);
    font-size: .88rem;
    line-height: 1.7;
    tab-size: 4;
}

/* --- CodeMirror 5 (static/vendor/codemirror, MIT) ----------------------- */
.editor .CodeMirror {
    height: auto;
    padding: 6px 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font-family: var(--mono);
    font-size: .88rem;
    line-height: 1.7;
}
.editor .CodeMirror-focused { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.editor .CodeMirror-gutters {
    background: var(--surface-2);
    border-right: 1px solid var(--border);
    padding-right: 2px;
}
.editor .CodeMirror-linenumber { color: var(--text-faint); font-size: .78rem; }
.editor .CodeMirror-cursor { border-left: 2px solid var(--text); }
.editor .CodeMirror-selected { background: var(--primary-soft); }
.editor .CodeMirror-matchingbracket { color: var(--primary); border-bottom: 1px solid var(--primary); }
.editor .CodeMirror pre.CodeMirror-line,
.editor .CodeMirror pre.CodeMirror-line-like { padding: 0 10px; }

/* Markdown tokens borrow the app palette, so light/dark switch with the theme. */
.cm-s-altarra .cm-header { color: var(--primary); font-weight: 700; }
.cm-s-altarra .cm-strong { font-weight: 700; }
.cm-s-altarra .cm-em { font-style: italic; }
.cm-s-altarra .cm-quote { color: var(--text-muted); font-style: italic; }
.cm-s-altarra .cm-link, .cm-s-altarra .cm-url { color: var(--info); }
.cm-s-altarra .cm-image { color: var(--success); }
.cm-s-altarra .cm-comment { color: var(--text-muted); }
.cm-s-altarra .cm-formatting { color: var(--text-faint); }
.cm-s-altarra .cm-variable-2, .cm-s-altarra .cm-variable-3 { color: var(--primary); }
.cm-s-altarra .cm-keyword { color: var(--code-keyword); }
.cm-s-altarra .cm-string { color: var(--code-string); }
.cm-s-altarra .cm-number { color: var(--code-number); }
.cm-s-altarra .cm-builtin { color: var(--code-builtin); }
.cm-s-altarra .cm-tag { color: var(--code-type); }
.cm-s-altarra .cm-attribute { color: var(--code-attr); }
.cm-s-altarra .cm-hr { color: var(--text-faint); }
.cm-s-altarra .cm-meta { color: var(--text-muted); }
.input--search { padding-left: 32px; background-image: none; }
.search { position: relative; flex: 1; min-width: 180px; }
.search svg {
    position: absolute; left: 10px; top: 50%;
    transform: translateY(-50%);
    width: 15px; height: 15px;
    color: var(--text-faint);
    pointer-events: none;
}
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { width: 16px; height: 16px; accent-color: var(--primary); }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 600;
    background: var(--surface-3);
    color: var(--text-muted);
    white-space: nowrap;
}
.badge--primary { background: var(--primary-soft); color: var(--primary); }
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning  { background: var(--warning-soft); color: var(--warning); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--info { background: var(--info-soft); color: var(--info); }
.badge--project { background: var(--surface-3); color: var(--text-muted); border: 1px solid var(--border); }
.badge--project::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 5px;
    border-radius: 50%;
    background: currentColor;
    opacity: .65;
    vertical-align: middle;
}

.project-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex: 0 0 auto;
    box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 12%, transparent);
}

.project-swatch {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, .15);
    cursor: pointer;
    padding: 0;
}
/* --- shared task audience & task page ---------------------------------- */
.checklist {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 6px 14px;
    max-height: 220px;
    overflow-y: auto;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.checklist__item { display: flex; align-items: center; gap: 8px; font-size: .92rem; cursor: pointer; }
.checklist__item input { width: 15px; height: 15px; accent-color: var(--primary); }
.task-check--static { pointer-events: none; opacity: .8; }
.task-item.has-flag { box-shadow: inset 3px 0 0 var(--warning); }
.task-item[role="button"] { cursor: pointer; }
.badge svg { width: 12px; height: 12px; vertical-align: -1px; margin-right: 3px; }
.project-swatch:hover { transform: scale(1.12); }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    font-size: .78rem;
    background: var(--surface);
    cursor: pointer;
    color: var(--text-muted);
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip:disabled { opacity: .55; cursor: default; }
.chip:disabled:hover { border-color: var(--border-strong); color: var(--text-muted); }
/* In-place panel refresh: a short fade instead of a full page re-render. */
.is-refreshing { opacity: .55; transition: opacity .15s ease; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab {
    padding: 9px 14px;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-weight: 550;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }

/* --- content components ------------------------------------------------ */
.stat {
    padding: 16px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.stat__label { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); }
.stat__value { font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; margin-top: 4px; }
.stat__meta { font-size: .8rem; color: var(--text-muted); }
.stat--progress .stat__value { color: var(--primary); }
.stat--overall .stat__value { color: var(--primary); }
.stat--done .stat__value { color: var(--success); }
.stat--upcoming .stat__value { color: var(--info); }
.stat--overdue .stat__value { color: var(--danger); }

.progress { height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress__bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s ease; }
.progress__bar--done { background: var(--success); }

.list { display: flex; flex-direction: column; }
.list__item {
    display: flex;
    gap: 12px;
    padding: 13px 16px;
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    background: transparent;
    border-left: 3px solid transparent;
    text-align: left;
    width: 100%;
    align-items: flex-start;
}
.list__item:last-child { border-bottom: 0; }
.list__item:hover { background: var(--surface-2); }
.list__item.is-active { background: var(--primary-soft); border-left-color: var(--primary); }
.list__body { min-width: 0; flex: 1; }
.list__title { font-weight: 600; }
.list__meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .78rem; color: var(--text-faint); margin-top: 3px; }

.task-item { align-items: flex-start; }
.task-check {
    width: 20px; height: 20px;
    border-radius: 50%;
    border: 2px solid var(--border-strong);
    background: transparent;
    cursor: pointer;
    flex: 0 0 auto;
    margin-top: 2px;
    display: grid;
    place-items: center;
    color: transparent;
}
.task-check:hover { border-color: var(--success); color: var(--success); }
.task-check.is-done { background: var(--success); border-color: var(--success); color: #fff; }
.task-check.is-done:hover { color: #fff; }
.task-check.is-done.is-missed { background: var(--danger); border-color: var(--danger); color: #fff; }
.task-check.is-done.is-missed:hover { border-color: var(--danger); color: #fff; }
.task-check svg { width: 12px; height: 12px; }
.task-item.is-done .list__title { text-decoration: line-through; color: var(--text-muted); }
.task-item.is-done.is-missed { border-left-color: var(--danger); box-shadow: none; }
.task-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    text-decoration: none;
}
.task-mark svg { width: 14px; height: 14px; stroke-width: 2.5; }
.task-mark--ok { color: var(--success); }
.task-mark--fail { color: var(--danger); }

.board { display: grid; grid-template-columns: repeat(3, minmax(240px, 1fr)); gap: 14px; align-items: start; }
.board--2 { grid-template-columns: repeat(2, minmax(260px, 1fr)); }

/* --- dashboard sticky notes -------------------------------------------- */
/* Colour follows the task priority; the ink stays dark so the paper reads
   the same in the light and dark theme. */
.task-note {
    --note-bg: #fdf3c8;
    --note-border: #f4e3a1;
    --note-ink: #4a3f14;
    position: relative;
    padding: 14px 14px 14px;
    border-radius: 4px 4px 14px 4px;
    background: var(--note-bg);
    border: 1px solid var(--note-border);
    box-shadow: 0 10px 20px -16px rgba(19, 25, 38, .65), 0 2px 3px rgba(19, 25, 38, .10);
    color: var(--note-ink);
    cursor: pointer;
    transform: rotate(-.4deg);
    transition: transform .16s ease, box-shadow .16s ease, opacity .16s ease;
}
.task-note:nth-child(even) { transform: rotate(.5deg); }
.task-note::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: 0;
    width: 18px;
    height: 18px;
    border-radius: 4px 0 0 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, .7), rgba(19, 25, 38, .12));
    border-left: 1px solid rgba(19, 25, 38, .08);
    border-top: 1px solid rgba(19, 25, 38, .08);
}
.task-note:hover, .task-note:focus-visible {
    transform: rotate(0deg) translateY(-3px);
    box-shadow: 0 18px 28px -18px rgba(19, 25, 38, .7), 0 4px 8px rgba(19, 25, 38, .12);
    outline: none;
}
.task-note--low { --note-bg: #e4f6ea; --note-border: #c7ebd5; --note-ink: #1d4030; }
.task-note--medium { --note-bg: #fdf3c8; --note-border: #f4e3a1; --note-ink: #4a3f14; }
.task-note--high { --note-bg: #ffe7cb; --note-border: #ffd4a8; --note-ink: #5a3612; }
.task-note--urgent { --note-bg: #ffdcdc; --note-border: #ffc1c1; --note-ink: #5c1d1d; }

.task-note__title { font-weight: 650; margin-bottom: 6px; }
.task-note__meta, .task-note__foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: .76rem;
    opacity: .85;
}
.task-note__foot { margin-top: 8px; }
.task-note .badge,
.task-note .badge--primary,
.task-note .badge--success,
.task-note .badge--info,
.task-note .badge--project {
    background: rgba(255, 255, 255, .64);
    color: var(--note-ink);
    border: 1px solid rgba(19, 25, 38, .10);
}
.task-note .badge--warning { background: rgba(180, 83, 9, .12); color: #92400e; border-color: rgba(146, 64, 14, .22); }
.task-note .badge--danger { background: rgba(185, 28, 28, .12); color: #9f1239; border-color: rgba(159, 18, 57, .22); }
.task-note__progress {
    height: 6px;
    margin-top: 10px;
    background: rgba(19, 25, 38, .12);
}
.task-note__progress .progress__bar { background: rgba(19, 25, 38, .5); }

/* The "Akan datang" column is faded until its tasks become active;
   it stays clickable and clears up on hover. */
.board__column--upcoming .task-note { opacity: .6; }
.board__column--upcoming .task-note:hover,
.board__column--upcoming .task-note:focus-visible { opacity: 1; }
.board__column {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    min-height: 160px;
    transition: border-color .15s ease, background .15s ease;
}
.board__column.is-over { border-color: var(--primary); background: var(--primary-soft); }
.board__head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-weight: 600; font-size: .9rem; }
.board__cards { display: flex; flex-direction: column; gap: 10px; }
.task-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    cursor: grab;
    box-shadow: var(--shadow-sm);
}
.task-card:active { cursor: grabbing; }
.task-card.is-dragging { opacity: .5; }
.task-card__title { display: flex; align-items: flex-start; gap: 6px; font-weight: 600; margin-bottom: 6px; }
.task-card__title .task-mark { margin-top: 3px; }
.task-card.is-done .task-card__title span:last-child { text-decoration: line-through; color: var(--text-muted); }
.task-card.is-done.is-missed { border-left: 3px solid var(--danger); }
.task-card__meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: .76rem; color: var(--text-faint); }
.task-detail-card.is-done.is-missed { border-left: 3px solid var(--danger); }
.task-detail-card__title { display: flex; align-items: center; gap: 8px; }
.task-detail-card__title .task-mark svg { width: 20px; height: 20px; }

.markdown { font-size: .95rem; line-height: 1.7; overflow-wrap: break-word; }
.markdown > :first-child { margin-top: 0; }
.markdown h1 { font-size: 1.5rem; margin-top: 1.2em; }
.markdown h2 { font-size: 1.25rem; margin-top: 1.1em; }
.markdown h3 { font-size: 1.08rem; margin-top: 1em; }
.markdown ul, .markdown ol { padding-left: 1.4em; margin: 0 0 .9em; }
.markdown li { margin-bottom: .25em; }
.markdown code {
    font-family: var(--mono);
    font-size: .86em;
    background: var(--surface-3);
    padding: .15em .4em;
    border-radius: 5px;
}
.markdown pre {
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 13px 15px;
    overflow-x: auto;
    margin: 0 0 1em;
}
.markdown pre code { background: transparent; padding: 0; font-size: .85em; line-height: 1.6; }

/* --- syntax highlighting (highlight.js token classes, bundled locally) --- */
.hljs { color: var(--text); }
.hljs-comment, .hljs-quote { color: var(--code-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag, .hljs-meta .hljs-keyword {
    color: var(--code-keyword);
}
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute, .hljs-meta .hljs-string {
    color: var(--code-string);
}
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-link, .hljs-selector-attr, .hljs-selector-pseudo {
    color: var(--code-number);
}
.hljs-title, .hljs-title.function_, .hljs-section, .hljs-name { color: var(--code-function); }
.hljs-type, .hljs-class .hljs-title, .hljs-title.class_, .hljs-built_in, .hljs-selector-id {
    color: var(--code-type);
}
.hljs-attr, .hljs-variable, .hljs-template-variable, .hljs-selector-class, .hljs-property {
    color: var(--code-attr);
}
.hljs-builtin-name, .hljs-meta, .hljs-tag { color: var(--code-builtin); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }
.hljs-deletion { color: var(--danger); }
.hljs-params { color: var(--text); }
.markdown blockquote {
    margin: 0 0 1em;
    padding: 6px 16px;
    border-left: 3px solid var(--primary);
    background: var(--surface-2);
    color: var(--text-muted);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.markdown table { border-collapse: collapse; width: 100%; margin-bottom: 1em; font-size: .9rem; }
/* Wide tables scroll inside the text block instead of being clipped by the card. */
.markdown { overflow-x: auto; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.markdown th { background: var(--surface-3); }
.markdown img {
    display: block;
    max-width: 100%;
    max-height: 520px;
    margin: .5em 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    object-fit: contain;
}
.markdown a { text-decoration: underline; }
.markdown--compact { font-size: .88rem; line-height: 1.55; }
.markdown--compact > :last-child { margin-bottom: 0; }
.markdown--compact img { max-height: 320px; }

/* --- tables, files, modal, toast -------------------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
    text-align: left;
    padding: 10px 14px;
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-faint);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    font-weight: 600;
    white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table__actions { display: flex; gap: 4px; justify-content: flex-end; }

.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.file-card {
    display: flex;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
.file-card__icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    display: grid; place-items: center;
    background: var(--surface-3);
    color: var(--text-muted);
    flex: 0 0 auto;
}
.file-card__icon svg { width: 18px; height: 18px; }
.file-card__name { font-weight: 600; overflow-wrap: anywhere; }
.file-card__meta { font-size: .76rem; color: var(--text-faint); margin-top: 2px; }

.dropzone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 26px 18px;
    text-align: center;
    color: var(--text-muted);
    background: var(--surface-2);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone strong { display: block; color: var(--text); margin-bottom: 4px; }

.empty {
    padding: 34px 18px;
    text-align: center;
    color: var(--text-muted);
}
.empty__title { font-weight: 650; color: var(--text); margin-bottom: 4px; }

.modal-root {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(9, 12, 18, .55);
    overflow-y: auto;
}
.modal {
    width: 100%;
    max-width: 620px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: rise .2s ease both;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    /* Same reason as .card: the scrolling body must not square the corners. */
    overflow: hidden;
}
.modal--wide { max-width: 900px; }
.modal__head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal__head h2 { margin: 0; font-size: 1.05rem; }
.modal__body { padding: 18px; overflow-y: auto; }
.modal__foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--border); }

.toast-root {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 80;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(92vw, 380px);
}
.toast {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    box-shadow: var(--shadow);
    animation: rise .2s ease both;
}
.toast--success { border-left-color: var(--success); }
.toast--error { border-left-color: var(--danger); }
.toast--info { border-left-color: var(--info); }
.toast__text { font-size: .88rem; }

.skeleton {
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3));
    background-size: 200% 100%;
    animation: shimmer 1.2s linear infinite;
    height: 14px;
    margin-bottom: 10px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* --- dashboard: numbers strip + month calendar ------------------------- */
/* The dashboard owns the area under the topbar: the page does not scroll and
   the calendar takes every pixel the numbers leave over. The height comes from
   static/js/views/dashboard.js (fillViewport), because only the browser knows
   how tall the topbar is. */
body.is-dashboard { overflow: hidden; }

.view--dashboard {
    flex: 0 0 auto;
    max-width: none;
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.dash { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }

.dash__stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.dash__stats .stat { padding: 9px 12px; border-radius: var(--radius-sm); }
.dash__stats .stat__label { font-size: .7rem; }
.dash__stats .stat__value { font-size: 1.3rem; margin-top: 2px; }
.dash__stats .stat__meta { font-size: .72rem; }

.dash__main {
    --cal-line: #b3bcc8;
    --cal-line-soft: #d5dbe3;
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 3fr);
    gap: 10px;
}
[data-theme="dark"] .dash__main {
    --cal-line: #4b5a6b;
    --cal-line-soft: #38434f;
}

.dash-today {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px 12px;
    background: var(--surface);
    border: 1px solid var(--cal-line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.dash-today__head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--cal-line-soft);
}
.dash-today__title-wrap { min-width: 0; flex: 1; }
.dash-today__title {
    margin: 0;
    font-size: .95rem;
    font-weight: 650;
    letter-spacing: -.01em;
    line-height: 1.25;
}
.dash-today__date {
    font-size: .72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dash-today__actions { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.dash-today__count {
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: .72rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.dash-today__list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 2px;
}
.dash-today__empty {
    margin: auto 0;
    padding: 16px 8px;
    text-align: center;
}
.dash-today__empty-title {
    font-size: .86rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.dash-today__empty p { margin: 0; }

.today-task {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 100%;
    padding: 8px 10px;
    font: inherit;
    text-align: left;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.today-task:hover { border-color: var(--primary); background: var(--primary-soft); }
.today-task:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.today-task--low { border-left-color: #22c55e; }
.today-task--medium { border-left-color: #d97706; }
.today-task--high { border-left-color: #ea580c; }
.today-task--urgent { border-left-color: #dc2626; }
[data-theme="dark"] .today-task--low { border-left-color: #34d97b; }
[data-theme="dark"] .today-task--medium { border-left-color: #f0a63c; }
[data-theme="dark"] .today-task--high { border-left-color: #fb8b3c; }
[data-theme="dark"] .today-task--urgent { border-left-color: #ff6b6b; }
.today-task.is-done { opacity: .82; }
.today-task.is-done .today-task__title { text-decoration: line-through; color: var(--text-muted); }
.today-task.is-done.is-missed { border-left-color: #dc2626; }
[data-theme="dark"] .today-task.is-done.is-missed { border-left-color: #ff6b6b; }
.today-task__top {
    display: flex;
    align-items: flex-start;
    gap: 6px;
}
.today-task__top .task-mark { margin-top: 2px; }
.today-task__title {
    flex: 1;
    min-width: 0;
    font-size: .84rem;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.today-task__pct {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: .72rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    padding-top: 1px;
}
.today-task__meta {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    font-size: .7rem;
}
.today-task__meta .badge { font-size: .66rem; padding: 1px 6px; }
.today-task__meta .badge svg { width: 10px; height: 10px; margin-right: 0; flex: 0 0 auto; }

.cal {
    /* Local palette: grid lines and day numbers must stay crisp in both themes,
       so they do not rely on the very soft global borders. */
    --cal-line: #b3bcc8;
    --cal-line-soft: #d5dbe3;
    --cal-line-out: #e8ebef;
    --cal-num: var(--text);
    --cal-num-dim: var(--text-muted);
    --cal-num-out: .5;
    --cal-num-past: .38;
    --cal-friday-bg: #eef8f1;
    --cal-friday-line: #cfe9d9;
    --cal-friday-ink: #14653b;
    --cal-holiday-bg: #fdeeee;
    --cal-holiday-line: #f0b7bc;
    --cal-past-bg: #e6eaef;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px 12px;
    background: var(--surface);
    border: 1px solid var(--cal-line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: opacity .15s ease;
}
[data-theme="dark"] .cal {
    --cal-line: #4b5a6b;
    --cal-line-soft: #38434f;
    --cal-line-out: #212932;
    --cal-num: #f2f5fa;
    --cal-num-dim: #b0bac8;
    --cal-num-out: .45;
    --cal-num-past: .35;
    --cal-friday-bg: #14251c;
    --cal-friday-line: #1f3a2a;
    --cal-friday-ink: #7ee0a8;
    --cal-holiday-bg: #2b1719;
    --cal-holiday-line: #52262a;
    --cal-past-bg: #1c232c;
}
.cal.is-loading { opacity: .55; pointer-events: none; }
.cal__bar { display: flex; align-items: center; gap: 8px; }
.cal__month { font-weight: 650; letter-spacing: -.01em; }
.cal__nav { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.cal__next svg { transform: rotate(180deg); }
.cal__weekdays {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
    padding-bottom: 3px;
    border-bottom: 1px solid var(--cal-line-soft);
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--cal-num-dim);
}
.cal__weekdays span { padding: 0 4px; }
/* The week ends on Sunday: a day off, so the label is red like the date. */
.cal__weekdays span:last-child { color: var(--danger); }
.cal__grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-auto-rows: minmax(0, 1fr);
    gap: 6px;
}
.cal__day {
    --cal-cell-bg: var(--surface);
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-height: 0;
    padding: 5px 6px 6px;
    font: inherit;
    text-align: left;
    color: var(--text);
    background: var(--cal-cell-bg);
    /* Slightly bolder than the global border so the cells read as a grid. */
    border: 1px solid var(--cal-line);
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.cal__day:hover { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.cal__day:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
/* Friday: the short day of the week — a quiet green tint, deep green number. */
.cal__day.is-friday { --cal-cell-bg: var(--cal-friday-bg); border-color: var(--cal-friday-line); }
.cal__day.is-friday .cal__num { color: var(--cal-friday-ink); }

/* Days already behind us: a grey box; the border keeps its normal strength. */
.cal__day.is-past { --cal-cell-bg: var(--cal-past-bg); }

/* Sunday and public holidays are days off: the same red box and red number. */
.cal__day.is-sunday,
.cal__day.is-holiday {
    --cal-cell-bg: var(--cal-holiday-bg);
    border-color: var(--cal-holiday-line);
}
.cal__day.is-sunday .cal__num,
.cal__day.is-holiday .cal__num { color: var(--danger); }
/* The tint must not swallow the hover/focus feedback. */
.cal__day.is-friday:hover,
.cal__day.is-sunday:hover,
.cal__day.is-holiday:hover,
.cal__day.is-friday:focus-visible,
.cal__day.is-sunday:focus-visible,
.cal__day.is-holiday:focus-visible { border-color: var(--primary); }

/* Days of the neighbouring months: the number and the box step back the most. */
.cal__day.is-outside {
    --cal-cell-bg: var(--bg);
    border-style: dashed;
    border-color: var(--cal-line-out);
}
.cal__day.is-outside .cal__num { opacity: var(--cal-num-out); font-weight: 600; }
.cal__day.is-outside .cal__chip { opacity: .45; }
/* The fade of the numbers comes last so it wins over any colour above. */
.cal__day.is-past .cal__num { opacity: var(--cal-num-past); }
.cal__day.is-past .cal__chip { opacity: .65; }

.cal__day.is-today { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.cal__day.is-today .cal__num { background: var(--primary); color: #fff; opacity: 1; }
.cal__top { display: flex; align-items: center; gap: 4px; }
.cal__num {
    min-width: 22px;
    height: 22px;
    display: inline-grid;
    place-items: center;
    border-radius: 6px;
    color: var(--cal-num);
    font-size: .78rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.01em;
}
.cal__count {
    margin-left: auto;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--cal-num-dim);
    font-size: .64rem;
    font-weight: 700;
}
/* Name of a public holiday or observance, always visible above the chips. */
.cal__holiday {
    display: block;
    font-size: .62rem;
    font-weight: 650;
    line-height: 1.25;
    color: var(--danger);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal__holiday--soft { color: var(--cal-num-dim); font-weight: 600; }
.cal__chips { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: 3px; }

.cal__chip {
    flex: 0 0 auto;
    padding: 1px 5px;
    border-radius: 5px;
    border-left: 3px solid var(--border-strong);
    background: var(--surface-3);
    font-size: .68rem;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal__chip--low { border-left-color: #22c55e; background: rgba(34, 197, 94, .13); }
.cal__chip--medium { border-left-color: #d97706; background: rgba(217, 119, 6, .13); }
.cal__chip--high { border-left-color: #ea580c; background: rgba(234, 88, 12, .15); }
.cal__chip--urgent { border-left-color: #dc2626; background: rgba(220, 38, 38, .15); }
/* The same tints need more body on a dark background. */
[data-theme="dark"] .cal__chip--low { border-left-color: #34d97b; background: rgba(52, 217, 123, .2); }
[data-theme="dark"] .cal__chip--medium { border-left-color: #f0a63c; background: rgba(240, 166, 60, .2); }
[data-theme="dark"] .cal__chip--high { border-left-color: #fb8b3c; background: rgba(251, 139, 60, .22); }
[data-theme="dark"] .cal__chip--urgent { border-left-color: #ff6b6b; background: rgba(255, 107, 107, .24); }
.cal__chip.is-done { text-decoration: line-through; color: var(--cal-num-dim); }
.cal__chip .task-mark { vertical-align: -1.5px; margin-right: 3px; }
.cal__chip .task-mark svg { width: 11px; height: 11px; stroke-width: 2.6; }
.cal__chip.is-done.is-missed { border-left-color: #dc2626; background: rgba(220, 38, 38, .12); }
[data-theme="dark"] .cal__chip.is-done.is-missed { border-left-color: #ff6b6b; background: rgba(255, 107, 107, .22); }
/* "+N" for the chips that do not fit; painted over the cell background. */
.cal__more {
    position: absolute;
    right: 5px;
    bottom: 4px;
    padding: 0 5px;
    border-radius: 5px;
    background: var(--cal-cell-bg);
    box-shadow: 0 0 0 2px var(--cal-cell-bg);
    color: var(--cal-num-dim);
    font-size: .64rem;
    font-weight: 700;
}
/* Phones show priority dots instead of titles (see the media query below). */
.cal__dots { display: none; }
.cal__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong); }
.cal__dot--low { background: #22c55e; }
.cal__dot--medium { background: #d97706; }
.cal__dot--high { background: #ea580c; }
.cal__dot--urgent { background: #dc2626; }
.cal__dot.is-done.is-completed { background: var(--success); }
.cal__dot.is-done.is-missed { background: var(--danger); }

/* --- task list inside the day dialog ---------------------------------- */
.day-list { display: flex; flex-direction: column; gap: 8px; }
.day-holiday {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    margin-bottom: 10px;
    border-radius: var(--radius-sm);
    background: var(--danger-soft);
    color: var(--danger);
    font-size: .86rem;
    font-weight: 600;
}
.day-holiday svg { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 2px; }
.day-holiday--soft { background: var(--surface-2); color: var(--text-muted); }
.day-task {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    font: inherit;
    text-align: left;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.day-task:hover { border-color: var(--primary); background: var(--primary-soft); }
.day-task.is-done .day-task__title { text-decoration: line-through; color: var(--text-muted); }
.day-task.is-done.is-missed { border-left-color: var(--danger); }
.day-task.is-done.is-missed:hover { border-left-color: var(--danger); }
.day-task__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.day-task__title { font-weight: 600; }
.day-task__meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .76rem; }
.day-task__pct { color: var(--text-muted); font-size: .82rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* --- team management & hierarchy --------------------------------------- */
.team-mgmt-list { display: flex; flex-direction: column; }
.team-mgmt-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.team-mgmt-row:last-child { border-bottom: 0; }
.team-tree { display: flex; flex-direction: column; gap: 14px; }
.team-node {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.team-node--leader {
    background: var(--primary-soft);
    border-color: rgba(37, 99, 235, .28);
}
[data-theme="dark"] .team-node--leader { border-color: rgba(91, 140, 255, .35); }
.team-node--admin { background: var(--surface-2); }
.team-node__info { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.team-node__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 2px; }
.team-branch {
    position: relative;
    margin-left: 20px;
    padding-left: 16px;
    border-left: 2px solid var(--border-strong);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.team-branch__label {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-faint);
    font-weight: 650;
}

/* --- KPI fleet & detail ------------------------------------------------ */
.avatar--md { width: 56px; height: 56px; font-size: 1.15rem; }
.kpi-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}
.kpi-fleet { display: flex; flex-direction: column; }
.kpi-row {
    display: grid;
    grid-template-columns: minmax(220px, 1.4fr) minmax(280px, 1.5fr) auto;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 13px 16px;
    border: 0;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background .15s ease;
}
.kpi-row:last-child { border-bottom: 0; }
.kpi-row:hover { background: var(--surface-2); }
.kpi-row__who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.kpi-row__identity { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.kpi-row__metrics {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.kpi-pill {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 6px 10px;
    min-width: 78px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: .86rem;
    font-variant-numeric: tabular-nums;
}
.kpi-pill__label { font-size: .68rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; }
.kpi-pill--ok strong { color: var(--success); }
.kpi-pill--fail { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }
.kpi-pill--fail strong { color: var(--danger); }
.kpi-pill--bar { min-width: 120px; flex: 1 1 120px; max-width: 170px; }
.kpi-row__score {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    min-width: 112px;
}
.kpi-score {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-variant-numeric: tabular-nums;
}
.kpi-score__num { font-size: 1.35rem; font-weight: 750; line-height: 1; }
.kpi-score--great .kpi-score__num, .kpi-score--great .kpi-score-box__val { color: var(--success); }
.kpi-score--good .kpi-score__num, .kpi-score--good .kpi-score-box__val { color: var(--primary); }
.kpi-score--warn .kpi-score__num, .kpi-score--warn .kpi-score-box__val { color: var(--warning); }
.kpi-score--low .kpi-score__num, .kpi-score--low .kpi-score-box__val { color: var(--danger); }
.kpi-score--none .kpi-score__num, .kpi-score--none .kpi-score-box__val { color: var(--text-faint); }

.kpi-detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.kpi-detail-head__user { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1; }
.kpi-detail-head__score { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.kpi-score-box {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.kpi-score-box__val {
    font-size: 1.9rem;
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.kpi-open-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    background: var(--primary-soft);
}
.kpi-task-note {
    margin-top: 6px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border-left: 2px solid var(--border-strong);
}

@media (max-width: 960px) {
    .kpi-row {
        grid-template-columns: minmax(0, 1fr);
        align-items: flex-start;
    }
    .kpi-row__score {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        width: 100%;
    }
}

/* --- responsive ------------------------------------------------------- */
.only-mobile { display: none; }

@media (max-width: 1080px) {
    .grid--sidebar { grid-template-columns: minmax(0, 1fr); }
    .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid--5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
    .only-mobile { display: inline-grid; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: var(--shadow-lg);
        height: 100vh;
        width: min(84vw, var(--sidebar-width));
    }
    .sidebar.is-open { transform: translateX(0); }
    .view { padding: 16px; }
    .topbar { padding: 10px 14px; }
    .board { grid-template-columns: minmax(0, 1fr); }
    .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .table--responsive thead { display: none; }
    .table--responsive tr { display: block; border-bottom: 1px solid var(--border); padding: 8px 0; }
    .table--responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 6px 14px; }
    .table--responsive td::before {
        content: attr(data-label);
        font-size: .74rem;
        text-transform: uppercase;
        letter-spacing: .05em;
        color: var(--text-faint);
        font-weight: 600;
    }
}

@media (max-width: 620px) {
    .grid--2, .grid--3, .grid--4, .grid--5 { grid-template-columns: minmax(0, 1fr); }
    .board, .board--2 { grid-template-columns: minmax(0, 1fr); }
    .task-note, .task-note:nth-child(even) { transform: none; }
    .auth__card { padding: 22px; }
    .toast-root { left: 14px; right: 14px; bottom: 14px; max-width: none; }
    h1 { font-size: 1.15rem; }
}

/* --- dashboard responsive -------------------------------------------- */
/* Keep the numbers on a single row and the calendar usable once the screen
   gets narrow; the heights stay fixed, so nothing starts to scroll. */
@media (max-width: 1080px) {
    .dash__stats .stat__meta { display: none; }
}

@media (max-width: 860px) {
    .view--dashboard { padding: 8px; }
    .dash__main {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(120px, 32%) minmax(0, 1fr);
        gap: 8px;
    }
    .dash-today { padding: 8px; gap: 6px; }
    .cal { padding: 8px; gap: 6px; }
    .cal__chip { font-size: .62rem; }
    .cal__count { display: none; }
}

@media (max-width: 620px) {
    body.is-dashboard { overflow: hidden; }
    .view--dashboard { padding: 6px; }
    .dash { gap: 6px; }
    .dash__stats { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
    .dash__stats .stat { flex: 0 0 auto; min-width: 132px; padding: 7px 10px; }
    .dash__main {
        grid-template-rows: minmax(100px, 30%) minmax(0, 1fr);
        gap: 6px;
    }
    .dash-today { padding: 6px 8px; gap: 4px; }
    .today-task { padding: 6px 8px; gap: 3px; }
    .cal { padding: 6px; gap: 4px; }
    .cal__weekdays { font-size: .62rem; }
    .cal__chips, .cal__more { display: none; }
    .cal__holiday { font-size: .56rem; font-weight: 600; }
    .cal__dots { display: flex; gap: 3px; margin-top: auto; }
    .cal__grid { gap: 3px; }
    .cal__day { padding: 3px 4px; border-radius: 8px; }
    .cal__num { min-width: 16px; height: 16px; font-size: .64rem; }
    .cal__bar .btn { padding: 4px 8px; }
}

@media print {
    .sidebar, .topbar, .toast-root, .modal-root { display: none !important; }
}
