:root {
    --bg: #ffffff;
    --bg-elevated: #f2f2f2;
    --bg-hover: #e5e5e5;
    --text: #0f0f0f;
    --text-secondary: #606060;
    --accent: #ff0000;
    --accent-hover: #cc0000;
    --border: #e0e0e0;
    --card-radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Roboto', 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

a { color: inherit; text-decoration: none; }

/* ===== 通用 SVG 图标 ===== */
.icon {
    width: 18px;
    height: 18px;
    fill: currentColor;
    flex-shrink: 0;
}
.icon-sm { width: 16px; height: 16px; }

/* ===== 顶部导航 ===== */
/* 三列 grid（1fr auto 1fr）：左右两列等宽弹性，中间列放搜索框，
   保证搜索框相对整页水平居中，与左右内容（logo/按钮）宽度无关 */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: grid;
    /* 中间列上限 680px = 搜索框 max-width 640px + .search-box 左右内边距 40px */
    grid-template-columns: 1fr minmax(0, 680px) 1fr;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    height: 56px;
    /* YouTube 风格毛玻璃：半透明白底 + 背景模糊，滚动时内容透出磨砂感 */
    background: rgba(255, 255, 255, 0.72);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    backdrop-filter: blur(18px) saturate(160%);
    border-bottom: 1px solid rgba(224, 224, 224, 0.55);
}
/* 不支持 backdrop-filter 的老浏览器回退为纯白底 */
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .topbar { background: #ffffff; }
}
.topbar > .logo { justify-self: start; }
.topbar > .topbar-actions { justify-self: end; }
.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 20px;
    font-weight: 700;
    white-space: nowrap;
    color: var(--text);
    flex: none;
}
.logo .logo-badge {
    width: 32px;
    height: 32px;
    display: block;
}
.logo img {
    height: 32px;
    max-width: 160px;
    object-fit: contain;
}
.logo .logo-name {
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}
.topbar .spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex: none; }

/* ===== 顶部搜索框（YouTube 风格，水平居中，一体式胶囊） ===== */
.search-box {
    min-width: 0;               /* 允许在窄屏收缩，避免溢出 */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
}
.search-field {
    width: 100%;
    max-width: 640px;
    height: 40px;
    display: flex;
    align-items: center;
    padding: 0 6px 0 16px;
    background: #f1f1f1;
    border-radius: 20px;
    overflow: hidden;
    transition: background .15s;
}
.search-box:focus-within .search-field {
    background: #fff;
    box-shadow: inset 0 0 0 1px #0f0f0f;
}
.search-field input[type=text] {
    flex: 1;
    min-width: 0;
    height: 100%;
    width: auto;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    outline: 0;
    background: transparent;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
    font-size: 15px;
    color: var(--text);
}
.search-field input[type=text]::placeholder { color: var(--text-secondary); }
.search-field input[type=text]:focus {
    border-color: transparent;
    box-shadow: none;
}
.search-field .search-btn {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border: 0;
    outline: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}
.search-field .search-btn:hover { background: rgba(0, 0, 0, .08); }
.search-field .search-btn .icon { width: 20px; height: 20px; }

/* ===== 按钮（YouTube 设计规范） =====
 * 标准按钮：高 36px / 全圆角 18px / Roboto 14px Medium / 水平内边距 16px
 * 紧凑按钮：高 32px / 圆角 16px
 * 大按钮：高 40px / 圆角 20px
 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 16px;
    border-radius: 18px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s;
    background: var(--bg-elevated);
    color: var(--text);
}
.btn:hover { background: var(--bg-hover); }
.btn:active { background: var(--bg-hover); }
.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-hover); }
.btn-danger { background: transparent; color: #d32f2f; border: 1px solid #f2b8b5; }
.btn-danger:hover { background: #fef2f2; }
/* 紧凑按钮：表格行内操作、次要操作 */
.btn-sm {
    height: 32px;
    padding: 0 12px;
    border-radius: 16px;
    font-size: 13px;
}
/* 大按钮：登录、主要 CTA */
.btn-lg {
    height: 40px;
    padding: 0 20px;
    border-radius: 20px;
    font-size: 15px;
}

/* ===== 内容区 ===== */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px;
}
/* 静态站首页 h1：仅供搜索引擎识别页面主题，视觉上不占版面（无障碍/SEO 通用做法） */
.static-hero {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.section-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}
.video-grid {
    display: grid;
    /* YouTube 风格：最多一行 3 个 */
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px 16px;
}

/* ===== 视频卡片 ===== */
.video-card {
    cursor: pointer;
    display: block;
    border-radius: var(--card-radius);
    transition: transform .2s ease, box-shadow .2s ease;
    will-change: transform;
}
.video-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.video-card .thumb img {
    transition: transform .3s ease;
}
.video-card:hover .thumb img {
    transform: scale(1.06);
}
.thumb {
    position: relative;
    aspect-ratio: 16/9;
    border-radius: var(--card-radius);
    overflow: hidden;
    background: var(--bg-elevated);
    margin-bottom: 10px;
}
.thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.thumb .duration {
    position: absolute;
    right: 8px;
    bottom: 8px;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(0,0,0,.8);
    color: #fff;
    font-size: 12px;
    font-weight: 500;
}
.thumb .views-badge {
    position: absolute;
    left: 8px;
    top: 8px;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(0,0,0,.65);
    font-size: 11px;
    color: #fff;
}
.video-meta { display: flex; gap: 12px; }
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
    background: var(--bg-elevated);
}
.video-info { min-width: 0; }
.video-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
    margin: 0 0 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 4px;
    color: var(--text);
}
.video-channel {
    font-size: 13px;
    color: var(--text-secondary);
}
.empty-tip {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-secondary);
}
.empty-tip .empty-icon {
    width: 56px;
    height: 56px;
    fill: #c4c4c4;
    margin-bottom: 12px;
}

/* ===== 播放页 ===== */
.watch-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 24px;
    align-items: start;
}
.watch-main { min-width: 0; }
.player-box {
    aspect-ratio: 16/9;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 16px;
}
.player-frame {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: #000;
}
.player-empty {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
}
.watch-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text);
}
.watch-meta-row {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    font-size: 14px;
    color: var(--text-secondary);
}
.meta-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.watch-desc {
    background: var(--bg-elevated);
    border-radius: var(--card-radius);
    padding: 16px;
    font-size: 14px;
    white-space: pre-wrap;
    margin-bottom: 20px;
    color: var(--text);
}

/* 侧边推荐 */
.side-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text);
}
.rec-item {
    display: flex;
    gap: 10px;
    padding: 8px;
    margin: 0 -8px;
    border-radius: 8px;
}
.rec-item:hover { background: var(--bg-elevated); }
.rec-thumb {
    width: 160px;
    aspect-ratio: 16/9;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--bg-elevated);
}
.rec-thumb img { width: 100%; height: 100%; object-fit: cover; }
.rec-info { min-width: 0; }
.rec-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--text);
}
.rec-meta { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* ===== 后台 ===== */
.admin-body { background: #f9f9f9; color: var(--text); }
.admin-nav {
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.admin-nav .topbar { border-bottom: none; }
.admin-nav .btn { background: var(--bg-elevated); color: var(--text); }
.admin-nav .btn:hover { background: var(--bg-hover); }
.admin-nav .btn-active { background: var(--bg-hover); }
.admin-container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 24px;
}
.admin-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
    margin-bottom: 20px;
}
.admin-card h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text);
}
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #3f3f46;
}
.form-group .hint { font-size: 12px; color: #a1a1aa; margin-top: 4px; }
input[type=text], input[type=password], input[type=url], input[type=number], textarea, select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d4d4d8;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: #18181b;
    font-family: inherit;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: #ff0000;
    box-shadow: 0 0 0 3px rgba(255,0,0,.1);
}
input[type=file] { font-size: 13px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .form-row { grid-template-columns: 1fr; } }

/* 后台表格 */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    color: #71717a;
    padding: 10px 12px;
    border-bottom: 2px solid #e4e4e7;
}
.data-table td {
    padding: 12px;
    border-bottom: 1px solid #f0f0f1;
    font-size: 14px;
    vertical-align: middle;
    color: var(--text);
}
.data-table tr:hover td { background: #fafafa; }
.table-thumb {
    width: 100px;
    aspect-ratio: 16/9;
    border-radius: 6px;
    object-fit: cover;
    display: block;
}
.row-actions { display: flex; gap: 8px; }
.row-actions a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    padding: 0 12px;
    border-radius: 15px;
    font-size: 13px;
    font-weight: 500;
    color: #fff;
}
.edit-link { background: #6366f1; }
.edit-link:hover { background: #4f46e5; }
.del-link { background: #ef4444; }
.del-link:hover { background: #dc2626; }
/* 表格行内删除按钮（POST + CSRF 表单用，视觉与 .del-link 一致） */
.row-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    padding: 0 12px;
    border-radius: 15px;
    border: 0;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    color: #fff;
    cursor: pointer;
}
.row-actions button.row-action-del { background: #ef4444; }
.row-actions button.row-action-del:hover { background: #dc2626; }
.add-btn { margin-bottom: 16px; }

/* 登录页 */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}
.login-box {
    width: 100%;
    max-width: 380px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 36px 32px;
    box-shadow: 0 10px 40px rgba(0,0,0,.08);
    text-align: center;
}
.login-box .login-logo {
    width: 56px;
    height: 56px;
    margin: 0 auto 14px;
    display: block;
}
.login-box h1 {
    font-size: 22px;
    margin-bottom: 6px;
    color: #18181b;
}
.login-box .sub {
    color: #71717a;
    font-size: 13px;
    margin-bottom: 24px;
}
.login-box .btn-primary { width: 100%; height: 40px; border-radius: 20px; margin-top: 6px; }
.alert {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
    text-align: left;
}
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.alert-info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* 页脚 */
.footer {
    text-align: center;
    padding: 32px 24px;
    color: var(--text-secondary);
    font-size: 13px;
    border-top: 1px solid var(--border);
    margin-top: 40px;
}

/* 响应式 */
@media (max-width: 900px) {
    .watch-layout { grid-template-columns: 1fr; }
    .video-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .search-box { padding: 0 12px; }
}
@media (max-width: 540px) {
    .video-grid { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
    .topbar { padding: 0 12px; gap: 10px; }
    .search-box { padding: 0 8px; }
    .search-field { padding-left: 12px; }
    .logo .logo-name { display: none; }
}
