/* =====================================================================
   Zrantita — App Styles
   System preference dark/light with manual toggle override
   ===================================================================== */

/* ── CSS Custom Properties ─────────────────────────────────────────── */
:root {
    --bg:           #f8f9fb;
    --surface:      #ffffff;
    --surface-2:    #f1f3f7;
    --border:       #e2e6ed;
    --text:         #1a1d23;
    --text-muted:   #6b7280;
    --accent:       #6366f1;
    --accent-hover: #4f52d4;
    --accent-light: #eef2ff;
    --success:      #10b981;
    --success-bg:   #ecfdf5;
    --warning:      #f59e0b;
    --warning-bg:   #fffbeb;
    --danger:       #ef4444;
    --danger-bg:    #fef2f2;
    --sidebar-w:    240px;
    --radius:       8px;
    --radius-lg:    12px;
    --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg:    0 4px 6px rgba(0,0,0,.07), 0 10px 15px rgba(0,0,0,.06);
    --transition:   150ms ease;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:           #0f1117;
        --surface:      #1a1d27;
        --surface-2:    #242736;
        --border:       #2e3346;
        --text:         #e8eaf0;
        --text-muted:   #8b92a8;
        --accent-light: #2a2d5e;
        --success-bg:   #0d2e22;
        --warning-bg:   #2e2310;
        --danger-bg:    #2d1515;
    }
}

body.dark-mode {
    --bg:           #0f1117;
    --surface:      #1a1d27;
    --surface-2:    #242736;
    --border:       #2e3346;
    --text:         #e8eaf0;
    --text-muted:   #8b92a8;
    --accent-light: #2a2d5e;
    --success-bg:   #0d2e22;
    --warning-bg:   #2e2310;
    --danger-bg:    #2d1515;
}

body.light-mode {
    --bg:           #f8f9fb;
    --surface:      #ffffff;
    --surface-2:    #f1f3f7;
    --border:       #e2e6ed;
    --text:         #1a1d23;
    --text-muted:   #6b7280;
    --accent-light: #eef2ff;
    --success-bg:   #ecfdf5;
    --warning-bg:   #fffbeb;
    --danger-bg:    #fef2f2;
}

/* ── Reset & Base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Ensure [hidden] always wins over display utilities */
[hidden] { display: none !important; }

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

ul, ol { list-style: none; }

/* ── Layout ─────────────────────────────────────────────────────────── */
.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────────── */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
}

.brand-icon { font-size: 1.5rem; }
.brand-name { font-size: 1.1rem; font-weight: 700; letter-spacing: -.01em; }

.sidebar-nav {
    flex: 1;
    padding: .75rem .75rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .6rem .75rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: .875rem;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    text-decoration: none;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-light); color: var(--accent); }

.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-icon svg { width: 100%; height: 100%; display: block; }

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

/* ── Main Content ───────────────────────────────────────────────────── */
.main-content {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow: hidden;
}

/* ── Topbar ─────────────────────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.topbar-user {
    font-size: .875rem;
    font-weight: 500;
    color: var(--text-muted);
}

.sidebar-toggle {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: .25rem;
}

.sidebar-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-muted);
    border-radius: 2px;
    transition: background var(--transition);
}

/* Theme Toggle */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    padding: .375rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    transition: border-color var(--transition), color var(--transition);
}

.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle svg { display: block; width: 16px; height: 16px; }

.icon-sun  { display: none; }
.icon-moon { display: block; }

@media (prefers-color-scheme: dark) {
    .icon-sun  { display: block; }
    .icon-moon { display: none; }
}

body.dark-mode  .icon-sun  { display: block; }
body.dark-mode  .icon-moon { display: none; }
body.light-mode .icon-sun  { display: none; }
body.light-mode .icon-moon { display: block; }

/* ── Page Body ──────────────────────────────────────────────────────── */
.page-body {
    flex: 1;
    padding: 1.5rem;
    max-width: 1200px;
    width: 100%;
}

/* ── Page Header ────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: .75rem;
}

.page-header-left { display: flex; align-items: center; gap: .75rem; }
.page-header-right { display: flex; align-items: center; gap: .5rem; }

.page-title { font-size: 1.375rem; font-weight: 700; letter-spacing: -.02em; }
.page-subtitle { font-size: .875rem; color: var(--text-muted); margin-top: .125rem; }

.back-link {
    display: flex;
    align-items: center;
    gap: .25rem;
    font-size: .875rem;
    color: var(--text-muted);
    text-decoration: none;
}

.back-link:hover { color: var(--accent); text-decoration: none; }

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .375rem;
    padding: .5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
    text-decoration: none;
    white-space: nowrap;
    background: none;
    line-height: 1.5;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-primary    { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }

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

.btn-success    { background: var(--success); color: #fff; }
.btn-success:hover { background: #0d9e71; color: #fff; }

.btn-danger     { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }

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

.btn-full       { width: 100%; justify-content: center; }
.btn-sm         { padding: .3rem .75rem; font-size: .8125rem; }
.btn-lg         { padding: .75rem 1.25rem; font-size: 1rem; }
.btn-icon       { width: 16px; height: 16px; flex-shrink: 0; }

.inline-form { display: inline; }
.mt-2 { margin-top: .5rem; }

/* ── Forms ──────────────────────────────────────────────────────────── */
.form-group  { display: flex; flex-direction: column; gap: .375rem; }
.form-row    { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-label  { font-size: .875rem; font-weight: 500; color: var(--text); }
.required    { color: var(--danger); }
.form-hint   { font-size: .75rem; color: var(--text-muted); margin-top: .125rem; }

.form-input,
.form-select,
.form-textarea {
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-size: .875rem;
    font-family: inherit;
    line-height: 1.5;
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

.form-textarea { resize: vertical; min-height: 80px; }
.form-select   { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .5rem center; background-size: 16px; padding-right: 2rem; }

.textarea-wrap { position: relative; }
.ai-assist-btn {
    position: absolute;
    bottom: .5rem;
    right: .5rem;
    display: flex;
    align-items: center;
    gap: .25rem;
    padding: .25rem .5rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: calc(var(--radius) - 2px);
    font-size: .75rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition);
}

.ai-assist-btn:hover { background: var(--accent-hover); }

.ai-hint-btn {
    display: inline-flex;
    align-items: center;
    padding: .1rem .375rem;
    background: var(--accent-light);
    color: var(--accent);
    border: none;
    border-radius: 4px;
    font-size: .7rem;
    font-weight: 600;
    cursor: pointer;
    margin-left: .375rem;
    transition: background var(--transition);
}

.ai-hint-btn:hover { background: var(--accent); color: #fff; }

.ai-hint {
    margin-top: .375rem;
    padding: .5rem .75rem;
    background: var(--accent-light);
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: .8125rem;
    color: var(--accent);
}

.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-section-title {
    font-size: .875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    margin-bottom: .25rem;
}

.form-layout { max-width: 720px; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }

/* Urgency card */
.urgency-card { background: var(--warning-bg); border-color: var(--warning); }
.urgency-indicator { display: flex; align-items: flex-start; gap: .75rem; }
.urgency-icon { font-size: 1.5rem; }
.urgency-reason { font-size: .875rem; color: var(--text-muted); margin-top: .125rem; }

/* ── Cards ──────────────────────────────────────────────────────────── */
.detail-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.detail-section-title {
    font-size: .875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    margin-bottom: .75rem;
}

.detail-text { font-size: .9375rem; line-height: 1.7; }

.detail-list { display: grid; grid-template-columns: auto 1fr; gap: .5rem 1rem; align-items: center; }
.detail-list dt { font-size: .8125rem; font-weight: 500; color: var(--text-muted); white-space: nowrap; }
.detail-list dd { font-size: .875rem; }

/* ── Stats Grid ─────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-value { font-size: 2rem; font-weight: 700; letter-spacing: -.03em; }
.stat-label { font-size: .8125rem; color: var(--text-muted); margin-top: .25rem; font-weight: 500; }

.stat-pending  .stat-value { color: var(--warning); }
.stat-progress .stat-value { color: var(--accent); }
.stat-done     .stat-value { color: var(--success); }
.stat-overdue  .stat-value { color: var(--text-muted); }
.stat-overdue.has-overdue  { border-color: var(--danger); }
.stat-overdue.has-overdue .stat-value { color: var(--danger); }

/* ── AI Widget ──────────────────────────────────────────────────────── */
.ai-widget {
    background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    color: #fff;
    box-shadow: var(--shadow-lg);
}

.ai-widget-header {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: .75rem;
}

.ai-widget-icon  { font-size: 1.25rem; }
.ai-widget-title { font-size: .875rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; flex: 1; }

.ai-refresh-btn {
    background: rgba(255,255,255,.2);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: #fff;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), transform var(--transition);
}

.ai-refresh-btn:hover { background: rgba(255,255,255,.3); }
.ai-refresh-btn.spinning svg { animation: spin .8s linear infinite; }
.btn-icon.spinning              { animation: spin 1s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

.ai-widget-body { font-size: .9375rem; line-height: 1.65; opacity: .95; }
.ai-loading { opacity: .7; font-style: italic; }

.ai-summary-card {
    background: var(--accent-light);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: .875rem 1rem;
    margin-bottom: 1rem;
}

.ai-summary-card p { font-size: .9375rem; margin-top: .375rem; }

.ai-badge {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    font-size: .75rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.ai-summary-box {
    background: var(--accent-light);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: .625rem .875rem;
    font-size: .875rem;
    color: var(--accent);
    line-height: 1.5;
}

/* ── Dashboard Grid ─────────────────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
}

.dashboard-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .875rem;
}

.section-title { font-size: .9375rem; font-weight: 600; display: flex; align-items: center; gap: .5rem; }
.section-link  { font-size: .8125rem; color: var(--accent); }
.section-link:hover { text-decoration: underline; }

/* ── Task Lists ─────────────────────────────────────────────────────── */
.task-list-compact { display: flex; flex-direction: column; gap: .5rem; }

.task-item-compact {
    padding: .625rem .75rem;
    background: var(--surface-2);
    border-radius: var(--radius);
    border-left: 3px solid var(--border);
    transition: background var(--transition);
}

.task-item-compact:hover { background: var(--border); }
.task-item-compact.priority-high   { border-left-color: var(--danger); }
.task-item-compact.priority-medium { border-left-color: var(--warning); }
.task-item-compact.priority-low    { border-left-color: var(--success); }
.task-item-overdue                 { background: var(--danger-bg) !important; }

.task-item-title {
    display: block;
    font-size: .875rem;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    margin-bottom: .25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.task-item-title:hover { color: var(--accent); text-decoration: none; }

.task-item-meta { display: flex; align-items: center; gap: .375rem; flex-wrap: wrap; }
.task-deadline  { font-size: .75rem; color: var(--text-muted); }
.task-client    { font-size: .75rem; color: var(--text-muted); }

/* ── Badges ─────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}

.badge-high   { background: var(--danger-bg);   color: var(--danger); }
.badge-medium { background: var(--warning-bg);  color: var(--warning); }
.badge-low    { background: var(--success-bg);  color: var(--success); }
.badge-danger { background: var(--danger);      color: #fff; }

.badge-status-pending     { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.badge-status-in-progress { background: var(--accent-light); color: var(--accent); }
.badge-status-done        { background: var(--success-bg); color: var(--success); }

.badge-source                { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.badge-source-slack          { background: #4a154b22; color: #4a154b; }
.badge-source-whatsapp       { background: #25d36622; color: #128c3e; }
.badge-source-upwork         { background: #14a80022; color: #14a800; }
.badge-source-manual         { background: var(--surface-2); color: var(--text-muted); }
.badge-source-telegram       { background: #229ed922; color: #0088cc; }

@media (prefers-color-scheme: dark) {
    .badge-source-slack    { background: rgba(74,21,75,.3);  color: #d07cd9; }
    .badge-source-whatsapp { background: rgba(37,211,102,.15); color: #4ade80; }
    .badge-source-upwork   { background: rgba(20,168,0,.15);  color: #4ade80; }
    .badge-source-telegram { background: rgba(34,158,217,.15); color: #4db8f0; }
}
body.dark-mode .badge-source-slack    { background: rgba(74,21,75,.3);  color: #d07cd9; }
body.dark-mode .badge-source-whatsapp { background: rgba(37,211,102,.15); color: #4ade80; }
body.dark-mode .badge-source-upwork   { background: rgba(20,168,0,.15);  color: #4ade80; }
body.dark-mode .badge-source-telegram { background: rgba(34,158,217,.15); color: #4db8f0; }

/* ── Task Table ─────────────────────────────────────────────────────── */
.task-table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.task-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.task-table th {
    padding: .75rem 1rem;
    text-align: left;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.task-table td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.task-table tbody tr:last-child td { border-bottom: none; }
.task-table tbody tr:hover td { background: var(--surface-2); }

.task-row.row-overdue td { background: var(--danger-bg); }
.task-row.row-overdue:hover td { filter: brightness(.97); }

.priority-row-high   { border-left: 3px solid var(--danger); }
.priority-row-medium { border-left: 3px solid var(--warning); }
.priority-row-low    { border-left: 3px solid var(--success); }

.task-title-cell { max-width: 280px; }

.task-link {
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.task-link:hover { color: var(--accent); text-decoration: none; }

.task-actions { white-space: nowrap; display: flex; gap: .25rem; align-items: center; }

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    background: none;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
    text-decoration: none;
}

.action-btn:hover           { background: var(--surface-2); color: var(--text); text-decoration: none; }
.action-btn-danger:hover    { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }

/* ── Tags ───────────────────────────────────────────────────────────── */
.tag-list { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .375rem; }

.tag {
    display: inline-flex;
    padding: .125rem .5rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}

.tag:hover { background: var(--accent-light); color: var(--accent); border-color: var(--accent); text-decoration: none; }

/* ── Filters Bar ────────────────────────────────────────────────────── */
.filters-bar {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    padding: .875rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.filter-group { display: flex; align-items: center; gap: .375rem; }
.filter-search { min-width: 200px; }
.filter-select { min-width: 130px; width: auto; }

/* ── Multi-Select Dropdown ──────────────────────────────────────────── */
.multi-select { position: relative; }

.multi-select-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    cursor: pointer;
    user-select: none;
    text-align: left;
    white-space: nowrap;
}

.multi-select-btn::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    opacity: .6;
    flex-shrink: 0;
    transition: transform .15s;
}

.multi-select.is-open .multi-select-btn::after { transform: rotate(180deg); }

.multi-select-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 200;
    min-width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,.12);
    padding: .25rem 0;
}

.multi-select-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .4rem .75rem;
    cursor: pointer;
    font-size: .8125rem;
    color: var(--text);
    white-space: nowrap;
}

.multi-select-item:hover { background: var(--surface-alt); }

.multi-select-item input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
}

.multi-select-btn.has-selection { color: var(--accent); border-color: var(--accent); }

/* ── Task List Container (AJAX loading state) ───────────────────────── */
.task-list-container { position: relative; }

.task-list-container.is-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(var(--surface-rgb, 255,255,255), .6);
    border-radius: var(--radius-lg);
    z-index: 10;
}

.task-list-container.is-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 11;
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}

/* ── Task Detail ────────────────────────────────────────────────────── */
.task-detail-layout {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 1.25rem;
    align-items: start;
}

.overdue-label {
    display: inline-flex;
    padding: .1rem .4rem;
    background: var(--danger);
    color: #fff;
    border-radius: 4px;
    font-size: .7rem;
    font-weight: 600;
    margin-left: .375rem;
    text-transform: uppercase;
}

/* ── Alerts ─────────────────────────────────────────────────────────── */
.alert {
    padding: .875rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.alert-error   { background: var(--danger-bg);  color: var(--danger);  border-color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); border-color: var(--success); }

.error-list { padding-left: 1.25rem; }
.error-list li { list-style: disc; }

/* ── Empty States ───────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-icon     { font-size: 3rem; margin-bottom: .75rem; }
.empty-state p  { margin-bottom: 1rem; }
.empty-state-sm { font-size: .875rem; color: var(--text-muted); padding: .5rem 0; }

/* ── Modal ──────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    backdrop-filter: blur(2px);
}
/* visibility controlled by the hidden attribute via [hidden]{display:none!important} */

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 540px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.modal-title  { font-size: 1rem; font-weight: 600; }
.modal-close  { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); line-height: 1; padding: .25rem; }
.modal-close:hover { color: var(--text); }

.modal-body   { padding: 1.25rem; display: flex; flex-direction: column; gap: .75rem; }
.modal-desc   { font-size: .875rem; color: var(--text-muted); }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; gap: .5rem; justify-content: flex-end; }

.ai-result {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    font-size: .875rem;
    line-height: 1.6;
}

.ai-result-title { font-weight: 600; margin-bottom: .375rem; }
.ai-result-field { display: grid; grid-template-columns: 100px 1fr; gap: .25rem .5rem; margin-bottom: .25rem; }
.ai-result-label { font-size: .75rem; font-weight: 500; color: var(--text-muted); }
.ai-steps        { padding-left: 1rem; }
.ai-steps li     { list-style: decimal; margin-bottom: .25rem; font-size: .875rem; }

/* ── Login ──────────────────────────────────────────────────────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-container { width: 100%; max-width: 400px; padding: 1rem; }

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-lg);
}

.login-brand  { text-align: center; margin-bottom: 2rem; }
.login-icon   { font-size: 3rem; display: block; margin-bottom: .75rem; }
.login-title  { font-size: 1.5rem; font-weight: 700; }
.login-subtitle { font-size: .875rem; color: var(--text-muted); margin-top: .25rem; }
.login-form   { display: flex; flex-direction: column; gap: 1rem; }

/* ── Settings ───────────────────────────────────────────────────────── */
.settings-form { max-width: 640px; }

/* ── Text utilities ─────────────────────────────────────────────────── */
.text-danger  { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.text-muted   { color: var(--text-muted) !important; }

/* ── @Mention System ────────────────────────────────────────────────── */
.mention-wrap {
    position: relative;
}

.mention-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    max-height: 220px;
    overflow-y: auto;
    list-style: none;
    padding: .25rem 0;
}

.mention-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem;
    font-size: .875rem;
    cursor: pointer;
    transition: background var(--transition);
}

.mention-item:hover,
.mention-item.active {
    background: var(--accent-light);
    color: var(--accent);
}

.mention-item-label { font-weight: 500; }

.mention-item-sub {
    font-size: .75rem;
    color: var(--text-muted);
    margin-left: auto;
}

.mention-item:hover .mention-item-sub,
.mention-item.active .mention-item-sub {
    color: var(--accent);
    opacity: .7;
}

.mention-pills {
    display: flex;
    flex-wrap: wrap;
    gap: .375rem;
}

.mention-pills:empty { display: none; }

.mention-pill {
    display: inline-flex;
    align-items: center;
    gap: .375rem;
    padding: .25rem .625rem;
    border-radius: 999px;
    font-size: .8125rem;
    font-weight: 500;
}

.mention-pill-client  { background: var(--accent-light); color: var(--accent); border: 1px solid var(--accent); }
.mention-pill-project { background: var(--success-bg);   color: var(--success); border: 1px solid var(--success); }

.mention-pill-remove {
    cursor: pointer;
    opacity: .6;
    font-size: 1rem;
    line-height: 1;
    transition: opacity var(--transition);
}

.mention-pill-remove:hover { opacity: 1; }

kbd {
    display: inline-flex;
    padding: .1rem .35rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: .75rem;
    font-family: monospace;
    color: var(--text-muted);
}

/* ── Clients ────────────────────────────────────────────────────────── */
.clients-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.client-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: .875rem;
    box-shadow: var(--shadow);
    transition: box-shadow var(--transition);
}

.client-card:hover { box-shadow: var(--shadow-lg); }

.client-card-header { display: flex; align-items: center; gap: .75rem; }

.client-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.client-info    { flex: 1; min-width: 0; }
.client-name    { font-weight: 600; font-size: .9375rem; color: var(--text); text-decoration: none; display: block; }
.client-name:hover { color: var(--accent); text-decoration: none; }
.client-company { font-size: .8125rem; color: var(--text-muted); margin-top: .1rem; }

.client-stats { display: flex; gap: 1rem; }

.client-stat        { text-align: center; }
.client-stat-value  { display: block; font-size: 1.25rem; font-weight: 700; }
.client-stat-label  { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.client-stat-danger .client-stat-value { color: var(--danger); }

.client-contact { display: flex; flex-direction: column; gap: .25rem; }

.client-contact-item {
    display: flex;
    align-items: center;
    gap: .375rem;
    font-size: .8125rem;
    color: var(--text-muted);
    text-decoration: none;
}

.client-contact-item:hover { color: var(--accent); text-decoration: none; }

.client-actions { display: flex; gap: .375rem; border-top: 1px solid var(--border); padding-top: .75rem; }

/* ── Projects ───────────────────────────────────────────────────────── */
.projects-list { display: flex; flex-direction: column; gap: .5rem; }

.project-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .625rem .75rem;
    background: var(--surface-2);
    border-radius: var(--radius);
}

.project-row-left  { display: flex; align-items: center; gap: .625rem; flex: 1; min-width: 0; }
.project-row-right { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }

.project-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.project-status-dot.status-active    { background: var(--success); }
.project-status-dot.status-on_hold   { background: var(--warning); }
.project-status-dot.status-completed { background: var(--text-muted); }

.badge-status-on-hold    { background: var(--warning-bg); color: var(--warning); }
.badge-status-active     { background: var(--success-bg); color: var(--success); }
.badge-status-completed  { background: var(--surface-2);  color: var(--text-muted); border: 1px solid var(--border); }

.project-name       { font-size: .875rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-desc       { font-size: .75rem; color: var(--text-muted); margin-top: .1rem; }
.project-task-count { font-size: .75rem; color: var(--text-muted); white-space: nowrap; }

/* ── View Toggle ────────────────────────────────────────────────────── */
.view-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.view-toggle-btn {
    padding: .375rem .625rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    transition: background var(--transition), color var(--transition);
}

.view-toggle-btn:hover { background: var(--surface-2); color: var(--text); }
.view-toggle-btn.active { background: var(--accent-light); color: var(--accent); }

/* ── Client Chips ───────────────────────────────────────────────────── */
.client-chips {
    display: flex;
    gap: .375rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: .25rem .75rem;
    border-radius: 999px;
    font-size: .8125rem;
    font-weight: 500;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    text-decoration: none;
    transition: border-color var(--transition), color var(--transition), background var(--transition);
    white-space: nowrap;
}

.chip:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.chip-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-active:hover { color: #fff; }

/* ── Inline Selects (Status / Priority in table) ────────────────────── */
.inline-select {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: .2rem .55rem;
    border-radius: 999px;
    white-space: nowrap;
    font-family: inherit;
    outline: none;
    transition: opacity var(--transition);
}

.inline-select:hover { opacity: .8; }
.inline-select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Status colours */
.inline-select-status-pending     { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.inline-select-status-in-progress { background: var(--accent-light); color: var(--accent); }
.inline-select-status-done        { background: var(--success-bg); color: var(--success); }

/* Priority colours */
.inline-select-priority-high   { background: var(--danger-bg);  color: var(--danger); }
.inline-select-priority-medium { background: var(--warning-bg); color: var(--warning); }
.inline-select-priority-low    { background: var(--success-bg); color: var(--success); }

/* ── Inline Date Input ──────────────────────────────────────────────── */
.inline-date {
    border: none;
    background: transparent;
    font-size: .875rem;
    color: var(--text);
    cursor: pointer;
    padding: 0;
    font-family: inherit;
    outline: none;
    width: 110px;
    transition: color var(--transition);
}

.inline-date:hover { color: var(--accent); }
.inline-date:focus { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.inline-date-overdue { color: var(--danger); }
.inline-date::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .5; }
.inline-date::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* ── Board / Kanban View ────────────────────────────────────────────── */
.board-view {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    align-items: start;
}

.board-col {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: .75rem;
    min-height: 120px;
}

.board-col-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .75rem;
    padding-bottom: .5rem;
    border-bottom: 1px solid var(--border);
}

.board-col-title {
    font-size: .8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
}

.board-col-count {
    font-size: .75rem;
    background: var(--border);
    color: var(--text-muted);
    padding: .1rem .45rem;
    border-radius: 999px;
    font-weight: 600;
}

.board-cards { display: flex; flex-direction: column; gap: .5rem; }

.board-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .75rem;
    box-shadow: var(--shadow);
    border-left: 3px solid var(--border);
    transition: box-shadow var(--transition);
}

.board-card:hover { box-shadow: var(--shadow-lg); }
.board-card-overdue { background: var(--danger-bg); }

.board-card-title {
    font-size: .875rem;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    display: block;
    margin-bottom: .5rem;
    line-height: 1.4;
}

.board-card-title:hover { color: var(--accent); text-decoration: none; }

.board-card-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .375rem;
}

.board-card-deadline {
    font-size: .75rem;
    color: var(--text-muted);
}

.board-card-client {
    font-size: .75rem;
    color: var(--text-muted);
    margin-left: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
}

.board-empty {
    font-size: .8125rem;
    color: var(--text-muted);
    text-align: center;
    padding: 1rem 0;
    font-style: italic;
}

/* Drag & drop */
.board-card[draggable] { cursor: grab; user-select: none; }
.board-card[draggable]:active { cursor: grabbing; }
.board-card.is-dragging { opacity: .35; box-shadow: none; }
.board-cards.drag-over {
    background: var(--accent-light);
    border-radius: var(--radius);
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
}

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
    .stats-grid    { grid-template-columns: repeat(3, 1fr); }
    .dashboard-grid { grid-template-columns: 1fr 1fr; }
    .board-view { grid-template-columns: repeat(2, 1fr); }
    .board-view .board-col:last-child { grid-column: 1 / -1; }
}

@media (max-width: 800px) {
    :root { --sidebar-w: 0px; }

    .app-layout { grid-template-columns: 1fr; }

    .sidebar {
        position: fixed;
        left: -260px;
        width: 240px;
        transition: left .25s ease;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open { left: 0; }

    .sidebar-toggle { display: flex; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid { grid-template-columns: 1fr; }
    .task-detail-layout { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .board-view { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
    .page-body    { padding: 1rem; }
    .stats-grid   { grid-template-columns: 1fr 1fr; }
    .filters-bar  { flex-direction: column; align-items: stretch; }
    .filter-search, .filter-select { width: 100%; min-width: unset; }
    .multi-select, .multi-select-btn { width: 100%; }
    .multi-select-menu { min-width: 100%; }
    .task-table th:nth-child(3),
    .task-table td:nth-child(3),
    .task-table th:nth-child(6),
    .task-table td:nth-child(6) { display: none; }
}
