:root {
  --bg: #eef0f3;
  --panel: #ffffff;
  --panel-border: #d3d8e0;
  --text: #1a2230;
  --text-dim: #5c6675;
  --text-faint: #8b93a3;
  --accent: #1a56db;
  --ok: #2f855a;
  --warn: #c05621;
  --danger: #c53030;
  --danger-dark: #9b2c2c;
  --live: #c53030;
  --eagle: #1a56db;
  --automation: #2f855a;
  --fallback: #c05621;
  --radius: 6px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  height: 100%;
}

a { color: var(--accent); }

button {
  font-family: var(--sans);
  cursor: pointer;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  transition: background .1s, transform .05s;
}
button:hover { background: #f5f7fa; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: var(--accent); color: white; border-color: var(--accent); }
button.primary:hover { background: #1543ad; }
button.danger { background: var(--danger); color: white; border-color: var(--danger); }
button.danger:hover { background: var(--danger-dark); }
button.ghost { background: transparent; }

input, select, textarea {
  font-family: var(--sans);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13px;
  background: white;
  color: var(--text);
}

.chip {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 3px;
  color: white;
}

/* ---------- Layout ---------- */

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

/* ---------- Header / status bar ---------- */

.status-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 18px;
  background: #101828;
  color: #e8ecf3;
  border-bottom: 3px solid var(--panel-border);
}
.status-bar .brand {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: .03em;
  color: white;
}
.status-bar .clock {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  color: #cbd5e1;
}
.status-bar .sep { width: 1px; height: 24px; background: #2d3748; }
.status-bar .spacer { flex: 1; }

.source-indicators { display: flex; gap: 6px; }
.source-pill {
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
  border: 2px solid #2d3748;
  color: #8b93a3;
  background: #1a2332;
}
.source-pill.active {
  color: white;
  box-shadow: 0 0 0 2px rgba(255,255,255,.15);
}
.source-pill.active.EAGLE { background: var(--eagle); border-color: var(--eagle); }
.source-pill.active.LOCAL_LIVE { background: var(--live); border-color: var(--live); animation: pulse-live 1.6s infinite; }
.source-pill.active.LOCAL_AUTOMATION { background: var(--automation); border-color: var(--automation); }
.source-pill.active.FALLBACK { background: var(--fallback); border-color: var(--fallback); }

@keyframes pulse-live {
  0%, 100% { box-shadow: 0 0 0 2px rgba(255,255,255,.15); }
  50% { box-shadow: 0 0 0 5px rgba(197,48,48,.35); }
}

.eagle-health-badge {
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
}
.eagle-health-badge.HEALTHY { background: #1c3d2d; color: #6ee7a8; }
.eagle-health-badge.DEGRADED { background: #4a3410; color: #fbbf24; }
.eagle-health-badge.DOWN { background: #4a1414; color: #fca5a5; }

.control-mode-badge {
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  background: #1a2332;
  color: #cbd5e1;
  border: 1px solid #2d3748;
}
.control-mode-badge.MANUAL { background: #4a3410; color: #fbbf24; border-color: #6b4a12; }

.operator-name { font-size: 12px; color: #cbd5e1; }
.operator-name b { color: white; }

/* ---------- Main grid ---------- */

.main-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  grid-template-rows: auto 1fr;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
  height: 100%;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-header {
  padding: 8px 14px;
  border-bottom: 1px solid var(--panel-border);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-body { padding: 12px; overflow-y: auto; flex: 1; }

/* Now Playing */

.now-playing { grid-column: 1; grid-row: 1; min-height: 230px; }
.np-title { font-size: 30px; font-weight: 800; line-height: 1.1; margin: 0 0 2px; }
.np-artist { font-size: 16px; color: var(--text-dim); margin: 0 0 10px; }
.np-meta { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.np-times {
  display: flex; justify-content: space-between; align-items: baseline;
  font-family: var(--mono); font-size: 15px; color: var(--text-dim); margin-bottom: 6px;
}
.np-times .big { font-size: 34px; font-weight: 700; color: var(--text); }
.progress-track {
  height: 14px; background: #e2e6ec; border-radius: 7px; overflow: hidden; position: relative;
  border: 1px solid var(--panel-border);
}
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #3b82f6); transition: width .2s linear; }
.progress-fill.LOCAL_LIVE { background: linear-gradient(90deg, var(--live), #e53e3e); }
.progress-fill.LOCAL_AUTOMATION { background: linear-gradient(90deg, var(--automation), #38a169); }
.progress-fill.FALLBACK { background: linear-gradient(90deg, var(--fallback), #dd6b20); }
.intro-countdown {
  margin-top: 8px; font-family: var(--mono); font-size: 13px; color: var(--warn); font-weight: 700;
}
.np-controls { display: flex; gap: 8px; margin-top: 14px; }
.np-controls button { flex: 1; padding: 14px 0; font-size: 14px; }
.np-empty { color: var(--text-faint); font-style: italic; padding: 40px 0; text-align: center; }
.np-alert {
  background: #fff3e0; border: 1px solid var(--warn); color: #7a3a0f;
  padding: 8px 10px; border-radius: 6px; font-size: 12px; margin-bottom: 10px; font-weight: 600;
}

/* Source control */

.source-control { grid-column: 2; grid-row: 1; min-height: 230px; }
.source-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.source-buttons button {
  padding: 16px 8px; font-size: 13px; text-align: left; position: relative;
}
.source-buttons button .sb-label { display: block; font-size: 14px; font-weight: 800; }
.source-buttons button .sb-sub { display: block; font-size: 10px; opacity: .7; font-weight: 500; margin-top: 2px; }
.source-buttons button.EAGLE.current { background: var(--eagle); color: white; border-color: var(--eagle); }
.source-buttons button.LOCAL_LIVE.current { background: var(--live); color: white; border-color: var(--live); }
.source-buttons button.LOCAL_AUTOMATION.current { background: var(--automation); color: white; border-color: var(--automation); }
.source-buttons button.FALLBACK.current { background: var(--fallback); color: white; border-color: var(--fallback); }
.source-buttons button.LOCAL_LIVE { border-width: 2px; border-color: var(--live); }
.auto-row { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--panel-border); }
.eagle-recovery-bar { margin-top: 10px; }
.eagle-recovery-bar .track { height: 8px; background: #e2e6ec; border-radius: 4px; overflow: hidden; }
.eagle-recovery-bar .fill { height: 100%; background: var(--ok); }

/* Queue */

.queue-panel { grid-column: 1; grid-row: 2; }
.queue-list { list-style: none; margin: 0; padding: 0; }
.queue-row {
  display: grid; grid-template-columns: 60px 1fr 70px 90px; gap: 8px; align-items: center;
  padding: 7px 6px; border-bottom: 1px solid #eef0f3; cursor: grab;
}
.queue-row:hover { background: #f7f9fb; }
.queue-row.playing { background: #fef3e2; }
.queue-row .qi-title { font-weight: 600; }
.queue-row .qi-artist { color: var(--text-dim); font-size: 12px; }
.queue-row .qi-dur { font-family: var(--mono); text-align: right; color: var(--text-dim); }
.queue-row .qi-actions { display: flex; gap: 4px; justify-content: flex-end; }
.queue-row .qi-actions button { padding: 3px 6px; font-size: 11px; }
.queue-empty { color: var(--text-faint); font-style: italic; padding: 20px 0; text-align: center; }

/* Cart wall + library */

.lower-panel { grid-column: 2; grid-row: 2; display: flex; flex-direction: column; }
.tab-bar { display: flex; gap: 4px; padding: 8px 10px 0; }
.tab-bar button { padding: 6px 12px; font-size: 12px; border-radius: 4px 4px 0 0; }
.tab-bar button.active { background: var(--bg); border-bottom-color: var(--bg); position: relative; top: 1px; }

.cart-pages { display: flex; gap: 4px; padding: 8px 10px; flex-wrap: wrap; border-bottom: 1px solid var(--panel-border); }
.cart-pages button { padding: 5px 10px; font-size: 11px; }
.cart-pages button.active { background: var(--accent); color: white; border-color: var(--accent); }

.cart-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 10px;
}
.cart-btn {
  aspect-ratio: 2.2 / 1; display: flex; flex-direction: column; justify-content: space-between;
  align-items: flex-start; padding: 8px 10px; text-align: left; color: white; border: none;
  border-radius: 6px; overflow: hidden;
}
.cart-btn .cb-name { font-weight: 800; font-size: 12.5px; line-height: 1.2; }
.cart-btn .cb-meta { font-size: 10px; opacity: .85; font-family: var(--mono); }
.cart-btn.empty { background: #f5f7fa; color: var(--text-faint); border: 1px dashed var(--panel-border); justify-content: center; align-items: center; }
.cart-btn:active { filter: brightness(.85); }

.library-search { padding: 10px; display: flex; gap: 6px; border-bottom: 1px solid var(--panel-border); }
.library-search input { flex: 1; }
.library-results { overflow-y: auto; flex: 1; }
.lib-row {
  display: grid; grid-template-columns: 50px 1fr auto; gap: 8px; align-items: center;
  padding: 7px 10px; border-bottom: 1px solid #eef0f3;
}
.lib-row:hover { background: #f7f9fb; }
.lib-row .lr-title { font-weight: 600; }
.lib-row .lr-artist { color: var(--text-dim); font-size: 12px; }
.lib-row .lr-actions { display: flex; gap: 4px; }
.lib-row .lr-actions button { padding: 4px 7px; font-size: 11px; }

.hidden { display: none !important; }

/* Login page */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg);
}
.login-box {
  background: white; border: 1px solid var(--panel-border); border-radius: 8px; padding: 32px;
  width: 340px; box-shadow: 0 4px 24px rgba(20,30,50,.08);
}
.login-box h1 { font-size: 20px; margin: 0 0 4px; }
.login-box .sub { color: var(--text-dim); font-size: 12px; margin-bottom: 20px; }
.login-box label { display: block; font-size: 12px; font-weight: 600; margin: 12px 0 4px; }
.login-box input { width: 100%; }
.login-box button { width: 100%; margin-top: 18px; padding: 10px; }
.login-error { color: var(--danger); font-size: 12px; margin-top: 10px; min-height: 14px; }

/* Admin */
.admin-shell { padding: 16px; max-width: 1400px; margin: 0 auto; }
.admin-tabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }
.admin-tabs button.active { background: var(--accent); color: white; border-color: var(--accent); }
.admin-section { background: white; border: 1px solid var(--panel-border); border-radius: 8px; padding: 18px; margin-bottom: 16px; }
.admin-section h2 { margin-top: 0; font-size: 16px; }
table.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.admin-table th { text-align: left; padding: 6px 8px; border-bottom: 2px solid var(--panel-border); color: var(--text-dim); font-size: 11px; text-transform: uppercase; }
table.admin-table td { padding: 6px 8px; border-bottom: 1px solid #eef0f3; }
.form-row { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; align-items: center; }
.form-row label { font-size: 12px; font-weight: 600; margin-right: 4px; }
.small { font-size: 11px; color: var(--text-dim); }
.top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.top-bar a { text-decoration: none; font-weight: 700; font-size: 13px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: 10px; font-weight: 700; }
.badge.ADMIN { background: #4a3410; color: #fbbf24; }
.badge.OPERATOR { background: #1c3d2d; color: #6ee7a8; }
.toast {
  position: fixed; bottom: 20px; right: 20px; background: #101828; color: white; padding: 10px 16px;
  border-radius: 6px; font-size: 13px; box-shadow: 0 4px 20px rgba(0,0,0,.25); z-index: 999;
}
