/* ═══════════════════════════════════════════════════════════
   TikTokMusic — Modern UI System
   Design: Linear / Vercel / Apple HIG inspired
   ═══════════════════════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
    --bg-primary: #f8f9fc;
    --bg-card: #ffffff;
    --bg-sidebar: linear-gradient(180deg, #0f0f1a 0%, #16162a 50%, #1a1a2e 100%);
    --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --accent-blue: #667eea;
    --accent-purple: #764ba2;
    --accent-glow: rgba(102, 126, 234, 0.3);
    --text-primary: #1a1a2e;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --border-light: rgba(255, 255, 255, 0.06);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
    --shadow-accent: 0 8px 24px rgba(102, 126, 234, 0.2);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ── */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent-blue); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--accent-purple); text-decoration: none; }
::selection { background: rgba(102, 126, 234, 0.15); }

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

/* ── Sidebar ── */
.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    color: #fff;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    z-index: 100;
}
.sidebar::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(ellipse at top left, rgba(102, 126, 234, 0.08) 0%, transparent 60%);
    pointer-events: none;
}
.sidebar-header {
    padding: 28px 24px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    position: relative;
}
.sidebar-header h2 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.sidebar-header .subtitle {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.nav-list { list-style: none; padding: 12px 12px; }
.nav-list li { margin-bottom: 2px; }
.nav-list li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: rgba(255, 255, 255, 0.6);
    transition: var(--transition);
    font-size: 13.5px;
    border-radius: 10px;
    font-weight: 450;
    position: relative;
}
.nav-list li a:hover {
    color: rgba(255, 255, 255, 0.95);
    background: rgba(255, 255, 255, 0.06);
    text-decoration: none;
}
.nav-list li a.active {
    color: #fff;
    background: var(--accent-gradient);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    text-decoration: none;
    font-weight: 550;
}
.nav-list li a .nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}
.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.25);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}

/* ── Content ── */
.content {
    margin-left: 240px;
    padding: 32px 40px;
    flex: 1;
    min-width: 0;
    max-width: 1400px;
}

/* ── Typography ── */
h1 {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 24px;
    letter-spacing: -0.03em;
    color: var(--text-primary);
}
h2 {
    font-size: 17px;
    font-weight: 650;
    margin: 28px 0 14px;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}
h3 { font-size: 15px; font-weight: 600; margin: 16px 0 8px; }

/* ── Cards Grid ── */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}
.card::before {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 80px; height: 80px;
    background: var(--accent-gradient);
    opacity: 0.04;
    border-radius: 0 0 0 80px;
    transition: var(--transition);
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: rgba(102, 126, 234, 0.2);
}
.card:hover::before { opacity: 0.08; }
.card-number {
    font-size: 32px;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}
.card-label { font-size: 13px; color: var(--text-secondary); margin-top: 6px; font-weight: 500; }
.card-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Tables ── */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}
thead { background: #f8fafc; }
th, td {
    padding: 13px 18px;
    text-align: left;
    border-bottom: 1px solid #f1f5f9;
    font-size: 13px;
}
th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
tr { transition: var(--transition); }
tr:hover { background: #f8fafc; }
tr:last-child td { border-bottom: none; }
.actions { white-space: nowrap; }
.actions a, .actions button { margin-right: 8px; }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-running { background: #dbeafe; color: #1e40af; position: relative; }
.badge-running::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #3b82f6;
    margin-right: 6px;
    animation: pulse-dot 1.5s infinite;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}
.badge-completed { background: #dcfce7; color: #166534; }
.badge-failed { background: #fee2e2; color: #991b1b; }
.badge-cancelled { background: #f1f5f9; color: #475569; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-warn { background: #fef3c7; color: #92400e; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    transition: var(--transition);
    white-space: nowrap;
}
.btn:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}
.btn:active { transform: scale(0.97); }
.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
    border: none;
    box-shadow: var(--shadow-accent);
}
.btn-primary:hover {
    filter: brightness(1.1);
    color: #fff;
    box-shadow: 0 8px 28px rgba(102, 126, 234, 0.35);
    transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0) scale(0.97); }
.btn-success {
    background: linear-gradient(135deg, #34d399, #059669);
    color: #fff;
    border: none;
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.2);
}
.btn-success:hover { filter: brightness(1.1); color: #fff; }
.btn-danger {
    background: linear-gradient(135deg, #f87171, #dc2626);
    color: #fff;
    border: none;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.2);
}
.btn-danger:hover { filter: brightness(1.1); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 6px; }
.btn-lg { padding: 12px 36px; font-size: 15px; border-radius: var(--radius-md); font-weight: 600; }
.btn-link { background: none; border: none; cursor: pointer; font-size: 13px; padding: 0; color: var(--accent-blue); }
.btn-link:hover { color: var(--accent-purple); }
.btn-link.btn-danger { color: #ef4444; }

/* ── Forms ── */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-weight: 550;
    margin-bottom: 7px;
    font-size: 13px;
    color: var(--text-primary);
}
.form-group input[type="text"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    transition: var(--transition);
    background: var(--bg-card);
    color: var(--text-primary);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }
.form-inline { display: flex; gap: 12px; align-items: flex-end; }
.form-inline input { flex: 1; }
.checkbox-group { display: flex; flex-wrap: wrap; gap: 12px; }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.radio-group label { display: block; margin-bottom: 6px; font-size: 13px; cursor: pointer; font-weight: normal; }
.help-text { font-size: 12px; color: var(--text-muted); }
.inline { display: inline; }
.code-editor {
    font-family: "JetBrains Mono", "Cascadia Code", "Fira Code", "Consolas", monospace;
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
    min-height: 400px;
    background: #1e1e2e;
    color: #cdd6f4;
    border-color: #313244;
    border-radius: var(--radius-md);
}
.code-editor:focus { border-color: var(--accent-blue); }

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}
.page-header h1 { margin-bottom: 0; }

/* ── Card Form ── */
.card-form {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
}
.card-form h3 { margin-top: 0; }

/* ── Flash Messages ── */
.flash-messages { margin-bottom: 20px; }
.flash {
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideDown 0.3s ease;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.flash-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.flash-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Progress Bar ── */
.progress-bar {
    height: 8px;
    background: #f1f5f9;
    border-radius: 100px;
    overflow: hidden;
    flex: 1;
    position: relative;
}
.progress-bar-lg { height: 22px; border-radius: 100px; margin-bottom: 8px; }
.progress-fill {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: inherit;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 0;
    position: relative;
    overflow: hidden;
}
.progress-fill::after {
    content: '';
    position: absolute;
    top: 0; left: -100%; right: 0; bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: shimmer 2s infinite;
}
@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}
.progress-text { font-size: 12px; color: var(--text-secondary); margin-left: 8px; }
.progress-stats { display: flex; gap: 24px; font-size: 13px; color: var(--text-secondary); }
.progress-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
}

/* ── Task Info ── */
.task-info {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 24px;
}
.info-row { display: flex; gap: 12px; padding: 6px 0; }
.info-label { color: var(--text-secondary); min-width: 80px; font-weight: 500; }
.cancel-form { margin-bottom: 20px; }

/* ── Task Form ── */
.task-form {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    max-width: 680px;
}

/* ── Log Viewer ── */
.log-viewer {
    background: #0d1117;
    color: #c9d1d9;
    padding: 24px;
    border-radius: var(--radius-md);
    font-family: "JetBrains Mono", "Cascadia Code", "Fira Code", "Consolas", monospace;
    font-size: 12px;
    line-height: 1.9;
    overflow: auto;
    max-height: 600px;
    white-space: pre-wrap;
    word-break: break-all;
    border: 1px solid #21262d;
    position: relative;
}
.log-viewer::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 40px;
    background: linear-gradient(180deg, #0d1117, transparent);
    pointer-events: none;
    z-index: 1;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.log-box {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
}
.log-line {
    padding: 4px 0;
    font-size: 12px;
    font-family: "JetBrains Mono", "Cascadia Code", "Fira Code", "Consolas", monospace;
    border-bottom: 1px solid #f1f5f9;
}
.log-time { color: var(--text-muted); margin-right: 8px; }
.log-level { font-weight: 600; margin-right: 4px; }
.log-info .log-level { color: #3b82f6; }
.log-warning .log-level { color: #f59e0b; }
.log-error .log-level { color: #ef4444; }

/* ── Empty State ── */
.empty {
    color: var(--text-muted);
    font-size: 14px;
    padding: 40px 0;
    text-align: center;
}

/* ── Phase Steps (Batch Detail) ── */
.phase-steps { display: flex; gap: 0; margin-bottom: 1.5rem; }
.phase-steps .step {
    flex: 1;
    padding: 12px 18px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    background: #f8fafc;
    border: 1px solid var(--border-color);
    position: relative;
    transition: var(--transition);
}
.phase-steps .step:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.phase-steps .step:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.phase-steps .step.active {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #93c5fd;
}
.phase-steps .step.done {
    background: #ecfdf5;
    color: #059669;
    border-color: #6ee7b7;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 100px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); }
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* ── Animations ── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.content { animation: fadeIn 0.3s ease; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar { width: 0; overflow: hidden; }
    .content { margin-left: 0; padding: 16px; }
    .form-row { flex-direction: column; gap: 0; }
    .cards { grid-template-columns: 1fr 1fr; }
}
