/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --brand: #9f1127; --brand-dark: #7d0e1f; --brand-light: #fdf2f4;
  --bg: #f8f9fb; --surface: #fff; --border: #e5e7eb;
  --text: #111827; --text-secondary: #6b7280; --text-muted: #9ca3af;
  --green: #10b981; --green-bg: #ecfdf5; --red: #ef4444; --red-bg: #fef2f2;
  --yellow: #f59e0b; --yellow-bg: #fffbeb; --blue: #3b82f6; --blue-bg: #eff6ff;
  --sidebar-w: 260px; --header-h: 56px;
  --radius: 8px; --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.1);
}
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ── Login Screen ── */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(135deg, #fdf2f4 0%, #f0f4ff 100%);
}
.login-box {
  background: var(--surface); border-radius: var(--radius-lg); padding: 40px;
  width: 400px; max-width: 90vw; box-shadow: var(--shadow-lg); text-align: center;
}
.login-box h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.login-box .subtitle { color: var(--text-secondary); margin-bottom: 28px; font-size: 14px; }
.login-box .logo { font-size: 36px; margin-bottom: 16px; display: block; }
.login-box input {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 16px; font-size: 14px; outline: none; transition: border .2s;
}
.login-box input:focus { border-color: var(--brand); }
.login-box .btn-login {
  width: 100%; padding: 10px; background: var(--brand); color: #fff; border: none;
  border-radius: var(--radius); font-weight: 600; font-size: 14px; transition: background .2s;
}
.login-box .btn-login:hover { background: var(--brand-dark); }
.login-box .error { color: var(--red); font-size: 13px; margin-top: 8px; display: none; }

/* ── App Shell ── */
#app { display: none; }
#app.active { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w); background: var(--text); color: #fff; position: fixed;
  top: 0; left: 0; bottom: 0; z-index: 100; display: flex; flex-direction: column;
  transition: transform .3s;
}
.sidebar-header {
  padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-header h2 { font-size: 16px; font-weight: 700; }
.sidebar-header .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }
.nav-section { padding: 0 12px; margin-bottom: 8px; }
.nav-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: rgba(255,255,255,.4); padding: 8px 8px 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 6px;
  color: rgba(255,255,255,.7); font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all .15s; text-decoration: none;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item .badge { margin-left: auto; background: var(--brand); padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.nav-item.active .badge { background: rgba(255,255,255,.2); }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-footer .btn-logout {
  width: 100%; padding: 8px; background: rgba(255,255,255,.1); color: rgba(255,255,255,.7);
  border: none; border-radius: 6px; font-size: 13px; font-weight: 500; transition: all .15s;
}
.sidebar-footer .btn-logout:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ── Main Content ── */
.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; }
.main-header {
  height: var(--header-h); background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 28px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.main-header h1 { font-size: 18px; font-weight: 700; }
.main-header .header-actions { display: flex; align-items: center; gap: 12px; }
.main-content { padding: 24px 28px; }

/* ── Cards & Components ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; margin-bottom: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-header h3 { font-size: 15px; font-weight: 600; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.stat-card .label { font-size: 12px; font-weight: 500; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 8px; }
.stat-card .value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-card .change { font-size: 12px; margin-top: 6px; font-weight: 500; }
.stat-card .change.up { color: var(--green); }
.stat-card .change.down { color: var(--red); }
.stat-card .icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.stat-card .icon.green { background: var(--green-bg); color: var(--green); }
.stat-card .icon.blue { background: var(--blue-bg); color: var(--blue); }
.stat-card .icon.yellow { background: var(--yellow-bg); color: var(--yellow); }
.stat-card .icon.red { background: var(--red-bg); color: var(--red); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .03em; padding: 10px 14px; border-bottom: 2px solid var(--border); }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
tr:hover td { background: var(--bg); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
  border-radius: var(--radius); font-weight: 500; font-size: 13px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); transition: all .15s;
}
.btn:hover { border-color: #d1d5db; box-shadow: var(--shadow); text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }
.btn svg, .toolbar svg { width: 16px; height: 16px; flex-shrink: 0; }
h3 svg, h4 svg { width: 20px; height: 20px; flex-shrink: 0; display: inline-block; vertical-align: middle; }

/* ── Badges ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-gray { background: #f3f4f6; color: var(--text-secondary); }

/* ── Form Elements ── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.form-control {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  outline: none; transition: border .2s;
}
.form-control:focus { border-color: var(--brand); }
select.form-control { cursor: pointer; }

/* ── Search Bar ── */
.search-bar {
  display: flex; align-items: center; gap: 8px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 12px;
}
.search-bar input { border: none; background: none; outline: none; flex: 1; font-size: 13px; }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; }
.pagination .info { font-size: 13px; color: var(--text-secondary); }
.pagination .pages { display: flex; gap: 4px; }
.pagination .page-btn {
  width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); display: flex; align-items: center; justify-content: center;
  font-size: 13px; cursor: pointer; transition: all .15s;
}
.pagination .page-btn:hover { border-color: var(--brand); }
.pagination .page-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ── Spinner ── */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-state { display: flex; align-items: center; justify-content: center; padding: 60px; flex-direction: column; gap: 12px; color: var(--text-secondary); }

/* ── Empty State ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-secondary); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .4; }
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 4px; }

/* ── Tabs ── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 16px; font-size: 13px; font-weight: 500; color: var(--text-secondary);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ── Toolbar ── */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

/* ── Score Bar ── */
.score-bar { width: 100px; height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; }
.score-bar .fill { height: 100%; border-radius: 3px; transition: width .3s; }
.score-bar .fill.green { background: var(--green); }
.score-bar .fill.yellow { background: var(--yellow); }
.score-bar .fill.red { background: var(--red); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); padding: 24px;
  width: 560px; max-width: 90vw; max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal h2 { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ── Toast ── */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; box-shadow: var(--shadow-lg); font-size: 13px; min-width: 280px;
  display: flex; align-items: center; gap: 8px; animation: slideIn .3s;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--blue); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } }

/* ── Progress ── */
.progress-bar { width: 100%; height: 8px; background: #e5e7eb; border-radius: 4px; overflow: hidden; }
.progress-bar .fill { height: 100%; background: var(--brand); border-radius: 4px; transition: width .3s; }

/* ── Modal (progress + confirm) ── */
.mux-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
  z-index: 500; display: flex; align-items: center; justify-content: center;
  padding: 24px; animation: fadeIn .15s;
}
.mux-modal {
  background: var(--surface); border-radius: 10px; box-shadow: 0 30px 80px rgba(0,0,0,.35);
  max-width: 560px; width: 100%; max-height: 85vh; display: flex; flex-direction: column;
  animation: modalIn .2s;
}
.mux-modal.wide { max-width: 760px; }
.mux-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.mux-modal-head h3 { margin: 0; font-size: 15px; }
.mux-modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); padding: 0 4px; }
.mux-modal-body { padding: 18px 20px; overflow: auto; }
.mux-modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.mux-btn { padding: 8px 16px; border-radius: 6px; font-size: 13px; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 500; }
.mux-btn:hover { background: #f9fafb; }
.mux-btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.mux-btn.primary:hover { background: var(--brand-dark, #7d0e1f); }
.mux-btn.danger { background: #ef4444; color: #fff; border-color: #ef4444; }
.mux-btn.danger:hover { background: #dc2626; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px); } }

/* ── Progress steps + log ── */
.mux-steps { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.mux-step { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.mux-step-dot { width: 18px; height: 18px; border-radius: 50%; background: #e5e7eb; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; color: #fff; flex-shrink: 0; }
.mux-step.active .mux-step-dot { background: var(--brand); animation: pulse 1.2s infinite; }
.mux-step.done .mux-step-dot { background: var(--green); }
.mux-step.done .mux-step-dot::after { content: '✓'; }
.mux-step.error .mux-step-dot { background: var(--red); }
.mux-step.error .mux-step-dot::after { content: '!'; }
.mux-step-label { flex: 1; }
.mux-step-meta { color: var(--text-muted); font-size: 11px; }
.mux-log { background: #0f172a; color: #cbd5e1; font-family: ui-monospace, monospace; font-size: 11px; padding: 12px; border-radius: 6px; max-height: 200px; overflow-y: auto; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.mux-log .log-time { color: #64748b; margin-right: 8px; }
.mux-log .log-err { color: #f87171; }
.mux-log .log-ok { color: #4ade80; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(159, 17, 39, .4); } 50% { box-shadow: 0 0 0 6px rgba(159, 17, 39, 0); } }

/* ── Sticky / actionable toast extensions ── */
.toast.sticky { padding-right: 32px; }
.toast-dismiss { position: absolute; top: 4px; right: 8px; background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; }
.toast { position: relative; }
.toast-action { margin-left: 8px; color: var(--brand); text-decoration: underline; cursor: pointer; font-weight: 500; }
.toast-detail { margin-top: 6px; font-size: 11px; color: var(--text-muted); max-width: 320px; }

/* ── Top-bar activity badge ── */
.activity-badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; background: #f3f4f6; border: 1px solid var(--border); border-radius: 16px; font-size: 12px; cursor: pointer; transition: all .15s; }
.activity-badge:hover { background: #e5e7eb; }
.activity-badge.busy { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.activity-badge.busy .activity-pulse { width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; animation: pulse 1.2s infinite; }
.activity-badge .activity-dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.activity-drawer { position: fixed; top: 60px; right: 16px; width: 420px; max-height: 70vh; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.25); z-index: 250; display: flex; flex-direction: column; animation: modalIn .2s; }
.activity-drawer-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.activity-drawer-body { padding: 8px; overflow-y: auto; }
.activity-item { padding: 10px 12px; border-radius: 6px; margin-bottom: 6px; background: #f9fafb; font-size: 13px; }
.activity-item:hover { background: #f3f4f6; }
.activity-item .kind { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.activity-item .label { font-weight: 500; margin-top: 2px; }
.activity-item .bar { margin-top: 6px; height: 4px; background: #e5e7eb; border-radius: 2px; overflow: hidden; }
.activity-item .bar .fill { height: 100%; background: var(--brand); transition: width .3s; }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr; }
  .main-content { padding: 16px; }
}