* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --white: #ffffff;
    --off-white: #f7f6f3;
    --gray-100: #f0eeea;
    --gray-200: #e2dfd8;
    --gray-400: #9e9b94;
    --gray-600: #5a5750;
    --gray-800: #2a2825;
    --black: #141312;
    --green: #1d7a4a;
    --green-light: #f0faf5;
    --green-hover: #166b3e;
    --red: #c53030;
    --red-light: #fef2f2;
    --orange: #b7791f;
    --orange-light: #fefce8;
    --sidebar-width: 260px;
}

body {
    font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
    background: var(--off-white);
    color: var(--black);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    display: flex;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--white);
    border-left: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 50;
    transition: transform 0.2s ease;
}

.sidebar-header {
    padding: 20px 18px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--gray-100);
}

.sidebar-header h1 {
    font-size: 1.15em;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.2em;
    cursor: pointer;
    color: var(--gray-400);
    display: none;
}

.sidebar-search {
    padding: 12px 14px;
}

.sidebar-search input {
    width: 100%;
    background: var(--off-white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 0.88em;
    font-family: inherit;
    color: var(--black);
    transition: border-color 0.15s;
}
.sidebar-search input:focus {
    outline: none;
    border-color: var(--black);
    background: var(--white);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px;
}

.nav-section {
    margin-bottom: 16px;
}

.nav-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    font-size: 0.75em;
    font-weight: 600;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    font-size: 1.1em;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s;
}
.btn-icon:hover { background: var(--gray-100); color: var(--black); }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.12s;
    text-decoration: none;
    color: var(--gray-800);
    font-size: 0.9em;
    font-weight: 500;
}
.nav-item:hover { background: var(--gray-100); }
.nav-item.active { background: var(--gray-100); color: var(--black); font-weight: 600; }

.nav-icon { font-size: 1.05em; width: 22px; text-align: center; flex-shrink: 0; }
.nav-text { flex: 1; min-width: 0; }
.nav-label { display: block; }
.nav-desc {
    display: block;
    font-size: 0.75em;
    color: var(--gray-500);
    font-weight: 400;
    line-height: 1.3;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-count {
    background: var(--gray-100);
    color: var(--gray-600);
    font-size: 0.72em;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}
.nav-item.active .nav-count { background: var(--black); color: var(--white); }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
    flex: 1;
    margin-right: var(--sidebar-width);
    padding: 0 32px 40px;
    max-width: 800px;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px 0 14px;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 16px;
}

.topbar h2 {
    font-size: 1.3em;
    font-weight: 700;
    flex: 1;
    letter-spacing: -0.02em;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.sidebar-toggle-mobile {
    display: none;
    background: none;
    border: none;
    font-size: 1.3em;
    cursor: pointer;
    color: var(--gray-600);
}

/* Quick Add */
.quick-add {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.quick-add input {
    flex: 1;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 11px 16px;
    font-size: 0.92em;
    font-family: inherit;
    color: var(--black);
    transition: border-color 0.15s;
}
.quick-add input:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(29, 122, 74, 0.08);
}
.quick-add input::placeholder { color: var(--gray-400); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.15s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary { background: var(--black); color: var(--white); }
.btn-primary:hover { background: var(--gray-800); }

.btn-secondary { background: var(--white); color: var(--black); border: 1px solid var(--gray-200); }
.btn-secondary:hover { background: var(--gray-100); border-color: var(--gray-400); }

.btn-logout { background: transparent; color: var(--gray-400); font-size: 0.85em; padding: 8px 14px; }
.btn-logout:hover { color: var(--black); }

.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 7px 14px; font-size: 0.82em; border-radius: 6px; }

.btn-done { background: var(--green-light); color: var(--green); border: 1px solid #c0e8d0; }
.btn-done:hover { background: var(--green); color: white; }

.btn-reopen { background: var(--orange-light); color: var(--orange); border: 1px solid #f0e68c; }
.btn-reopen:hover { background: var(--orange); color: white; }

.btn-subtask { background: var(--gray-100); color: var(--gray-600); border: 1px solid var(--gray-200); }
.btn-subtask:hover { background: var(--gray-200); color: var(--black); }

.btn-edit { background: var(--white); color: var(--gray-600); border: 1px solid var(--gray-200); }
.btn-edit:hover { border-color: var(--gray-400); color: var(--black); }

.btn-delete { background: var(--white); color: var(--gray-400); border: 1px solid var(--gray-200); }
.btn-delete:hover { background: var(--red-light); color: var(--red); border-color: #fca5a5; }

/* ============================================================
   STATS BAR
   ============================================================ */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 14px;
    text-align: center;
}

.stat-number {
    font-size: 1.6em;
    font-weight: 700;
    color: var(--black);
    line-height: 1;
    margin-bottom: 3px;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 0.75em;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

/* ============================================================
   FILTERS
   ============================================================ */
.filters {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filters select {
    background: var(--white);
    color: var(--black);
    border: 1px solid var(--gray-200);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.88em;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s;
}
.filters select:focus { outline: none; border-color: var(--black); }

/* ============================================================
   TASK CARDS
   ============================================================ */
.task-list { display: flex; flex-direction: column; gap: 6px; }

.section-header {
    font-size: 0.82em;
    font-weight: 600;
    color: var(--gray-600);
    padding: 12px 4px 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 4px;
}

.task-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 14px 16px;
    transition: all 0.15s ease;
}
.task-card:hover { border-color: var(--gray-400); box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
.task-card.done { opacity: 0.5; }
.task-card.cancelled { opacity: 0.35; }
.task-card.overdue { border-right: 3px solid var(--red); }

.task-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.task-priority { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.task-priority.urgent { background: var(--red); }
.task-priority.high { background: var(--orange); }
.task-priority.medium { background: var(--gray-400); }
.task-priority.low { background: #c0e8d0; }

.task-title { font-size: 0.93em; font-weight: 500; color: var(--black); flex: 1; }
.task-card.done .task-title { text-decoration: line-through; color: var(--gray-400); }

.subtask-count {
    font-size: 0.72em;
    color: var(--gray-400);
    background: var(--gray-100);
    padding: 2px 6px;
    border-radius: 8px;
    font-weight: 500;
}

.task-status {
    font-size: 0.72em;
    padding: 3px 9px;
    border-radius: 20px;
    background: var(--gray-100);
    color: var(--gray-600);
    white-space: nowrap;
    font-weight: 500;
}
.task-status.done-status { background: var(--green-light); color: var(--green); }

.task-desc {
    color: var(--gray-600);
    font-size: 0.84em;
    margin-bottom: 6px;
    padding-right: 16px;
    line-height: 1.5;
}

.task-labels {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.label-tag {
    font-size: 0.72em;
    background: var(--gray-100);
    color: var(--gray-600);
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

.task-meta {
    display: flex;
    gap: 14px;
    font-size: 0.78em;
    color: var(--gray-400);
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.overdue-text { color: var(--red); font-weight: 600; }

.task-actions { display: flex; gap: 5px; flex-wrap: wrap; }

/* Subtasks */
.subtask-list {
    margin: 8px 0;
    padding-right: 12px;
    border-right: 2px solid var(--gray-200);
}

.subtask-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    font-size: 0.85em;
}
.subtask-item.done .subtask-title { text-decoration: line-through; color: var(--gray-400); }

.subtask-check {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1em;
    color: var(--gray-400);
    padding: 0;
}
.subtask-check:hover { color: var(--green); }

.subtask-title { color: var(--gray-800); }

/* ============================================================
   MODALS
   ============================================================ */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(20, 19, 18, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-content {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 14px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.12);
}

.modal-sm { max-width: 380px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 22px 0;
}
.modal-header h2 { font-size: 1.1em; font-weight: 600; }

.btn-close {
    background: none;
    border: none;
    color: var(--gray-400);
    font-size: 1.4em;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}
.btn-close:hover { color: var(--black); }

form { padding: 0; }

.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    margin-bottom: 5px;
    color: var(--gray-600);
    font-size: 0.82em;
    font-weight: 500;
}
.label-hint {
    font-weight: 400;
    color: var(--gray-400);
    font-size: 0.9em;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    background: var(--off-white);
    color: var(--black);
    border: 1px solid var(--gray-200);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.9em;
    font-family: inherit;
    transition: border-color 0.15s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--black);
    background: var(--white);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.form-body { padding: 18px 22px 8px; max-height: 60vh; overflow-y: auto; }

/* Sticky form buttons at bottom */
.form-actions-sticky {
    position: sticky;
    bottom: 0;
    background: var(--white);
    padding: 14px 22px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    gap: 10px;
    border-radius: 0 0 14px 14px;
}

/* Assign badges */
.assign-badge {
    font-size: 0.72em;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}
.assign-human { background: #e8f4fd; color: #1a73e8; }
.assign-agent { background: #f3e8fd; color: #7c3aed; }
.assign-human_agent { background: #fef3c7; color: #92400e; }

.agent-badge {
    font-size: 0.72em;
    padding: 2px 8px;
    border-radius: 10px;
    background: #f3e8fd;
    color: #7c3aed;
    font-weight: 500;
}

.note-badge {
    font-size: 0.75em;
    cursor: pointer;
    color: var(--gray-400);
}
.note-badge:hover { color: var(--black); }

/* Notes panel */
.notes-panel {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--gray-200);
}
.notes-panel h3 {
    font-size: 0.85em;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--gray-600);
}
.notes-list { max-height: 200px; overflow-y: auto; margin-bottom: 8px; }
.notes-empty { color: var(--gray-400); font-size: 0.85em; }
.note-item {
    padding: 6px 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.85em;
}
.note-actor { font-weight: 600; font-size: 0.82em; }
.note-time { color: var(--gray-400); font-size: 0.75em; margin-right: 8px; }
.note-item p { margin-top: 2px; color: var(--gray-800); }

.notes-add {
    display: flex;
    gap: 6px;
}
.notes-add input {
    flex: 1;
    background: var(--off-white);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 0.85em;
    font-family: inherit;
}
.notes-add input:focus { outline: none; border-color: var(--black); }

/* Activity Log */
.activity-list { display: flex; flex-direction: column; gap: 4px; }
.activity-item {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85em;
}
.activity-actor { font-size: 1.1em; }
.activity-action { font-weight: 600; color: var(--gray-800); min-width: 80px; }
.activity-details { flex: 1; color: var(--gray-600); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-time { color: var(--gray-400); font-size: 0.8em; white-space: nowrap; }

/* Agent key result */
.agent-key-box {
    margin: 12px 22px 22px;
    padding: 14px;
    background: var(--green-light);
    border: 1px solid #c0e8d0;
    border-radius: 8px;
}
.agent-key-box code {
    display: block;
    padding: 8px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    font-family: 'DM Mono', monospace;
    font-size: 0.85em;
    word-break: break-all;
    margin: 6px 0;
}
.agent-key-note { font-size: 0.8em; color: var(--gray-600); margin-top: 6px; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-box {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 14px;
    padding: 44px 40px;
    width: 100%;
    max-width: 360px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.04);
}
.login-box h1 { font-size: 1.5em; margin-bottom: 4px; font-weight: 600; letter-spacing: -0.02em; }
.login-box h2 { color: var(--gray-400); font-size: 0.9em; margin-bottom: 32px; font-weight: 400; }

.error {
    background: var(--red-light);
    border: 1px solid #fca5a5;
    color: var(--red);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.88em;
}

.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--gray-400);
    font-size: 1em;
}

/* ============================================================
   MOBILE
   ============================================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: -4px 0 20px rgba(0,0,0,0.1);
    }
    .sidebar-toggle-mobile { display: block; }
    .sidebar-toggle { display: block; }

    .main-content {
        margin-right: 0;
        padding: 0 16px 30px;
    }

    .topbar { flex-wrap: wrap; }
    .form-row { grid-template-columns: 1fr; }
    .stats-bar { grid-template-columns: repeat(2, 1fr); }
}
