:root {
    --bg: #f6f7fb;
    --bg-alt: #ffffff;
    --card: #ffffff;
    --text: #171923;
    --text-soft: #6b7080;
    --text-faint: #9aa0b1;
    --border: #e5e7f0;
    --border-strong: #d7dae6;
    --primary: #3f51e0;
    --primary-dark: #3241bd;
    --primary-soft: #eceeff;
    --accent: #0f9d80;
    --accent-soft: #e3f7f2;
    --danger: #d64545;
    --danger-soft: #fbeaea;
    --success: #1a9e63;
    --success-soft: #e7f7ef;
    --shadow: 0 8px 24px rgba(23, 25, 35, 0.06);
    --shadow-sm: 0 2px 8px rgba(23, 25, 35, 0.05);
    --radius: 14px;
    --radius-sm: 9px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] {
    --bg: #101117;
    --bg-alt: #171923;
    --card: #191b25;
    --text: #edeef3;
    --text-soft: #9195a8;
    --text-faint: #676c81;
    --border: #262838;
    --border-strong: #33364a;
    --primary: #7c8bf5;
    --primary-dark: #97a3f7;
    --primary-soft: #232544;
    --accent: #35c9a8;
    --accent-soft: #17332c;
    --danger: #ea6b6b;
    --danger-soft: #34201f;
    --success: #3fd991;
    --success-soft: #15301f;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    transition: background 0.2s ease, color 0.2s ease;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; letter-spacing: -0.01em; font-weight: 600; }

.icon { display: block; flex-shrink: 0; }

/* ---------- Auth (Login/Setup) ---------- */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 24px;
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px 32px;
    box-shadow: var(--shadow);
}
.auth-logo {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 18px;
}
.auth-card h1 { font-size: 20px; margin-bottom: 6px; }
.auth-sub { color: var(--text-soft); font-size: 13.5px; margin: 0 0 26px; }
.auth-form .form-row { margin-bottom: 16px; }
.auth-divider { border: none; border-top: 1px solid var(--border); margin: 22px 0; }
.auth-footnote { text-align: center; font-size: 12px; color: var(--text-faint); margin: 14px 0 0; }

/* ---------- Form elements ---------- */
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-row label { font-size: 12.5px; font-weight: 600; color: var(--text-soft); }
.form-row .hint { font-weight: 400; color: var(--text-faint); font-size: 12px; }

input[type="text"], input[type="password"], input[type="date"], input[type="number"],
select, textarea {
    width: 100%;
    padding: 10px 13px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--bg-alt);
    color: var(--text);
    font-size: 13.5px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { resize: vertical; line-height: 1.55; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
    font-family: inherit;
    white-space: nowrap;
}
.btn:active { opacity: 0.85; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.btn-secondary:hover { filter: brightness(0.97); }
.btn-ghost { background: var(--card); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--bg); border-color: var(--text-faint); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }

.icon-btn {
    width: 34px; height: 34px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
    background: var(--card); cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: var(--text-soft); transition: background 0.12s ease, color 0.12s ease;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* ---------- Alerts / Toast ---------- */
.alert {
    display: flex; align-items: flex-start; gap: 9px;
    padding: 10px 13px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 18px;
}
.alert .icon { margin-top: 1px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: var(--text);
    color: var(--bg);
    padding: 11px 18px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 9px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 200;
    box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- App shell ---------- */
.app-shell { max-width: 1080px; margin: 0 auto; padding: 24px 20px 80px; }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 20px;
    box-shadow: var(--shadow-sm); margin-bottom: 20px; flex-wrap: wrap; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
    width: 38px; height: 38px; border-radius: 10px; background: var(--primary-soft); color: var(--primary);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand h1 { font-size: 16px; }
.brand-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--text-soft); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions .btn span { display: inline; }

/* ---------- Stats ---------- */
.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px; margin-bottom: 20px;
}
.stat-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px;
    box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 5px; position: relative;
}
.stat-icon {
    position: absolute; top: 16px; right: 16px; color: var(--text-faint);
}
.stat-label { font-size: 11.5px; color: var(--text-soft); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; padding-right: 20px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text); }

/* ---------- Toolbar ---------- */
.toolbar {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px;
    margin-bottom: 18px;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select { width: auto; min-width: 150px; padding: 8px 12px; font-size: 13px; }
.toolbar-actions { display: flex; gap: 8px; }

/* ---------- Entries ---------- */
.week-group { margin-bottom: 22px; }
.week-heading {
    display: flex; align-items: baseline; justify-content: space-between;
    margin-bottom: 8px; padding: 0 2px;
}
.week-heading h3 { font-size: 12.5px; color: var(--text-soft); font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.week-heading span { font-size: 12.5px; color: var(--text-faint); }

.entry-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px;
    margin-bottom: 10px;
    display: flex; align-items: flex-start; gap: 16px;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.entry-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.entry-date-col { min-width: 64px; text-align: center; padding-top: 2px; }
.entry-date-day { font-size: 18px; font-weight: 700; }
.entry-date-sub { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.03em; }
.entry-main { flex: 1; min-width: 0; }
.entry-tags { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; flex-wrap: wrap; }
.tag {
    font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
    padding: 3px 9px; border-radius: 6px; background: var(--primary-soft); color: var(--primary);
}
.tag.hours { background: var(--accent-soft); color: var(--accent); }
.entry-activities { margin: 0; padding-left: 18px; color: var(--text); font-size: 13.5px; line-height: 1.65; }
.entry-actions { display: flex; gap: 4px; flex-shrink: 0; }
.entry-actions button {
    background: transparent; border: none; cursor: pointer; color: var(--text-faint);
    width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
    transition: background 0.12s ease, color 0.12s ease;
}
.entry-actions button:hover { background: var(--bg); color: var(--text); }
.entry-actions button[data-delete]:hover { color: var(--danger); }

.empty-state {
    text-align: center; padding: 56px 20px; background: var(--card); border: 1px dashed var(--border-strong);
    border-radius: var(--radius); color: var(--text-soft);
}
.empty-state-icon {
    display: inline-flex; align-items: center; justify-content: center; color: var(--text-faint);
    width: 52px; height: 52px; border-radius: 14px; background: var(--bg); margin-bottom: 14px;
}
.empty-state p { margin: 0 0 18px; font-size: 13.5px; }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15, 16, 24, 0.45);
    display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; max-width: 460px;
    max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 15px; }
.modal-body { padding: 20px; }
.modal-body h3 { font-size: 13.5px; margin-bottom: 14px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.settings-msg { font-size: 12.5px; margin-top: 10px; min-height: 18px; }
.settings-msg.error { color: var(--danger); }
.settings-msg.success { color: var(--success); }

@media (max-width: 640px) {
    .entry-card { flex-direction: column; }
    .entry-date-col { display: flex; align-items: center; gap: 8px; text-align: left; }
    .topbar { flex-direction: column; align-items: flex-start; }
    .topbar-actions .btn span { display: none; }
}
