/* =================================================================
   Study Assistant — design system
   ================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

:root {
    --bg: #fafaf9;
    --bg-card: #ffffff;
    --bg-subtle: #f5f5f4;

    --border: #e7e5e4;
    --border-strong: #d6d3d1;

    --text: #1c1917;
    --text-muted: #6b7280;
    --text-subtle: #9ca3af;

    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-soft: #eef2ff;
    --primary-text: #4338ca;

    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --warning: #f59e0b;
    --warning-soft: #fffbeb;
    --success: #10b981;
    --success-soft: #ecfdf5;
    --info: #0ea5e9;
    --info-soft: #f0f9ff;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
    --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
    --sp-12: 48px; --sp-16: 64px;

    --r-sm: 6px;
    --r: 10px;
    --r-lg: 14px;
    --r-xl: 20px;
    --r-full: 9999px;

    --sh-xs: 0 1px 2px rgba(28, 25, 23, 0.04);
    --sh-sm: 0 1px 3px rgba(28, 25, 23, 0.05), 0 1px 2px rgba(28, 25, 23, 0.03);
    --sh-md: 0 4px 12px -2px rgba(28, 25, 23, 0.06), 0 2px 6px -1px rgba(28, 25, 23, 0.04);
    --sh-lg: 0 12px 24px -6px rgba(28, 25, 23, 0.08), 0 6px 12px -4px rgba(28, 25, 23, 0.04);
    --sh-focus: 0 0 0 3px rgba(99, 102, 241, 0.15);

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --dur-fast: 120ms;
    --dur: 200ms;
}

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    animation: pageFadeIn var(--dur) var(--ease);
}
@keyframes pageFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---------- Type ---------- */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1.25;
    margin: 0 0 var(--sp-2);
}
h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.03em; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; }
h5 { font-size: 14px; }
h6 { font-size: 13px; }

p { margin: 0 0 var(--sp-3); }
a { color: var(--primary-text); }
.text-muted { color: var(--text-muted) !important; }
.text-subtle { color: var(--text-subtle) !important; }
.fw-semibold { font-weight: 600 !important; }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.color-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    vertical-align: middle;
    flex-shrink: 0;
}

/* ---------- Page shell ---------- */
.container { max-width: 1200px; }
.page-wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--sp-8) var(--sp-5) var(--sp-16);
}

.title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--sp-4);
    flex-wrap: wrap;
    margin-bottom: var(--sp-6);
}
.title-row h1 { font-size: 26px; margin: 0; }
.title-row .subtitle { color: var(--text-muted); font-size: 13.5px; margin-top: 4px; }

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--sp-3);
}
.section-head h2 {
    font-size: 16px; font-weight: 600;
    margin: 0; letter-spacing: -0.01em;
}

/* ---------- Buttons ---------- */
.btn {
    font-family: var(--font);
    font-weight: 500;
    font-size: 13.5px;
    line-height: 1;
    padding: 9px 14px;
    border-radius: var(--r-sm);
    border: 1px solid transparent;
    transition: all var(--dur-fast) var(--ease);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    cursor: pointer;
}
.btn:focus-visible { outline: none; box-shadow: var(--sh-focus); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-lg { padding: 12px 20px; font-size: 15px; }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover); border-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px -2px rgba(99, 102, 241, 0.35);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }

.btn-outline-primary { background: transparent; border-color: var(--border-strong); color: var(--primary-text); }
.btn-outline-primary:hover:not(:disabled) { background: var(--primary-soft); border-color: var(--primary); }

.btn-outline-secondary { background: var(--bg-card); border-color: var(--border); color: var(--text); }
.btn-outline-secondary:hover:not(:disabled) { background: var(--bg-subtle); border-color: var(--border-strong); }

.btn-outline-danger { background: transparent; border-color: var(--border); color: var(--danger); }
.btn-outline-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

.btn-outline-success { background: transparent; border-color: var(--border); color: var(--success); }
.btn-outline-success:hover:not(:disabled) { background: var(--success-soft); border-color: var(--success); }

.btn-link { color: var(--primary-text); text-decoration: none; padding: 9px 12px; }
.btn-link:hover { text-decoration: underline; }

/* ---------- Forms ---------- */
.form-control, .form-select {
    font-family: var(--font);
    font-size: 13.5px;
    padding: 8px 12px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
    min-height: 38px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: var(--sh-focus);
    outline: none;
}
.form-control::placeholder { color: var(--text-subtle); }
.form-label { font-weight: 500; font-size: 13px; color: var(--text); margin-bottom: 6px; }
.form-text { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.form-check-input { width: 16px; height: 16px; border-color: var(--border-strong); cursor: pointer; }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
.form-check-input:focus { border-color: var(--primary); box-shadow: var(--sh-focus); }
.form-check-label { font-size: 13.5px; cursor: pointer; }

/* ---------- Cards ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--sh-xs);
    transition: all var(--dur) var(--ease);
}
.card-body { padding: var(--sp-5); }
.card-title { margin-bottom: var(--sp-2); }
.shadow-sm { box-shadow: var(--sh-sm) !important; }

.course-card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 140px;
    padding: 18px 18px 16px 22px;
    cursor: pointer;
}

.course-card:hover,
.course-card:has(.dropdown.show) {
    z-index: 10;
}
.course-card::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--course-color, var(--primary));
    border-radius: var(--r) 0 0 var(--r);
    transition: width var(--dur) var(--ease);
}
.course-card:hover::before { width: 5px; }
.course-card:hover {
    box-shadow: var(--sh-md);
    transform: translateY(-1px);
    border-color: var(--border-strong);
}
.course-card .name {
    font-weight: 600;
    font-size: 14.5px;
    line-height: 1.35;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.course-card .meta {
    color: var(--text-muted);
    font-size: 12.5px;
    line-height: 1.5;
    margin-bottom: 2px;
}
.course-card .badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: auto;
    padding-top: 12px;
}
.course-card .dropdown-menu {
    z-index: 1050;
}
/* ---------- Badges ---------- */
.badge {
    font-weight: 500;
    font-size: 11.5px;
    padding: 3px 8px;
    border-radius: var(--r-full);
    line-height: 1.5;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.badge.bg-light, .badge.bg-light.text-dark, .badge.bg-light.text-dark.border {
    background: var(--bg-subtle) !important;
    border: 1px solid var(--border) !important;
    color: var(--text-muted) !important;
    font-weight: 500;
}
.badge.bg-primary-subtle {
    background: var(--primary-soft) !important;
    color: var(--primary-text) !important;
    border-color: #c7d2fe !important;
}

/* ---------- Chips ---------- */
.chip-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--r-full);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    font-size: 12.5px;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--dur-fast) var(--ease);
    cursor: pointer;
    white-space: nowrap;
}
.chip-btn:hover { border-color: var(--border-strong); color: var(--text); text-decoration: none; }
.chip-btn.active { background: var(--text); color: #fff; border-color: var(--text); }
.chip-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.chip-danger:hover { color: #fff; filter: brightness(1.05); }
.chip-warning { background: var(--warning); color: #1c1917; border-color: var(--warning); }
.chip-info { background: var(--info); color: #fff; border-color: var(--info); }
.chip-info:hover { color: #fff; }
.chip-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip-primary:hover { color: #fff; }

/* ---------- Work items ---------- */
.work-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 14px 16px 14px 18px;
    margin-bottom: 8px;
    cursor: pointer;
    position: relative;
    transition: all var(--dur) var(--ease);
    box-shadow: var(--sh-xs);
    display: flex;
    align-items: flex-start;
    gap: 12px;
}
.work-item::before {
    content: '';
    position: absolute;
    left: -1px; top: -1px; bottom: -1px;
    width: 3px;
    border-radius: var(--r) 0 0 var(--r);
    background: var(--bucket-color, var(--border));
    transition: width var(--dur) var(--ease);
}
.work-item:hover {
    box-shadow: var(--sh-md);
    border-color: var(--border-strong);
    transform: translateY(-1px);
}
.work-item:hover::before { width: 4px; }
.work-item .body { flex-grow: 1; min-width: 0; }
.work-item .item-title {
    font-weight: 600;
    font-size: 13.5px;
    margin-bottom: 2px;
}
.work-item .item-meta {
    color: var(--text-muted);
    font-size: 12.5px;
    line-height: 1.4;
}
.work-item .badges {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

/* ---------- Alerts ---------- */
.alert {
    padding: 12px 16px;
    border-radius: var(--r);
    border: 1px solid;
    font-size: 13.5px;
    box-shadow: var(--sh-xs);
}
.alert-success { background: var(--success-soft); border-color: #a7f3d0; color: #065f46; }
.alert-danger  { background: var(--danger-soft);  border-color: #fecaca; color: #991b1b; }
.alert-warning { background: var(--warning-soft); border-color: #fde68a; color: #92400e; }
.alert-info    { background: var(--info-soft);    border-color: #bae6fd; color: #075985; }

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: var(--sp-12) var(--sp-5);
    color: var(--text-muted);
}
.empty-state-icon {
    font-size: 40px;
    margin-bottom: var(--sp-3);
    display: inline-block;
    opacity: 0.7;
}
.empty-state h3 { color: var(--text); margin-bottom: var(--sp-2); font-size: 17px; }
.empty-state p {
    max-width: 340px;
    margin: 0 auto var(--sp-4);
    font-size: 13.5px;
}

/* ---------- Nav ---------- */
.app-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(250, 250, 249, 0.8);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.app-nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--sp-5);
    height: 56px;
    display: flex;
    align-items: center;
    gap: var(--sp-6);
}

.app-brand {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.02em;
    color: var(--text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.app-brand:hover { color: var(--text); }
.app-brand-dot {
    width: 20px; height: 20px;
    border-radius: 6px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    box-shadow: 0 2px 8px -2px rgba(99, 102, 241, 0.5);
}

.app-nav-links { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; }
.app-nav-link {
    padding: 8px 12px;
    border-radius: var(--r-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 13.5px;
    transition: all var(--dur-fast) var(--ease);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.app-nav-link:hover { color: var(--text); background: var(--bg-subtle); text-decoration: none; }
.app-nav-link.active { color: var(--primary-text); background: var(--primary-soft); }

.app-nav-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.app-nav-btn {
    padding: 7px 11px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    font-size: 12.5px;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--dur-fast) var(--ease);
    display: flex;
    align-items: center;
    gap: 5px;
}
.app-nav-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-subtle); }

.app-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: all var(--dur-fast) var(--ease);
    padding: 0;
    background: none;
    display: flex;
    align-items: center;
    justify-content: center;
}
.app-avatar:hover { border-color: var(--border-strong); transform: scale(1.05); }
.app-avatar img { width: 100%; height: 100%; object-fit: cover; }
.app-avatar-initial {
    width: 100%; height: 100%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
}

.app-dropdown {
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--sh-lg);
    padding: 6px;
    min-width: 200px;
    background: var(--bg-card);
    margin-top: 8px !important;
}
.app-dropdown .dropdown-item {
    padding: 8px 10px;
    border-radius: var(--r-sm);
    font-size: 13.5px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background var(--dur-fast) var(--ease);
}
.app-dropdown .dropdown-item:hover { background: var(--bg-subtle); }
.app-dropdown .dropdown-header {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-subtle);
    padding: 8px 10px 4px;
    font-weight: 600;
}

@media (max-width: 768px) {
    .app-nav-inner { padding: 0 var(--sp-3); gap: var(--sp-3); }
    .app-nav-link span:last-child { display: none; }
    .app-nav-btn span:last-child { display: none; }
}

/* ---------- Toasts ---------- */
.toast-stack {
    position: fixed;
    bottom: var(--sp-5);
    right: var(--sp-5);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast-item {
    background: var(--text);
    color: #fff;
    padding: 12px 16px;
    border-radius: var(--r);
    box-shadow: var(--sh-lg);
    font-size: 13.5px;
    font-weight: 500;
    min-width: 240px;
    max-width: 400px;
    pointer-events: auto;
    animation: toastIn 280ms var(--ease-out);
}
.toast-item.success { background: #065f46; }
.toast-item.error   { background: #991b1b; }
.toast-item.info    { background: #1e40af; }
.toast-item.removing { animation: toastOut 220ms var(--ease) forwards; }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}
@keyframes toastOut {
    to { opacity: 0; transform: translateY(6px); }
}

/* ---------- Modals ---------- */
.modal-content {
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-lg);
    overflow: hidden;
}
.modal-header { padding: var(--sp-5) var(--sp-5) var(--sp-3); border-bottom: none; }
.modal-title { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.modal-body { padding: var(--sp-5); }
.modal-footer { padding: var(--sp-3) var(--sp-5) var(--sp-5); border-top: none; gap: 8px; }
.btn-close { opacity: 0.5; transition: opacity var(--dur-fast) var(--ease); }
.btn-close:hover { opacity: 1; }
.modal-backdrop.show { opacity: 0.4; }

/* ---------- Progress ---------- */
.progress { height: 6px; background: var(--bg-subtle); border-radius: var(--r-full); overflow: hidden; }
.progress-bar { background: linear-gradient(90deg, var(--primary), #8b5cf6); transition: width 400ms var(--ease-out); }

/* ---------- Login ---------- */
.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-5);
    background:
        radial-gradient(ellipse at top, rgba(99, 102, 241, 0.08), transparent 55%),
        radial-gradient(ellipse at bottom right, rgba(139, 92, 246, 0.06), transparent 55%),
        var(--bg);
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: var(--sp-12) var(--sp-8);
    max-width: 420px;
    width: 100%;
    text-align: center;
    box-shadow: var(--sh-lg);
}
.login-logo { display: flex; justify-content: center; margin-bottom: var(--sp-6); }
.login-title {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: var(--sp-3);
}
.login-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: var(--sp-8);
}
.login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 20px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--bg-card);
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    transition: all var(--dur) var(--ease);
    width: 100%;
}
.login-btn:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
    box-shadow: var(--sh-md);
    color: var(--text);
}
.login-foot {
    color: var(--text-subtle);
    font-size: 12px;
    margin: var(--sp-6) 0 0;
}

/* ---------- Daily briefing ---------- */
.briefing-card {
    background: linear-gradient(135deg, #ffffff 0%, #fafaff 100%);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-5) var(--sp-6);
    position: relative;
    overflow: hidden;
    box-shadow: var(--sh-sm);
}
.briefing-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 3px; height: 100%;
    background: linear-gradient(180deg, #6366f1, #8b5cf6);
}
.briefing-label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--primary-text);
    margin-bottom: 8px;
}
.briefing-text {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    margin: 0;
    font-weight: 500;
}

/* ---------- Skeleton ---------- */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
.skeleton {
    background: linear-gradient(90deg, var(--bg-subtle) 25%, #ededed 50%, var(--bg-subtle) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--r-sm);
    display: block;
}

/* ---------- Spinner ---------- */
.spinner-border {
    border-width: 2px;
    width: 16px; height: 16px;
}
.spinner-border-sm { width: 14px; height: 14px; }

/* ---------- Misc utility ---------- */
.gap-1 { gap: 4px !important; }
.gap-2 { gap: 8px !important; }
.gap-3 { gap: 12px !important; }

/* ============================================================
   Loading + state components
   ============================================================ */

/* Button spinner — inline, tiny, doesn't shift layout */
.btn.is-loading {
    color: transparent !important;
    position: relative;
    pointer-events: none;
}
.btn.is-loading::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 14px; height: 14px;
    margin: -7px 0 0 -7px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 600ms linear infinite;
    color: #fff;
}
.btn-outline-secondary.is-loading::after,
.btn-outline-primary.is-loading::after,
.btn-outline-danger.is-loading::after,
.btn-link.is-loading::after {
    color: var(--text);
}
.btn-primary.is-loading::after,
.btn-danger.is-loading::after {
    color: #fff;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* State box (empty / error / loading) */
.state-box {
    text-align: center;
    padding: var(--sp-12) var(--sp-5);
    color: var(--text-muted);
}
.state-box.compact { padding: var(--sp-8) var(--sp-5); }
.state-icon {
    font-size: 38px;
    line-height: 1;
    margin-bottom: var(--sp-3);
    opacity: 0.75;
    display: inline-block;
}
.state-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}
.state-msg {
    font-size: 13.5px;
    max-width: 340px;
    margin: 0 auto var(--sp-4);
}
.state-box.error .state-icon { color: var(--danger); opacity: 1; }
.state-box.error .state-title { color: var(--danger); }

/* Smooth page transitions */
/* Smooth page transitions — pure CSS fade-in, no JS required */
body {
    animation: pageFadeIn 200ms var(--ease-out) both;
}
@keyframes pageFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Fade-out on link click — JS adds .page-leaving */
body.page-leaving {
    animation: none;
    opacity: 0;
    transition: opacity 140ms var(--ease-out);
}

/* Modal animation tuning */
.modal.fade .modal-dialog {
    transition: transform 220ms var(--ease-out), opacity 180ms var(--ease-out);
    transform: translateY(12px) scale(0.98);
}
.modal.show .modal-dialog {
    transform: none;
}

/* Skeleton inline on text — auto width */
.text-skeleton {
    display: inline-block;
    height: 1em;
    width: 100%;
    background: linear-gradient(90deg, var(--bg-subtle) 25%, #ededed 50%, var(--bg-subtle) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
    vertical-align: middle;
}

/* Press feedback on interactive items */
.work-item:active,
.course-card:active,
.chip-btn:active {
    transform: scale(0.995);
}

/* ============================================================
   Sync progress panel
   ============================================================ */

.sync-overlay {
    position: fixed;
    inset: 0;
    background: rgba(28, 25, 23, 0.06);
    backdrop-filter: blur(1px);
    -webkit-backdrop-filter: blur(1px);
    z-index: 9000;
    opacity: 0;
    transition: opacity 200ms var(--ease-out);
    pointer-events: none;
}
.sync-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.sync-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 360px;
    max-width: calc(100vw - 32px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-lg);
    padding: 18px 20px;
    z-index: 9001;
    transform: translateY(12px) scale(0.98);
    opacity: 0;
    transition: transform 240ms var(--ease-out), opacity 180ms var(--ease-out);
}
.sync-panel.show {
    transform: none;
    opacity: 1;
}

.sync-panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    gap: 8px;
}
.sync-panel-title {
    font-size: 13.5px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.sync-panel-icon {
    width: 16px; height: 16px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 700ms linear infinite;
    flex-shrink: 0;
}
.sync-panel.done .sync-panel-icon,
.sync-panel.failed .sync-panel-icon {
    animation: none;
    border: none;
    width: 18px; height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
}
.sync-panel.done .sync-panel-icon { background: var(--success); }
.sync-panel.done .sync-panel-icon::after { content: '✓'; }
.sync-panel.failed .sync-panel-icon { background: var(--danger); }
.sync-panel.failed .sync-panel-icon::after { content: '!'; }

.sync-panel-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 0 6px;
    line-height: 1;
    display: none;
    border-radius: var(--r-sm);
    transition: all var(--dur-fast) var(--ease);
}
.sync-panel-close:hover { background: var(--bg-subtle); color: var(--text); }
.sync-panel.done .sync-panel-close,
.sync-panel.failed .sync-panel-close { display: block; }

.sync-progress {
    height: 4px;
    background: var(--bg-subtle);
    border-radius: var(--r-full);
    overflow: hidden;
    margin-bottom: 12px;
}
.sync-progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--primary), #8b5cf6);
    border-radius: var(--r-full);
    transition: width 900ms var(--ease-out);
}
.sync-panel.done .sync-progress-bar { background: var(--success); }
.sync-panel.failed .sync-progress-bar { background: var(--danger); }

.sync-panel-phase {
    font-size: 12.5px;
    color: var(--text-muted);
    min-height: 18px;
    line-height: 1.45;
}

.sync-panel-time {
    font-size: 11.5px;
    color: var(--text-subtle);
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

/* ============================================================
   Plan page — tabs, panels
   ============================================================ */

.plan-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-subtle);
    border-radius: var(--r);
    margin-bottom: var(--sp-5);
    width: fit-content;
    max-width: 100%;
    overflow-x: auto;
}
.plan-tab {
    padding: 8px 16px;
    border-radius: var(--r-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: all var(--dur-fast) var(--ease);
    white-space: nowrap;
    background: transparent;
    border: none;
    cursor: pointer;
}
.plan-tab:hover { color: var(--text); }
.plan-tab.active {
    background: var(--bg-card);
    color: var(--text);
    font-weight: 600;
    box-shadow: var(--sh-xs);
}

/* Stat tiles */
.stat-tile {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 14px 16px;
    transition: all var(--dur) var(--ease);
}
.stat-tile:hover { box-shadow: var(--sh-sm); }
.stat-tile .label {
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-subtle);
    margin-bottom: 4px;
}
.stat-tile .value {
    font-size: 26px;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.03em;
    color: var(--text);
}
.stat-tile .value.warn  { color: var(--danger); }
.stat-tile .value.muted { color: var(--text-subtle); }

/* Next-up card */
.next-up-card {
    background: linear-gradient(135deg, #ffffff 0%, #fafaff 100%);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 18px 20px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--sh-xs);
}
.next-up-card::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, var(--primary), #8b5cf6);
    border-radius: var(--r) 0 0 var(--r);
}
.next-up-label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--primary-text);
    margin-bottom: 6px;
}
.next-up-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: -0.01em;
}
.next-up-time {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    background: var(--primary-soft);
    color: var(--primary-text);
    font-size: 11.5px;
    font-weight: 600;
    border-radius: var(--r-full);
    vertical-align: middle;
}

/* Fixed-block chip row */
.block-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border-radius: var(--r-full);
    background: var(--success-soft);
    border: 1px solid #a7f3d0;
    color: #065f46;
    font-size: 12.5px;
    font-weight: 500;
}
.block-chip .chip-time {
    font-variant-numeric: tabular-nums;
    opacity: 0.7;
}

/* Weekly day column */
.day-col {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 12px;
    height: 100%;
    min-height: 220px;
    transition: all var(--dur) var(--ease);
}
.day-col:hover { box-shadow: var(--sh-sm); }
.day-col.is-today {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.08);
}
.day-col h6 {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 11px;
    color: var(--text-muted);
    margin: 0 0 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.day-col h6 .date-num {
    font-weight: 500;
    color: var(--text-subtle);
    text-transform: none;
    letter-spacing: 0;
    font-size: 12px;
}
.day-event {
    padding: 5px 8px;
    border-radius: 5px;
    background: var(--bg-subtle);
    border-left: 3px solid var(--border-strong);
    margin-bottom: 4px;
    font-size: 12px;
    line-height: 1.35;
}
.day-event.class    { border-left-color: var(--primary); background: var(--primary-soft); }
.day-event.prayer   { border-left-color: var(--success); background: var(--success-soft); }
.day-event.exam     { border-left-color: var(--danger);  background: var(--danger-soft); }
.day-event.meeting  { border-left-color: var(--warning); background: var(--warning-soft); }
.day-event .ev-title {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}
.day-event .ev-time {
    color: var(--text-muted);
    font-size: 10.5px;
    font-variant-numeric: tabular-nums;
}
.day-deadline {
    display: inline-block;
    background: var(--danger);
    color: #fff;
    font-size: 10.5px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: var(--r-full);
    margin: 3px 3px 0 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}
.day-empty {
    color: var(--text-subtle);
    font-size: 11.5px;
    font-style: italic;
    padding: 4px 2px;
}

/* Regenerate button group */
.plan-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* Chip-style radio/checkbox — selected state */
.btn-check:checked + .chip-btn {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    font-weight: 600;
    box-shadow: 0 2px 6px -1px rgba(99, 102, 241, 0.35);
}
.btn-check:checked + .chip-btn:hover {
    background: var(--primary-hover);
    color: #fff;
}
.btn-check:focus-visible + .chip-btn {
    outline: none;
    box-shadow: var(--sh-focus);
}
/* Make sure the hidden radio doesn't take space */
.btn-check {
    position: absolute;
    clip: rect(0, 0, 0, 0);
    pointer-events: none;
}

/* ============================================================
   Modals — work detail, merge
   ============================================================ */
.work-modal-header {
    padding: 20px 24px 8px;
    border-bottom: none;
}
.work-modal-body {
    padding: 20px 24px;
}
.work-modal-footer {
    padding: 8px 24px 20px;
    border-top: none;
    gap: 8px;
}
.work-modal-title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.015em;
    margin: 4px 0 4px;
    word-break: break-word;
    color: var(--text);
}
.work-modal-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12.5px;
    color: var(--text-muted);
}
.work-modal-desc {
    white-space: pre-wrap;
    line-height: 1.6;
    font-size: 13.5px;
    color: var(--text);
}
.work-modal-section-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-subtle);
    margin: 20px 0 8px;
}
.work-modal-section-title.primary {
    color: var(--primary-text);
    letter-spacing: 0.08em;
}
.ai-summary-card {
    background: var(--bg-subtle);
    border-radius: var(--r);
    padding: 14px 16px;
    margin-bottom: 12px;
}
.ai-summary-card.primary-tint {
    background: var(--primary-soft);
}
.ai-summary-card ul {
    margin: 0;
    padding-left: 18px;
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text);
}
.ai-summary-card li { margin-bottom: 4px; }
.ai-summary-card li:last-child { margin-bottom: 0; }

.work-attachment {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-top: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
    transition: padding var(--dur-fast) var(--ease);
    font-size: 13.5px;
}
.work-attachment:first-child { border-top: none; }
.work-attachment:hover {
    color: var(--primary-text);
    padding-left: 4px;
}
.work-attachment .icon { font-size: 1rem; flex-shrink: 0; }
.work-attachment .name { flex-grow: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.work-attachment .arrow { color: var(--text-subtle); font-size: 12px; flex-shrink: 0; }

.related-card {
    border: 1px dashed var(--border-strong);
    background: var(--bg-subtle);
    border-radius: var(--r);
    padding: 12px 14px;
    margin-bottom: 8px;
}
.related-card .text {
    font-size: 12.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
    max-height: 60px;
    overflow: hidden;
    line-height: 1.5;
}

details.work-desc-collapse summary {
    cursor: pointer;
    user-select: none;
    list-style: none;
    font-size: 12.5px;
    color: var(--text-muted);
    padding: 6px 0;
    transition: color var(--dur-fast) var(--ease);
}
details.work-desc-collapse summary::-webkit-details-marker { display: none; }
details.work-desc-collapse summary::before {
    content: '▸ ';
    display: inline-block;
    transition: transform var(--dur-fast) var(--ease);
}
details.work-desc-collapse[open] summary::before {
    transform: rotate(90deg);
}
details.work-desc-collapse summary:hover { color: var(--text); }

/* Merge modal */
.merge-target-btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    margin-bottom: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border-strong);
    border-radius: var(--r-sm);
    transition: all var(--dur-fast) var(--ease);
    cursor: pointer;
}
.merge-target-btn:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    transform: translateX(2px);
}
.merge-target-btn .title {
    font-weight: 600;
    font-size: 13.5px;
    color: var(--text);
    margin-bottom: 2px;
}
.merge-target-btn .meta {
    font-size: 12px;
    color: var(--text-muted);
}

/* Timetable upload drop zone */
.drop-zone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--r-lg);
    padding: 48px 24px;
    text-align: center;
    background: var(--bg-card);
    transition: all var(--dur) var(--ease);
    cursor: pointer;
    position: relative;
}
.drop-zone:hover { border-color: var(--primary); background: var(--primary-soft); }
.drop-zone.dragging {
    border-color: var(--primary);
    background: var(--primary-soft);
    transform: scale(1.01);
}
.drop-zone .dz-icon {
    font-size: 40px;
    margin-bottom: 12px;
    display: block;
    opacity: 0.6;
}
.drop-zone .dz-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}
.drop-zone .dz-sub {
    font-size: 13px;
    color: var(--text-muted);
}
.drop-zone input[type=file] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.preview-thumb {
    max-width: 100%;
    border-radius: var(--r);
    border: 1px solid var(--border);
    box-shadow: var(--sh-sm);
}

/* Timetable review layout */
.review-shell {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
}
@media (max-width: 992px) {
    .review-shell { grid-template-columns: 1fr; }
}
.sticky-pane {
    position: sticky;
    top: 76px;
    max-height: calc(100vh - 100px);
    overflow: auto;
}
.review-table {
    width: 100%;
    background: var(--bg-card);
    border-radius: var(--r);
    border: 1px solid var(--border);
    overflow: hidden;
}
.review-table th {
    background: var(--bg-subtle);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
.review-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.review-table tr:last-child td { border-bottom: none; }
.review-table .day-sep td {
    background: var(--bg-subtle);
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 6px 12px;
}
.review-table input,
.review-table select {
    font-size: 12.5px;
    padding: 5px 8px;
    min-height: 30px;
}.upload-spinner {
    width: 42px;
    height: 42px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 700ms linear infinite;
    margin: 0 auto 4px;
}
/* ============================================================
   Mobile bottom navigation
   ============================================================ */

.app-bottom-nav { display: none; }

@media (max-width: 768px) {
    /* Hide desktop nav links and button labels */
    .app-nav-links { display: none; }
    .app-nav-btn-label { display: none; }

    /* Compact top bar */
    .app-nav-inner {
        padding: 0 12px;
        gap: 8px;
        height: 52px;
    }
    .app-brand { font-size: 14px; }
    .app-brand-dot { width: 18px; height: 18px; border-radius: 5px; }
    .app-nav-actions { gap: 4px; }
    .app-nav-btn {
        padding: 8px 10px;
        font-size: 14px;
    }

    /* Bottom nav bar */
    .app-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 62px;
        background: rgba(255, 255, 255, 0.94);
        backdrop-filter: saturate(180%) blur(14px);
        -webkit-backdrop-filter: saturate(180%) blur(14px);
        border-top: 1px solid var(--border);
        z-index: 900;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .app-bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        text-decoration: none;
        color: var(--text-muted);
        font-size: 10.5px;
        font-weight: 500;
        padding: 8px 4px;
        transition: color var(--dur-fast) var(--ease);
        -webkit-tap-highlight-color: transparent;
    }
    .app-bottom-nav-item .icon {
        font-size: 20px;
        line-height: 1;
        transition: transform var(--dur) var(--ease);
    }
    .app-bottom-nav-item .label {
        letter-spacing: 0.02em;
    }
    .app-bottom-nav-item.active {
        color: var(--primary);
    }
    .app-bottom-nav-item.active .icon {
        transform: scale(1.12);
    }

    /* Push content above the bottom nav */
    body {
        padding-bottom: 72px;
    }

    /* Raise the toast stack above the bottom nav */
    .toast-stack {
        bottom: 76px;
        right: 12px;
        left: 12px;
    }
    .toast-item {
        min-width: 0;
        max-width: 100%;
    }

    /* Page padding adjustments */
    .page-wrap {
        padding: 20px 16px 40px;
    }
    .title-row h1 { font-size: 22px; }
    .title-row { margin-bottom: 20px; }

    /* Modals full-width-ish */
    .modal-dialog {
        margin: 8px;
        max-width: calc(100vw - 16px);
    }
    .modal-dialog.modal-lg { max-width: calc(100vw - 16px); }
    .modal-body { padding: 16px 18px; }
    .modal-header { padding: 16px 18px 8px; }
    .modal-footer { padding: 8px 18px 16px; }

    /* Work items: bigger tap targets */
    .work-item {
        padding: 12px 12px 12px 14px;
    }
    .work-item .item-title { font-size: 13px; }

    /* Cards */
    .card-body { padding: 16px; }

    /* Stat tiles — tighter */
    .stat-tile { padding: 12px 14px; }
    .stat-tile .value { font-size: 22px; }

    /* Buttons — minimum tap size */
    .btn-sm {
        min-height: 34px;
        padding: 8px 12px;
    }
    .btn {
        min-height: 40px;
    }

    /* Section heads */
    .section-head { margin-bottom: 10px; }
}

/* ============================================================
   Preferences wizard — mobile
   ============================================================ */
@media (max-width: 480px) {
    .step-shell {
        padding: 0 12px;
        margin: 12px auto;
    }
    .step-card {
        padding: 20px 16px;
        border-radius: var(--r);
    }
    .step-question { font-size: 17px; }
    .step-hint { font-size: 12.5px; margin-bottom: 16px; }

    /* Day grid: stack day name on top, wake/sleep side by side */
    .day-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        background: var(--bg-subtle);
        padding: 10px 12px;
        border-radius: var(--r-sm);
        margin-bottom: 8px;
    }
    .day-grid .day-name {
        grid-column: 1 / -1;
        font-size: 12px;
        font-weight: 600;
        color: var(--text);
        margin-bottom: 2px;
    }
    .day-grid input[type="time"] {
        font-size: 12.5px;
        padding: 6px 8px;
        min-height: 34px;
    }

    /* Group boxes for weekday/weekend */
    .group-box { padding: 12px; }
    .group-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* Summary rows */
    .summary-row {
        font-size: 13px;
        padding: 8px 0;
    }

    /* Custom blocks (recurring commitments) — stack vertically */
    .custom-row .row > [class*="col-"] {
        margin-bottom: 6px;
    }
    .custom-row .col-md-1 {
        text-align: right;
    }
}