/* =========================================================
   LIFE OS — Design System (Phase 5)
   Dark/Light themes, RTL/LTR, sidebar shell, components.
   ========================================================= */

:root {
    color-scheme: dark;
    --bg: #070d18;
    --bg-soft: #0b1424;
    --surface: #0f1b2e;
    --surface-2: #13233b;
    --surface-3: #1a2f4d;
    --border: #1e3a5f;
    --border-soft: #172b46;
    --text: #e6edf7;
    --muted: #93a4bd;
    --muted-2: #6b7f9c;
    --accent: #38bdf8;
    --accent-strong: #0ea5e9;
    --accent-soft: rgba(56, 189, 248, .14);
    --ok: #34d399;
    --ok-soft: rgba(52, 211, 153, .12);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, .12);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, .12);
    --purple: #a78bfa;
    --purple-soft: rgba(167, 139, 250, .14);
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 22px 48px -28px rgba(0, 0, 0, .8);
    --sidebar-width: 268px;
    --topbar-height: 68px;
    --font: "Segoe UI", Tahoma, Arial, sans-serif;
    --mono: Consolas, "Courier New", monospace;
}

html[data-theme="light"] {
    color-scheme: light;
    --bg: #f1f6fc;
    --bg-soft: #e9f1fa;
    --surface: #ffffff;
    --surface-2: #f4f8fd;
    --surface-3: #e8f0fa;
    --border: #d6e1ee;
    --border-soft: #e4ecf6;
    --text: #0f1b2e;
    --muted: #556883;
    --muted-2: #7b8aa1;
    --accent: #0284c7;
    --accent-strong: #0369a1;
    --accent-soft: rgba(2, 132, 199, .1);
    --ok: #047857;
    --ok-soft: rgba(4, 120, 87, .09);
    --warn: #b45309;
    --warn-soft: rgba(180, 83, 9, .1);
    --danger: #dc2626;
    --danger-soft: rgba(220, 38, 38, .08);
    --purple: #6d28d9;
    --purple-soft: rgba(109, 40, 217, .09);
    --shadow: 0 20px 44px -30px rgba(15, 27, 46, .45);
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font);
    background:
        radial-gradient(circle at 85% -10%, var(--accent-soft) 0%, transparent 42%),
        radial-gradient(circle at 15% 110%, var(--purple-soft) 0%, transparent 38%),
        var(--bg);
    background-attachment: fixed;
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; }
p { margin: 0; }
img, svg { display: block; }
::selection { background: var(--accent-soft); }

.icon { width: 18px; height: 18px; flex: 0 0 auto; }
.icon-sm { width: 15px; height: 15px; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }
.mono { font-family: var(--mono); direction: ltr; unicode-bidi: embed; }
.inline-form { display: inline; }
.divider { height: 1px; background: var(--border-soft); border: 0; margin: 16px 0; }

/* ---------- App shell ---------- */
.app-shell { min-height: 100vh; display: flex; }

.sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: var(--sidebar-width);
    padding: 18px 14px;
    background: var(--surface);
    border-inline-end: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    z-index: 50;
    transition: transform .22s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px 18px;
    text-decoration: none;
    color: var(--text);
}
.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 13px;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    display: grid;
    place-items: center;
    color: #04121f;
    font-weight: 800;
    font-size: 15px;
    letter-spacing: .3px;
    box-shadow: 0 8px 20px -10px var(--accent);
}
.brand-text strong { display: block; font-size: 15px; letter-spacing: .4px; }
.brand-text span { display: block; font-size: 11px; color: var(--muted-2); }

.nav-group { margin-top: 8px; }
.nav-label {
    font-size: 10px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted-2);
    padding: 8px 10px 4px;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 10px;
    color: var(--muted);
    text-decoration: none;
    font-size: 13.5px;
    border: 1px solid transparent;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: rgba(56, 189, 248, .18);
    font-weight: 600;
}
.nav-link .icon { opacity: .9; }
.sidebar-footer {
    margin-top: auto;
    padding: 14px 10px 4px;
    border-top: 1px solid var(--border-soft);
    color: var(--muted-2);
    font-size: 11px;
    line-height: 1.7;
}

.main-shell {
    margin-inline-start: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    min-height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 24px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 700; font-size: 16px; }
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }

.menu-toggle, .icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease;
}
.menu-toggle:hover, .icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.menu-toggle { display: none; }

.theme-icon-light { display: none; }
html[data-theme="dark"] .theme-icon-light { display: grid; }
html[data-theme="dark"] .theme-icon-dark { display: none; }

.locale-form { display: flex; align-items: center; gap: 6px; }
.locale-form .icon { color: var(--muted); }
.select-control, .lang-select {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 10px;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
}
.select-control:focus, .lang-select:focus { outline: 1px solid var(--accent); }

.user-menu { position: relative; }
.user-menu summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 12px;
    cursor: pointer;
    border: 1px solid transparent;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu[open] summary { background: var(--surface-2); border-color: var(--border); }
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--accent-soft), var(--purple-soft));
    color: var(--accent);
    font-weight: 700;
    font-size: 13px;
}
.user-name { font-size: 13px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-panel {
    position: absolute;
    inset-inline-end: 0;
    top: calc(100% + 8px);
    width: 250px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 8px;
    z-index: 60;
}
.user-menu-head { padding: 10px; border-bottom: 1px solid var(--border-soft); margin-bottom: 6px; }
.user-menu-head strong { display: block; font-size: 13px; }
.user-menu-head span { display: block; font-size: 11.5px; color: var(--muted); direction: ltr; text-align: start; }
.user-menu-panel a, .user-menu-panel button {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 9px;
    padding: 9px 10px;
    border-radius: 8px;
    color: var(--muted);
    text-decoration: none;
    background: none;
    border: 0;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    text-align: start;
}
.user-menu-panel a:hover, .user-menu-panel button:hover { background: var(--surface-2); color: var(--text); }
.user-menu-panel .danger-link { color: var(--danger); }

.content {
    flex: 1;
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    padding: 28px 24px 40px;
}
.site-footer {
    border-top: 1px solid var(--border);
    color: var(--muted-2);
    font-size: 11.5px;
    text-align: center;
    padding: 14px;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(3, 8, 16, .55);
    backdrop-filter: blur(2px);
    z-index: 40;
}

/* ---------- Guest shell ---------- */
.guest-shell { min-height: 100vh; display: flex; flex-direction: column; }
.guest-topbar {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 18px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.guest-topbar .brand { padding: 0; }
.guest-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }
.guest-main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 12px 24px 48px; }

/* ---------- Page primitives ---------- */
.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}
.page-head h1 { font-size: clamp(22px, 2.6vw, 28px); }
.page-head p { margin-top: 6px; color: var(--muted); max-width: 720px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.stack { display: grid; gap: 20px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-main-aside { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, 1fr); gap: 20px; align-items: start; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-header h2 { font-size: 15.5px; }
.card-header .hint { color: var(--muted); font-size: 12px; }
.card-link { color: var(--accent); text-decoration: none; font-size: 12.5px; }
.card-link:hover { text-decoration: underline; }

.stat-card { display: flex; align-items: center; gap: 14px; }
.stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent);
    flex: 0 0 auto;
}
.stat-icon.ok { background: var(--ok-soft); color: var(--ok); }
.stat-icon.warn { background: var(--warn-soft); color: var(--warn); }
.stat-icon.purple { background: var(--purple-soft); color: var(--purple); }
.stat-label { font-size: 11.5px; color: var(--muted); }
.stat-value { font-size: 21px; font-weight: 700; line-height: 1.25; }
.stat-foot { font-size: 11.5px; color: var(--muted-2); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: var(--accent);
    color: #04121f;
    font-weight: 700;
    font-size: 13.5px;
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s ease, border-color .15s ease, color .15s ease, transform .1s ease;
}
.btn:hover { background: var(--accent-strong); color: #02121f; }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); font-weight: 600; }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn.subtle { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- Forms ---------- */
.form-grid { display: grid; gap: 16px; }
.form-grid.two { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.field .control,
.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-family: inherit;
    font-size: 13.5px;
    transition: border-color .15s ease, outline .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus, .field .control:focus {
    outline: 1px solid var(--accent);
    border-color: var(--accent);
}
.field input[readonly] { opacity: .75; cursor: default; }
.field .hint { margin-top: 6px; font-size: 11.5px; color: var(--muted-2); }
.field .error { margin-top: 6px; font-size: 11.5px; color: var(--danger); }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 4px; }
.check-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-wrap th, .table-wrap td { padding: 12px 14px; text-align: start; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table-wrap th {
    font-size: 10.5px;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--muted-2);
    background: var(--surface-2);
    font-weight: 600;
    white-space: nowrap;
}
.table-wrap tbody tr:last-child td { border-bottom: 0; }
.table-wrap tbody tr:hover { background: var(--surface-2); }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Badges / alerts / chips ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
}
.badge-ok { color: var(--ok); border-color: rgba(52, 211, 153, .35); background: var(--ok-soft); }
.badge-bad { color: var(--danger); border-color: rgba(248, 113, 113, .35); background: var(--danger-soft); }
.badge-warn { color: var(--warn); border-color: rgba(251, 191, 36, .35); background: var(--warn-soft); }
.badge-accent { color: var(--accent); border-color: rgba(56, 189, 248, .35); background: var(--accent-soft); }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 11.5px;
    color: var(--muted);
}

.alert {
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 13px;
    margin-bottom: 16px;
}
.alert ul { margin: 6px 0 0; padding-inline-start: 18px; }
.alert-success { border-color: rgba(52, 211, 153, .35); background: var(--ok-soft); color: var(--ok); }
.alert-error { border-color: rgba(248, 113, 113, .35); background: var(--danger-soft); color: var(--danger); }
.alert-info { border-color: rgba(56, 189, 248, .3); background: var(--accent-soft); color: var(--accent); }
.alert strong { font-weight: 700; }

/* ---------- Hero / landing ---------- */
.hero { max-width: 780px; padding: 44px 0 12px; }
.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 700;
}
.hero h1 { font-size: clamp(30px, 4.4vw, 46px); line-height: 1.14; margin: 14px 0 18px; }
.hero .lead { font-size: 15.5px; color: var(--muted); line-height: 1.95; max-width: 680px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 26px; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 26px; }

.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(245px, 1fr)); gap: 16px; margin-top: 46px; }
.feature-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.feature-icon {
    width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
    background: var(--accent-soft); color: var(--accent); margin-bottom: 14px;
}
.feature-card h3 { font-size: 15px; margin-bottom: 8px; }
.feature-card p { font-size: 12.5px; color: var(--muted); line-height: 1.8; }

.status-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 18px;
    margin-top: 34px;
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

/* ---------- Module cards ---------- */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.module-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    transition: border-color .15s ease, transform .15s ease;
}
.module-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.module-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.module-icon {
    width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
    background: var(--purple-soft); color: var(--purple);
}
.module-card h3 { font-size: 14px; }
.module-card p { font-size: 12px; color: var(--muted); line-height: 1.7; }
.badge-phase { font-size: 10px; padding: 2px 8px; }
.module-detail-icon {
    width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center;
    background: var(--accent-soft); color: var(--accent); margin-bottom: 18px;
}

/* ---------- Auth ---------- */
.auth-wrap { max-width: 440px; margin: 34px auto 50px; }
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 28px;
    box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.auth-card h1 { font-size: 23px; margin-bottom: 8px; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.auth-note { margin-top: 18px; font-size: 11.5px; color: var(--muted-2); line-height: 1.8; }
.auth-security {
    display: flex; align-items: center; gap: 8px; margin-top: 18px;
    padding-top: 16px; border-top: 1px solid var(--border-soft);
    font-size: 11px; color: var(--muted-2);
}

/* ---------- Tokens / code ---------- */
.token-box {
    direction: ltr;
    text-align: start;
    word-break: break-all;
    background: var(--bg-soft);
    border: 1px dashed var(--accent);
    border-radius: 10px;
    padding: 12px;
    font-family: var(--mono);
    font-size: 12.5px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.token-value { word-break: break-all; }
code {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px 6px;
    font-family: var(--mono);
    font-size: 12px;
    direction: ltr;
    display: inline-block;
}

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty-state .icon { width: 34px; height: 34px; margin: 0 auto 10px; color: var(--muted-2); }
.empty-state p { font-size: 13px; }

/* ---------- Error pages ---------- */
.error-page { max-width: 620px; margin: 46px auto; }
.error-code {
    font-size: 64px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -.02em;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 14px;
}
.error-page h1 { font-size: 24px; margin-bottom: 10px; }
.error-page .lead { color: var(--muted); font-size: 14px; }
.error-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.debug-box {
    margin-top: 20px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    font-family: var(--mono);
    font-size: 12px;
    direction: ltr;
    text-align: start;
    overflow: auto;
    white-space: pre-wrap;
}

/* ---------- Misc ---------- */
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Tasks & projects ---------- */
.comment {
    background: var(--surface-2);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 13px;
}
.comment p { margin: 0; }
.color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    vertical-align: middle;
    margin-inline-end: 6px;
}
.card .meta-line { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.card .meta-line strong { color: var(--text); font-weight: 600; }
.card .meta-line:last-child { margin-bottom: 0; }

/* ---------- Calendar ---------- */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
}
.calendar-weekday {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--muted);
    text-align: center;
    padding: 6px 0;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.calendar-cell {
    min-height: 92px;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    background: var(--surface-2);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.calendar-cell.is-empty { background: transparent; border-color: transparent; }
.calendar-cell.is-today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent-soft); }
.calendar-day { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.calendar-cell.is-today .calendar-day { color: var(--accent); }
.event-chip {
    display: flex;
    gap: 5px;
    align-items: baseline;
    border-inline-start: 3px solid var(--chip-color, var(--accent));
    background: var(--surface);
    border-radius: 6px;
    padding: 3px 6px;
    font-size: 11.5px;
    line-height: 1.4;
    color: var(--text);
    text-decoration: none;
    overflow: hidden;
}
.event-chip:hover { background: var(--surface-3, var(--surface-2)); }
.event-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-chip.is-cancelled { text-decoration: line-through; opacity: .65; }
.event-time { color: var(--muted); font-size: 10.5px; }
.checkbox-line { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.checkbox-line input { width: 16px; height: 16px; }

@media (max-width: 640px) {
    .calendar-grid { gap: 3px; }
    .calendar-cell { min-height: 68px; padding: 4px; }
    .event-chip { font-size: 10px; padding: 2px 4px; }
    .event-time { display: none; }
}

/* ---------- Finance ---------- */
.progress {
    height: 6px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border-soft);
    overflow: hidden;
    margin: 6px 0;
}
.progress > span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--accent);
    transition: width .2s ease;
}
.progress > span.is-over { background: var(--danger); }
.progress > span.is-done { background: var(--ok); }
.amount-pos { color: var(--ok); }
.amount-neg { color: var(--danger); }
.stat-value small { font-size: 11px; color: var(--muted); font-weight: 500; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary.btn { display: inline-flex; align-items: center; gap: 6px; }
.list-plain { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-soft);
}
.list-item:last-child { border-bottom: 0; }
.list-item .icon { color: var(--muted); }
.list-main { min-width: 0; }
.list-main strong { display: block; font-size: 12.5px; font-weight: 600; }
.list-main span { display: block; font-size: 11.5px; color: var(--muted-2); }
.section-title { font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.meta-line { font-size: 11.5px; color: var(--muted-2); }
.progress-note {
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px dashed var(--border);
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.8;
}

/* ---------- Goals & Habits ---------- */
.habit-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px 18px;
    padding: 16px 0;
    border-bottom: 1px solid var(--border-soft);
}
.habit-row:last-child { border-bottom: 0; }
.habit-row.is-inactive { opacity: .62; }
.habit-main { min-width: 0; display: grid; gap: 8px; }
.habit-title-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.habit-title-line strong { font-size: 13.5px; }
.habit-actions { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.habit-days { display: flex; gap: 4px; flex-wrap: wrap; }
.habit-day {
    width: 16px;
    height: 16px;
    border-radius: 5px;
    border: 1px solid var(--border-soft);
    background: var(--surface-2);
}
.habit-day.is-done { background: var(--ok); border-color: var(--ok); }
.habit-day.is-skipped { background: var(--warn); border-color: var(--warn); }
.habit-day.is-missed { background: var(--danger); border-color: var(--danger); }
.habit-edit { grid-column: 1 / -1; }
.habit-edit form { border-top: 1px dashed var(--border-soft); padding-top: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    html[dir="rtl"] .sidebar { transform: translateX(100%); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-backdrop { display: block; }
    .main-shell { margin-inline-start: 0; }
    .menu-toggle { display: grid; }
    .grid-main-aside { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
    .content { padding: 20px 14px 34px; }
    .topbar { padding: 9px 14px; }
    .topbar-title { font-size: 14px; }
    .user-name { display: none; }
    .hero { padding-top: 26px; }
    .hero h1 { font-size: 30px; }
    .card { padding: 16px; }
    .guest-topbar { padding: 14px; }
    .guest-main { padding: 8px 14px 36px; }
    .locale-form .icon { display: none; }
    .lang-select { max-width: 110px; }
    .auth-card { padding: 22px 18px; }
    .table-wrap th, .table-wrap td { padding: 10px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

/* PWA: مناطق آمنة على الجوال + وضع التطبيق المستقل */
@supports (padding: env(safe-area-inset-bottom)) {
    .content { padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
    .sidebar { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
}

@media (display-mode: standalone) {
    .site-footer { display: none; }
    .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
    .guest-topbar { padding-top: max(10px, env(safe-area-inset-top)); }
}

