:root {
  --brand-deep: #881337;
  --brand-mid: #be123c;
  --brand-bright: #e11d48;
  --bg: #f4f2f3;
  --surface: #ffffff;
  --surface-soft: #faf9fa;
  --border: #ece8ea;
  --text: #1a1d21;
  --muted: #6b7280;
  --ok: #16a34a;
  --warn: #ea580c;
  --err: #be123c;
  --shadow: 0 1px 3px rgba(136, 19, 55, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 8px 24px rgba(190, 18, 60, 0.12);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
}
.hidden { display: none !important; }
.center { text-align: center; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.brand-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-bright), var(--brand-deep));
  display: inline-block; flex: 0 0 auto;
  box-shadow: 0 0 0 4px rgba(225, 29, 72, 0.12);
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #fff1f2, var(--bg));
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; padding: 28px;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 14px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-brand h1 { font-size: 18px; margin: 0; }
.login-brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.login-card input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; outline: none; background: var(--surface-soft);
}
.login-card input:focus { border-color: var(--brand-bright); background: #fff; }
.login-error { color: var(--err); font-size: 13px; background: #fff1f2; padding: 8px 10px; border-radius: 8px; }

/* ---------- Buttons ---------- */
button { font: inherit; cursor: pointer; border-radius: 10px; }
.btn-primary, #login-btn {
  background: linear-gradient(135deg, var(--brand-bright), var(--brand-mid));
  color: #fff; border: none; padding: 10px 16px; font-weight: 600;
}
.btn-primary:hover, #login-btn:hover { filter: brightness(1.05); }
.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 8px 14px;
}
.btn-ghost:hover { background: var(--surface-soft); }
button:disabled { opacity: 0.6; cursor: default; }

/* ---------- App shell (sidebar + main) ---------- */
.layout { display: flex; height: 100vh; overflow: hidden; }

/* ---------- Sidebar ---------- */
.sidebar {
  flex: 0 0 auto; width: 234px;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px;
  font-weight: 700; letter-spacing: 0.01em; font-size: 15px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1 1 auto; }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 10px 12px; border: none; background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 600; border-radius: 10px; text-align: left;
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 auto; }
.nav-item:hover { background: var(--surface-soft); color: var(--text); }
.nav-item.active {
  background: var(--brand-rose-soft, #fff1f2); color: var(--brand-mid);
}
.sidebar-footer { flex: 0 0 auto; border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 2px 6px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--brand-bright), var(--brand-deep)); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.user-label { color: var(--text); font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-block { width: 100%; }

/* ---------- Main ---------- */
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.main-header {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.main-header h1 { font-size: 18px; margin: 0; font-weight: 700; }

.module { flex: 1 1 auto; min-height: 0; }
.module-scroll { overflow: auto; padding: 22px 24px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 0 0 12px; font-weight: 700; }
.module-scroll .section-title:not(:first-child) { margin-top: 26px; }

/* ---------- Workflows module layout ---------- */
.module-workflows .table-wrap { margin-top: 0; }

/* ---------- Dialers module layout ---------- */
.module-dialers { display: flex; flex-direction: column; overflow: hidden; padding: 18px 24px 0; }
.dialers-body { flex: 1 1 auto; min-height: 0; overflow: auto; }
.module-dialers .dialer-cards { margin-bottom: 12px; }

/* ---------- Users module ---------- */
/* .users-panel { max-width: 1100px; } */
.users-panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px;
}
.users-panel-head .section-title { margin: 0; }
.user-modal-form { display: flex; flex-direction: column; gap: 14px; }
.user-modal-form label {
  display: flex; flex-direction: column; gap: 5px; font-size: 11px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em;
}
.user-modal-form input {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-soft); font-size: 13px; text-transform: none; font-weight: 400; color: var(--text);
}
.user-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.modal-sm { max-width: 420px; width: 100%; }
.form-msg { font-size: 13px; font-weight: 600; }
.form-msg.ok { color: var(--ok); }
.form-msg.err { color: var(--err); }
.cron-panel-modal { border: none; box-shadow: none; padding: 0; margin: 0; }

/* ---------- Recordings module layout ---------- */
.module-recordings { display: flex; flex-direction: column; overflow: hidden; }
.rec-controls { flex: 0 0 auto; padding: 18px 24px 0; }
.module-recordings .table-wrap { margin: 0 24px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px;
}
.stat-card .stat-icon {
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-rose-soft, #fff1f2); color: var(--brand-mid);
}
.stat-card .stat-icon svg { width: 20px; height: 20px; }
.stat-card .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.stat-card .value { font-size: 26px; font-weight: 700; line-height: 1; color: var(--text); }

/* ---------- Filters ---------- */
.filters {
  flex: 0 0 auto;
  display: flex; flex-direction: column; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.filters-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.filters-row-top { align-items: flex-end; }
.filters-row-top .filter-search { flex: 1 1 320px; }
.filters-row-top .filter-actions { margin-left: auto; }
.filter-field { display: flex; flex-direction: column; gap: 5px; }
.filter-field label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.filter-field input, .filter-field select {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-soft); outline: none; min-width: 160px; font-size: 13px;
}
.filter-search input { width: 100%; }
.filter-field input:focus, .filter-field select:focus { border-color: var(--brand-bright); background: #fff; }
.filter-actions { display: flex; gap: 8px; }

/* ---------- Table (scrollable body) ---------- */
.table-wrap {
  flex: 1 1 auto; min-height: 0; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); padding: 11px 12px; border-bottom: 1px solid var(--border); background: var(--surface-soft);
  white-space: nowrap; position: sticky; top: 0; z-index: 2;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fffafb; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--surface-soft); border: 1px solid var(--border); color: var(--muted); white-space: nowrap;
}
.badge.completed { background: #f0fdf4; color: var(--ok); border-color: #bbf7d0; }
.badge.queued { background: #eff6ff; color: #2563eb; border-color: #bfdbfe; }
.badge.processing { background: #fff7ed; color: var(--warn); border-color: #fed7aa; }
.badge.failed { background: #fff1f2; color: var(--err); border-color: #fecdd3; }
.badge.skipped { background: #f8fafc; color: #64748b; border-color: #e2e8f0; }
.badge.running { background: #fff7ed; color: var(--warn); border-color: #fed7aa; }

.disp { font-weight: 600; }
.link { color: var(--brand-mid); text-decoration: none; font-weight: 600; background: none; border: none; padding: 0; }
.link:hover { text-decoration: underline; }

/* ---------- Player ---------- */
.btn-play {
  width: 34px; height: 34px; border-radius: 50%; border: none; color: #fff;
  background: linear-gradient(135deg, var(--brand-bright), var(--brand-mid));
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px;
}
.btn-play:hover { filter: brightness(1.08); }
.btn-play.disabled { background: #cbd5e1; cursor: default; }
.row-player { display: flex; align-items: center; gap: 8px; }
.row-player audio { height: 34px; max-width: 230px; }

.detail-action { text-align: right; }

/* ---------- Pagination (fixed footer) ---------- */
.pagination-bar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-block: 12px;
  padding-inline: max(24px, calc((100% - 1320px) / 2 + 24px));
  background: var(--surface); border-top: 1px solid var(--border);
}
.pg-info { color: var(--muted); font-size: 13px; flex: 0 0 auto; }
.pg-pages { display: flex; align-items: center; justify-content: center; gap: 6px; flex: 1 1 auto; }
.pg-btn {
  min-width: 32px; height: 32px; padding: 0 8px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center;
}
.pg-btn:hover:not(:disabled):not(.active) { background: var(--surface-soft); border-color: var(--brand-rose-mid, #fecdd3); }
.pg-btn.active {
  background: linear-gradient(135deg, var(--brand-bright), var(--brand-mid));
  color: #fff; border-color: transparent; cursor: default;
}
.pg-btn:disabled { opacity: 0.4; cursor: default; }
.pg-ellipsis { color: var(--muted); padding: 0 4px; }
.pg-perpage { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; flex: 0 0 auto; }
.pg-perpage select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: 13px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(26, 29, 33, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: 16px; max-width: 560px; width: 100%;
  box-shadow: var(--shadow-lg); max-height: 90vh; overflow: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; margin: 0; }
.modal-body { padding: 20px; }
.modal-body audio { width: 100%; margin-bottom: 16px; }
.meta-list { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; margin: 0; }
.meta-list dt { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; }
.meta-list dd { margin: 0; font-size: 14px; word-break: break-word; }

/* ---------- Recording URL + copy ---------- */
.url-row {
  display: flex; align-items: stretch; gap: 8px; margin-bottom: 18px;
}
.url-row .url-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 6px; display: block; }
.url-field { flex: 1 1 auto; min-width: 0; }
.url-input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-soft); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text); outline: none;
}
.url-input:focus { border-color: var(--brand-bright); background: #fff; }
.btn-copy {
  flex: 0 0 auto; align-self: flex-end; border: 1px solid var(--brand-rose-mid, #fecdd3);
  background: var(--brand-rose-soft, #fff1f2); color: var(--brand-mid);
  padding: 9px 14px; font-weight: 600; border-radius: 9px;
}
.btn-copy:hover { filter: brightness(0.98); }
.btn-copy.copied { background: #f0fdf4; color: var(--ok); border-color: #bbf7d0; }

.error-banner { background: #fff1f2; color: var(--err); padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid #fecdd3; }

/* ---------- Dashboard: dialer summary ---------- */
.dash-dialers { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.mini-dialer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.mini-dialer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mini-dialer-name { font-weight: 700; }
.mini-dialer-total { font-size: 28px; font-weight: 700; margin-top: 8px; line-height: 1; }
.mini-dialer-sub { color: var(--muted); font-size: 12px; margin-top: 4px; text-transform: capitalize; }

/* ---------- Dashboard: cron status ---------- */
.cron-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 8px;
}
.cron-panel-head {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding-bottom: 16px; border-bottom: 1px solid var(--border); margin-bottom: 16px;
}
.cron-panel-status { display: flex; align-items: center; gap: 10px; }
.cron-panel-sub { color: var(--muted); font-size: 13px; }
.cron-panel-meta { display: flex; flex-direction: column; gap: 4px; font-size: 13px; text-align: right; }
.meta-label {
  display: inline-block; min-width: 88px; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600; margin-right: 6px;
}
.cron-run-summary { margin-bottom: 18px; }
.cron-run-title { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 14px; }
.cron-run-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 16px;
  font-size: 13px; margin-bottom: 14px;
}
.cron-run-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px;
}
.cron-stat {
  background: var(--surface-soft); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 8px; text-align: center;
}
.cron-stat .num { font-size: 20px; font-weight: 700; line-height: 1; }
.cron-stat .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); margin-top: 4px; }
.cron-table-wrap { margin-top: 16px; }
.cron-table-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 8px; font-weight: 700; }
.cron-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cron-table th, .cron-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.cron-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
.cron-empty { margin: 8px 0 0; }
.cron-errors ul { margin: 0; padding-left: 18px; font-size: 13px; color: var(--err); }
.cron-errors li { margin-bottom: 6px; }

/* ---------- Dialers module: cards ---------- */
.dialer-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.dialer-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.dialer-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.dialer-card-name { font-weight: 700; font-size: 15px; }
.dialer-card-id { color: var(--muted); font-size: 12px; margin-top: 2px; }
.dialer-card-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.dialer-card-stats > div { display: flex; flex-direction: column; align-items: center; gap: 2px; background: var(--surface-soft); border-radius: 10px; padding: 10px 4px; }
.dialer-card-stats .num { font-size: 18px; font-weight: 700; }
.dialer-card-stats .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.dialer-card-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--brand-rose-soft, #fff1f2); color: var(--brand-mid); border: 1px solid var(--brand-rose-mid, #fecdd3); }
