:root {
    --bg-main: #060d1c;
    --bg-surface: #0b162d;
    --bg-elevated: #112244;
    --bg-hover: #172e5c;
    --border: #1e3a6d;
    --border-bright: #2c559e;
    --primary: #2563eb;
    --primary-hover: #3b82f6;
    --accent-cyan: #38bdf8;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Inter", "Noto Sans Thai", system-ui, sans-serif;
    background: radial-gradient(circle at top right, #0f2554 0%, var(--bg-main) 55%);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
}

.hidden { display: none !important; }

/* Topbar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 24px;
    background: rgba(6, 13, 28, 0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-badge {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, #2563eb, #0284c7);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 16px;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
}

.brand-title { margin: 0; font-size: 16px; font-weight: 700; }
.brand-sub { margin: 2px 0 0; font-size: 12px; color: var(--accent-cyan); }

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.nav-tabs { display: flex; align-items: center; gap: 6px; margin-right: 6px; }
.nav-tabs .btn.active {
    background: rgba(37, 99, 235, 0.22);
    border-color: var(--primary);
    color: #fff;
}

.count-pill {
    background: var(--warning);
    color: #09111f;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 999px;
}

.user-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    font-size: 13px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.role-pill {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.16);
    color: var(--accent-cyan);
    border: 1px solid rgba(56, 189, 248, 0.35);
}

/* Buttons & Inputs */
.btn {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: 0.15s ease;
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 11px; border-radius: 6px; }
.btn-block { width: 100%; padding: 11px 16px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-outline { background: transparent; border-color: var(--border-bright); color: var(--accent-cyan); }
.btn-outline:hover:not(:disabled) { background: rgba(56, 189, 248, 0.1); }

.btn-ghost { background: var(--bg-elevated); border-color: var(--border); color: var(--text-main); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); }

.btn-danger { background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.45); color: #fca5a5; }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.28); color: #fff; }

.btn-success { background: rgba(34, 197, 94, 0.16); border-color: rgba(34, 197, 94, 0.45); color: #86efac; }
.btn-success:hover:not(:disabled) { background: rgba(34, 197, 94, 0.28); color: #fff; }

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
}
.icon-btn:hover { color: var(--text-main); }

.input, .search-input, .select-input, .catalog-search {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 12px;
    color: var(--text-main);
    font-size: 13px;
    font-family: inherit;
    outline: none;
}

.input-sm { padding: 7px 10px; font-size: 12px; min-width: 220px; }
.input:focus, .search-input:focus, .select-input:focus, .catalog-search:focus {
    border-color: var(--accent-cyan);
}

/* Alerts */
.alert {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    margin-bottom: 14px;
    border: 1px solid var(--border);
    background: rgba(37, 99, 235, 0.12);
    color: #dbeafe;
}
.alert.error {
    border-color: rgba(239, 68, 68, 0.45);
    background: rgba(239, 68, 68, 0.14);
    color: #fecaca;
}
.alert.success {
    border-color: rgba(34, 197, 94, 0.45);
    background: rgba(34, 197, 94, 0.14);
    color: #bbf7d0;
}
.alert.warning {
    border-color: rgba(245, 158, 11, 0.45);
    background: rgba(245, 158, 11, 0.14);
    color: #fde68a;
}

/* Auth Shell */
.auth-shell {
    flex: 1;
    display: grid;
    place-items: center;
    padding: 32px 16px;
}

.auth-card {
    width: 100%;
    max-width: 440px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 26px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.auth-header h2 { margin: 0 0 6px; font-size: 20px; }
.auth-header p { margin: 0 0 18px; font-size: 13px; color: var(--text-muted); }

.auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 4px;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 18px;
}

.auth-tab {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 9px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}
.auth-tab.active {
    background: var(--primary);
    color: #fff;
}

.auth-form { display: flex; flex-direction: column; gap: 14px; }

.form-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
}

.form-hint {
    margin: 0;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    padding: 8px 10px;
    background: rgba(56, 189, 248, 0.08);
    border-radius: 8px;
    border: 1px solid rgba(56, 189, 248, 0.2);
}

/* Workspace Layout */
.workspace {
    display: grid;
    grid-template-columns: 290px 1fr;
    flex: 1;
    min-height: 0;
}

.sidebar {
    background: rgba(11, 22, 45, 0.72);
    border-right: 1px solid var(--border);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sidebar-title {
    margin: 0 0 10px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.sidebar-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.sidebar-title-row .sidebar-title { margin-bottom: 0; }

.btn-link {
    background: transparent;
    border: none;
    color: var(--accent-cyan);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    padding: 2px 4px;
}
.btn-link:hover { text-decoration: underline; }

.quick-list { display: flex; flex-direction: column; gap: 6px; }
.quick-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-main);
    font-size: 13px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}
.quick-item:hover { background: var(--bg-elevated); border-color: var(--border); }

.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 5px 11px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
}
.chip:hover { color: var(--text-main); border-color: var(--border-bright); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.muted-note { font-size: 12px; color: var(--text-dim); }
.muted-inline { font-size: 11px; color: var(--text-dim); font-weight: 400; }

/* Song Catalog */
.sidebar-catalog-section { display: flex; flex-direction: column; min-height: 0; }
.catalog-search { width: 100%; margin-bottom: 8px; font-size: 12px; padding: 7px 10px; }
.catalog-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 360px;
    overflow-y: auto;
    padding-right: 4px;
}

.catalog-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 7px 9px;
    border-radius: 8px;
    background: rgba(17, 34, 68, 0.45);
    border: 1px solid transparent;
    color: var(--text-main);
    text-align: left;
    font-family: inherit;
    cursor: pointer;
}
.catalog-item:hover { background: var(--bg-elevated); border-color: var(--border); }
.catalog-item.active {
    background: rgba(37, 99, 235, 0.25);
    border-color: var(--accent-cyan);
}
.catalog-item-top { display: flex; align-items: center; gap: 6px; min-width: 0; }
.catalog-pv {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 5px;
    background: rgba(56, 189, 248, 0.16);
    color: var(--accent-cyan);
    border: 1px solid rgba(56, 189, 248, 0.35);
    font-family: ui-monospace, monospace;
}
.catalog-title {
    font-size: 12px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.catalog-sub {
    font-size: 11px;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Main Content */
.content {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; }
.crumb {
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.crumb:hover { background: var(--bg-elevated); color: var(--text-main); }
.crumb.active { color: var(--accent-cyan); font-weight: 600; cursor: default; }
.crumb-sep { color: var(--text-dim); }

.search-wrap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search-input { min-width: 240px; }

.song-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius);
    background: rgba(37, 99, 235, 0.16);
    border: 1px solid var(--border-bright);
}
.song-banner-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.song-banner-title { font-size: 14px; font-weight: 700; color: var(--text-main); }
.song-banner-meta { font-size: 12px; color: var(--text-muted); }

.pv-badge {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 11px;
    background: rgba(56, 189, 248, 0.14);
    border: 1px solid rgba(56, 189, 248, 0.3);
    color: var(--accent-cyan);
    white-space: nowrap;
}

.batch-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: var(--radius);
    background: rgba(37, 99, 235, 0.16);
    border: 1px solid var(--primary);
    font-size: 13px;
}
.batch-actions { display: flex; gap: 8px; }

.state-panel {
    margin: 30px auto;
    max-width: 520px;
    text-align: center;
    padding: 32px 24px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
}
.state-icon { font-size: 40px; margin-bottom: 10px; }
.state-panel h2 { margin: 0 0 8px; font-size: 18px; }
.state-panel p { margin: 0 0 18px; font-size: 13px; color: var(--text-muted); line-height: 1.6; }
.state-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

/* Tables */
.table-wrap {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}

.file-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.file-table th {
    text-align: left;
    padding: 11px 14px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    background: rgba(17, 34, 68, 0.6);
    border-bottom: 1px solid var(--border);
}
.file-table td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(30, 58, 109, 0.45);
    vertical-align: middle;
}
.file-table tbody tr:hover { background: rgba(23, 46, 92, 0.45); }

.col-check { width: 38px; text-align: center; }
.col-type { width: 95px; color: var(--text-muted); }
.col-size { width: 105px; color: var(--text-muted); }
.col-date { width: 155px; color: var(--text-muted); }
.col-action { width: 110px; text-align: right; }

.name-cell { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.file-link { color: var(--text-main); cursor: pointer; font-weight: 500; word-break: break-all; }
.file-link:hover { color: var(--accent-cyan); text-decoration: underline; }
.file-link.is-folder { color: var(--accent-cyan); font-weight: 600; }

.pagination-bar { padding: 14px; display: flex; justify-content: center; }

/* Admin Shell */
.admin-shell {
    padding: 24px;
    max-width: 1320px;
    width: 100%;
    margin: 0 auto;
}

.admin-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 20px;
    align-items: start;
}

.panel-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
}

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}
.panel-head h2 { margin: 0 0 4px; font-size: 16px; }
.panel-sub { margin: 0; font-size: 12px; color: var(--text-muted); line-height: 1.5; }

.admin-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
}

.status-pill {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}
.status-pending { background: rgba(245, 158, 11, 0.16); color: #fcd34d; border: 1px solid rgba(245, 158, 11, 0.4); }
.status-approved { background: rgba(34, 197, 94, 0.16); color: #86efac; border: 1px solid rgba(34, 197, 94, 0.4); }
.status-rejected { background: rgba(239, 68, 68, 0.16); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.4); }
.status-disabled { background: rgba(148, 163, 184, 0.16); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, 0.35); }

.user-meta-main { font-weight: 600; color: var(--text-main); }
.user-meta-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.drive-summary {
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    font-size: 12px;
    line-height: 1.7;
    margin-bottom: 14px;
}

.drive-form { display: flex; flex-direction: column; gap: 12px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.copy-row { display: flex; gap: 8px; }
.copy-row .input { flex: 1; font-family: ui-monospace, monospace; font-size: 12px; }
.drive-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

/* Download Drawer */
.download-drawer {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 340px;
    background: var(--bg-surface);
    border: 1px solid var(--border-bright);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    z-index: 40;
}
.drawer-header {
    padding: 10px 14px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
}
.drawer-list { max-height: 240px; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 10px; }
.dl-item { font-size: 12px; }
.dl-top { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.dl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-bar-bg { height: 6px; background: var(--bg-elevated); border-radius: 999px; overflow: hidden; }
.dl-bar-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--primary), var(--accent-cyan)); transition: width 0.15s; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2, 6, 17, 0.78); }
.modal-card {
    position: relative;
    width: 100%;
    max-width: 440px;
    background: var(--bg-surface);
    border: 1px solid var(--border-bright);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.modal-header {
    padding: 14px 18px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 18px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

code {
    background: var(--bg-elevated);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--accent-cyan);
    font-size: 12px;
}

@media (max-width: 1024px) {
    .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
    .workspace { grid-template-columns: 1fr; }
    .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
    .col-date, .col-type { display: none; }
    .form-row-2 { grid-template-columns: 1fr; }
}
