:root {
    --bg: #F5F5F7;
    --card: #FFFFFF;
    --primary: #165DFF;
    --primary-soft: #E8F3FF;
    --success-bg: #F0FCF6;
    --success: #00B42A;
    --text: #1D2129;
    --text-secondary: #4E5969;
    --text-muted: #86909C;
    --border: #E5E6EB;
    --danger: #F53F3F;
    --danger-soft: #FFF1F0;
    --warning-bg: #FFF7E8;
    --warning: #B75D00;
    --shadow: 0 10px 28px rgba(15, 35, 95, 0.06);
    --radius: 10px;
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.panel, .install-card, .password-card, .admin-login-card, .stat-card, .resource-card, .banner-item, .banner-empty, .preview-toolbar, .preview-body, .site-footer {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.site-header {
    background: rgba(255, 255, 255, 0.98);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 20px rgba(15, 35, 95, 0.05);
}

.header-inner, .footer-inner, .admin-topbar, .panel-head, .card-actions, .form-actions, .admin-topbar-right, .preview-toolbar, .visitor-tip-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.header-inner {
    max-width: 1280px;
    margin: 0 auto;
    min-height: 76px;
    padding: 0 20px;
}

.brand, .admin-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.brand img {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    object-fit: cover;
}

.brand strong, .admin-brand strong {
    display: block;
    font-size: 16px;
}

.brand span, .admin-brand span, .header-user {
    color: var(--text-muted);
    font-size: 13px;
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--primary-soft);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.top-nav, .admin-nav, .header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.top-nav-dynamic {
    margin-left: auto;
    justify-content: flex-end;
    flex: 1 1 auto;
    min-width: 0;
}

.top-nav a, .admin-nav a {
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--text-secondary);
}

.top-nav a:hover, .top-nav .is-active, .admin-nav a:hover, .admin-nav .is-active {
    background: var(--primary-soft);
    color: var(--primary);
}

.page-shell, .admin-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 20px 40px;
}

.hero-section {
    margin-bottom: 20px;
}

.hero-banner-only {
    width: 100vw;
    max-width: none;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
}

.banner-slider {
    position: relative;
    width: 100%;
    min-height: 340px;
    overflow: hidden;
}

.banner-slider-wide {
    width: 100vw;
    min-height: 360px;
}

.banner-item, .banner-empty {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    overflow: hidden;
    opacity: 0;
    transition: opacity .4s ease;
}

.banner-item.is-active, .banner-empty {
    opacity: 1;
}

.banner-slider-wide .banner-item,
.banner-slider-wide .banner-empty {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
}

.banner-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.banner-caption {
    position: absolute;
    left: 24px;
    right: 24px;
    bottom: 24px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 10px;
    border: 1px solid rgba(229, 230, 235, 0.9);
    color: var(--text);
}

.banner-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    padding: 20px;
}

.panel {
    padding: 22px;
    margin-bottom: 20px;
}

.filter-panel { padding-bottom: 10px; }
.filters, .form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.filters {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: end;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field span {
    color: var(--text-secondary);
    font-size: 13px;
}

.field-full { grid-column: 1 / -1; }
.compact span { font-size: 12px; }
.field-note {
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.6;
}

input[type="text"], input[type="password"], input[type="email"], input[type="number"], input[type="date"], select, textarea, input[type="file"] {
    width: 100%;
    padding: 11px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    outline: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.12);
}

textarea { resize: vertical; }

.btn {
    border: 0;
    border-radius: 8px;
    padding: 10px 16px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #fff; color: var(--primary); border: 1px solid rgba(22, 93, 255, 0.18); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(245, 63, 63, 0.16); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; }
.btn[disabled] {
    opacity: .6;
    cursor: not-allowed;
}

.visitor-tip {
    background: #FFFFFF;
}

.visitor-tip-inner strong {
    display: block;
    margin-bottom: 6px;
}

.visitor-tip-inner p {
    margin: 0;
    color: var(--text-secondary);
}

.card-grid, .stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.media-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.resource-card, .stat-card { padding: 20px; }
.resource-card h3 { margin: 12px 0 10px; font-size: 18px; }
.resource-desc, .inline-muted { color: var(--text-secondary); line-height: 1.7; }
.inline-muted { margin: 4px 0 0; font-size: 13px; }
.resource-meta, .meta-list, .pagination, .check-row, .permission-grid, .permission-category-item, .kv-list > div {
    display: flex;
}

.resource-card-preview {
    margin-bottom: 14px;
    height: 180px;
    border-radius: 8px;
    overflow: hidden;
    background: #F7F8FA;
    border: 1px solid var(--border);
}

.resource-cover-image, .resource-cover-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.resource-cover-placeholder, .thumb-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    background: var(--primary-soft);
}

.media-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease;
}

.media-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 30px rgba(15, 35, 95, 0.1);
}

.media-card-preview {
    height: 250px;
    background: #F7F8FA;
    overflow: hidden;
}

.media-card-image,
.media-card-video,
.media-card-pdf {
    width: 100%;
    height: 100%;
    border: 0;
    object-fit: cover;
    display: block;
    background: #F7F8FA;
}

.media-card-pdf {
    pointer-events: none;
}

.media-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 16px;
}

.media-card-title {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.media-card-user {
    flex-shrink: 0;
}

.user-avatar,
.user-avatar-fallback,
.admin-user-avatar-preview,
.admin-user-avatar-list,
.media-modal-avatar {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 700;
    border: 1px solid rgba(22, 93, 255, 0.12);
}

.user-avatar,
.admin-user-avatar-preview img,
.admin-user-avatar-list img,
.media-modal-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.admin-user-avatar-preview,
.admin-user-avatar-list {
    width: 56px;
    height: 56px;
}

.admin-user-avatar-preview span,
.admin-user-avatar-list span {
    font-size: 18px;
}

.modal-open {
    overflow: hidden;
}

.media-modal[hidden],
.admin-modal[hidden] {
    display: none;
}

.media-modal,
.admin-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
}

.media-modal-backdrop,
.admin-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 25, 40, 0.5);
}

.media-modal-dialog {
    position: relative;
    z-index: 1;
    width: min(1100px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    margin: 16px auto;
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 20px 48px rgba(15, 35, 95, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.media-modal-close,
.admin-modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-secondary);
    font-size: 24px;
    line-height: 1;
    flex-shrink: 0;
}

.media-modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 2;
}

.media-modal-head,
.admin-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
}

.media-modal-user,
.media-modal-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.media-modal-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.media-modal-meta strong {
    font-size: 18px;
}

.media-modal-meta span {
    color: var(--text-secondary);
    font-size: 13px;
}

.media-modal-body,
.admin-modal-body {
    padding: 20px 24px 24px;
    overflow: auto;
}

.media-modal-image,
.media-modal-video,
.media-modal-frame {
    width: 100%;
    max-height: calc(100vh - 180px);
    border: 0;
    border-radius: 8px;
    background: #F7F8FA;
    display: block;
}

.media-modal-image {
    object-fit: contain;
}

.media-modal-video {
    background: #000;
}

.admin-modal {
    display: block;
}

.admin-modal-dialog {
    position: relative;
    z-index: 1;
    width: min(760px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    margin: 24px auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 20px 48px rgba(15, 35, 95, 0.16);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-md { width: min(720px, calc(100vw - 32px)); }
.modal-lg { width: min(860px, calc(100vw - 32px)); }
.modal-xl { width: min(1000px, calc(100vw - 32px)); }

.admin-modal-head h3,
.admin-modal-head p {
    margin: 0;
}

.admin-modal-head p,
.panel-subtext {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.7;
}

.admin-modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px 22px;
    border-top: 1px solid var(--border);
    background: #fff;
}

.form-section {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #FCFCFD;
    margin-bottom: 16px;
    overflow: hidden;
}

.form-section:last-child {
    margin-bottom: 0;
}

.form-section summary {
    list-style: none;
    cursor: pointer;
    padding: 14px 16px;
    font-weight: 700;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    background: #fff;
}

.form-section summary::-webkit-details-marker {
    display: none;
}

.form-section[open] summary {
    background: #F8F9FB;
}

.form-section .form-grid,
.form-section .permission-grid,
.form-section .permission-category-list {
    padding: 16px;
}

.panel-toolbar {
    margin-bottom: 18px;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.toolbar-filter-form {
    margin-bottom: 18px;
    padding: 16px;
    border-radius: 8px;
    background: #FBFBFC;
    border: 1px solid var(--border);
}

.toolbar-filter-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
    gap: 16px;
    align-items: end;
}

.filter-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.resource-meta {
    justify-content: space-between;
    align-items: center;
    color: var(--text-muted);
    font-size: 13px;
}

.badge,
.inline-badge,
.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.badge,
.inline-badge {
    background: var(--primary-soft);
    color: var(--primary);
    padding: 6px 10px;
}

.inline-badge {
    margin-left: 8px;
    vertical-align: middle;
}

.status-pill {
    padding: 5px 10px;
    background: #F2F3F5;
    color: var(--text-secondary);
}

.status-pill.is-active {
    background: var(--success-bg);
    color: var(--success);
}

.meta-list { flex-direction: column; gap: 8px; margin: 16px 0; }
.meta-list div, .kv-list > div {
    justify-content: space-between;
    gap: 12px;
}
.meta-list dt, .kv-list dt { color: var(--text-muted); }
.meta-list dd, .kv-list dd { margin: 0; color: var(--text-secondary); text-align: right; }
.pagination { gap: 10px; justify-content: center; margin-top: 24px; }

.page-link {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: #fff;
    border: 1px solid var(--border);
}

.page-link.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }

.site-footer {
    max-width: 1280px;
    margin: 0 auto 24px;
    padding: 16px 22px;
}

.footer-inner { color: var(--text-secondary); }

.alert {
    margin-bottom: 18px;
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.alert-success { background: var(--success-bg); color: var(--success); border-color: rgba(0, 180, 42, 0.16); }
.alert-error { background: var(--warning-bg); color: var(--warning); border-color: rgba(255, 125, 0, 0.18); }
.alert-info { background: #F2F3F5; color: var(--text-secondary); }

.install-page, .password-page, .admin-login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.install-shell { width: 100%; max-width: 980px; }
.password-card, .admin-login-card { width: min(100%, 460px); }
.install-card, .password-card, .admin-login-card, .preview-body { padding: 28px; }

.section-heading h1, .admin-topbar h1 {
    margin: 10px 0;
    font-size: 32px;
    line-height: 1.2;
}

.section-heading p, .admin-topbar p {
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.7;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
}

.admin-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px 1fr;
}

.admin-sidebar {
    padding: 24px 18px;
    border-right: 1px solid var(--border);
    background: #FAFAFB;
}

.admin-brand { margin-bottom: 26px; }
.admin-nav { flex-direction: column; }
.admin-main { padding: 24px; }
.admin-content, .admin-topbar { max-width: none; margin: 0; padding: 0; }
.admin-topbar { margin-bottom: 20px; }
.admin-grid {
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    gap: 20px;
}

.form-aside-grid { align-items: start; }
.panel h2 { margin: 0; font-size: 18px; }

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th, .table td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.table th { color: var(--text-secondary); font-weight: 600; font-size: 13px; }
.table-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.table-preview { width: 120px; }
.table-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 28px 12px;
}

.stats-grid { margin-bottom: 20px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card span { color: var(--text-muted); font-size: 13px; }
.stat-card strong { display: block; margin-top: 10px; font-size: 28px; }

.check-row { align-items: center; gap: 10px; color: var(--text-secondary); }
.permission-grid { flex-wrap: wrap; gap: 10px 18px; }
.permission-category-list { display: grid; gap: 14px; }
.permission-category-item {
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #FCFCFD;
}

.subsection-title { margin-bottom: 10px; font-size: 14px; font-weight: 700; }
.thumb { width: 72px; height: 44px; object-fit: cover; border-radius: 6px; }
.thumb-large { width: 120px; height: 72px; }
.thumb-video {
    width: 120px;
    height: 72px;
    object-fit: cover;
    border-radius: 6px;
    background: #000;
}

.admin-preview-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.inline-form { margin-top: 18px; }

.preview-shell {
    min-height: 100vh;
    padding: 20px;
}

.preview-toolbar { margin-bottom: 20px; }
.preview-toolbar span { display: block; margin-top: 6px; color: var(--text-muted); }
.preview-toolbar-actions { display: flex; gap: 10px; }

.preview-body {
    min-height: calc(100vh - 140px);
}

.preview-frame, .video-player, .resource-preview-frame {
    width: 100%;
    min-height: 72vh;
    border: 0;
    border-radius: 8px;
}

.resource-preview-image {
    width: 100%;
    max-height: 75vh;
    object-fit: contain;
    border-radius: 8px;
    background: #F7F8FA;
}

.resource-preview-video {
    width: 100%;
    max-height: 75vh;
    border-radius: 8px;
    background: #000;
}

.document-preview {
    max-width: 900px;
    margin: 0 auto;
    color: var(--text-secondary);
    line-height: 1.9;
}

.empty-state {
    padding: 36px 20px;
    text-align: center;
    color: var(--text-muted);
    border: 1px dashed var(--border);
    border-radius: 10px;
    background: #FCFCFD;
}

@media (max-width: 1180px) {
    .header-inner {
        align-items: flex-start;
        padding-top: 14px;
        padding-bottom: 14px;
    }
}

@media (max-width: 1100px) {
    .admin-grid, .stats-grid, .card-grid, .media-grid, .filters, .toolbar-filter-grid {
        grid-template-columns: 1fr;
    }

    .filter-actions {
        justify-content: flex-start;
    }
}

@media (max-width: 900px) {
    .admin-shell { grid-template-columns: 1fr; }
    .admin-sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
}

@media (max-width: 720px) {
    .page-shell, .admin-main { padding-left: 14px; padding-right: 14px; }
    .header-inner, .footer-inner, .admin-topbar, .preview-toolbar, .visitor-tip-inner, .panel-toolbar, .admin-modal-foot { flex-direction: column; align-items: flex-start; }
    .filters, .form-grid { grid-template-columns: 1fr; }
    .brand, .admin-brand { align-items: flex-start; }
    .top-nav-dynamic {
        margin-left: 0;
        width: 100%;
        justify-content: flex-start;
    }
    .banner-slider-wide { min-height: 240px; }
    .table-preview { width: 90px; }
    .thumb-large, .thumb-video { width: 90px; height: 60px; }
    .media-card-preview { height: 220px; }
    .media-modal-dialog,
    .admin-modal-dialog,
    .modal-md,
    .modal-lg,
    .modal-xl {
        width: calc(100vw - 20px);
        margin: 10px auto;
        max-height: calc(100vh - 20px);
    }
    .media-modal-head, .admin-modal-head { padding: 16px; flex-direction: column; align-items: flex-start; }
    .media-modal-body, .admin-modal-body { padding: 16px; }
    .admin-modal-foot { padding: 16px; width: 100%; }
    .toolbar-actions, .filter-actions { width: 100%; }
}
