/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:      #4F46E5;
    --primary-dark: #4338CA;
    --success:      #10B981;
    --warning:      #F59E0B;
    --danger:       #EF4444;
    --info:         #3B82F6;
    --secondary:    #6B7280;
    --bg:           #F1F5F9;
    --surface:      #FFFFFF;
    --border:       #E2E8F0;
    --text:         #1E293B;
    --text-muted:   #64748B;
    --sidebar-w:    240px;
    --topbar-h:     60px;
    --radius:       10px;
    --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

html { font-size: 14px; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: "Consolas", "Monaco", monospace; background: #F1F5F9; padding: 2px 6px; border-radius: 4px; font-size: 13px; }

/* ─── Login ─────────────────────────────────────────────────────────────────── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-container { width: 100%; max-width: 420px; padding: 20px; }
.login-card { background: var(--surface); border-radius: 16px; padding: 40px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.login-logo { text-align: center; margin-bottom: 16px; }
.login-title { text-align: center; font-size: 22px; font-weight: 700; color: var(--text); }
.login-subtitle { text-align: center; color: var(--text-muted); margin-top: 4px; margin-bottom: 28px; }

/* ─── Admin Layout ───────────────────────────────────────────────────────────── */
.admin-body { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform .25s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 20px;
    font-size: 15px; font-weight: 700; color: var(--text);
    border-bottom: 1px solid var(--border);
}
.nav-close { color: #64748B !important; }
.nav-close:hover { background: #F8FAFC !important; color: #334155 !important; }
.sidebar-overlay {
    display: none;
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 90;
}
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 20px;
    color: var(--text-muted); font-size: 14px;
    cursor: pointer; border: none; background: none;
    width: 100%; text-align: left;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: #F8FAFC; color: var(--text); text-decoration: none; }
.nav-item.active { background: #EEF2FF; color: var(--primary); font-weight: 600; }
.nav-section-label {
    padding: 14px 20px 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
    opacity: .6;
    user-select: none;
}
.nav-section-label:first-child { padding-top: 4px; }
.sidebar-footer { padding: 12px 0; border-top: 1px solid var(--border); }
.nav-logout { color: var(--danger) !important; }
.nav-logout:hover { background: #FEF2F2 !important; }

.admin-main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    height: var(--topbar-h);
    background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; position: sticky; top: 0; z-index: 50;
}
.sidebar-toggle { display: none; background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 6px; border-radius: 6px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-admin { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 13px; }

.admin-content { flex: 1; padding: 24px; max-width: 1200px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 20px; font-weight: 700; }
.page-desc { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── Stats ──────────────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 20px; display: flex; align-items: center; gap: 16px; box-shadow: var(--shadow); border-left: 4px solid transparent; }
.stat-success { border-left-color: var(--success); }
.stat-danger  { border-left-color: var(--danger); }
.stat-warning { border-left-color: var(--warning); }
.stat-info    { border-left-color: var(--info); }
.stat-icon { color: var(--text-muted); flex-shrink: 0; }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ─── Card ───────────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden; }
.card-header { padding: 14px 20px; font-weight: 600; font-size: 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header-link { font-size: 12px; font-weight: 400; color: var(--primary); }
.card-body { padding: 20px; }
.card-body.p-0 { padding: 0; }

/* ─── Table ──────────────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { padding: 10px 16px; text-align: left; font-weight: 600; color: var(--text-muted); background: #F8FAFC; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #FAFBFC; }
.action-btns { display: flex; gap: 6px; flex-wrap: wrap; }

/* ─── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.form-input { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 7px; font-size: 14px; color: var(--text); background: var(--surface); transition: border-color .15s, box-shadow .15s; outline: none; }
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
textarea.form-input { resize: vertical; min-height: 80px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.inline-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline-form .form-input { width: auto; }

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 7px; font-size: 13px; font-weight: 500; cursor: pointer; border: none; transition: background .15s, opacity .15s; white-space: nowrap; }
.btn:hover { opacity: .88; text-decoration: none; }
.btn:active { opacity: .75; }
.btn-block { width: 100%; justify-content: center; padding: 11px; font-size: 15px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-primary   { background: var(--primary);   color: #fff; }
.btn-success   { background: var(--success);   color: #fff; }
.btn-warning   { background: var(--warning);   color: #fff; }
.btn-danger    { background: var(--danger);    color: #fff; }
.btn-secondary { background: #E2E8F0;          color: var(--text); }
.btn-info      { background: var(--info);      color: #fff; }

/* ─── Alerts ─────────────────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-success { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.alert-error   { background: #FEF2F2; color: #991B1B; border: 1px solid #FECACA; }
.alert-warning { background: #FFFBEB; color: #92400E; border: 1px solid #FDE68A; }
.alert-info    { background: #EFF6FF; color: #1E40AF; border: 1px solid #BFDBFE; }

/* ─── Badges ─────────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-success   { background: #D1FAE5; color: #065F46; }
.badge-secondary { background: #E2E8F0; color: var(--secondary); }
.badge-warning   { background: #FEF3C7; color: #92400E; }
.badge-danger    { background: #FEE2E2; color: #991B1B; }
.card-header .badge { background: #EEF2FF; color: var(--primary); margin-left: 8px; }

/* ─── Quick Actions ──────────────────────────────────────────────────────────── */
.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ─── Code Block ─────────────────────────────────────────────────────────────── */
.code-block { display: flex; align-items: center; gap: 10px; background: #F8FAFC; border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; }
.code-block code { background: none; padding: 0; flex: 1; word-break: break-all; }

/* ─── Pagination ─────────────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.page-btn { padding: 6px 12px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: 13px; }
.page-btn:hover { background: #EEF2FF; border-color: var(--primary); color: var(--primary); text-decoration: none; }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ─── Utilities ──────────────────────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: 12px; }

/* ─── Screenshot Preview ─────────────────────────────────────────────────────── */
.screenshot-container {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}
.screenshot-preview {
    max-width: 150px;
    max-height: 150px;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all .2s;
    object-fit: cover;
}
.screenshot-preview:hover {
    border-color: var(--primary);
    transform: scale(1.02);
}

/* ─── Modal ───────────────────────────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal.active {
    display: flex;
}
.modal-content {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    width: 90%;
    max-width: 450px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal-header {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}
.modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 15px;
}

/* ─── Image Modal ─────────────────────────────────────────────────────────────── */
.image-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9998;
    cursor: pointer;
}
.image-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 50px;
    box-sizing: border-box;
}
.image-large {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.image-close {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    z-index: 10000;
    transition: background .2s;
}
.image-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-open .sidebar-overlay { display: block; }
    .admin-main { margin-left: 0; }
    .sidebar-toggle { display: flex; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .admin-content { padding: 16px; }
    .table { font-size: 12px; }
    .table th, .table td { padding: 8px 10px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .login-card { padding: 28px 20px; }
    .inline-form { flex-direction: column; align-items: stretch; }
    .inline-form .form-input { width: 100%; }
}
