/* =========================
   BIẾN MÀU - LIGHT MODE
   ========================= */
:root {
    --bg: #ffffff;
    --bg-soft: #f9f9f9;
    --bg-elevated: #ffffff;
    --card: #ffffff;
    --card-2: #f7f7f7;
    --border: rgba(0, 0, 0, 0.08);

    --text: #0f0f0f;
    --text-soft: #606060;
    --text-faint: #8a8a8a;

    --brand: #ff2d2d;
    --brand-soft: rgba(255, 45, 45, 0.10);

    --hover: rgba(0, 0, 0, 0.05);
    --active-bg: rgba(0, 0, 0, 0.08);

    --sidebar-w: 248px;
    --topbar-h: 64px;
    --category-h: 56px;

    --radius: 16px;
    --radius-sm: 12px;
    --radius-xs: 10px;

    --shadow: 0 6px 18px rgba(0, 0, 0, 0.08);

    --input-bg: #ffffff;
    --input-border: #d3d3d3;

    --btn-bg: #f2f2f2;
    --btn-bg-hover: #e7e7e7;

    --chip-bg: #f2f2f2;
    --chip-hover: #e7e7e7;
    --chip-active-bg: #0f0f0f;
    --chip-active-text: #ffffff;

    --overlay: rgba(0, 0, 0, 0.45);
}

/* =========================
   BIẾN MÀU - DARK MODE
   ========================= */
html[data-theme="dark"] {
    --bg: #0f0f0f;
    --bg-soft: #181818;
    --bg-elevated: #202020;
    --card: #1a1a1a;
    --card-2: #222222;
    --border: rgba(255, 255, 255, 0.08);

    --text: #f3f3f3;
    --text-soft: #a9a9a9;
    --text-faint: #7f7f7f;

    --brand: #ff2d2d;
    --brand-soft: rgba(255, 45, 45, 0.14);

    --hover: rgba(255, 255, 255, 0.08);
    --active-bg: rgba(255, 255, 255, 0.12);

    --shadow: 0 8px 24px rgba(0, 0, 0, 0.28);

    --input-bg: #121212;
    --input-border: #303030;

    --btn-bg: #222222;
    --btn-bg-hover: #2f2f2f;

    --chip-bg: #272727;
    --chip-hover: #343434;
    --chip-active-bg: #ffffff;
    --chip-active-text: #111111;

    --overlay: rgba(0, 0, 0, 0.55);
}

/* =========================
   RESET CHUNG
   ========================= */
* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.45;
    transition: background-color 0.2s ease, color 0.2s ease;
}

body {
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-width: 100%;
    display: block;
}

button,
input,
textarea,
select {
    font: inherit;
}

input,
textarea,
select {
    color: var(--text);
}

button {
    -webkit-tap-highlight-color: transparent;
}

::selection {
    background: var(--brand-soft);
}

/* =========================
   SCROLLBAR NHẸ
   ========================= */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--text-faint) transparent;
}

*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

*::-webkit-scrollbar-thumb {
    background: rgba(127, 127, 127, 0.45);
    border-radius: 999px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

/* =========================
   TOPBAR
   ========================= */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1040;
    height: var(--topbar-h);
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr) 132px;
    align-items: center;
    gap: 16px;
    padding: 0 16px;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.topbar-left,
.topbar-center,
.topbar-right {
    min-width: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-left: auto;
}

/* Logo */
.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    font-weight: 700;
    white-space: nowrap;
}

.brand-logo {
    width: 34px;
    height: 34px;
    object-fit: contain;
    flex-shrink: 0;
}

.brand-text {
    font-size: 1rem;
    letter-spacing: 0.2px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Nút tròn chung */
.icon-btn {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.icon-btn:hover {
    background: var(--hover);
}

.icon-btn:active {
    transform: scale(0.98);
}

.icon-btn i {
    font-size: 1.1rem;
}

/* Nút đổi theme */
.theme-toggle-btn {
    position: relative;
    background: var(--btn-bg);
    border: 1px solid var(--border);
}

.theme-toggle-btn:hover {
    background: var(--btn-bg-hover);
}

.theme-toggle-btn .theme-icon-light,
.theme-toggle-btn .theme-icon-dark {
    position: absolute;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

html[data-theme="light"] .theme-icon-light {
    opacity: 1;
    transform: scale(1);
}

html[data-theme="light"] .theme-icon-dark {
    opacity: 0;
    transform: scale(0.7);
}

html[data-theme="dark"] .theme-icon-light {
    opacity: 0;
    transform: scale(0.7);
}

html[data-theme="dark"] .theme-icon-dark {
    opacity: 1;
    transform: scale(1);
}

/* =========================
   FORM TÌM KIẾM
   ========================= */
.global-search-form {
    max-width: 760px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-shell {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    overflow: hidden;
    border: 1px solid var(--input-border);
    border-radius: 999px;
    background: var(--input-bg);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-shell:focus-within {
    border-color: color-mix(in srgb, var(--brand) 45%, var(--input-border));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 10%, transparent);
}

.global-search-input {
    flex: 1;
    min-width: 0;
    height: 42px;
    background: transparent;
    border: 0;
    color: var(--text);
    padding: 0 16px;
    outline: none;
    font-size: 0.94rem;
}

.global-search-input::placeholder {
    color: var(--text-soft);
}

.search-submit {
    width: 58px;
    height: 42px;
    border: 0;
    background: var(--btn-bg);
    color: var(--text);
    border-left: 1px solid var(--input-border);
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s ease;
}

.search-submit:hover {
    background: var(--btn-bg-hover);
}

.voice-btn {
    background: var(--btn-bg);
    border: 1px solid var(--border);
}

.voice-btn:hover {
    background: var(--btn-bg-hover);
}

/* =========================
   SIDEBAR
   ========================= */
.app-sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    padding: 12px;
    overflow-y: auto;
    background: var(--bg);
    border-right: 1px solid var(--border);
    z-index: 1030;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Link menu chính */
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 44px;
    padding: 0 14px;
    border-radius: 12px;
    color: var(--text);
    transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar-link:hover {
    background: var(--hover);
}

.sidebar-link.active,
.sidebar-link[aria-current="page"] {
    background: var(--active-bg);
    color: var(--text);
    font-weight: 600;
}

.sidebar-icon {
    width: 22px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    flex-shrink: 0;
}

/* Text mặc định menu thường: 1 dòng */
.sidebar-text {
    min-width: 0;
    font-size: 0.92rem;
    font-weight: 500;
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 14px 0;
}

.sidebar-section-title {
    color: var(--text-soft);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0 14px 10px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

/* =========================
   CHUYÊN MỤC TRONG SIDEBAR
   ========================= */
.sidebar-category-section {
    display: block;
}

.sidebar-nav-categories {
    gap: 6px;
}

.sidebar-link-category {
    align-items: flex-start;
    min-height: 44px;
    padding: 10px 12px;
    gap: 12px;
}

/* icon category */
.sidebar-link-category .sidebar-icon {
    width: 20px;
    margin-top: 2px;
    flex-shrink: 0;
}

/* text category: cho phép nhiều dòng */
.sidebar-link-category .sidebar-text {
    flex: 1;
    min-width: 0;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: unset !important;
    display: block !important;
    line-height: 1.4;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* active category kiểu YouTube */
.sidebar-link-category.active,
.sidebar-link-category[aria-current="page"] {
    background: var(--active-bg);
    color: var(--text);
    font-weight: 600;
}

.sidebar-link-category.active .sidebar-icon,
.sidebar-link-category[aria-current="page"] .sidebar-icon,
.sidebar-link-category.active .sidebar-text,
.sidebar-link-category[aria-current="page"] .sidebar-text {
    color: var(--text);
}

/* =========================
   MAIN LAYOUT
   ========================= */
.app-layout {
    min-height: 100vh;
}

.app-main {
    margin-left: var(--sidebar-w);
    min-height: calc(100vh - var(--topbar-h));
}

/* Thanh category phía trên */
.top-category-strip {
    position: sticky;
    top: var(--topbar-h);
    z-index: 1020;
    height: var(--category-h);
    display: flex;
    align-items: center;
    background: color-mix(in srgb, var(--bg) 95%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
}

.page-content {
    padding: 10px 20px 0;
}

/* =========================
   CHIP DANH MỤC HORIZONTAL
   ========================= */
.category-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    width: 100%;
    scrollbar-width: none;
}

.category-bar::-webkit-scrollbar {
    display: none;
}

.category-chip {
    flex: 0 0 auto;
    padding: 8px 14px;
    border-radius: 10px;
    background: var(--chip-bg);
    color: var(--text);
    font-size: 0.86rem;
    font-weight: 500;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.category-chip:hover {
    background: var(--chip-hover);
}

.category-chip.active {
    background: var(--chip-active-bg);
    color: var(--chip-active-text);
}

/* =========================
   CARD / SURFACE CƠ BẢN
   ========================= */
.surface-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.thumb-16x9 {
    position: relative;
    width: 100%;
    padding-top: 56.25%;
    overflow: hidden;
    border-radius: 16px;
    background: #111;
}

.thumb-16x9 > img,
.thumb-16x9 > video,
.thumb-16x9 > iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumb-9x16 {
    position: relative;
    width: 100%;
    aspect-ratio: 9 / 16;
    overflow: hidden;
    border-radius: 18px;
    background: #111;
}

.thumb-9x16 > img,
.thumb-9x16 > video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* =========================
   TOAST
   ========================= */
.toast-container-custom {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.app-toast {
    min-width: 240px;
    max-width: 320px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    box-shadow: var(--shadow);
}

/* =========================
   OVERLAY MOBILE
   ========================= */
.app-overlay {
    position: fixed;
    inset: 0;
    z-index: 1025;
    background: var(--overlay);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.app-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* =========================
   RESPONSIVE - LARGE TABLET
   ========================= */
@media (max-width: 1199.98px) {
    .app-topbar {
        grid-template-columns: 200px minmax(0, 1fr) 132px;
    }
}

/* =========================
   RESPONSIVE - TABLET
   ========================= */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 1035;
        width: 280px;
        box-shadow: 8px 0 24px rgba(0, 0, 0, 0.18);
    }

    .app-sidebar.show {
        transform: translateX(0);
    }

    .app-main {
        margin-left: 0;
    }

    .app-topbar {
        grid-template-columns: 180px minmax(0, 1fr) 100px;
    }

    .brand-text {
        display: none;
    }

    .sidebar-link-category {
        min-height: 44px;
        padding: 10px 12px;
    }

    .sidebar-link-category .sidebar-text {
        font-size: 0.89rem;
        line-height: 1.4;
    }
}

/* =========================
   RESPONSIVE - MOBILE
   ========================= */
@media (max-width: 767.98px) {
    .app-topbar {
        gap: 8px;
        padding: 0 10px;
        grid-template-columns: auto minmax(0, 1fr) auto;
    }

    .topbar-left {
        width: auto;
        min-width: max-content;
        gap: 8px;
    }

    .topbar-center {
        width: 100%;
        min-width: 0;
    }

    .topbar-right {
        width: auto;
        min-width: max-content;
        margin-left: 0;
        justify-content: flex-end;
        gap: 0;
    }

    .topbar-home-btn {
        display: none !important;
    }

    .global-search-form {
        width: 100%;
        max-width: 100%;
        gap: 8px;
    }

    .search-shell {
        min-width: 0;
        width: 100%;
    }

    .global-search-input {
        font-size: 0.9rem;
        padding: 0 12px;
    }

    .search-submit {
        width: 48px;
        flex: 0 0 48px;
    }

    .voice-btn,
    .theme-toggle-btn {
        width: 38px;
        height: 38px;
        flex: 0 0 38px;
    }

    .brand-logo {
        width: 30px;
        height: 30px;
    }

    .brand-text {
        display: none;
    }

    .page-content {
        padding: 14px 12px 0;
    }

    .top-category-strip {
        padding: 0 10px;
    }

    .category-bar {
        gap: 8px;
    }

    .category-chip {
        padding: 7px 12px;
        font-size: 0.83rem;
    }

    .app-sidebar {
        width: min(84vw, 320px);
        padding: 10px;
    }

    .sidebar-link {
        min-height: 42px;
        padding: 0 12px;
        gap: 12px;
    }

    .sidebar-link-category {
        min-height: 44px;
        padding: 10px;
        gap: 10px;
    }

    .sidebar-link-category .sidebar-text {
        font-size: 0.88rem;
        line-height: 1.4;
    }

    .toast-container-custom {
        right: 12px;
        left: 12px;
        bottom: 12px;
    }

    .app-toast {
        min-width: 0;
        max-width: none;
        width: 100%;
    }
}

/* =========================
   RESPONSIVE - VERY SMALL
   ========================= */
@media (max-width: 420px) {
    .app-topbar {
        padding: 0 8px;
    }

    .page-content {
        padding: 12px 10px 0;
    }

    .top-category-strip {
        padding: 0 8px;
    }

    .category-chip {
        padding: 7px 10px;
        font-size: 0.8rem;
    }

    .sidebar-section-title {
        padding-left: 10px;
        padding-right: 10px;
    }

    .sidebar-link-category {
        padding: 9px 10px;
    }

    .sidebar-link-category .sidebar-text {
        font-size: 0.86rem;
    }
}