/* ==========================================================================
   STUDYVERSE - SHARED STYLES (Single Source of Truth)
   Used by ALL pages: index.html, todo/mylist.html, schedule/create.html, career/chat.html
   ========================================================================== */

/* --- CSS VARIABLES --- */
:root {
    --bg-color: #05070a;
    --card-bg: #0d1117;
    --card-hover-bg: #141b26;
    /* Accent: đổi theo theme qua [data-theme] ở dưới */
    --primary-blue: #007AFF;
    --primary-rgb: 0, 122, 255;
    --primary-blue-glow: rgba(var(--primary-rgb), 0.35);
    --accent-secondary: #5856D6;
    --text-white: #ffffff;
    --text-gray: rgba(255, 255, 255, 0.6);
    --text-muted: rgba(255, 255, 255, 0.45);
    --border-soft: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(255, 255, 255, 0.15);
    --white-glow: 0 10px 30px -5px rgba(0, 0, 0, 0.3), 0 0 20px rgba(255, 255, 255, 0.03);
    --navbar-bg: rgba(5, 7, 10, 0.88);
    --panel-bg: #121824;
    --user-bubble-bg: var(--primary-blue);
}

/* --- THEME PALETTES (đổi --primary-* + --accent-secondary) --- */
/* midnight = mặc định ở trên (xanh iOS) — khai báo lại để theme nào cũng set data-theme */
[data-theme="midnight"] {
    --primary-blue: #007AFF;
    --primary-rgb: 0, 122, 255;
    --primary-blue-glow: rgba(0, 122, 255, 0.35);
    --accent-secondary: #5856D6;
}

[data-theme="ocean"] {
    --primary-blue: #14b8a6;
    --primary-rgb: 20, 184, 166;
    --primary-blue-glow: rgba(20, 184, 166, 0.35);
    --accent-secondary: #0ea5e9;
}

[data-theme="cyan"] {
    --bg-color: #c8f3f8;
    --card-bg: #e8fcff;
    --card-hover-bg: #b5edf4;
    --primary-blue: #0891b2;
    --primary-rgb: 8, 145, 178;
    --primary-blue-glow: rgba(8, 145, 178, 0.24);
    --accent-secondary: #22d3ee;
    --text-white: #12343b;
    --text-gray: rgba(18, 52, 59, 0.72);
    --text-muted: rgba(18, 52, 59, 0.52);
    --border-soft: rgba(18, 52, 59, 0.12);
    --border-highlight: rgba(8, 145, 178, 0.30);
    --white-glow: 0 10px 30px -5px rgba(8, 84, 102, 0.13);
    --navbar-bg: rgba(232, 252, 255, 0.94);
    --panel-bg: #e8fcff;
    --user-bubble-bg: #06b6d4;
}

[data-theme="sunset"] {
    --primary-blue: #f97316;
    --primary-rgb: 249, 115, 22;
    --primary-blue-glow: rgba(249, 115, 22, 0.35);
    --accent-secondary: #ec4899;
}

[data-theme="royal"] {
    --primary-blue: #8b5cf6;
    --primary-rgb: 139, 92, 246;
    --primary-blue-glow: rgba(139, 92, 246, 0.35);
    --accent-secondary: #d946ef;
}

[data-theme="forest"] {
    --primary-blue: #22c55e;
    --primary-rgb: 34, 197, 94;
    --primary-blue-glow: rgba(34, 197, 94, 0.35);
    --accent-secondary: #14b8a6;
}

[data-theme="light"] {
    --bg-color: #f4f7fb;
    --card-bg: #ffffff;
    --card-hover-bg: #eef2f7;
    --primary-blue: #2563eb;
    --primary-rgb: 37, 99, 235;
    --primary-blue-glow: rgba(37, 99, 235, 0.24);
    --accent-secondary: #7c3aed;
    --text-white: #172033;
    --text-gray: rgba(23, 32, 51, 0.72);
    --text-muted: rgba(23, 32, 51, 0.52);
    --border-soft: rgba(23, 32, 51, 0.12);
    --border-highlight: rgba(23, 32, 51, 0.22);
    --white-glow: 0 10px 30px -5px rgba(31, 41, 55, 0.12);
    --navbar-bg: rgba(255, 255, 255, 0.9);
    --panel-bg: #ffffff;
}

[data-theme="pink"] {
    --bg-color: #ffd9e8;
    --card-bg: #ffffff;
    --card-hover-bg: #fff0f5;
    --primary-blue: #d86b93;
    --primary-rgb: 216, 107, 147;
    --primary-blue-glow: rgba(216, 107, 147, 0.24);
    --accent-secondary: #ff88b4;
    --text-white: #111827;
    --text-gray: rgba(17, 24, 39, 0.74);
    --text-muted: rgba(17, 24, 39, 0.54);
    --border-soft: rgba(17, 24, 39, 0.12);
    --border-highlight: rgba(216, 107, 147, 0.3);
    --white-glow: 0 10px 30px -5px rgba(157, 23, 77, 0.16);
    --navbar-bg: rgba(255, 255, 255, 0.92);
    --panel-bg: #ffffff;
    --user-bubble-bg: #d86b93;
}

/* --- GLOBAL RESET --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

/* Không để trang lộ palette mặc định trong lúc shared.js áp theme đã lưu.
   Class này được gỡ ngay sau khi theme được áp dụng. */
html.sv-theme-loading body {
    visibility: hidden;
}

body {
    background-color: var(--bg-color);
    color: var(--text-white);
    overflow-x: hidden;
}

/* --- NAVBAR HEADER --- */
.navbar {
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    height: 110px;
    background: var(--navbar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: flex-end;
    padding-bottom: 10px;
    z-index: 1000;
}

.nav-container {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 36px;
    font-weight: 800;
    text-decoration: none;
    color: var(--text-white);
    letter-spacing: -0.5px;
}

.logo span {
    color: var(--primary-blue);
}

/* --- NAVIGATION --- */
.navigation {
    position: relative;
    width: 350px;
    height: 65px;
    background: var(--card-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 14px;
    border: 1px solid var(--border-soft);
}

.navigation ul {
    display: flex;
    position: relative;
    padding: 0;
    margin: 0;
    list-style: none;
}

.navigation ul li {
    position: relative;
    list-style: none;
    width: 70px;
    height: 65px;
    z-index: 10;
}

.navigation ul li a {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 100%;
    text-align: center;
    font-weight: 500;
    color: #fff;
    text-decoration: none;
}

.navigation ul li a .icon {
    position: relative;
    display: block;
    line-height: 70px;
    font-size: 1.4em;
    text-align: center;
    transition: 0.5s;
    color: #fff;
    z-index: 1000;
}

[data-theme="light"] .navigation ul li a .icon,
[data-theme="pink"] .navigation ul li a .icon,
[data-theme="cyan"] .navigation ul li a .icon {
    color: var(--text-white);
}

.navigation ul li a .text {
    position: absolute;
    font-weight: 400;
    font-size: 0.75em;
    letter-spacing: 0.05em;
    transition: 0.5s;
    opacity: 0;
    transform: translateY(20px);
    z-index: 100;
    white-space: nowrap; /* label tiếng Việt dài không xuống dòng */
}

.navigation ul li.active a .icon,
.navigation ul li.hover-effect a .icon {
    color: #fff;
    transform: translateY(-32px);
}

.navigation ul li.active a .text,
.navigation ul li.hover-effect a .text {
    opacity: 1;
    transform: translateY(8px);
}

.icon i {
    position: relative !important;
    z-index: 999 !important;
}

/* --- INDICATOR --- */
.indicator {
    position: absolute;
    top: -45%;
    width: 65px;
    height: 65px;
    background: var(--primary-blue);
    border-radius: 50%;
    border: 5px solid var(--bg-color);
    transition: 0.5s;
    z-index: 1;
}

/* --- SETTINGS BUTTON (navbar, inject bởi shared.js) --- */
.nav-settings {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card-bg);
    border: 1px solid var(--border-soft);
    border-radius: 50%;
    color: var(--text-gray);
    font-size: 1.05rem;
    cursor: pointer;
    transition: all 0.25s ease;
    flex-shrink: 0;
}

.nav-settings:hover {
    color: var(--text-white);
    border-color: var(--border-highlight);
    box-shadow: 0 0 14px var(--primary-blue-glow);
}

.nav-settings i { transition: transform 0.4s ease; }
.nav-settings:hover i { transform: rotate(90deg); }
.nav-settings.open { color: var(--primary-blue); border-color: var(--primary-blue); }

@media (max-width: 768px) {
    .nav-settings { width: 38px; height: 38px; font-size: 0.95rem; }
}

/* --- SETTINGS PANEL --- */
.sv-settings-panel {
    position: fixed;
    top: 122px; /* navbar desktop cao 110px + 12px khoảng nghỉ */
    right: 20px;
    width: 292px;
    max-width: calc(100vw - 24px);
    /* Không bao giờ tràn khỏi màn hình thấp (điện thoại nằm ngang, laptop nhỏ) */
    max-height: calc(100vh - 134px);
    max-height: calc(100dvh - 134px);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--panel-bg);
    border: 1px solid var(--border-highlight);
    border-radius: 16px;
    padding: 18px;
    z-index: 1001;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6), 0 0 30px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
    transform-origin: top right;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.sv-settings-panel.open {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

/* Navbar thu nhỏ còn 90px ở khoảng 769-900px: panel phải bám theo */
@media (max-width: 900px) {
    .sv-settings-panel {
        top: 100px;
        max-height: calc(100vh - 112px);
        max-height: calc(100dvh - 112px);
    }
}

@media (max-width: 768px) {
    .sv-settings-panel {
        top: 74px; /* navbar mobile cao 64px + 10px khoảng nghỉ */
        right: 12px;
        max-height: calc(100vh - 86px);
        max-height: calc(100dvh - 86px);
    }
}

.sv-settings-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sv-settings-title i { color: var(--primary-blue); }

/* Bàn phím: nút bấm trong panel phải thấy rõ focus */
.nav-settings:focus-visible,
.sv-lang-btn:focus-visible,
.sv-theme-swatch:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-blue-glow);
}

.sv-settings-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin: 14px 0 8px;
}

.sv-lang-row { display: flex; gap: 6px; }

.sv-lang-btn {
    flex: 1;
    padding: 8px 0;
    border-radius: 10px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-soft);
    color: var(--text-gray);
    font-weight: 600;
    font-size: 0.82rem;
    font-family: inherit;
    transition: all 0.2s;
}

.sv-lang-btn:hover { color: #fff; }
.sv-lang-btn.active { background: var(--primary-blue); border-color: transparent; color: #fff; }

.sv-theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(42px, 1fr));
    gap: 8px;
}

.sv-theme-swatch {
    height: 40px;
    border-radius: 12px;
    cursor: pointer;
    position: relative;
    border: 2px solid transparent;
    transition: transform 0.15s, border-color 0.15s;
}

.sv-theme-swatch:hover { transform: translateY(-2px); }
.sv-theme-swatch.active { border-color: #fff; }
.sv-theme-swatch[aria-pressed="false"] { opacity: 0.85; }
.sv-theme-swatch[aria-pressed="false"]:hover { opacity: 1; }

.sv-theme-swatch.active::after {
    content: '\f00c';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.8rem;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* Bảng màu xem trước dùng màu CỐ ĐỊNH của từng theme — không dùng var(--primary-*)
   vì biến đó đổi theo theme đang chọn, khiến ô "Đêm" đổi màu theo theme khác. */
.sv-sw-midnight { background: linear-gradient(135deg, #007AFF, #5856D6); }
.sv-sw-ocean { background: linear-gradient(135deg, #14b8a6, #0ea5e9); }
.sv-sw-cyan { background: linear-gradient(135deg, #06b6d4, #67e8f9); }
.sv-sw-sunset { background: linear-gradient(135deg, #f97316, #ec4899); }
.sv-sw-royal { background: linear-gradient(135deg, #8b5cf6, #d946ef); }
.sv-sw-forest { background: linear-gradient(135deg, #22c55e, #14b8a6); }
.sv-sw-light { background: linear-gradient(135deg, #ffffff, #dbeafe); border-color: rgba(15, 23, 42, 0.18); }
.sv-sw-pink { background: linear-gradient(135deg, #ffd9e8 0%, #ff88b4 52%, #d86b93 100%); }

/* --- SV MODAL POPUP (thay alert/confirm/prompt mặc định, dùng chung 4 trang) --- */
.sv-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(3, 5, 9, 0.7);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    animation: svOverlayIn 0.2s ease-out;
}

@keyframes svOverlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.sv-modal {
    width: 100%;
    max-width: 400px;
    background: var(--panel-bg);
    border: 1px solid var(--border-highlight);
    border-radius: 20px;
    padding: 28px 26px 22px;
    text-align: center;
    color: var(--text-white);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.65), 0 0 40px rgba(var(--primary-rgb), 0.08);
    animation: svModalIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes svModalIn {
    from { opacity: 0; transform: scale(0.9) translateY(14px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.sv-modal-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 14px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    color: var(--primary-blue);
    background: rgba(var(--primary-rgb), 0.12);
    border: 1px solid rgba(var(--primary-rgb), 0.3);
}

.sv-modal.warn .sv-modal-icon {
    color: #ffb340;
    background: rgba(255, 149, 0, 0.12);
    border-color: rgba(255, 149, 0, 0.35);
}

.sv-modal.success .sv-modal-icon {
    color: #34C759;
    background: rgba(52, 199, 89, 0.12);
    border-color: rgba(52, 199, 89, 0.35);
}

.sv-modal.danger .sv-modal-icon {
    color: #ff6b6b;
    background: rgba(255, 59, 48, 0.12);
    border-color: rgba(255, 59, 48, 0.35);
}

.sv-modal-title {
    font-size: 1.08rem;
    font-weight: 700;
    color: var(--text-white);
    margin-bottom: 8px;
}

.sv-modal-message {
    font-size: 0.88rem;
    line-height: 1.55;
    color: var(--text-gray);
    margin-bottom: 20px;
    word-break: break-word;
}

.sv-modal-input {
    width: 100%;
    background: var(--card-hover-bg);
    border: 1px solid var(--border-soft);
    padding: 11px 14px;
    border-radius: 10px;
    color: var(--text-white);
    font-size: 0.92rem;
    font-family: inherit;
    outline: none;
    margin-bottom: 18px;
    transition: all 0.2s;
    text-align: left;
}

.sv-modal-input:focus {
    border-color: var(--primary-blue);
    background: var(--card-bg);
    box-shadow: 0 0 0 3px var(--primary-blue-glow);
}

.sv-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.sv-modal-btn {
    flex: 1;
    max-width: 160px;
    padding: 11px 18px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.88rem;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.sv-modal-btn-confirm {
    background: linear-gradient(135deg, var(--primary-blue), var(--accent-secondary));
    color: white;
    box-shadow: 0 4px 15px rgba(var(--primary-rgb), 0.3);
}

.sv-modal-btn-confirm:hover {
    filter: brightness(1.12);
    transform: translateY(-1px);
}

.sv-modal-btn-confirm:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-blue-glow);
}

.sv-modal.danger .sv-modal-btn-confirm {
    background: #ff3b30;
    box-shadow: 0 4px 15px rgba(255, 59, 48, 0.35);
}

.sv-modal-btn-cancel {
    background: var(--card-hover-bg);
    border-color: var(--border-soft);
    color: var(--text-gray);
}

.sv-modal-btn-cancel:hover {
    background: rgba(var(--primary-rgb), 0.1);
    border-color: var(--border-highlight);
    color: var(--text-white);
}

.sv-modal-btn-cancel:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.15);
}

@media (max-width: 480px) {
    .sv-modal {
        padding: 22px 18px 18px;
    }

    .sv-modal-btn {
        max-width: none;
    }
}

/* --- RESPONSIVE --- */
@media (max-width: 1024px) {
    .nav-container {
        padding: 0 16px;
    }
}

@media (max-width: 900px) {
    .navbar { height: 90px; }
    .logo { font-size: 28px; }
    .navigation { width: 280px; height: 55px; }
    .navigation ul li { width: 56px; height: 55px; }
    .navigation ul li a .icon { font-size: 1.2rem; line-height: 55px; }
    .navigation ul li.active a .icon { transform: translateY(-28px); }
    .indicator { width: 55px; height: 55px; top: -40%; }
}

@media (max-width: 768px) {
    /* Navbar mobile 1 hàng gọn: logo trái - pill icon phải.
       Icon đứng yên trong pill, label ẩn (pill 50px không đủ chỗ cho
       icon nhảy + label nên trước đây bị tràn xuống), indicator chạy
       bên trong pill thay vì nhô lên trên. */
    .navbar { height: 64px; align-items: center; padding-bottom: 0; }
    .nav-container {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 0 16px;
    }
    .logo { font-size: 22px; }
    .navigation {
        width: auto;
        height: 44px;
        border-radius: 22px;
        padding: 0 6px;
    }
    .navigation ul { gap: 2px; }
    .navigation ul li { width: 46px; height: 44px; }
    .navigation ul li a .icon {
        font-size: 1.05rem;
        line-height: 44px;
        transform: none !important; /* icon đứng yên, không nhảy ra ngoài pill */
    }
    .navigation ul li a .text { display: none; }
    .navigation ul li.active a .icon,
    .navigation ul li.hover-effect a .icon { color: #fff; }
    .indicator {
        width: 40px;
        height: 36px;
        top: 50%;
        margin-top: -18px;
        border-width: 4px;
        border-radius: 18px;
    }
}

@media (max-width: 480px) {
    .logo { font-size: 20px; }
    .navigation ul li { width: 44px; }
    .indicator { width: 38px; }
}

/* Điện thoại hẹp (<=400px): logo + pill menu + nút Cài đặt không còn đủ chỗ trên
   1 hàng nên trước đây nút Cài đặt bị đẩy tràn ra ngoài màn hình (bị overflow-x:
   hidden cắt mất). Thu nhỏ từng phần để cả 3 vẫn nằm gọn trong navbar. */
@media (max-width: 400px) {
    .nav-container { padding: 0 10px; }
    .logo { font-size: 17px; }
    .navigation { padding: 0 4px; }
    .navigation ul li { width: 39px; }
    .nav-settings { width: 34px; height: 34px; font-size: 0.9rem; }
}

/* Màn hình rất hẹp (<=330px, vd Galaxy Fold) cần thu thêm một nấc */
@media (max-width: 330px) {
    .logo { font-size: 15px; }
    .navigation { padding: 0 2px; }
    .navigation ul li { width: 36px; }
    .indicator { width: 34px; }
    .nav-settings { width: 30px; height: 30px; font-size: 0.82rem; }
}

/* --- IN ẤN: nút và panel Cài đặt không bao giờ được in ra --- */
@media print {
    .nav-settings,
    .sv-settings-panel,
    .sv-modal-overlay {
        display: none !important;
    }
}

/* --- SHARED ANIMATIONS --- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
