:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-muted: #f1f5f9;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-soft: #eef2ff;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --amber: #d97706;
    --amber-soft: #fffbeb;
    --success: #10b981;
    --success-soft: #ecfdf5;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --sidebar-w: 250px;
    --bottom-nav-h: 64px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    min-height: 100%;
}

.hidden {
    display: none !important;
}

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

/* Auth */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(145deg, #eef2ff 0%, #f8fafc 60%, #ecfdf5 100%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 28px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.auth-brand h1 {
    margin: 0;
    font-size: 1.4rem;
}

.auth-brand p {
    margin: 2px 0 0;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.brand-badge {
    width: 44px;
    height: 44px;
    border-radius: 13px;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.25rem;
    flex-shrink: 0;
}

/* Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 18px 14px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 6px;
}

.brand-title {
    font-weight: 700;
    font-size: 1.05rem;
}

.brand-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.nav-btn {
    border: none;
    background: transparent;
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    text-align: left;
    font-weight: 500;
    color: var(--text-muted);
    transition: background 0.15s, color 0.15s;
}

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

.nav-btn.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 700;
}

.nav-icon {
    width: 22px;
    text-align: center;
}

.nav-label {
    flex: 1;
}

.nav-badge, .bottom-badge {
    background: var(--primary);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    border-radius: 999px;
    padding: 1px 7px;
}

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

.user-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    color: var(--text-muted);
    font-size: 0.78rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.main-column {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(248, 250, 252, 0.92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 64px;
}

.topbar-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.topbar-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
}

.topbar-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
}

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

.view-root {
    flex: 1;
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 16px 20px 32px;
}

/* Bottom nav mobile */
.bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--bottom-nav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 30;
    align-items: stretch;
}

.bottom-nav-btn {
    flex: 1;
    border: none;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.72rem;
    position: relative;
    padding: 4px 2px;
}

.bottom-nav-btn.active {
    color: var(--primary);
    font-weight: 700;
}

.bottom-nav-icon {
    font-size: 1.08rem;
}

.bottom-nav-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.bottom-badge {
    position: absolute;
    top: 5px;
    right: 16%;
    padding: 0 5px;
    font-size: 0.65rem;
}

@media (max-width: 859px) {
    .sidebar {
        display: none;
    }
    .bottom-nav {
        display: flex;
    }
    .view-root {
        padding: 14px 14px calc(var(--bottom-nav-h) + 24px);
    }
    .topbar {
        padding: 10px 14px;
    }
}

/* Controls & Buttons */
.btn {
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 9px 14px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 0.82rem;
    border-radius: 8px;
}

.btn-block {
    width: 100%;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

.btn-tonal {
    background: var(--primary-soft);
    color: var(--primary);
}

.btn-tonal:hover:not(:disabled) {
    background: #e0e7ff;
}

.btn-outline {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

.btn-outline:hover:not(:disabled) {
    background: var(--surface-muted);
}

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

.btn-danger-outline {
    background: var(--surface);
    border-color: #fecaca;
    color: var(--danger);
}

.icon-btn {
    border: 1px solid transparent;
    background: transparent;
    border-radius: 999px;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    flex-shrink: 0;
}

.icon-btn:hover:not(:disabled) {
    background: var(--surface-muted);
    color: var(--text);
}

.icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Segmented & Chips */
.segmented {
    display: flex;
    background: var(--surface-muted);
    border-radius: 12px;
    padding: 4px;
    gap: 4px;
}

.segmented-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 10px;
    border-radius: 9px;
    font-weight: 600;
    font-size: 0.86rem;
    color: var(--text-muted);
    cursor: pointer;
}

.segmented-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.chips-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.chip {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.83rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.chip.active {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
}

.chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
}

/* Cards & Lists */
.stack-md {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stack-sm {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.section-title {
    margin: 14px 0 8px;
    font-size: 0.96rem;
    font-weight: 700;
    color: var(--text);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.card-clickable {
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.card-clickable:hover {
    border-color: #cbd5e1;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
}

.task-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    border-left: 4px solid var(--border);
}

.task-card.priority-high {
    border-left-color: var(--danger);
}

.task-card.priority-general {
    border-left-color: var(--amber);
}

.task-card.is-completed {
    opacity: 0.72;
}

.task-check {
    width: 22px;
    height: 22px;
    margin-top: 2px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

.task-main {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.task-title {
    font-weight: 600;
    word-break: break-word;
}

.task-card.is-completed .task-title {
    text-decoration: line-through;
    color: var(--text-muted);
}

.task-notes {
    margin-top: 4px;
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: pre-line;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    align-items: center;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.76rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--surface-muted);
    color: var(--text-muted);
}

.pill-danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.pill-amber {
    background: var(--amber-soft);
    color: var(--amber);
}

.pill-success {
    background: var(--success-soft);
    color: #047857;
}

.pill-primary {
    background: var(--primary-soft);
    color: var(--primary);
}

.task-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

/* Forms */
.form-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.field label {
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--text-muted);
}

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="number"],
.field input[type="datetime-local"],
.field textarea,
.field select,
.search-input {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    outline: none;
    transition: border-color 0.15s;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.search-input:focus {
    border-color: var(--primary);
}

.checkbox-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.checkbox-row input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* Alerts & Empty */
.alert {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
}

.alert-error {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-info {
    background: var(--primary-soft);
    color: var(--primary);
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
}

.empty-state h3 {
    margin: 0 0 6px;
    color: var(--text);
}

/* AI Chat */
.ai-shell {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: calc(100vh - 150px);
}

.ai-history {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-prompt-bubble {
    align-self: flex-end;
    max-width: 85%;
    background: var(--primary-soft);
    color: #1e1b4b;
    padding: 11px 14px;
    border-radius: 16px 16px 4px 16px;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-reply-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
}

.ai-reply-body {
    white-space: pre-wrap;
    word-break: break-word;
    margin-top: 8px;
}

.ai-composer {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    position: sticky;
    bottom: 12px;
}

.ai-composer textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: vertical;
    min-height: 42px;
    max-height: 150px;
    background: transparent;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(15, 23, 42, 0.48);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-dialog {
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    background: var(--surface);
    border-radius: 22px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.modal-title {
    margin: 0;
    font-size: 1.08rem;
    font-weight: 700;
}

.modal-body {
    padding: 18px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.snooze-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.swatch-btn {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    border: 2px solid transparent;
    cursor: pointer;
}

.swatch-btn.active {
    border-color: var(--text);
    box-shadow: 0 0 0 2px #fff inset;
}

/* Toast */
.toast-root {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 360px;
}

.toast {
    background: #0f172a;
    color: #fff;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.86rem;
    box-shadow: var(--shadow);
}

.toast.error {
    background: var(--danger);
}

@media (max-width: 859px) {
    .toast-root {
        bottom: calc(var(--bottom-nav-h) + 12px);
        left: 14px;
        right: 14px;
        max-width: none;
    }
}
