:root {
    --bg: #f7f7f8;
    --surface: #ffffff;
    --surface-2: #f1f1f3;
    --border: #e3e3e6;
    --text: #1a1a1e;
    --text-muted: #6b6b74;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success: #16a34a;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}

[data-theme="dark"] {
    --bg: #121214;
    --surface: #1c1c1f;
    --surface-2: #232327;
    --border: #303035;
    --text: #f0f0f2;
    --text-muted: #9a9aa2;
    --accent: #6366f1;
    --accent-hover: #7c7ff0;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background .2s ease, color .2s ease;
    min-height: 100vh;
}

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

.container {
    max-width: 880px;
    margin: 0 auto;
    padding: 0 20px 60px;
}

/* ---------- Navbar ---------- */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 20;
}
.navbar .brand {
    font-weight: 700;
    font-size: 17px;
    color: var(--text);
}
.navbar nav {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}
.navbar nav a, .navbar nav button {
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-muted);
    border: none;
    background: transparent;
    cursor: pointer;
}
.navbar nav a.active, .navbar nav a:hover, .navbar nav button:hover {
    background: var(--surface-2);
    color: var(--text);
}
.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}
.icon-btn:hover { background: var(--surface-2); }

.lang-select {
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
}

/* ---------- Cards / auth ---------- */
.center-screen {
    min-height: calc(100vh - 0px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    width: 100%;
}
.card.auth { max-width: 380px; }
.card h1, .card h2 { margin-top: 0; }

.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.field input, .field textarea {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}
.field input:focus, .field textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.field textarea { min-height: 120px; resize: vertical; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: var(--accent);
    color: #fff;
    transition: background .15s ease;
}
.btn:hover { background: var(--accent-hover); }
.btn.full { width: 100%; }
.btn.secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn.secondary:hover { background: var(--border); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: var(--danger-hover); }
.btn.small { padding: 6px 10px; font-size: 13px; }

.muted { color: var(--text-muted); font-size: 14px; }
.auth-switch { margin-top: 18px; text-align: center; font-size: 14px; }

/* ---------- Flash ---------- */
.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin: 16px 0;
    font-size: 14px;
}
.flash.success { background: rgba(22,163,74,.12); color: var(--success); }
.flash.error { background: rgba(220,38,38,.12); color: var(--danger); }

/* ---------- Dashboard ---------- */
.hero { padding: 32px 0 8px; }
.hero h1 { margin-bottom: 6px; }
.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 24px 0;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
}
.stat-card .num { font-size: 28px; font-weight: 700; }
.stat-card .label { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

.quick-links { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }

/* ---------- List pages ---------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: 28px 0 16px;
}
.page-header h1 { margin: 0; font-size: 22px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input[type=search] {
    flex: 1;
    min-width: 180px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.list { display: flex; flex-direction: column; gap: 10px; }
.item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.item .info .item-title { font-weight: 600; }
.item .info .item-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.item .actions { display: flex; gap: 8px; flex-shrink: 0; }

.note-item { flex-direction: column; align-items: stretch; }
.note-item .note-header { display: flex; justify-content: space-between; align-items: center; }
.note-item .note-content { color: var(--text-muted); font-size: 14px; margin-top: 8px; white-space: pre-wrap; }

.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--text-muted);
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}
.modal h2 { margin-top: 0; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ---------- Sync page ---------- */
.sync-result {
    margin-top: 20px;
    background: var(--surface-2);
    border-radius: 8px;
    padding: 14px 16px;
    font-size: 14px;
    white-space: pre-wrap;
    word-break: break-word;
}

@media (max-width: 520px) {
    .navbar { padding: 12px 14px; }
    .navbar .brand { font-size: 15px; }
    .card { padding: 20px; }
    .stats { grid-template-columns: 1fr; }
}
