/* ==========================================================================
   Edu App Admin — layout and theme on top of Bootstrap 5
   Palette: deep ink sidebar, calm paper background, marigold accent for "you are here".
   ========================================================================== */

:root {
    --ink: #17223b;
    --ink-soft: #24314f;
    --ink-text: #c8d1e2;
    --paper: #f4f6fa;
    --line: #e2e7f0;
    --accent: #e3a322;
    --primary: #2b59c3;
    --primary-dark: #234aa3;
    --primary-darker: #1c3d88;
    --sidebar-width: 256px;
    --topbar-height: 60px;
}

body {
    background: var(--paper);
    color: #1f2937;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}

.min-w-0 { min-width: 0; }

/* ---------- Buttons & form accents ---------- */
.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary-dark);
    --bs-btn-hover-border-color: var(--primary-dark);
    --bs-btn-active-bg: var(--primary-darker);
    --bs-btn-active-border-color: var(--primary-darker);
    --bs-btn-disabled-bg: var(--primary);
    --bs-btn-disabled-border-color: var(--primary);
}

.btn-outline-primary {
    --bs-btn-color: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary);
    --bs-btn-hover-border-color: var(--primary);
    --bs-btn-active-bg: var(--primary-dark);
    --bs-btn-active-border-color: var(--primary-dark);
    --bs-btn-disabled-color: var(--primary);
    --bs-btn-disabled-border-color: var(--primary);
}

.form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

.btn-icon {
    border: 0;
    padding: .25rem .5rem;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--ink);
}

/* ---------- Shell ---------- */
.admin-main {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.admin-content {
    flex: 1;
    padding: 1.75rem;
}

/* ---------- Sidebar ---------- */
.admin-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--sidebar-width);
    background: var(--ink);
    color: var(--ink-text);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform .2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    height: var(--topbar-height);
    padding: 0 1.1rem;
    color: #fff;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    flex-shrink: 0;
}

.sidebar-brand:hover { color: #fff; }

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: var(--ink);
    font-size: 1.15rem;
    flex-shrink: 0;
}

.brand-name {
    display: block;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-sub {
    display: block;
    font-size: .75rem;
    color: var(--ink-text);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: .9rem .75rem 1.5rem;
}

.sidebar-nav .nav { gap: 2px; }

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .55rem .75rem;
    border-radius: 8px;
    color: var(--ink-text);
    font-size: .92rem;
}

.sidebar-nav .nav-link .bi { font-size: 1.05rem; width: 1.1rem; text-align: center; }

.sidebar-nav .nav-link:hover,
.sidebar-nav .nav-link:focus-visible {
    background: rgba(255, 255, 255, .06);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background: var(--ink-soft);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar-nav .nav-link.is-pending {
    opacity: .5;
    cursor: default;
}

.sidebar-nav .nav-link.is-pending:hover { background: transparent; color: var(--ink-text); }

.nav-label {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-soon {
    font-size: .68rem;
    padding: .1rem .4rem;
    border-radius: 4px;
    background: rgba(255, 255, 255, .1);
}

.nav-count {
    font-size: .72rem;
    min-width: 1.4rem;
    text-align: center;
    padding: .1rem .4rem;
    border-radius: 999px;
    background: var(--accent);
    color: var(--ink);
    font-weight: 600;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(23, 34, 59, .45);
    z-index: 1035;
}

/* ---------- Top bar ---------- */
.admin-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 0 1.25rem;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.topbar-title {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-shrink: 0;
}

.topbar-actions:empty { display: none; }

.topbar-actions .btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    white-space: nowrap;
    --bs-btn-padding-y: .35rem;
    --bs-btn-padding-x: .8rem;
    --bs-btn-font-size: .9rem;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: .5rem;
    border: 0;
    max-width: 240px;
}

.avatar-sm {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.avatar-initial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--ink);
    color: #fff;
    font-weight: 600;
}

/* ---------- Cards, tables, forms ---------- */
.card {
    border-color: var(--line);
    border-radius: 10px;
}

.card-header {
    background: #fff;
    border-bottom-color: var(--line);
    padding: .85rem 1.25rem;
}

.card-footer {
    background: #fff;
    border-top-color: var(--line);
}

.card-title-sm {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: var(--ink);
}

.table > thead th {
    font-size: .8rem;
    font-weight: 600;
    color: #6b7280;
    background: #f8fafc;
    white-space: nowrap;
}

.table > :not(caption) > * > * { padding: .7rem 1rem; }

.cell-truncate {
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.field-narrow { max-width: 280px; }
.field-medium { max-width: 420px; }

.image-preview,
.image-placeholder {
    width: 88px;
    height: 88px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #eef2f8;
}

.image-preview { object-fit: cover; display: block; }

.image-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9aa5b8;
    font-size: 1.6rem;
}

/* ---------- Settings navigation ---------- */
.settings-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .6rem;
    text-align: left;
    color: #374151;
    border-radius: 8px;
    padding: .6rem .8rem;
    font-size: .92rem;
}

.settings-nav .nav-link:hover { background: #f1f4f9; }

.settings-nav .nav-link.active {
    background: var(--ink);
    color: #fff;
}

/* ---------- Sign-in page ---------- */
.auth-page { min-height: 100vh; }

.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background:
        linear-gradient(180deg, var(--ink) 0, var(--ink) 38vh, var(--paper) 38vh);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 2rem;
    box-shadow: 0 12px 32px rgba(23, 34, 59, .12);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1.75rem;
}

/* ---------- Listing tables (categories, folders, content) ---------- */
.col-drag { width: 36px; padding-right: 0 !important; }
.col-thumb { width: 64px; }
.col-status { width: 90px; }

.drag-handle {
    cursor: grab;
    color: #9aa5b8;
    font-size: 1.1rem;
    display: inline-flex;
    padding: .25rem;
}

.drag-handle:active { cursor: grabbing; }

.sortable-ghost { background: #eef3ff; }
.sortable-ghost td { opacity: .6; }

.thumb {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--line);
    background: #eef2f8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.thumb-empty { color: #9aa5b8; font-size: 1.15rem; }

.row-title {
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
    word-break: break-word;
}

.row-title:hover { color: var(--primary); text-decoration: underline; }

.row-meta { font-size: .8rem; color: #6b7280; margin-top: .1rem; }

.type-badge {
    display: inline-block;
    font-size: .75rem;
    font-weight: 600;
    padding: .2rem .55rem;
    border-radius: 6px;
    white-space: nowrap;
}

.type-folder { background: #fff4d6; color: #8a5a00; }
.type-pdf { background: #fde8e8; color: #a3232d; }
.type-article { background: #e3effd; color: #1d4f91; }
.type-quiz { background: #e5f6ec; color: #1b6b3a; }

.empty-state {
    text-align: center;
    color: #6b7280;
    padding: 2.5rem 1rem;
}

.empty-state .bi {
    display: block;
    font-size: 2rem;
    color: #b6bfce;
    margin-bottom: .5rem;
}

.admin-breadcrumb {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: .55rem .9rem;
    margin-bottom: 1.25rem;
    font-size: .9rem;
}

.admin-breadcrumb a { text-decoration: none; color: var(--primary); }

.quiz-settings {
    border-top: 1px dashed var(--line);
    margin-top: 1rem;
    padding-top: 1rem;
}

.quiz-settings-title {
    font-weight: 600;
    color: var(--ink);
    margin-bottom: .75rem;
}

/* ---------- Content Details column ---------- */
.col-details { min-width: 190px; max-width: 280px; }

.content-details {
    font-size: .8rem;
    line-height: 1.45;
    white-space: normal;
    word-break: break-word;
}

.detail-line + .detail-line { margin-top: .1rem; }
.detail-label { color: #6b7280; }
.detail-value { color: #1f2937; font-weight: 500; }
.detail-value.tone-success { color: #1b6b3a; font-weight: 600; }
.detail-value.tone-danger { color: #b42318; font-weight: 600; }
.detail-value.tone-warning { color: #9a6700; font-weight: 600; }
.detail-value.tone-info { color: #1d4f91; font-weight: 600; }
.detail-value.tone-muted { color: #6b7280; }

.pdf-settings {
    border-top: 1px dashed var(--line);
    padding-top: 1rem;
}

/* ---------- Content pages (PDF, Article, Quiz) ---------- */
.pdf-preview {
    display: block;
    width: 100%;
    height: 78vh;
    min-height: 480px;
    border: 0;
    border-radius: 0 0 10px 10px;
}

.quiz-tabs { border-bottom-color: var(--line); }
.quiz-tabs .nav-link { color: #4b5563; font-weight: 500; }
.quiz-tabs .nav-link.active { color: var(--ink); font-weight: 600; }
.quiz-tab-content { padding-top: 1.25rem; }

.quiz-summary {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1.5rem;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: .75rem 1rem;
    margin-bottom: 1rem;
    font-size: .92rem;
    color: #374151;
}

.col-number { width: 44px; }

.question-cell { min-width: 240px; max-width: 520px; }

.question-thumb {
    max-width: 160px;
    max-height: 64px;
    border-radius: 6px;
    border: 1px solid var(--line);
    object-fit: contain;
    background: #f8fafc;
}

.answer-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #e5f6ec;
    color: #1b6b3a;
    font-weight: 700;
}

.correct-option-btn { min-width: 52px; font-weight: 600; }

.image-preview-wide { width: 200px; height: 110px; }
.image-preview.image-preview-wide { object-fit: contain; background: #f8fafc; }

.quiz-total {
    background: #f1f5fd;
    border: 1px solid #dbe5f8;
    color: #1f3b73;
    border-radius: 8px;
    padding: .6rem .9rem;
    font-size: .92rem;
}

.fixed-schedule {
    border-top: 1px dashed var(--line);
    padding-top: 1.25rem;
}

.fixed-schedule-title {
    font-weight: 600;
    color: var(--ink);
    margin-bottom: .75rem;
}

/* ---------- Rich editor (Summernote) ---------- */
.note-editor.note-frame { border-color: #dee2e6; border-radius: 8px; }
.note-editor.note-frame .note-toolbar { background: #f8fafc; border-radius: 8px 8px 0 0; }
.note-editor.is-invalid { border-color: #dc3545 !important; }
.note-editable img { max-width: 100%; height: auto; }

.app-button,
.note-editable .app-button {
    display: inline-block;
    padding: .45rem 1.1rem;
    border-radius: 8px;
    background: var(--primary);
    color: #fff !important;
    font-weight: 600;
    text-decoration: none !important;
}

/* ---------- Content Search (top bar) ---------- */
.content-search {
    position: relative;
    width: 260px;
}

.content-search .form-control { padding-left: 2rem; }

.content-search-icon-left {
    position: absolute;
    left: .65rem;
    top: 50%;
    transform: translateY(-50%);
    color: #9aa5b8;
    pointer-events: none;
}

.content-search-results {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: min(460px, 92vw);
    max-height: 70vh;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(23, 34, 59, .16);
    z-index: 1060;
    padding: .35rem;
}

.content-search-item {
    display: flex;
    gap: .65rem;
    align-items: flex-start;
    padding: .5rem .6rem;
    border-radius: 8px;
    color: inherit;
    text-decoration: none;
}

.content-search-item:hover,
.content-search-item:focus { background: #f1f5fd; outline: none; }

.content-search-body { display: flex; flex-direction: column; min-width: 0; }
.content-search-title { font-weight: 600; color: var(--ink); display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.content-search-path { font-size: .78rem; color: #6b7280; word-break: break-word; }
.content-search-empty { padding: .75rem; color: #6b7280; font-size: .88rem; }

/* ---------- Content Picker ---------- */
.picker-tree, .picker-results { min-height: 200px; }

.picker-node {
    display: flex;
    align-items: center;
    gap: .15rem;
}

.picker-toggle {
    border: 0;
    background: transparent;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    color: #6b7280;
    flex-shrink: 0;
}

.picker-toggle:hover { background: #eef2f8; }
.picker-toggle .bi { transition: transform .15s ease; display: inline-block; }
.picker-toggle.open .bi { transform: rotate(90deg); }

.picker-label {
    display: flex;
    align-items: center;
    gap: .5rem;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 8px;
    padding: .35rem .6rem;
    text-align: left;
    flex: 1 1 auto;
    min-width: 0;
    color: #1f2937;
}

.picker-label:hover:not(:disabled) { background: #f1f5fd; }
.picker-label.selected { background: #e3ecff; border-color: #b8ccf5; }
.picker-label:disabled { opacity: .55; cursor: not-allowed; }

.picker-label-text { display: flex; flex-direction: column; min-width: 0; }
.picker-title { word-break: break-word; }
.picker-path { font-size: .76rem; color: #6b7280; word-break: break-word; }

.picker-loading, .picker-empty { color: #6b7280; font-size: .88rem; padding: .4rem .6rem .4rem 2.2rem; }
.picker-selected { font-size: .88rem; color: #374151; min-width: 0; }

.tree-type-icon { font-size: 1.05rem; flex-shrink: 0; }
.type-icon-category { color: #5b3fb0; }
.type-icon-folder { color: #c68a00; }
.type-icon-pdf { color: #c0343f; }
.type-icon-article { color: #1d4f91; }
.type-icon-quiz { color: #1b6b3a; }
.tree-badge { font-size: .68rem; font-weight: 500; }

/* ---------- Question selection ---------- */
.col-check { width: 40px; padding-right: 0 !important; }
.col-check .form-check-input { margin: 0; cursor: pointer; }
tr.row-selected > td { background: #f1f5fd; }

.selection-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem .75rem;
    background: #e3ecff;
    border: 1px solid #b8ccf5;
    border-radius: 10px;
    padding: .55rem .9rem;
    margin-bottom: 1rem;
}

.selection-count { color: var(--ink); margin-right: .25rem; }

/* ---------- Folder ZIP export / import progress ---------- */
.transfer-progress { text-align: left; }
.transfer-progress .progress { height: 12px; border-radius: 6px; }
.transfer-progress .progress-bar { background-color: var(--primary); }
.transfer-status { margin-top: .6rem; font-size: .88rem; color: #4b5563; }
.transfer-hint { margin-top: .5rem; font-size: .82rem; color: #9a6700; }
.transfer-summary { text-align: left; font-size: .92rem; margin: .5rem 0 0; padding-left: 1.2rem; }

/* ---------- MCQ import ---------- */
.import-help { padding-left: 1.1rem; }

.import-errors {
    margin-top: 1rem;
    border: 1px solid #f3c1c1;
    background: #fff6f6;
    border-radius: 8px;
    padding: .75rem 1rem;
    font-size: .88rem;
    color: #8a1c1c;
    max-height: 260px;
    overflow-y: auto;
}

.import-errors-title { font-weight: 600; margin-bottom: .35rem; }
.import-errors ol { padding-left: 1.2rem; }

/* ---------- Banner Management ---------- */
.col-banner-thumb { width: 150px; }

.banner-thumb-wrap {
    display: inline-block;
    border-radius: 8px;
    cursor: zoom-in;
}

.banner-thumb-wrap:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.banner-thumb {
    display: block;
    width: 128px;
    height: 56px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #eef2f8;
}

.banner-hover-preview {
    position: fixed;
    z-index: 1080;
    padding: 6px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(23, 34, 59, .18);
    pointer-events: none;
}

.banner-hover-preview img {
    display: block;
    max-width: min(480px, 70vw);
    max-height: 60vh;
    border-radius: 6px;
}

.image-preview.banner-image-preview,
.image-placeholder.banner-image-preview {
    width: 100%;
    max-width: 360px;
    height: 150px;
}

.image-preview.banner-image-preview { object-fit: contain; background: #f8fafc; }

.action-badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .78rem;
    font-weight: 600;
    padding: .25rem .6rem;
    border-radius: 6px;
}

.action-share_app { background: #e5f6ec; color: #1b6b3a; }
.action-external_link { background: #fff4d6; color: #8a5a00; }
.action-open_content { background: #e3effd; color: #1d4f91; }

.col-target { min-width: 220px; max-width: 420px; }
.target-path { word-break: break-word; }
.target-link { word-break: break-all; }

.type-category { background: #efe9fb; color: #5b3fb0; }

/* ---------- Pages ---------- */
.col-public-link { min-width: 260px; max-width: 420px; }
.col-public-link .form-control { font-size: .82rem; }

.slug-prefix {
    max-width: 55%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    color: #6b7280;
    font-size: .85rem;
    line-height: 1.5;
}

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .admin-sidebar { transform: translateX(-100%); }
    body.sidebar-open .admin-sidebar { transform: none; }
    body.sidebar-open .sidebar-backdrop { display: block; }
    .admin-main { margin-left: 0; }
    .admin-content { padding: 1.25rem 1rem; }
    .admin-topbar { padding: 0 .75rem; }
}

/* Tablets: the search box gets narrower. */
@media (max-width: 991.98px) {
    .content-search { width: 180px; }
}

/* Small phones: action buttons show only their icons. */
@media (max-width: 575.98px) {
    .topbar-actions .btn-label { display: none; }
    .topbar-actions .btn { --bs-btn-padding-x: .6rem; }
    .content-search { width: 130px; }
}

@media (prefers-reduced-motion: reduce) {
    .admin-sidebar { transition: none; }
}
