:root {
  --bg-canvas: #F8FAFC;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F1F5F9;
  --bg-hover: #F8FAFC;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #64748B;

  --brand: #0D7A5F;
  --brand-hover: #09624B;
  --brand-tint: #ECFDF5;
  --brand-tint-strong: #D1FAE5;
  --brand-ring: rgba(13, 122, 95, 0.16);

  --success: #059669;
  --success-bg: #ECFDF5;
  --warning: #D97706;
  --warning-bg: #FFFBEB;
  --danger: #DC2626;
  --danger-bg: #FEF2F2;
  --info: #0284C7;
  --info-bg: #F0F9FF;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 45px -12px rgba(15, 23, 42, 0.18), 0 4px 12px rgba(15, 23, 42, 0.06);

  --sidebar-w: 254px;
  --topbar-h: 60px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* Boot loader */
.boot-loader {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
}

.spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Login Page */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 900px 420px at 50% -10%, rgba(13, 122, 95, 0.09), transparent 70%),
    var(--bg-canvas);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 34px 32px 30px;
  box-shadow: var(--shadow-sm);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 26px;
  text-align: center;
}

.login-logo {
  height: 44px;
  width: auto;
  max-width: 200px;
  object-fit: contain;
  display: block;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* App Shell */
.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  height: var(--topbar-h);
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-logo {
  height: 30px;
  width: auto;
  max-width: 130px;
  object-fit: contain;
  display: block;
}

.brand-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
}

.brand-tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-tint);
  padding: 2px 7px;
  border-radius: 999px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.nav-group-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0 10px 6px;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background 0.14s ease, color 0.14s ease;
}

.nav-item svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  opacity: 0.78;
}

.nav-item:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--brand-tint);
  color: var(--brand);
  font-weight: 600;
}

.nav-item.active svg {
  opacity: 1;
  color: var(--brand);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}

.user-pill {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: var(--radius-md);
  background: var(--bg-canvas);
  border: 1px solid var(--border);
}

.user-pill-top {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-pill-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.user-pill-actions .btn {
  padding: 5px 8px;
  font-size: 12px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-meta {
  min-width: 0;
  flex: 1;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Main Content */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mobile-menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  cursor: pointer;
  color: var(--text-primary);
}

.page-title-block h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

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

.tenant-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px 10px;
}

.tenant-switcher label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.tenant-switcher select {
  border: none;
  background: transparent;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  padding: 2px 4px;
}

.content {
  padding: 24px;
  max-width: 1360px;
  width: 100%;
  margin: 0 auto;
}

/* Page header & action bar */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.page-desc {
  color: var(--text-secondary);
  font-size: 13.5px;
  margin: 2px 0 0;
}

/* Cards & Grids */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.two-col-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 16px;
}

.kpi-grid > *,
.two-col-grid > *,
.card-grid > * {
  min-width: 0;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  min-width: 0;
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
}

.card-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
}

.card-body {
  padding: 18px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
}

.kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--brand-tint);
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-icon svg { width: 17px; height: 17px; }

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.kpi-foot {
  font-size: 12px;
  color: var(--text-muted);
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  padding: 11px 16px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

.mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.tabular { font-variant-numeric: tabular-nums; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--bg-subtle); color: var(--text-secondary); }
.badge-brand { background: var(--brand-tint); color: var(--brand); }

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.online {
  background: #10B981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
  animation: pulse-dot 2.2s infinite;
}

.status-dot.offline { background: #94A3B8; }

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.24); }
  50% { box-shadow: 0 0 0 5px rgba(16, 185, 129, 0.08); }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 13.5px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.14s ease;
  white-space: nowrap;
  text-decoration: none;
}

.btn svg { width: 15px; height: 15px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

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

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-subtle); border-color: var(--border-strong); }

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: #FECACA;
}
.btn-danger:hover:not(:disabled) { background: #FEE2E2; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 9px;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-subtle); color: var(--text-primary); }

.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: var(--radius-sm); }

.btn-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group.full { grid-column: 1 / -1; }

.form-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

.input, .select {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.input:focus, .select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

.input:disabled {
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 13.5px;
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
}

/* Filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}

.filter-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 150px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  animation: fadeIn 0.15s ease;
}

.modal {
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.16s ease;
}

.modal.modal-lg { max-width: 760px; }

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-canvas);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

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

/* Toasts */
.toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text-primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideUp 0.16s ease;
}

.toast.toast-success { background: #065F46; }
.toast.toast-error { background: #991B1B; }

/* Alert banner */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid transparent;
}

.alert-info { background: var(--info-bg); color: #075985; border-color: #BAE6FD; }
.alert-warning { background: var(--warning-bg); color: #92400E; border-color: #FDE68A; }

/* Visual components: SVG Chart, Day Toggles, Audio Player, Pagination */
.chart-wrap {
  width: 100%;
  height: 215px;
}

.day-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.day-pill {
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.day-pill.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.member-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.member-chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  background: var(--bg-surface);
}

.member-chip-toggle input { accent-color: var(--brand); }

.audio-mini {
  height: 30px;
  max-width: 220px;
}

.pagination {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
}

.empty-state {
  padding: 42px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state p { margin: 6px 0 0; font-size: 13.5px; }

.cred-box {
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: grid;
  grid-template-columns: 120px 1fr auto;
  gap: 10px 12px;
  align-items: center;
}

.cred-key {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.ivr-row {
  display: grid;
  grid-template-columns: 70px 150px 1fr 38px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.flow-arrow {
  color: var(--text-muted);
  margin: 0 6px;
}

/* Mobile Responsive */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 35;
}

@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main-wrap { margin-left: 0; }
  .mobile-menu-btn { display: inline-flex; }
  .form-grid { grid-template-columns: 1fr; }
  .ivr-row { grid-template-columns: 60px 1fr; }
}
