/* =============================================================================
 * app_v2.css — ground-up design system for dashboard + assignments pages.
 *
 * One stylesheet. No @layer. No !important. No theme switching. Light only.
 * Targets the EXISTING class names used in base.html + dashboard.html + the
 * ticket/board partials so templates don't need to change.
 *
 * Structure:
 *   1. Reset + tokens + typography
 *   2. App shell — sidebar / header / chat-panel / main
 *   3. Dashboard home — stats row, section toolbar
 *   4. Kanban — board, columns, tickets (Linear anatomy)
 *   5. Chips + buttons + inputs
 *   6. Modals, overlays, misc
 *   7. Responsive
 * ========================================================================== */

/* ---------- 1. Reset + tokens + typography ------------------------------ */

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

:root {
    --bg:          #eeeef2;
    --surface:     #ffffff;
    --surface-2:   #f7f7f7;
    --line:        #e8e8e8;
    --line-soft:   #f0f0f0;
    --text:        #18181b;
    --text-2:      #52525b;
    --text-3:      #a1a1aa;
    --text-muted:  #a1a1aa;
    /* Primary accent — readable blue вместо near-black. Даёт контраст
     * текста на кнопках и не сливается с фоном. Hover — blue-700. */
    --accent:       #2563eb;  /* blue-600 */
    --accent-hover-strong: #1d4ed8;  /* blue-700 for hover */
    --accent-text:  #ffffff;
    --accent-soft:  #eff6ff;  /* blue-50 для soft-fill */

    --danger:      #ef4444;
    --danger-bg:   #fef2f2;
    --warning:     #f59e0b;
    --warning-bg:  #fffbeb;
    --success:     #10b981;
    --success-bg:  #ecfdf5;

    --prio-block:     #dc2626;
    --prio-block-bg:  #fef7f7;
    --prio-high:      #f59e0b;
    --prio-high-bg:   #fffbf3;

    --p1-bg: #6366f1; --p1-fg: #ffffff;
    --p2-bg: #f97316; --p2-fg: #ffffff;
    --p3-bg: #0ea5e9; --p3-fg: #ffffff;
    --p4-bg: #10b981; --p4-fg: #ffffff;
    --p5-bg: #ec4899; --p5-fg: #ffffff;
    --p6-bg: #8b5cf6; --p6-fg: #ffffff;

    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px;
    --sp-4: 16px; --sp-5: 20px; --sp-6: 24px;

    --r-1: 6px; --r-2: 8px; --r-3: 10px; --r-4: 14px;

    --shadow-1: 0 1px 2px rgba(20,20,24,0.04);
    --shadow-2: 0 4px 12px rgba(20,20,24,0.06);
    --shadow-3: 0 10px 30px rgba(20,20,24,0.12);

    --sidebar-w: 72px;
    --chat-w:    510px;
    --header-h:  52px;
    --font: "Inter", "Inter Variable", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

    /* Legacy var aliases — keep inline style="var(--legacy-name)" in existing
     * templates working without having to edit each one. Do NOT use these
     * in new code; they exist only so v2 can host legacy markup cleanly. */
    --bg-main:      var(--surface);
    --bg-elevated:  var(--surface);
    --bg-hover:     var(--line-soft);
    --bg-active:    var(--line);
    --bg-input:     var(--surface);
    --bg-sidebar:   var(--surface);
    --bg-header:    var(--surface);
    --bg-secondary: var(--surface-2);
    --border:       var(--line);
    --border-hover: #d4d4d4;
    --border-input: var(--line);
    --accent-soft:  var(--line-soft);
    --accent-hover: var(--line);
    --danger-soft:  var(--danger-bg);
    --warning-soft: var(--warning-bg);
    --shadow-sm:    var(--shadow-1);
    --shadow-md:    var(--shadow-2);
    --shadow-lg:    var(--shadow-3);
}

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
h1 { font-size: 22px; line-height: 1.2; }
h2 { font-size: 17px; line-height: 1.3; }
h3 { font-size: 14px; line-height: 1.35; }

a { color: inherit; text-decoration: none; }

button {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

textarea, input { font: inherit; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.scroll-progress { display: none; }  /* v1 scroll indicator — not needed */
.skip-link { position: absolute; top: -60px; left: 0; background: var(--accent); color: var(--accent-text); padding: 8px 14px; z-index: 9999; font-weight: 600; border-radius: 0 0 var(--r-1) 0; }
.skip-link:focus { top: 0; }

/* ---------- 2. App shell ------------------------------------------------- */

/* V2 top bar — compact stats widget + search/notifications/user. Sits
 * above .layout as a fixed-height block; .layout fills the rest. */
.appbar {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    height: var(--header-h);
    padding: 0 var(--sp-5);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 500;
}

.appbar__stats {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
}

.appbar__stat {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    padding: 4px 10px;
    border-radius: var(--r-2);
    color: var(--text);
    transition: background 0.12s;
}
.appbar__stat:hover { background: var(--line-soft); }

.appbar__stat-label {
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.appbar__stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
}
.appbar__stat-overdue {
    color: var(--danger);
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: 0;
}

.appbar__actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
    position: relative;
}

.appbar__iconbtn {
    width: 32px; height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-2);
    color: var(--text-2);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.appbar__iconbtn:hover {
    background: var(--line-soft);
    color: var(--text);
}

.appbar__user {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 4px;
    margin-left: 6px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.12s;
}
.appbar__user:hover { background: var(--line-soft); }

.appbar__avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--p1-bg);
    color: var(--p1-fg);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1;
}
.appbar__user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.appbar__user-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 220px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-3);
    box-shadow: var(--shadow-3);
    padding: 6px;
    display: none;
    z-index: 520;
}
.appbar__user-menu.open { display: block; }
.appbar__menuitem {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--r-1);
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    background: transparent;
    border: none;
    text-align: left;
    transition: background 0.12s;
}
.appbar__menuitem:hover { background: var(--line-soft); }
.appbar__menuitem--muted { color: var(--text-2); }
.appbar__menu-divider { height: 1px; background: var(--line); margin: 4px 6px; }

/* V2 layout: sidebar + chat + main. Appbar (fixed-height block above)
 * handles stats/user — so no "header" grid row here. */
.layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) var(--chat-w) 1fr;
    grid-template-rows: 1fr;
    grid-template-areas: "sidebar chat main";
    height: calc(100vh - var(--header-h));
    overflow: hidden;
    /* Tiled shell: gap + padding make sidebar/chat/main float as cards
     * with the page --bg showing between them. */
    gap: 10px;
    padding: 10px;
    box-sizing: border-box;
    background: var(--bg);
}

/* Legacy .header block (still rendered by base.html) becomes dead weight
 * when appbar is present. */
body:has(.appbar) .header { display: none !important; }

/* Sidebar (wider, more breathable) */
:root { --sidebar-w: 104px; }

.sidebar {
    grid-area: sidebar;
    background: var(--surface);
    /* Tile: full border + shadow + rounded corners instead of bare border-right */
    border: 1px solid rgba(0,0,0,0.22);
    border-radius: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: var(--sp-3) 6px;
    gap: 3px;
    overflow-y: auto;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    margin-bottom: var(--sp-3);
    letter-spacing: -0.02em;
}

.sidebar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 10px 4px;
    border-radius: var(--r-2);
    color: var(--text-3);
    font-size: 10.5px;
    line-height: 1.2;
    text-align: center;
    transition: background 0.12s, color 0.12s;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar a .sidebar-label {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar a:hover {
    background: var(--line-soft);
    color: var(--text);
}

.sidebar a.active {
    background: var(--line-soft);
    color: var(--text);
    font-weight: 600;
}

.sidebar-label { font-size: 10.5px; }

.sidebar-divider { height: 1px; background: var(--line); margin: var(--sp-3) var(--sp-1); }
.sidebar-spacer  { flex: 1; }

/* Header */
.header {
    grid-area: header;
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    padding: 0 var(--sp-5);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.header h1 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0;
    flex: 0 0 auto;
}

.header .time {
    font-size: 13px;
    color: var(--text-3);
    flex: 1;
    text-align: center;
}

.rag-toggle {
    width: 32px; height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-2);
    color: var(--text-2);
    background: transparent;
    border: 1px solid var(--line);
    font-size: 14px;
    transition: background 0.12s;
}
.rag-toggle:hover { background: var(--line-soft); }

/* Chat panel */
.chat-panel {
    grid-area: chat;
    background: var(--surface);
    /* Tile: same chrome as sidebar/main so all three read as separated cards */
    border: 1px solid rgba(0,0,0,0.22);
    border-radius: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
    margin: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-panel-top {
    padding: var(--sp-3) var(--sp-4) var(--sp-3);
    border-bottom: 1px solid var(--line-soft);
    background: var(--surface);
}

.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-3);
}

.chat-panel-title { font-size: 13px; font-weight: 600; color: var(--text); }

.chat-panel-new {
    width: 24px; height: 24px;
    border-radius: var(--r-1);
    color: var(--text-3);
    background: transparent;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s;
}
.chat-panel-new:hover { background: var(--line-soft); color: var(--text); }

.chat-rag-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: var(--sp-2);
    font-size: 11px;
    color: var(--text-2);
}

.chat-rag-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    background: var(--line-soft);
    border-radius: 999px;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-2);
    border: 1px solid transparent;
}
.chat-rag-toggle input { margin: 0; }
.chat-rag-toggle:hover { background: #eaeaea; }

.chat-rag-project-select {
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface);
    font-size: 11px;
    color: var(--text-2);
    outline: none;
    cursor: pointer;
}

.chat-input-area {
    display: flex;
    align-items: center;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    background: var(--surface);
    padding: 6px 8px;
}

.chat-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 13px;
    color: var(--text);
    background: transparent;
    resize: none;
    min-height: 28px;
    max-height: 120px;
    padding: 2px 2px;
    font-family: inherit;
}
.chat-input::placeholder { color: var(--text-3); }

.chat-file-btn, .chat-voice-btn, .chat-send-btn {
    width: 28px; height: 28px;
    border-radius: var(--r-1);
    color: var(--text-2);
    background: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s;
}
.chat-file-btn:hover, .chat-voice-btn:hover { background: var(--line-soft); color: var(--text); }

.chat-send-btn {
    background: var(--accent);
    color: var(--accent-text);
}
.chat-send-btn:hover { background: var(--accent-hover-strong); }
.chat-send-btn svg { stroke: #fff; }
.chat-file-btn svg, .chat-voice-btn svg { stroke: currentColor; }

.chat-file-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    margin-right: 4px;
    background: var(--line-soft);
    border-radius: 999px;
    font-size: 11px;
    color: var(--text-2);
}
.chat-file-pill-close {
    background: none;
    color: var(--text-3);
    font-size: 13px;
    padding: 0 2px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--sp-3) var(--sp-4);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

.chat-welcome {
    text-align: center;
    color: var(--text-3);
    padding: var(--sp-6) var(--sp-4);
    font-size: 13px;
}
.chat-welcome-icon { font-size: 28px; margin-bottom: var(--sp-2); }
.chat-welcome-text { font-size: 12px; }

/* Chat bubbles — JS renders via .chat-bubble + .chat-bubble--{role} */
.chat-bubble {
    padding: 9px 12px;
    border-radius: var(--r-3);
    font-size: 13px;
    line-height: 1.5;
    max-width: 92%;
    word-wrap: break-word;
    position: relative;
}
.chat-bubble__body {
    white-space: pre-wrap;
    word-break: break-word;
}
.chat-bubble--user {
    align-self: flex-end;
    background: var(--accent);
    color: var(--accent-text);
    border-bottom-right-radius: 4px;
}
.chat-bubble--user .chat-bubble__body { color: var(--accent-text); }
.chat-bubble--assistant {
    align-self: flex-start;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line-soft);
    border-bottom-left-radius: 4px;
}
.chat-bubble--system {
    align-self: center;
    background: var(--warning-bg);
    color: #92400e;
    border: 1px solid #fde68a;
    font-size: 12px;
    padding: 6px 12px;
    border-radius: var(--r-2);
    max-width: 90%;
}
.chat-thinking {
    align-self: flex-start;
    background: var(--line-soft);
    color: var(--text-3);
    font-style: italic;
    padding: 8px 12px;
    border-radius: var(--r-3);
    font-size: 12.5px;
}

.chat-time, .chat-timing {
    font-size: 10.5px;
    color: var(--text-3);
    margin-top: 2px;
    text-align: right;
    align-self: flex-end;
    opacity: 0.75;
}
.chat-bubble--assistant + .chat-time,
.chat-bubble--assistant .chat-timing { align-self: flex-start; text-align: left; }

/* Tool-call blocks rendered inside assistant messages */
.chat-tools {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
    font-size: 11.5px;
}
.chat-tool {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    padding: 6px 8px;
}
.chat-tool__summary {
    cursor: pointer;
    color: var(--text-2);
    font-weight: 500;
    list-style: none;
}
.chat-tool__summary::-webkit-details-marker { display: none; }
.chat-tool__summary::before {
    content: "▸";
    display: inline-block;
    margin-right: 4px;
    transition: transform 0.12s;
}
.chat-tool[open] .chat-tool__summary::before { transform: rotate(90deg); }
.chat-tool__body {
    margin-top: 6px;
    padding: 8px 10px;
    background: var(--surface-2);
    border-radius: var(--r-1);
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 11px;
    color: var(--text-2);
}
.chat-tool__args, .chat-tool__result { white-space: pre-wrap; word-break: break-word; }
.chat-tool__error { color: var(--danger); }

/* Action bar under assistant messages (Copy / Retry) */
.chat-actions {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    opacity: 0;
    transition: opacity 0.12s;
}
.chat-bubble--assistant:hover + .chat-actions,
.chat-bubble:hover .chat-actions { opacity: 1; }
.chat-action-btn {
    padding: 3px 8px;
    font-size: 11px;
    color: var(--text-3);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--r-1);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.chat-action-btn:hover {
    background: var(--line-soft);
    color: var(--text);
    border-color: var(--line);
}

.chat-del-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px; height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-3);
    font-size: 13px;
    border-radius: var(--r-1);
    opacity: 0;
    transition: opacity 0.12s, background 0.12s;
}
.chat-bubble:hover .chat-del-btn { opacity: 0.7; }
.chat-del-btn:hover { background: var(--line); opacity: 1; }

.chat-notif {
    background: var(--warning-bg);
    border: 1px solid #fde68a;
    border-radius: var(--r-3);
    padding: 10px 12px;
    font-size: 12.5px;
    color: var(--text);
    align-self: stretch;
    max-width: 100%;
}
.chat-notif--email { background: #eff6ff; border-color: #bfdbfe; }
.chat-notif--task-reminder { background: var(--warning-bg); border-color: #fde68a; }

/* ---------- 6c. Notification cards (email/task-reminder) --------------- */
/* Porting the legacy .notif-* rules so the email card renders the same on
 * the v2 dashboard as it does on legacy pages. The only semantic change:
 * .notif-btn--primary now uses --accent (dark) + --accent-text (white) so
 * the label is readable — the legacy version relied on --accent-soft which
 * in v2 resolves to near-white → invisible text. */
.notif-header { font-weight: 600; margin-bottom: 4px; font-size: 12px; color: var(--text); }
.notif-meta { font-size: 11px; color: var(--text-2); margin-bottom: 4px; line-height: 1.4; }
.notif-body { font-size: 12.5px; line-height: 1.5; margin: 6px 0; color: var(--text); white-space: pre-line; }

.notif-email-meta {
    background: var(--surface);
    color: var(--text);
    border-radius: var(--r-2);
    padding: 8px 10px;
    margin: 6px 0;
    font-size: 12px;
    line-height: 1.5;
    border: 1px solid var(--line);
}
.notif-email-meta-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 3px;
}
.notif-email-meta-row:last-child { margin-bottom: 0; }
.notif-email-meta-label {
    color: var(--text-3);
    font-size: 10.5px;
    font-weight: 600;
    min-width: 42px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.notif-email-meta-value {
    color: var(--text);
    font-weight: 600;
    flex: 1;
    word-break: break-word;
}
.notif-email-meta-row--subject .notif-email-meta-value { font-size: 13px; }

.notif-class-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 6px 0 4px;
}
.notif-project-badge {
    font-size: 12.5px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: var(--r-1);
    background: #3b82f6;
    color: #fff;
    white-space: nowrap;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.notif-project-badge--unsure { background: #60a5fa; color: #fff; }
.notif-section-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: var(--r-1);
    background: color-mix(in srgb, #a78bfa 18%, transparent);
    border: 1px solid color-mix(in srgb, #a78bfa 40%, transparent);
    color: #6d28d9;
    white-space: nowrap;
}
.notif-level-badge { font-size: 14px; line-height: 1; }

.notif-email-body {
    background: color-mix(in srgb, var(--text) 4%, transparent);
    border-left: 3px solid var(--text-2);
    padding: 6px 10px;
    margin: 6px 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
}
.notif-email-body strong { color: var(--text); font-weight: 700; }

.notif-task-line {
    background: color-mix(in srgb, #3b82f6 10%, transparent);
    border-radius: var(--r-1);
    padding: 6px 10px;
    margin: 6px 0;
    font-size: 12px;
    color: var(--text);
    border-left: 3px solid #3b82f6;
}
.notif-task-line strong { color: #2563eb; }

/* Forward suggestion — visually parallel to task-line but violet to
 * signal "this is a second action" (передать исполнителю). */
.notif-forward-line {
    background: color-mix(in srgb, #8b5cf6 10%, transparent);
    border-radius: var(--r-1);
    padding: 6px 10px;
    margin: 6px 0;
    font-size: 12px;
    color: var(--text);
    border-left: 3px solid #8b5cf6;
}
.notif-forward-line strong { color: #7c3aed; }
.notif-forward-section {
    font-size: 11px;
    color: var(--text-3);
    margin-left: 4px;
}

/* Phase C: make task/forward rows act as click targets for their
 * inline checkboxes. Hover state hints interactivity, unchecked state
 * is dimmed so the "will be created" set is obvious. */
.notif-task-line--checkable,
.notif-forward-line--checkable {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    transition: background 120ms ease;
}
.notif-task-line--checkable:hover,
.notif-forward-line--checkable:hover {
    filter: brightness(1.05);
}
.notif-task-line--checkable > span,
.notif-forward-line--checkable > span {
    flex: 1;
    min-width: 0;
}
.notif-choice {
    margin-top: 2px;
    flex-shrink: 0;
    accent-color: var(--accent, #3b82f6);
    cursor: pointer;
}
.notif-task-line--checkable:has(.notif-choice:not(:checked)),
.notif-forward-line--checkable:has(.notif-choice:not(:checked)) {
    opacity: 0.55;
}
.notif-related-line {
    font-size: 11px;
    color: var(--text-3);
    margin-top: 4px;
    padding: 4px 10px;
    font-style: italic;
}

.notif-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.notif-btn {
    font-size: 11.5px;
    padding: 5px 11px;
    border-radius: var(--r-2);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-family: var(--font);
    transition: background 120ms, border-color 120ms, color 120ms;
}
.notif-btn:hover { background: var(--line-soft); border-color: var(--text-3); }
.notif-btn--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}
.notif-btn--primary:hover { background: var(--accent-hover-strong); border-color: var(--accent-hover-strong); color: var(--accent-text); }
.notif-btn:disabled { opacity: 0.4; cursor: default; }

.notif-feedback { display: flex; gap: 6px; margin-top: 6px; }
.notif-fb-btn {
    background: none; border: none; cursor: pointer;
    font-size: 16px; opacity: 0.5; transition: opacity 0.15s;
}
.notif-fb-btn:hover { opacity: 1; }
.notif--acted { opacity: 0.5; }

.chat-create-task-btn {
    margin: var(--sp-3) var(--sp-4);
    padding: 9px 12px;
    background: var(--accent);
    color: var(--accent-text);
    border-radius: var(--r-2);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s;
}
.chat-create-task-btn:hover { background: var(--accent-hover-strong); }

/* Main content area */
.main {
    grid-area: main;
    overflow-y: auto;
    /* Tile: white surface inside the gray page frame, matching sidebar/chat */
    background: var(--surface);
    border: 1px solid rgba(0,0,0,0.22);
    border-radius: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
    margin: 0;
    padding: var(--sp-5) var(--sp-6);
}

.main:focus { outline: none; }

/* ---------- 3. Dashboard home ------------------------------------------- */

/* Large .stats-row cards are hidden when the appbar is present — the
 * compact .appbar__stats block in the top bar replaces them. Browsers
 * that don't support :has() fall back to showing the cards (harmless). */
body:has(.appbar) .stats-row { display: none; }

.stats-row {
    display: flex;
    gap: var(--sp-3);
    margin-bottom: var(--sp-5);
}

.card, .stat-card-inline {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-3);
    padding: var(--sp-4) var(--sp-5);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    cursor: pointer;
    position: relative;
    transition: border-color 0.12s, box-shadow 0.12s;
}
.card:hover, .stat-card-inline:hover { border-color: #d4d4d4; box-shadow: var(--shadow-1); }

.stat-card-inline .label {
    font-size: 11px;
    color: var(--text-3);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stat-card-inline .value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
    letter-spacing: -0.02em;
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.stat-card-inline .value > span:first-child {
    font-size: 24px;
    color: var(--text);
}

.stat-sep {
    color: var(--text-3);
    margin: 0 6px;
    font-weight: 400;
}

.overdue-badge {
    color: var(--danger);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0;
}

.stat-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    box-shadow: var(--shadow-2);
    z-index: 50;
    display: none;
    padding: var(--sp-2);
    min-width: 280px;
}
.stat-dropdown.open { display: block; }

.stat-dropdown-filters {
    display: flex;
    gap: 4px;
    padding: var(--sp-1) 0;
    border-bottom: 1px solid var(--line-soft);
    margin-bottom: var(--sp-2);
    overflow-x: auto;
}

.stat-filter-btn {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    color: var(--text-2);
    background: transparent;
    white-space: nowrap;
    transition: background 0.12s, color 0.12s;
}
.stat-filter-btn:hover { background: var(--line-soft); color: var(--text); }
.stat-filter-btn.active { background: var(--accent); color: var(--accent-text); }

.stat-dropdown-list {
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 8px 10px;
    border-radius: var(--r-1);
    color: var(--text);
    font-size: 12.5px;
    transition: background 0.12s;
}
.stat-dropdown-item:hover { background: var(--line-soft); }

.stat-dropdown-item-health {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--success);
    flex: 0 0 auto;
}
.stat-dropdown-item-health--warning { background: var(--warning); }
.stat-dropdown-item-health--bad, .stat-dropdown-item-health--danger { background: var(--danger); }

.stat-dropdown-item-name {
    flex: 1;
    font-size: 12.5px;
    color: var(--text);
}

.stat-dropdown-item-badge {
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 500;
    background: var(--success-bg);
    color: var(--success);
}
.stat-dropdown-item-badge--bad { background: var(--danger-bg); color: var(--danger); }
.stat-dropdown-item-badge--ok  { background: var(--success-bg); color: var(--success); }

.stat-dropdown-empty {
    padding: var(--sp-3) var(--sp-2);
    color: var(--text-3);
    font-size: 12px;
    text-align: center;
}

/* Section (tasks) */
.section { margin-bottom: var(--sp-6); }

.section-toolbar {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    margin-bottom: var(--sp-4);
    padding-bottom: var(--sp-3);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.section-toolbar-search {
    flex: 1;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    color: var(--text-2);
    font-size: 13px;
}
.section-toolbar-search input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 13px;
    color: var(--text);
}
.section-toolbar-search input::placeholder { color: var(--text-3); }
.section-toolbar-search kbd {
    font-family: var(--font);
    font-size: 10.5px;
    padding: 2px 6px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-1);
    color: var(--text-3);
}

.view-tabs {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    background: var(--line-soft);
    border: 1px solid var(--line);
    border-radius: var(--r-2);
}
.view-tab {
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-2);
    border-radius: var(--r-1);
    transition: background 0.12s, color 0.12s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.view-tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.5); }
.view-tab--active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-1);
}

.btn-sm {
    padding: 6px 10px;
    font-size: 12px;
    color: var(--text-2);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.btn-sm:hover { background: var(--line-soft); border-color: #d4d4d4; color: var(--text); }

/* ---------- 4. Kanban --------------------------------------------------- */

.board {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--sp-4);
    align-items: start;
}

.board-col {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: transparent;
    border: none;
    padding: 0;
}

.board-col-header,
.board-col-header--overdue,
.board-col-header--today,
.board-col-header--future {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-1) var(--sp-1) var(--sp-3);
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    justify-content: flex-start;
    text-align: left;
}
.board-col-header .blink { display: none; }

.board-col-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 20px;
    padding: 0 7px;
    border-radius: var(--r-1);
    font-size: 12px;
    font-weight: 500;
    background: var(--line-soft);
    color: var(--text-2);
}

.board-col-header--overdue .board-col-count { background: var(--danger-bg); color: var(--danger); }
.board-col-header--today   .board-col-count { background: var(--warning-bg); color: var(--warning); }

.board-col-body {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    background: transparent;
    min-height: 200px;
}

.board-col-body.drag-over {
    outline: 2px dashed rgba(99, 102, 241, 0.4);
    outline-offset: 4px;
    border-radius: var(--r-3);
}

.board-subheader {
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--sp-2) var(--sp-1) 4px;
}

/* Ticket — Linear anatomy */
.ticket {
    position: relative;
    display: grid;
    grid-template-columns: 28px 1fr auto;
    grid-template-rows: auto auto;
    column-gap: 10px;
    row-gap: 3px;
    align-items: start;
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 1px solid var(--line);
    border-radius: var(--r-3);
    box-shadow: var(--shadow-1);
    padding: 12px 14px;
    color: var(--text);
    cursor: grab;
    transition: box-shadow 0.12s, border-color 0.12s;
    overflow: hidden;
}
.ticket:hover {
    border-color: #d4d4d4;
    box-shadow: var(--shadow-2);
}
.ticket:active { cursor: grabbing; }

.ticket--overdue  { border-left: 3px solid var(--danger); }
.ticket--today    { border-left: 3px solid var(--warning); }
.ticket--blocking { border-left: 3px solid var(--prio-block); background: var(--prio-block-bg); }
.ticket--high,
.ticket--urgent   { border-left: 3px solid var(--prio-high);  background: var(--prio-high-bg); }

.ticket--done { opacity: 0.5; }
.ticket--done .ticket-row2 { text-decoration: line-through; }

.ticket--dragging {
    opacity: 0.55;
    transform: rotate(0.8deg);
    box-shadow: var(--shadow-3);
}

/* Row 1 hosts icon-badge only (was project-badge). Other legacy spans hidden. */
.ticket-row1 {
    grid-row: 1 / 3;
    grid-column: 1;
    display: block;
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    min-height: 0;
    align-self: start;
}

/* Скрываем все элементы row1 кроме номера и project-бейджа (и spacer
 * чтобы бейдж уезжал вправо). Номер #N — первое что глазу надо увидеть. */
.ticket-row1 > *:not(.ticket-num):not(.ticket-project-badge):not(.ticket-spacer) { display: none; }
.ticket-row1 .ticket-num {
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3, #a1a1aa);
    letter-spacing: -0.01em;
}

.ticket-row1 .ticket-project-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 7px;
    background: var(--p1-bg);
    color: var(--p1-fg);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1;
    text-transform: uppercase;
    font-family: var(--font);
    overflow: hidden;
    white-space: nowrap;
    user-select: none;
    margin: 2px 0 0;
}

/* Adaptive font-size per label length — 3-char labels (МГЦ/БАД/К26) need
 * slight shrink to fit cleanly inside 28x28 square. */
.ticket-row1 .ticket-project-badge[data-label-len="3"] {
    font-size: 9.5px;
    letter-spacing: -0.04em;
}
.ticket-row1 .ticket-project-badge[data-label-len="4"] {
    font-size: 8.5px;
    letter-spacing: -0.05em;
}

.ticket-row1 .ticket-project-badge[data-proj-hue="2"] { background: var(--p2-bg); color: var(--p2-fg); }
.ticket-row1 .ticket-project-badge[data-proj-hue="3"] { background: var(--p3-bg); color: var(--p3-fg); }
.ticket-row1 .ticket-project-badge[data-proj-hue="4"] { background: var(--p4-bg); color: var(--p4-fg); }
.ticket-row1 .ticket-project-badge[data-proj-hue="5"] { background: var(--p5-bg); color: var(--p5-fg); }
.ticket-row1 .ticket-project-badge[data-proj-hue="6"] { background: var(--p6-bg); color: var(--p6-fg); }

/* Priority emoji (row 1, col 3) */
.tk-prio {
    grid-row: 1;
    grid-column: 3;
    justify-self: end;
    font-size: 13px;
    line-height: 1;
    margin-top: 2px;
    background: transparent;
    border: none;
    padding: 0;
}
.tk-prio::before { content: none; }

/* Row 2 — title (row 1, col 2) */
.ticket-row2 {
    grid-row: 1;
    grid-column: 2;
    margin: 2px 0 0;
    padding: 0;
    font-size: 13.5px;
    font-weight: 500;
    line-height: 1.35;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

/* Row 3 — meta (row 2, cols 2-3) */
.tk-meta {
    grid-row: 2;
    grid-column: 2 / 4;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    margin-top: 4px;
    padding: 0;
    border: none;
    font-size: 11.5px;
    color: var(--text-2);
    min-height: 18px;
}

.tk-meta-date {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
}
.tk-meta-date::before {
    content: "";
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    opacity: 0.65;
}

.ticket--overdue .tk-meta-date { color: var(--danger); }
.ticket--today   .tk-meta-date { color: var(--warning); }

.tk-meta-proj-name {
    color: var(--text-3);
    font-weight: 400;
}
.tk-meta-proj-name::before {
    content: "·";
    margin: 0 5px 0 2px;
    color: var(--text-3);
}

.tk-meta-spacer { flex: 1; }

/* Envelope icon on the card — shown when task originated from an email */
.tk-email-btn {
    grid-row: 1;
    grid-column: 3;
    justify-self: end;
    width: 22px; height: 22px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--r-1);
    color: var(--text-3);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    margin-top: 2px;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.tk-email-btn:hover {
    background: var(--line-soft);
    color: var(--text);
    border-color: var(--line);
}

/* Email-view modal — read-only full thread viewer */
.email-modal {
    background: var(--surface);
    border-radius: var(--r-4);
    width: 720px;
    max-width: 95%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-3);
}
.email-modal__head {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--line-soft);
}
.email-modal__subject {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}
.email-modal__meta {
    padding: var(--sp-3) var(--sp-5);
    background: var(--surface-2);
    border-bottom: 1px solid var(--line-soft);
    font-size: 12.5px;
    color: var(--text-2);
    display: grid;
    grid-template-columns: 70px 1fr;
    row-gap: 4px;
    column-gap: var(--sp-3);
}
.email-modal__meta-label { color: var(--text-3); }
.email-modal__body {
    padding: var(--sp-4) var(--sp-5);
    overflow-y: auto;
    flex: 1;
    font-size: 13px;
    color: var(--text);
    line-height: 1.55;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    background: var(--surface);
}
.email-modal__foot {
    display: flex;
    gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-5);
    border-top: 1px solid var(--line-soft);
    justify-content: flex-end;
}

/* Attachments icon + popup */
.tk-attach-btn {
    grid-row: 1;
    grid-column: 3;
    justify-self: end;
    width: 22px; height: 22px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--r-1);
    color: var(--text-3);
    font-size: 12px;
    cursor: pointer;
    margin-top: 2px;
    margin-right: 26px;  /* sit to the left of email icon */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s;
}
.tk-attach-btn:hover {
    background: var(--line-soft);
    color: var(--text);
}
.attach-popup {
    position: absolute;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    box-shadow: var(--shadow-3);
    padding: var(--sp-1);
    min-width: 260px;
    max-width: 380px;
    z-index: 1100;
    display: none;
}
.attach-popup.open { display: block; }
.attach-popup__item {
    display: block;
    padding: 8px 12px;
    border-radius: var(--r-1);
    color: var(--text);
    font-size: 13px;
    transition: background 0.12s;
    text-decoration: none;
    word-break: break-word;
}
.attach-popup__item:hover { background: var(--line-soft); }
.attach-popup__item-name { font-weight: 500; }
.attach-popup__item-hint { font-size: 11px; color: var(--text-3); display: block; margin-top: 2px; }

/* Mentioned-people avatars on cards */
.tk-people {
    display: inline-flex;
    align-items: center;
    gap: -6px;   /* negative → overlap */
    margin-left: 8px;
}
.tk-person {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--surface);
    background: var(--p1-bg);
    color: var(--p1-fg);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1;
    cursor: pointer;
    margin-left: -6px;
    padding: 0;
    transition: transform 0.12s, z-index 0.01s;
    z-index: 1;
    user-select: none;
}
.tk-person:first-child { margin-left: 0; }
.tk-person:hover {
    transform: scale(1.15) translateY(-1px);
    z-index: 5;
    box-shadow: var(--shadow-2);
}
.tk-person[data-hue="2"] { background: var(--p2-bg); color: var(--p2-fg); }
.tk-person[data-hue="3"] { background: var(--p3-bg); color: var(--p3-fg); }
.tk-person[data-hue="4"] { background: var(--p4-bg); color: var(--p4-fg); }
.tk-person[data-hue="5"] { background: var(--p5-bg); color: var(--p5-fg); }
.tk-person[data-hue="6"] { background: var(--p6-bg); color: var(--p6-fg); }

/* Compose drawer (right-slide panel for quick email) */
.compose-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 480px;
    max-width: 95vw;
    background: var(--surface);
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow-3);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    z-index: 1050;
}
.compose-drawer.open { transform: translateX(0); }

.compose-drawer__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20, 20, 24, 0.25);
    z-index: 1040;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.compose-drawer__backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.compose-drawer__head {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--line-soft);
}
.compose-drawer__title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
}
.compose-drawer__close {
    width: 28px; height: 28px;
    border-radius: var(--r-1);
    color: var(--text-3);
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s;
}
.compose-drawer__close:hover { background: var(--line-soft); color: var(--text); }

.compose-drawer__body {
    padding: var(--sp-4) var(--sp-5);
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}
.compose-field { display: flex; flex-direction: column; gap: 4px; }
.compose-field__label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.compose-field input,
.compose-field textarea {
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    background: var(--surface);
    font-size: 13px;
    color: var(--text);
    font-family: inherit;
    outline: none;
    transition: border-color 0.12s;
}
.compose-field input:focus,
.compose-field textarea:focus { border-color: var(--text-2); }
.compose-field textarea { min-height: 180px; resize: vertical; line-height: 1.5; }

.compose-drawer__foot {
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--line-soft);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--sp-2);
}
.compose-drawer__hint {
    font-size: 11.5px;
    color: var(--text-3);
}
.compose-drawer__actions {
    display: flex;
    gap: var(--sp-2);
}

.compose-loading {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--line);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin-right: 6px;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.tk-meta .ticket-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--r-1);
    color: var(--text-3);
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.12s, background 0.12s, color 0.12s;
    cursor: pointer;
}
.ticket:hover .tk-meta .ticket-btn,
.ticket:focus-within .tk-meta .ticket-btn { opacity: 1; }
.tk-meta .ticket-btn:hover { background: var(--line-soft); color: var(--text); }
.tk-meta .ticket-btn--del:hover { background: var(--danger-bg); color: var(--danger); }

.dep-handle {
    position: absolute;
    right: 6px;
    bottom: 6px;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-3);
    opacity: 0;
    transition: opacity 0.12s;
    cursor: crosshair;
}
.ticket:hover .dep-handle { opacity: 0.5; }
.dep-handle:hover { opacity: 1; transform: scale(1.4); }

/* Group container */
.ticket--group {
    display: block;
    background: var(--surface);
    border: 1px solid var(--line);
    padding: 10px 12px;
}
.ticket-group-header {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    cursor: pointer;
    padding: 0;
    background: transparent;
    border: none;
    min-height: 0;
}
.ticket-group-toggle { color: var(--text-3); font-size: 11px; }
.ticket-group-icon { font-size: 15px; }
.ticket-group-label { flex: 1; color: var(--text); font-weight: 600; font-size: 13px; }
.ticket-group-badge {
    padding: 2px 8px;
    background: var(--line-soft);
    color: var(--text-2);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
}
.ticket-group-children {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    padding: var(--sp-2) 0 0;
    border-left: 1px solid var(--line-soft);
    margin-left: 4px;
    padding-left: var(--sp-3);
}
.ticket-group-children[data-collapsed="true"] { display: none; }

/* Empty column state */
.board-col-empty,
.board-col-empty--illustrated {
    background: transparent;
    border: 1px dashed var(--line);
    border-radius: var(--r-3);
    padding: var(--sp-6) var(--sp-4);
    text-align: center;
}
.board-col-empty-illo { opacity: 0.5; margin: 0 auto; display: block; }
.board-col-empty-title { color: var(--text-2); font-size: 13px; font-weight: 600; margin-top: var(--sp-2); }
.board-col-empty-hint  { color: var(--text-3); font-size: 12px; margin-top: 4px; }

.agenda-empty {
    text-align: center;
    padding: var(--sp-6);
    color: var(--text-3);
}

/* ---------- 5. Chips + buttons + inputs --------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 8px 14px;
    border-radius: var(--r-2);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--line);
    transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--line-soft); border-color: #d4d4d4; }
.btn--primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn--primary:hover { background: var(--accent-hover-strong); border-color: var(--accent-hover-strong); }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--line-soft);
    color: var(--text-2);
    font-size: 11px;
    font-weight: 500;
}

/* ---------- 6. Modals & overlays ---------------------------------------- */

.create-task-overlay {
    position: fixed; inset: 0;
    background: rgba(20,20,24,0.35);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}
.create-task-overlay.open,
.create-task-overlay.active { display: flex; }

.create-task-dialog {
    background: var(--surface);
    border-radius: var(--r-4);
    padding: var(--sp-5);
    width: 420px;
    max-width: 92%;
    box-shadow: var(--shadow-3);
}

.create-task-dialog h3 { margin-bottom: var(--sp-3); }
.create-task-dialog label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.create-task-dialog textarea,
.create-task-dialog input,
.create-task-dialog select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    background: var(--surface);
    font-size: 13px;
    color: var(--text);
    margin-bottom: var(--sp-3);
    outline: none;
}

.create-task-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-2);
    margin-bottom: var(--sp-2);
}

.create-task-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-2);
    margin-top: var(--sp-3);
}

.ct-btn-cancel,
.ct-btn-create {
    padding: 8px 14px;
    border-radius: var(--r-2);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    transition: background 0.12s;
}
.ct-btn-cancel:hover { background: var(--line-soft); }
.ct-btn-create {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}
.ct-btn-create:hover { background: var(--accent-hover-strong); }

/* Task-detail modal (#taskModal) — hidden by default like create modal.
 * app.js toggles .active; base.html/compose uses .open — support both. */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(20,20,24,0.35);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open,
.modal-overlay.active { display: flex; }

/* Task modal body widgets (legacy class names retained for app.js JS) */
.modal-edit-text,
.modal-input {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.12s;
}
.modal-edit-text:focus,
.modal-input:focus { border-color: var(--text-2); }
.modal-edit-text { min-height: 70px; resize: vertical; line-height: 1.45; }

.modal-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}
.modal-tag {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 999px;
    background: var(--line-soft);
    color: var(--text-2);
}
.modal-tag--overdue { background: var(--danger-bg); color: var(--danger); }

.modal-snooze-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.modal-snooze-btn {
    padding: 6px 11px;
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    background: var(--surface);
    color: var(--text-2);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.modal-snooze-btn:hover { background: var(--line-soft); color: var(--text); }

.modal-actions {
    padding: var(--sp-3) var(--sp-5) var(--sp-4);
    display: flex;
    gap: var(--sp-2);
    align-items: center;
    border-top: 1px solid var(--line-soft);
}
.modal-btn {
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.modal-btn:hover { background: var(--line-soft); border-color: #d4d4d4; }
.modal-btn--primary {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}
.modal-btn--primary:hover { background: var(--accent-hover-strong); border-color: var(--accent-hover-strong); }
.modal-btn--danger { color: var(--danger); border-color: transparent; background: transparent; }
.modal-btn--danger:hover { background: var(--danger-bg); border-color: transparent; }

/* Pills (priority, status selectors) */
.modal-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 3px;
    background: var(--line-soft);
    border-radius: var(--r-2);
    width: fit-content;
}
.modal-pill {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-2);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--r-1);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.modal-pill:hover { color: var(--text); }
.modal-pill--active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-1);
}
.modal-pill--danger.modal-pill--active {
    background: var(--danger-bg);
    color: var(--danger);
    box-shadow: var(--shadow-1);
}
.modal-pill--waiting.modal-pill--active {
    background: var(--warning-bg);
    color: var(--warning);
    box-shadow: var(--shadow-1);
}

/* Inline button next to field label */
.modal-inline-btn {
    margin-left: auto;
    padding: 3px 9px;
    font-size: 10.5px;
    font-weight: 500;
    background: var(--line-soft);
    color: var(--text-2);
    border-radius: 999px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    text-transform: none;
    letter-spacing: 0;
}
.modal-inline-btn:hover { background: var(--line); color: var(--text); }
.modal-field-label { display: flex; align-items: center; }

/* Assignee chips (inside modal) — reuse person-avatar pattern */
.modal-assignees {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 28px;
}
.modal-assignee {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px 3px 3px;
    background: var(--line-soft);
    color: var(--text);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
}
.modal-assignee__avatar {
    width: 20px; height: 20px;
    border-radius: 50%;
    background: var(--p1-bg);
    color: var(--p1-fg);
    font-size: 9px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.modal-assignee__avatar[data-hue="2"] { background: var(--p2-bg); color: var(--p2-fg); }
.modal-assignee__avatar[data-hue="3"] { background: var(--p3-bg); color: var(--p3-fg); }
.modal-assignee__avatar[data-hue="4"] { background: var(--p4-bg); color: var(--p4-fg); }
.modal-assignee__avatar[data-hue="5"] { background: var(--p5-bg); color: var(--p5-fg); }
.modal-assignee__avatar[data-hue="6"] { background: var(--p6-bg); color: var(--p6-fg); }
.modal-assignee__remove {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: transparent;
    color: var(--text-3);
    font-size: 12px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: 2px;
}
.modal-assignee__remove:hover { background: var(--line); color: var(--text); }
.modal-assignees:empty::before {
    content: "— не назначены —";
    color: var(--text-3);
    font-size: 12px;
    font-style: italic;
}

/* Automation tag toggles */
.modal-tag-toggles {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.modal-tag-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--line-soft);
    border-radius: var(--r-2);
    cursor: pointer;
    font-size: 12.5px;
    color: var(--text);
    transition: background 0.12s;
}
.modal-tag-toggle:hover { background: #e5e5e5; }
.modal-tag-toggle input { margin: 0; accent-color: var(--accent); }
.modal-tag-toggle input:checked + span { font-weight: 500; }

/* Floating date/time picker (app.js _openPicker) */
.floating-picker {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    box-shadow: var(--shadow-3);
    padding: var(--sp-2);
    min-width: 260px;
}
.floating-picker-body {
    display: flex;
    gap: 6px;
    align-items: center;
}
.fp-input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: var(--r-1);
    background: var(--surface);
    font-size: 12px;
    color: var(--text);
    outline: none;
}
.fp-buttons { display: flex; gap: 4px; }
.fp-ok,
.fp-cancel {
    width: 30px; height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-1);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text-2);
}
.fp-ok:hover { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.fp-cancel:hover { background: var(--line-soft); color: var(--text); }

.modal {
    background: var(--surface);
    border-radius: var(--r-4);
    padding: 0;
    width: 520px;
    max-width: 92%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-3);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--line-soft);
}
.modal-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-close {
    width: 28px; height: 28px;
    border-radius: var(--r-1);
    color: var(--text-3);
    font-size: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s;
}
.modal-close:hover { background: var(--line-soft); color: var(--text); }

.modal-body {
    padding: var(--sp-4) var(--sp-5);
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}

.modal-field { display: flex; flex-direction: column; gap: 4px; }
.modal-field-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.modal-field input,
.modal-field select,
.modal-field textarea {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    background: var(--surface);
    font-size: 13px;
    color: var(--text);
    outline: none;
    font-family: inherit;
}

/* RAG panel — hidden by default on v2 pages */
.rag-panel {
    display: none;
    position: fixed;
    right: 0; top: var(--header-h);
    bottom: 0;
    width: 320px;
    background: var(--surface);
    border-left: 1px solid var(--line);
    z-index: 900;
    padding: var(--sp-4);
    overflow-y: auto;
}
.rag-panel.open { display: block; }

/* Floating picker (if present) */
.floating-picker {
    position: fixed;
    z-index: 9999;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    box-shadow: var(--shadow-3);
    padding: var(--sp-2);
}

/* ---------- 6b. List view & Calendar view (legacy partials) ------------- */

/* List view: flat task list sorted by time — same data model as kanban ticket */
.task-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: var(--sp-3);
}
.task-list-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 10px var(--sp-3);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
}
.task-list-item:hover { background: var(--line-soft); border-color: var(--line); }
.task-list-item--done { opacity: 0.5; }
.task-list-item--done .task-list-title { text-decoration: line-through; }
.task-list-item--overdue { border-left: 3px solid var(--danger); }
.task-list-check {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    width: 48px;
}
.task-list-content { flex: 1; min-width: 0; }
.task-list-title {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.4;
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px;
}
.task-list-title .ticket-inline-time,
.task-list-title .ticket-inline-project {
    font-size: 12px;
    color: var(--text-2);
    font-weight: 500;
}
.task-list-title .ticket-sep { color: var(--text-3); }
.task-list-title .ticket-text { flex: 1 1 280px; min-width: 200px; }
.task-list-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 3px;
    font-size: 11.5px;
    color: var(--text-3);
}
.task-list-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.task-list-actions .ticket-action {
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--r-2);
    color: var(--text-2);
    width: 28px; height: 28px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: background 120ms, border-color 120ms, color 120ms;
}
.task-list-actions .ticket-action:hover {
    background: var(--line-soft); border-color: var(--line);
}
.task-list-actions .ticket-action--del:hover {
    color: var(--danger); border-color: var(--danger);
}

/* Calendar view: month grid with task dots + day detail pane */
.cal-view {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: var(--sp-4);
    padding: var(--sp-3);
    min-height: 420px;
}
.cal-header {
    grid-column: 1 / 2;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    padding: 6px 2px 10px;
    text-transform: capitalize;
}
.cal-grid {
    grid-column: 1 / 2;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}
.cal-weekday {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    padding: 4px 0;
    text-transform: uppercase;
}
.cal-cell {
    position: relative;
    min-height: 68px;
    padding: 6px 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-2);
    cursor: pointer;
    transition: border-color 120ms ease, background 120ms ease;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.cal-cell:hover { border-color: var(--text-3); background: var(--line-soft); }
.cal-cell--empty { background: transparent; border-color: transparent; cursor: default; }
.cal-cell--empty:hover { border-color: transparent; background: transparent; }
.cal-cell--today {
    border-color: var(--accent, #3b82f6);
    box-shadow: 0 0 0 1px var(--accent, #3b82f6) inset;
}
.cal-cell--today .cal-day-num { color: var(--accent, #3b82f6); font-weight: 700; }
.cal-cell--has-tasks {
    background: color-mix(in srgb, var(--accent, #3b82f6) 6%, var(--surface));
}
.cal-day-num {
    display: block;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text);
}
.cal-dot-count {
    display: inline-block;
    padding: 1px 7px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--accent, #3b82f6);
    background: color-mix(in srgb, var(--accent, #3b82f6) 14%, transparent);
    border-radius: 10px;
    align-self: flex-start;
}
.cal-day-detail {
    grid-column: 2 / 3;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-3);
    padding: var(--sp-3);
    max-height: 560px;
    overflow-y: auto;
}
.cal-day-label {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
    padding: 2px 0 10px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 8px;
    text-transform: capitalize;
}
.cal-task {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 6px;
    border-bottom: 1px solid var(--line-soft);
    cursor: pointer;
    transition: background 120ms;
    border-radius: var(--r-2);
}
.cal-task:hover { background: var(--line-soft); }
.cal-task--done { opacity: 0.5; }
.cal-task--done .cal-task-title { text-decoration: line-through; }
.cal-task-time {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    min-width: 38px;
    font-variant-numeric: tabular-nums;
}
.cal-task-title {
    font-size: 13px;
    color: var(--text);
    flex: 1;
    min-width: 0;
    line-height: 1.35;
}

@media (max-width: 900px) {
    .cal-view { grid-template-columns: 1fr; }
    .cal-day-detail { grid-column: 1 / 2; max-height: none; }
}

/* ---------- 7. Responsive ---------------------------------------------- */

@media (max-width: 1100px) {
    .layout {
        grid-template-columns: var(--sidebar-w) 1fr;
        grid-template-areas:
            "sidebar header"
            "sidebar main";
    }
    .chat-panel { display: none; }
    .board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
    :root { --sidebar-w: 56px; }
    .main { padding: var(--sp-3); }
    .board { grid-template-columns: 1fr; gap: var(--sp-3); }
    .stats-row { flex-direction: column; }
    .header { padding: 0 var(--sp-3); }
}
