/* mtasks — design system. Vanilla CSS, mobile-first, no external deps.
   Spacing: 4/8/12/16/24/32/48/64. Type: 12/13/14/15/17/22/30.
   Theme switches via :root[data-theme]. Default = dark. */

:root[data-theme="dark"] {
    /* Surfaces — cool dark slate */
    --bg:           #0e0f12;
    --surface:      #16181c;
    --surface-2:    #1d1f24;
    --surface-3:    #262930;
    --surface-4:    #2f323a;

    /* Text */
    --text:         #e8eaee;
    --text-muted:   #9aa0ac;
    --text-faint:   #5b606b;

    /* Lines */
    --border:       #23262d;
    --border-strong:#323640;

    /* Brand — rose */
    --accent:       #d05e74;
    --accent-hover: #dd6f87;
    --accent-soft:  rgba(208, 94, 116, 0.14);
    --accent-ring:  rgba(208, 94, 116, 0.45);
    --accent-text:  #ffffff;

    /* Status */
    --danger:       #ef4444;
    --danger-soft:  rgba(239, 68, 68, 0.10);
    --success:      #22c55e;
    --warning:      #eab308;

    /* Elevation */
    --shadow-sm:    0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow:       0 4px 12px rgba(0, 0, 0, 0.32), 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-lg:    0 16px 48px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);

    --backdrop:     rgba(0, 0, 0, 0.55);
    color-scheme:   dark;
}

:root[data-theme="light"] {
    --bg:           #fbfbfa;
    --surface:      #ffffff;
    --surface-2:    #f5f5f4;
    --surface-3:    #e8e8e6;
    --surface-4:    #d6d6d3;

    --text:         #1a1d23;
    --text-muted:   #5b606b;
    --text-faint:   #9aa0ac;

    --border:       #e8e8e6;
    --border-strong:#d6d6d3;

    --accent:       #c04a62;
    --accent-hover: #b03a52;
    --accent-soft:  rgba(192, 74, 98, 0.10);
    --accent-ring:  rgba(192, 74, 98, 0.4);
    --accent-text:  #ffffff;

    --danger:       #dc2626;
    --danger-soft:  rgba(220, 38, 38, 0.08);
    --success:      #16a34a;
    --warning:      #ca8a04;

    --shadow-sm:    0 1px 2px rgba(26, 29, 35, 0.06);
    --shadow:       0 4px 12px rgba(26, 29, 35, 0.08), 0 1px 3px rgba(26, 29, 35, 0.05);
    --shadow-lg:    0 16px 48px rgba(26, 29, 35, 0.14), 0 2px 6px rgba(26, 29, 35, 0.06);

    --backdrop:     rgba(26, 29, 35, 0.4);
    color-scheme:   light;
}

:root {
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;

    --r-sm: 6px;
    --r:    10px;
    --r-lg: 14px;
    --r-pill: 999px;

    --t-xs:  12px;
    --t-sm:  13px;
    --t-md:  14px;
    --t-base:15px;
    --t-lg:  17px;
    --t-xl:  22px;
    --t-2xl: 30px;

    --w-thin:    400;
    --w-medium:  500;
    --w-semibold:600;
    --w-bold:    700;

    --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    --duration-fast: 90ms;
    --duration:      160ms;
    --duration-slow: 260ms;
    --ease:          cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font: var(--w-thin) var(--t-base)/1.5 var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none;
    text-rendering: optimizeLegibility;
}

#app {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

::selection {
    background: var(--accent-soft);
    color: var(--text);
}

.boot {
    margin: auto;
    color: var(--text-muted);
    padding: var(--space-5);
    font-size: var(--t-md);
}

button, input, textarea, select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: var(--r);
    padding: var(--space-2) var(--space-4);
    font-weight: var(--w-medium);
    font-size: var(--t-md);
    transition: background var(--duration-fast) var(--ease),
                border-color var(--duration-fast) var(--ease),
                color var(--duration-fast) var(--ease),
                transform var(--duration-fast) var(--ease);
}

button:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}

button:active { transform: translateY(1px); }

button:focus-visible {
    outline: 2px solid var(--accent-ring);
    outline-offset: 2px;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

button.primary {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
}

button.primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

button.ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
    padding: var(--space-2) var(--space-3);
}

button.ghost:hover {
    background: var(--surface-2);
    color: var(--text);
    border-color: transparent;
}

button.danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: transparent;
}

button.danger:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

input, textarea, select {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: var(--space-3);
    width: 100%;
    transition: border-color var(--duration-fast) var(--ease),
                box-shadow var(--duration-fast) var(--ease);
    font-size: var(--t-md);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

textarea { resize: vertical; min-height: 80px; }

a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
}

a:hover { border-bottom-color: var(--accent); }

kbd {
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 1px var(--space-2);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
}

/* ============================================================
   LOGIN
   ============================================================ */

.login-screen {
    margin: auto;
    width: min(380px, 92vw);
    padding: var(--space-6) var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.login-screen h1 {
    margin: 0;
    font-size: var(--t-2xl);
    font-weight: var(--w-bold);
    letter-spacing: -0.02em;
    color: var(--accent);
    text-align: center;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow);
}

.login-form label {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: var(--t-sm);
    font-weight: var(--w-medium);
    color: var(--text-muted);
}

.login-form .error {
    color: var(--danger);
    font-size: var(--t-sm);
    padding: var(--space-2) var(--space-3);
    background: var(--danger-soft);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: var(--r-sm);
}

.login-form button[type="submit"] { margin-top: var(--space-2); }

/* ============================================================
   SHELL
   ============================================================ */

.shell {
    display: grid;
    grid-template-rows: auto 1fr;
    flex: 1;
    min-height: 100vh;
    min-height: 100dvh;
}

/* ---- Topbar ---- */

.topbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 10;
    height: 56px;
}

.topbar .brand {
    font-weight: var(--w-bold);
    color: var(--accent);
    letter-spacing: -0.02em;
    font-size: var(--t-lg);
    margin-right: var(--space-2);
    user-select: none;
}

.topbar .search {
    flex: 1;
    max-width: 480px;
    position: relative;
}

.topbar .search input {
    padding: var(--space-2) var(--space-3);
    font-size: var(--t-md);
    background: var(--surface-2);
    border-color: transparent;
}

.topbar .search input:focus {
    background: var(--surface);
    border-color: var(--accent);
}

.topbar .topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
}

.topbar .icon-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r);
    font-size: var(--t-md);
}

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

/* ---- Body grid ---- */

.body {
    display: grid;
    grid-template-columns: 1fr;
    overflow: hidden;
    position: relative;
}

@media (min-width: 720px) {
    .body { grid-template-columns: 220px 1fr; }
}

/* ---- Sidebar ---- */

.sidebar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: row;
    padding: var(--space-2);
    gap: var(--space-1);
}

@media (min-width: 720px) {
    .sidebar {
        flex-direction: column;
        border-right: 1px solid var(--border);
        border-bottom: none;
        padding: var(--space-3);
        gap: 2px;
    }
}

.sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    color: var(--text-muted);
    font-size: var(--t-md);
    font-weight: var(--w-medium);
    border-radius: var(--r-sm);
    background: transparent;
    border: 1px solid transparent;
    white-space: nowrap;
    cursor: pointer;
    text-align: left;
    flex-shrink: 0;
    transition: background var(--duration-fast) var(--ease),
                color var(--duration-fast) var(--ease);
}

.sidebar .nav-item:hover {
    background: var(--surface-2);
    color: var(--text);
}

.sidebar .nav-item[aria-current="page"] {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: var(--w-semibold);
}

.sidebar .nav-item .nav-emoji {
    width: 18px;
    text-align: center;
    color: inherit;
    opacity: 0.85;
}

.sidebar .nav-item .count {
    margin-left: auto;
    font-size: var(--t-xs);
    color: var(--text-faint);
    padding: 1px var(--space-2);
    border-radius: var(--r-pill);
    background: var(--surface-3);
    font-variant-numeric: tabular-nums;
}

.sidebar .nav-item[aria-current="page"] .count {
    background: transparent;
    color: var(--accent);
}

/* ---- Main ---- */

.main {
    overflow-y: auto;
    padding: var(--space-5) var(--space-4) var(--space-7);
    max-width: 760px;
    width: 100%;
    margin: 0 auto;
}

@media (min-width: 720px) {
    .main { padding: var(--space-6); }
}

.main-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}

.main-header h2 {
    margin: 0;
    font-size: var(--t-xl);
    font-weight: var(--w-semibold);
    letter-spacing: -0.01em;
}

.main-header .count-pill {
    font-size: var(--t-sm);
    color: var(--text-faint);
    background: var(--surface-2);
    padding: 2px var(--space-3);
    border-radius: var(--r-pill);
    font-variant-numeric: tabular-nums;
}

/* ---- Compose ---- */

.compose {
    display: flex;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
    align-items: stretch;
}

.compose input {
    flex: 1;
    background: var(--surface);
    font-size: var(--t-base);
    padding: var(--space-3) var(--space-4);
}

.compose button { padding-inline: var(--space-5); }

/* ---- Task list ---- */

.task-list {
    display: flex;
    flex-direction: column;
    list-style: none;
    padding: 0;
    margin: 0;
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--r);
    overflow: hidden;
}

.task-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease);
    position: relative;
}

.task-item:hover { background: var(--surface-2); }

.task-item[aria-selected="true"] {
    background: var(--accent-soft);
}

.task-item[aria-selected="true"]::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent);
}

.task-check {
    width: 18px;
    height: 18px;
    margin-top: 3px;
    flex-shrink: 0;
    border-radius: 50%;
    border: 1.5px solid var(--border-strong);
    background: var(--surface);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-text);
    font-size: 11px;
    line-height: 1;
    transition: all var(--duration-fast) var(--ease);
}

.task-check:hover { border-color: var(--accent); }

.task-item.done .task-check {
    background: var(--accent);
    border-color: var(--accent);
}

.task-body {
    flex: 1;
    min-width: 0;
}

.task-title {
    font-size: var(--t-base);
    font-weight: var(--w-medium);
    word-break: break-word;
    line-height: 1.4;
    color: var(--text);
}

.task-item.done .task-title {
    color: var(--text-faint);
    text-decoration: line-through;
    text-decoration-thickness: 1px;
}

.task-meta {
    margin-top: var(--space-1);
    font-size: var(--t-xs);
    color: var(--text-muted);
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    align-items: center;
}

.task-meta .meta-overdue {
    color: var(--danger);
    font-weight: var(--w-medium);
}

.task-meta .priority-pip {
    color: var(--warning);
    font-weight: var(--w-bold);
    letter-spacing: 0.5px;
}

.task-meta .energy-chip {
    display: inline-flex;
    align-items: center;
    padding: 0 var(--space-2);
    border-radius: var(--r-pill);
    background: var(--surface-3);
    font-size: 11px;
    font-weight: var(--w-medium);
    line-height: 18px;
}

/* Quick actions on selected task */
.task-actions {
    display: flex;
    gap: var(--space-1);
    margin-left: var(--space-2);
    align-self: center;
    opacity: 0;
    transition: opacity var(--duration-fast) var(--ease);
}

.task-item:hover .task-actions,
.task-item[aria-selected="true"] .task-actions {
    opacity: 1;
}

.task-action {
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    padding: var(--space-1) var(--space-2);
    font-size: var(--t-sm);
    cursor: pointer;
    color: var(--text-muted);
    height: 28px;
    min-width: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.task-action:hover {
    background: var(--surface-3);
    color: var(--text);
    border-color: var(--border);
}

.task-action.active {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}

/* ---- Empty / loading state ---- */

.empty {
    padding: var(--space-7) var(--space-4);
    text-align: center;
    color: var(--text-muted);
    border: 1px dashed var(--border);
    border-radius: var(--r);
    background: var(--surface);
}

.empty .empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin-bottom: var(--space-3);
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text-faint);
}

.empty .empty-icon .icon {
    width: 22px;
    height: 22px;
}

.empty .empty-title {
    font-size: var(--t-md);
    font-weight: var(--w-medium);
    color: var(--text);
    margin-bottom: var(--space-1);
}

.empty .hint {
    font-size: var(--t-sm);
    color: var(--text-faint);
}

.skeleton {
    height: 56px;
    border-radius: var(--r);
    background: linear-gradient(90deg,
        var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.4s ease-in-out infinite;
    margin-bottom: var(--space-1);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================================
   TASK DETAIL PANEL (slide-in from right)
   ============================================================ */

.detail-overlay {
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    z-index: 30;
    opacity: 0;
    animation: fadeIn var(--duration) var(--ease) forwards;
}

@keyframes fadeIn { to { opacity: 1; } }

.detail-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(440px, 100vw);
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: 31;
    transform: translateX(100%);
    animation: slideIn var(--duration) var(--ease) forwards;
}

@keyframes slideIn { to { transform: translateX(0); } }

.detail-panel header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
}

.detail-panel header .title {
    flex: 1;
    font-size: var(--t-sm);
    color: var(--text-muted);
    font-weight: var(--w-medium);
}

.detail-form {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.detail-form .field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.detail-form .field-label {
    font-size: var(--t-xs);
    font-weight: var(--w-medium);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.detail-form .field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}

.detail-form .title-input {
    font-size: var(--t-lg);
    font-weight: var(--w-medium);
    border-color: transparent;
    background: transparent;
    padding: var(--space-2) 0;
}

.detail-form .title-input:focus {
    border-color: transparent;
    box-shadow: none;
    background: var(--surface-2);
    border-radius: var(--r-sm);
    padding-inline: var(--space-3);
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.chip {
    padding: var(--space-1) var(--space-3);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-pill);
    font-size: var(--t-sm);
    font-weight: var(--w-medium);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease);
}

.chip:hover { border-color: var(--border-strong); color: var(--text); }

.chip[aria-pressed="true"] {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.detail-panel footer {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.detail-panel footer .spacer { flex: 1; }

/* ============================================================
   FLOATING MENUS (snooze, etc.)
   ============================================================ */

.snooze-menu {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--shadow-lg);
    padding: var(--space-1);
    min-width: 180px;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 2px;
    animation: fadeIn var(--duration-fast) var(--ease);
}

.snooze-opt {
    background: transparent;
    border: 1px solid transparent;
    text-align: left;
    padding: var(--space-2) var(--space-3);
    cursor: pointer;
    border-radius: var(--r-sm);
    font-size: var(--t-md);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.snooze-opt:hover { background: var(--surface-2); }
.snooze-opt .opt-hint { color: var(--text-faint); font-size: var(--t-xs); }

/* ============================================================
   STREAK / TIMER chips in topbar
   ============================================================ */

.streak-chip {
    font-size: var(--t-sm);
    font-weight: var(--w-medium);
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--r-pill);
    user-select: none;
    white-space: nowrap;
    line-height: 18px;
    font-variant-numeric: tabular-nums;
}

.timer-chip {
    font-size: var(--t-sm);
    font-weight: var(--w-medium);
    color: var(--accent-text);
    background: var(--accent);
    border: 1px solid var(--accent);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--r-pill);
    cursor: pointer;
    white-space: nowrap;
    line-height: 18px;
    box-shadow: var(--shadow-sm);
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    position: relative;
}

.timer-chip::before {
    content: "";
    width: 6px;
    height: 6px;
    background: white;
    border-radius: 50%;
    animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.3; }
}

.timer-chip:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.streak-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.streak-chip .icon {
    color: var(--accent);
}

/* Inline icons inside text/buttons */
.icon { flex-shrink: 0; vertical-align: middle; }

.btn-icon { display: inline-flex; align-items: center; margin-right: var(--space-1); }

.nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: inherit;
    opacity: 0.85;
    width: 18px;
}

.nav-label { flex: 1; }

.task-actions .icon { color: inherit; }
.task-action.active .icon { color: var(--accent-text); }
.task-check .icon { width: 12px; height: 12px; }
.task-meta .meta-icon { display: inline-flex; align-items: center; color: var(--text-faint); }

.task-actions { gap: 2px; }

/* ============================================================
   HOTKEY HINT
   ============================================================ */

.hotkey-hint {
    position: fixed;
    bottom: var(--space-3);
    right: var(--space-4);
    font-size: var(--t-xs);
    color: var(--text-faint);
    background: var(--surface);
    border: 1px solid var(--border);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--r);
    box-shadow: var(--shadow-sm);
    pointer-events: none;
    user-select: none;
    line-height: 18px;
}

.hotkey-hint kbd { margin: 0 1px; }

@media (max-width: 720px) {
    .hotkey-hint { display: none; }
}

/* ============================================================
   ERROR BANNER
   ============================================================ */

.error-banner {
    background: var(--danger-soft);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--danger);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--r);
    margin-bottom: var(--space-3);
    font-size: var(--t-sm);
    font-weight: var(--w-medium);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}
