:root {
    --bg: #0f1115;
    --surface: #181b22;
    --surface-2: #20242d;
    --border: #2a2f3a;
    --text: #e7e9ee;
    --text-dim: #9aa0ac;
    --primary: #51e3f0;
    --primary-hover: #7eedf5;
    --accent: #ffb547;
    --danger: #ff6b6b;
    --success: #6bcf7a;
    --shadow: 0 8px 24px rgba(0,0,0,0.4);
    --radius: 12px;
}

* { box-sizing: border-box; }

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

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

/* ── Navbar ─────────────────────────────────────────────────────────────── */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
    padding-top: max(0.75rem, env(safe-area-inset-top));
}
.nav-brand { font-weight: 700; font-size: 1.1rem; color: var(--text); display: flex; align-items: center; }
.nav-logo { height: 28px; width: auto; display: block; border-radius: 4px; }
.nav-links { display: flex; gap: 0.5rem; align-items: center; }
.nav-link {
    color: var(--text-dim);
    padding: 0.4rem 0.7rem;
    border-radius: 8px;
    font-size: 0.9rem;
}
.nav-link.active { color: var(--text); background: var(--surface-2); }
.nav-logout { color: var(--text-dim); }

/* ── Container ──────────────────────────────────────────────────────────── */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 1rem;
    padding-bottom: calc(5rem + env(safe-area-inset-bottom));
}

h1 { margin: 0.5rem 0 1rem; font-size: 1.5rem; }
h2 { margin: 0.5rem 0 0.75rem; font-size: 1.1rem; }

.muted { color: var(--text-dim); font-size: 0.9rem; }

/* ── Tasks header / filters ─────────────────────────────────────────────── */
.tasks-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.filters { display: flex; gap: 0.25rem; }
.filter {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.85rem;
    cursor: pointer;
}
.filter.active { background: var(--primary); color: #0f1115; border-color: var(--primary); }

/* ── Task list ──────────────────────────────────────────────────────────── */
.task-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.task {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem;
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    transition: background 0.15s;
}
.task.done { opacity: 0.55; }
.task.done .task-title { text-decoration: line-through; }
.task.ctx-pro { border-left: 3px solid var(--accent); }
.task.ctx-perso { border-left: 3px solid var(--primary); }

.task-check { display: flex; align-items: center; }
.task-check input { width: 1.2rem; height: 1.2rem; accent-color: var(--primary); }
.task-body { flex: 1; cursor: pointer; min-width: 0; }
.task-title { font-weight: 500; word-wrap: break-word; }
.task-title .prio { color: var(--accent); margin-right: 0.25rem; }
.task-due, .task-rec, .task-notes {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-top: 0.25rem;
    word-wrap: break-word;
}
.task-del {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}
.task-del:hover { color: var(--danger); }

.task-loading, .task-empty, .task-error {
    text-align: center;
    color: var(--text-dim);
    padding: 2rem 1rem;
}
.task-error { color: var(--danger); }

/* ── FAB ────────────────────────────────────────────────────────────────── */
.fab {
    position: fixed;
    right: 1.25rem;
    bottom: calc(1.25rem + env(safe-area-inset-bottom));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: #0f1115;
    border: none;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow);
    z-index: 20;
}
.fab:hover { background: var(--primary-hover); }

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    width: min(90vw, 500px);
    box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
.modal h2 { margin-top: 0; }
.modal form { display: flex; flex-direction: column; gap: 0.75rem; }
.modal label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: var(--text-dim);
}
.modal input, .modal select, .modal textarea {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.6rem;
    border-radius: 8px;
    font: inherit;
    width: 100%;
}
.modal input:focus, .modal select:focus, .modal textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.5rem;
    align-items: center;
}
.btn-primary, .btn-secondary, .btn-voice {
    padding: 0.6rem 1.1rem;
    border-radius: 8px;
    border: none;
    font: inherit;
    cursor: pointer;
}
.btn-primary { background: var(--primary); color: #0f1115; font-weight: 600; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-voice {
    background: var(--surface-2);
    color: var(--text);
    margin-right: auto;
    font-size: 1.2rem;
    width: 44px; height: 44px;
    padding: 0;
}
.btn-voice.recording { background: var(--danger); color: white; animation: pulse 1s infinite; }
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* ── Cards (settings) ───────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}
.card ul { padding-left: 1.25rem; }
.push-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }
.btn-small { padding: 0.35rem 0.6rem; font-size: 0.85rem; }

/* ── Chat page ──────────────────────────────────────────────────────────── */
.chat-page {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - 4rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    min-height: 400px;
    margin: -1rem;
    padding: 1rem;
}
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.chat-messages {
    flex: 1;
    list-style: none;
    padding: 0;
    margin: 0 0 0.75rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.chat-empty {
    text-align: center;
    color: var(--text-dim);
    padding: 2rem 1rem;
}
.msg {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-width: 85%;
}
.msg-user { align-self: flex-end; align-items: flex-end; }
.msg-assistant, .msg-error { align-self: flex-start; align-items: flex-start; }
.msg .bubble {
    padding: 0.6rem 0.85rem;
    border-radius: 14px;
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.4;
}
.msg-user .bubble {
    background: var(--primary);
    color: #0f1115;
    border-bottom-right-radius: 4px;
}
.msg-assistant .bubble {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.msg-error .bubble {
    background: rgba(255, 107, 107, 0.15);
    border: 1px solid var(--danger);
    color: var(--danger);
}
.msg.pending .bubble {
    opacity: 0.6;
    animation: pulse 1.2s ease-in-out infinite;
}
.msg .action {
    font-size: 0.8rem;
    color: var(--text-dim);
    padding: 0.2rem 0.5rem;
    border-left: 2px solid var(--primary);
    margin-left: 0.5rem;
}

.chat-form {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}
#chat-input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.7rem 0.9rem;
    border-radius: 18px;
    font: inherit;
    resize: none;
    max-height: 160px;
    line-height: 1.4;
}
#chat-input:focus { outline: none; border-color: var(--primary); }
.btn-send {
    background: var(--primary);
    color: #0f1115;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.3rem;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
}
.btn-send:hover { background: var(--primary-hover); }

/* ── Login ──────────────────────────────────────────────────────────────── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 1rem;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 380px;
}
.login-logo {
    width: 100%;
    max-width: 280px;
    height: auto;
    display: block;
    margin: 0 auto 0.5rem;
    border-radius: 8px;
}
.login-subtitle { color: var(--text-dim); margin: 0 0 1.5rem; }
.login-error { color: var(--danger); margin-bottom: 1rem; }
.btn-login {
    display: block;
    background: var(--primary);
    color: #0f1115;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    text-decoration: none;
}
.btn-login:hover { background: var(--primary-hover); color: #0f1115; }
