:root {
  --bg: #0a0e15;
  --bg-2: #0d1320;
  --surface: #121826;
  --surface-2: #161d2e;
  --surface-3: #1c2536;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.13);
  --text: #e9edf5;
  --muted: #9aa4b8;
  --muted-2: #5d6679;
  --blue: #4c8dff;
  --blue-2: #2b63c7;
  --gold: #e8c15a;
  --green: #4ade80;
  --red: #f87171;
  --amber: #fbbf24;
  --violet: #a78bfa;
  --r: 10px;
  --r-sm: 8px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --font-d: "Bricolage Grotesque", "Inter", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 18px 44px -22px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.bg-mesh {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(900px 560px at 12% -12%, rgba(76, 141, 255, 0.09), transparent 62%),
    radial-gradient(760px 520px at 108% 112%, rgba(43, 99, 199, 0.07), transparent 60%);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 8px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); background-clip: padding-box; }

::selection { background: rgba(76, 141, 255, 0.35); }

a { color: var(--blue); text-decoration: none; }

code {
  font-family: var(--mono); font-size: 0.9em; color: var(--text);
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line);
  border-radius: 5px; padding: 1px 6px;
}

/* ============ LAYOUT ============ */
.layout { display: flex; min-height: 100vh; position: relative; z-index: 1; }

.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0;
  width: 248px; padding: 22px 14px 16px;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
}

.main {
  flex: 1; margin-left: 248px;
  padding: 36px 40px 60px;
  min-width: 0;
}

.page { display: none; }
.page.active { display: block; animation: fadeIn 0.18s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ============ SIDEBAR ============ */
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 2px 8px 20px; border-bottom: 1px solid var(--line);
}

.brand-logo {
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: 10px; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 14px -6px rgba(0, 0, 0, 0.6);
}
.brand-logo img { width: 100%; height: 100%; display: block; }

.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.2px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--muted-2); margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; margin-top: 18px; }
.nav-label { font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted-2); padding: 0 10px 8px; }

.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--muted); font-size: 13.5px; font-weight: 500;
  cursor: pointer; transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }
.nav-item.active { background: rgba(76, 141, 255, 0.14); color: #fff; font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: -14px; top: 20%; height: 60%; width: 3px;
  border-radius: 3px; background: var(--blue);
}
.nav-ico { display: inline-flex; color: var(--muted); flex-shrink: 0; }
.nav-item.active .nav-ico { color: var(--blue); }

.sidebar-foot { border-top: 1px solid var(--line); padding-top: 14px; display: flex; flex-direction: column; gap: 9px; font-size: 12px; color: var(--muted); }
.sidebar-foot > div:last-child { display: flex; align-items: center; gap: 6px; }

/* ============ PAGE HEAD ============ */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 28px; }
.page-title { font-family: var(--font-d); font-size: 24px; font-weight: 700; letter-spacing: -0.4px; line-height: 1.15; margin: 0; }
.page-title small { display: block; margin-top: 7px; font-family: var(--font); font-size: 13px; font-weight: 400; color: var(--muted); letter-spacing: 0; }

.bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 18px 0; }

/* ============ CARDS ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 20px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.card-title { font-size: 13px; font-weight: 600; color: var(--text); letter-spacing: -0.1px; display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.stats-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 22px; }
.stat { display: flex; align-items: center; gap: 13px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.stat-ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; }
.stat-num { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.1; }
.stat-lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ============ FORMS ============ */
.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--text); }

.input {
  width: 100%; padding: 10px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-2);
  background: #0d1322;
  color: var(--text); font-size: 13.5px; font-family: var(--font);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder { color: var(--muted-2); }
.input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(76, 141, 255, 0.16); }
select.input { appearance: none; -webkit-appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%235d6679' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }

.search { display: flex; align-items: center; gap: 8px; background: #0d1322; border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 0 12px; color: var(--muted-2); transition: border-color 0.15s, box-shadow 0.15s; }
.search .input { border: none; background: transparent; box-shadow: none; padding: 10px 0; }
.search:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(76, 141, 255, 0.16); }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2);
  background: var(--surface-2); color: var(--text);
  font-size: 13.5px; font-weight: 600; font-family: var(--font);
  cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--surface-3); border-color: rgba(255, 255, 255, 0.2); }
.btn.primary { background: var(--blue); border-color: transparent; color: #fff; box-shadow: 0 8px 22px -12px rgba(76, 141, 255, 0.6); }
.btn.primary:hover { background: #5d99ff; }
.btn.danger { background: transparent; border-color: rgba(248, 113, 113, 0.35); color: var(--red); }
.btn.danger:hover { background: rgba(248, 113, 113, 0.1); border-color: rgba(248, 113, 113, 0.5); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.icon-btn { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; transition: background 0.15s, color 0.15s; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.icon-btn.danger:hover { background: rgba(248, 113, 113, 0.12); color: var(--red); }

/* ============ TOGGLE ============ */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--line-2); cursor: pointer; transition: background 0.2s, border-color 0.2s; }
.slider::before { content: ""; position: absolute; left: 3px; top: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: transform 0.2s, background 0.2s; }
.switch input:checked + .slider { background: var(--blue); border-color: var(--blue); }
.switch input:checked + .slider::before { transform: translateX(18px); background: #fff; }

/* ============ BADGES / PILLS / DOTS ============ */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface-2); color: var(--muted); font-size: 11.5px; font-weight: 500; }

.status-badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 6px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.02em; border: 1px solid transparent; }
.badge-ready, .badge-pos.badge-ready { background: rgba(74, 222, 128, 0.12); color: #6ee7a0; border-color: rgba(74, 222, 128, 0.28); }
.badge-queued { background: rgba(76, 141, 255, 0.12); color: #8ab6ff; border-color: rgba(76, 141, 255, 0.3); }
.badge-downloading, .badge-busy { background: rgba(232, 193, 90, 0.12); color: #f0cf7d; border-color: rgba(232, 193, 90, 0.3); }
.badge-error { background: rgba(248, 113, 113, 0.12); color: #ff9b9b; border-color: rgba(248, 113, 113, 0.3); }
.badge-off { background: rgba(255, 255, 255, 0.05); color: var(--muted); border-color: var(--line); }
.badge-pos { position: absolute; top: 10px; left: 10px; }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; background: var(--muted-2); flex-shrink: 0; }
.dot-green { background: var(--green); box-shadow: 0 0 8px rgba(74, 222, 128, 0.5); }
.dot-gold { background: var(--amber); box-shadow: 0 0 8px rgba(251, 191, 36, 0.5); }
.dot-red { background: var(--red); box-shadow: 0 0 8px rgba(248, 113, 113, 0.5); }

/* ============ GROUPS / ROLES / TABLES ============ */
.group-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.group-tab { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 500; cursor: pointer; transition: border-color 0.15s, background 0.15s, color 0.15s; }
.group-tab:hover { border-color: var(--line-2); color: var(--text); }
.group-tab.active { background: rgba(76, 141, 255, 0.12); border-color: rgba(76, 141, 255, 0.38); color: #fff; }

.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; padding: 10px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted-2); font-weight: 600; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.tbl td { padding: 12px; border-bottom: 1px solid var(--line); color: var(--text); vertical-align: middle; }
.tbl tbody tr { transition: background 0.12s; }
.tbl tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }
.tbl tbody tr:last-child td { border-bottom: none; }

.role-pill-color { width: 12px; height: 12px; border-radius: 4px; display: inline-block; margin-right: 8px; vertical-align: -1px; }

.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; padding: 5px 10px; font-size: 12.5px; margin: 0 6px 6px 0; }

.empty { display: flex; align-items: center; justify-content: center; padding: 28px; color: var(--muted-2); font-size: 13px; text-align: center; border: 1px dashed var(--line-2); border-radius: var(--r); line-height: 1.6; }
.empty b { color: var(--text); font-weight: 600; }

/* ============ LOGS ============ */
.logs { font-family: var(--mono); font-size: 12px; line-height: 1.75; }
.log-line { padding: 6px 0; border-bottom: 1px dashed rgba(255, 255, 255, 0.05); color: var(--muted); }
.log-line:last-child { border-bottom: none; }
.lt { color: var(--muted-2); margin-right: 10px; }

/* ============ QR ============ */
.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 20px 0; text-align: center; }
.qr-frame { padding: 14px; background: #fff; border-radius: 12px; display: inline-flex; box-shadow: var(--shadow); }
.qr-frame canvas { border-radius: 6px; display: block; }
.qr-ok { width: 88px; height: 88px; border-radius: 16px; background: rgba(74, 222, 128, 0.12); color: #6ee7a0; display: grid; place-items: center; }
.qr-msg { font-size: 13px; color: var(--muted); line-height: 1.6; }
.qr-msg b { color: var(--text); }
.qr-steps { font-size: 12px; color: var(--muted-2); line-height: 1.6; }

/* ============ DOWNLOADS ============ */
.dl-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; display: flex; flex-direction: column; transition: border-color 0.15s; }
.dl-card:hover { border-color: var(--line-2); }
.dl-thumb { position: relative; aspect-ratio: 16 / 9; background: #0d1322; }
.dl-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dl-thumb.noimg img { display: none; }
.dl-thumb.noimg::after { content: "♫"; display: grid; place-items: center; height: 100%; font-size: 30px; color: var(--muted-2); }
.dl-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 0; }
.dl-title { font-size: 13px; font-weight: 600; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.dl-meta { font-size: 11.5px; color: var(--muted-2); display: flex; flex-direction: column; gap: 3px; line-height: 1.45; }
.dl-actions { display: flex; align-items: center; gap: 6px; margin-top: auto; flex-wrap: wrap; }
.dl-holyrics { font-size: 11px; margin-top: 2px; }
.time-ago { color: var(--muted-2); }
.progress { height: 4px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.progress > div { height: 100%; background: var(--blue); border-radius: 999px; transition: width 0.3s; }
.ph { display: grid; place-items: center; height: 100%; color: var(--muted-2); }

/* ============ HINOS / PLAYBACKS ============ */
.pb-head { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.pb-head b { color: var(--text); }
.pb-list { display: flex; flex-direction: column; gap: 8px; }
.pb-result { display: flex; align-items: center; gap: 14px; padding: 10px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.pb-result:hover { border-color: rgba(76, 141, 255, 0.45); background: var(--surface-2); }
.pb-num { width: 28px; height: 28px; border-radius: 8px; background: var(--surface-3); color: var(--muted); display: grid; place-items: center; font-size: 12.5px; font-weight: 700; flex-shrink: 0; }
.pb-thumb { position: relative; width: 112px; aspect-ratio: 16 / 9; border-radius: 7px; overflow: hidden; background: #0d1322; flex-shrink: 0; }
.pb-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pb-thumb.noimg img { display: none; }
.pb-thumb.noimg::after { content: "♫"; display: grid; place-items: center; height: 100%; font-size: 22px; color: var(--muted-2); }
.pb-dur { position: absolute; right: 6px; bottom: 6px; background: rgba(0, 0, 0, 0.78); color: #fff; font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 5px; font-family: var(--mono); }
.pb-info { flex: 1; min-width: 0; }
.pb-title { font-size: 13.5px; font-weight: 600; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-meta { font-size: 11.5px; color: var(--muted-2); margin-top: 3px; }
.pb-dlstatus { font-size: 13px; color: var(--muted); padding: 16px 20px; }

/* ============ HOLYRICS ============ */
.agent-row { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--line); }
.agent-row:last-child { border-bottom: none; }
.agent-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); flex-shrink: 0; }
.agent-row.online .agent-dot { background: var(--green); box-shadow: 0 0 8px rgba(74, 222, 128, 0.5); }
.pend-note { font-size: 11px; color: var(--muted-2); }

/* ============ ZIPS ============ */
.zip-ico { width: 36px; height: 36px; border-radius: 9px; background: rgba(167, 139, 250, 0.12); color: #a78bfa; display: grid; place-items: center; flex-shrink: 0; }

/* ============ MODAL ============ */
.modal-bg { position: fixed; inset: 0; z-index: 100; background: rgba(3, 6, 12, 0.65); backdrop-filter: blur(5px); display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-bg.show { display: flex; }
.modal { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 14px; width: 100%; max-width: 540px; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow); animation: modalIn 0.18s ease; }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface-2); }
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
#modalBody { padding: 22px; }

/* ============ TOASTS ============ */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; max-width: 370px; }
.toast { background: var(--surface-2); border: 1px solid var(--line-2); border-left: 3px solid var(--blue); border-radius: 10px; padding: 12px 16px; font-size: 13px; color: var(--text); box-shadow: var(--shadow); animation: toastIn 0.2s ease; }
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast.out { opacity: 0; transform: translateY(8px); transition: opacity 0.3s, transform 0.3s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ============ SPIN ============ */
.spin { animation: spin 1s linear infinite; display: inline-flex; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ LOGIN ============ */
.login-screen { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.login-box { width: 100%; max-width: 370px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 34px 32px 28px; text-align: center; box-shadow: var(--shadow); }
.login-box .brand-logo { width: 64px; height: 64px; margin: 0 auto; border-radius: 16px; }
.login-title { font-family: var(--font-d); font-size: 22px; font-weight: 700; letter-spacing: -0.3px; margin: 18px 0 4px; }
.login-tag { font-size: 12px; color: var(--muted-2); margin-bottom: 22px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 1100px) {
  .sidebar { width: 220px; }
  .main { margin-left: 220px; padding: 28px 24px 60px; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar { position: static; width: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .main { margin-left: 0; padding: 24px 16px 60px; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}