/* ----------------------------------------------------------------
   MediaGate PBX Admin — stylesheet
   ---------------------------------------------------------------- */

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

:root {
  --navy:    #1a2438;
  --blue:    #2563eb;
  --blue-dk: #1d4ed8;
  --green:   #16a34a;
  --red:     #dc2626;
  --orange:  #d97706;
  --gray-50: #f8fafc;
  --gray-100:#f1f5f9;
  --gray-200:#e2e8f0;
  --gray-400:#94a3b8;
  --gray-600:#475569;
  --gray-800:#1e293b;
  --white:   #ffffff;
  --radius:  6px;
  --shadow:  0 1px 3px rgba(0,0,0,.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-100);
  line-height: 1.5;
  scrollbar-gutter: stable;
}

/* ---- Top nav ---- */
.topnav {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--navy);
  color: var(--white);
  height: 52px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.topnav-brand { font-size: 16px; font-weight: 700; letter-spacing: .5px; margin-right: 32px; }
.brand-icon { margin-right: 8px; }
.topnav-links { display: flex; gap: 4px; flex: 1; }
.topnav-links a {
  color: rgba(255,255,255,.75);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: var(--radius);
  transition: background .15s;
}
.topnav-links a:hover { background: rgba(255,255,255,.1); color: var(--white); }
.topnav-links a.active { background: rgba(255,255,255,.18); color: var(--white); font-weight: 600; }
.topnav-user { display: flex; align-items: center; gap: 12px; }
.user-badge { font-size: 13px; color: rgba(255,255,255,.7); }
.btn-link {
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,.6); font-size: 13px; padding: 0;
}
.btn-link:hover { color: var(--white); text-decoration: underline; }

/* ---- Main content ---- */
.main-content { padding: 24px; max-width: 1200px; margin: 0 auto; }

/* ---- Page header ---- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h2 { font-size: 22px; font-weight: 700; color: var(--gray-800); }

/* ---- Cards ---- */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-200);
}
.card-header h3 { font-size: 16px; font-weight: 600; }
.mb-4 { margin-bottom: 20px; }
.mt-3 { margin-top: 12px; }

/* ---- Tables ---- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}
.table th { font-weight: 600; color: var(--gray-600); font-size: 12px; text-transform: uppercase; background: var(--gray-50); }
.table tbody tr:hover { background: var(--gray-50); }
.table tbody tr:last-child td { border-bottom: none; }
.row-muted { opacity: 0.55; }
.row-on-shift { background: #f0fdf4; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.totals-row td { background: var(--gray-50); font-weight: 600; border-top: 2px solid var(--gray-200); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: opacity .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { opacity: .88; }
.btn-primary  { background: var(--blue);   color: var(--white); }
.btn-success  { background: var(--green);  color: var(--white); }
.btn-danger   { background: var(--red);    color: var(--white); }
.btn-warning  { background: var(--orange); color: var(--white); }
.btn-secondary{ background: var(--gray-200); color: var(--gray-800); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* Icon-only action button (compact, square; pairs with table row actions). */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--gray-600);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  text-decoration: none;
}
.btn-icon svg { width: 16px; height: 16px; display: block; }
.btn-icon:hover { background: var(--gray-100); color: var(--gray-800); border-color: var(--gray-200); }
.btn-icon-danger:hover { background: #fee2e2; color: var(--red); border-color: #fecaca; }

/* Inline action cluster (small icon buttons sit side-by-side, no stacking). */
.actions-inline { white-space: nowrap; text-align: right; }
.actions-inline > * { vertical-align: middle; }
.actions-inline form { display: inline-block; margin: 0; }
.actions-inline .btn-icon + .btn-icon,
.actions-inline form + form,
.actions-inline form + .btn-icon,
.actions-inline .btn-icon + form { margin-left: 4px; }

/* ---- Forms ---- */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }
.form-group label { font-weight: 500; font-size: 13px; color: var(--gray-600); }
.form-control {
  padding: 8px 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  width: 100%;
  background: var(--white);
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.form-row { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 160px; }
.form-check { flex-direction: row; align-items: center; gap: 8px; }
.form-hint { font-size: 12px; color: var(--gray-400); }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.required { color: var(--red); }

/* ---- Flash messages ---- */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 500;
}
.flash ul { margin: 0; padding-left: 18px; }
.flash-success { background: #dcfce7; color: #14532d; border: 1px solid #86efac; }
.flash-error   { background: #fee2e2; color: #7f1d1d; border: 1px solid #fca5a5; }
.flash-warning { background: #fef9c3; color: #713f12; border: 1px solid #fde047; }

/* ---- Inline alert boxes (form errors) ---- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 13px;
}
.alert-error,
.alert-danger  { background: #fee2e2; color: #7f1d1d; border: 1px solid #fca5a5; }
.alert-warning { background: #fef9c3; color: #713f12; border: 1px solid #fde047; }
.alert-success { background: #dcfce7; color: #14532d; border: 1px solid #86efac; }

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.badge-primary   { background: #dbeafe; color: #1e40af; }
.badge-success   { background: #dcfce7; color: #14532d; }
.badge-secondary { background: var(--gray-200); color: var(--gray-600); }
.badge-default   { background: #f3f4f6; color: #374151; }
.badge-info      { background: #e0f2fe; color: #075985; margin-right: 6px; padding: 4px 10px; }

/* ---- Stats grid (dashboard) ---- */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat-box {
  text-align: center;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
}
.stat-green { border-color: #86efac; background: #f0fdf4; }
.stat-red   { border-color: #fca5a5; background: #fef2f2; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--gray-800); }
.stat-label { font-size: 12px; color: var(--gray-600); margin-top: 4px; }
.queue-breakdown { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- AMI status ---- */
.ami-status { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 12px; }
.ami-ok  { background: #dcfce7; color: #14532d; }
.ami-err { background: #fee2e2; color: #7f1d1d; }

/* ---- Audit log ---- */
.audit-action {
  font-family: monospace;
  font-size: 12px;
  background: var(--gray-100);
  padding: 1px 6px;
  border-radius: 3px;
  color: var(--gray-800);
}
.audit-ts { font-family: monospace; font-size: 12px; color: var(--gray-600); }
.audit-details summary { cursor: pointer; font-size: 12px; color: var(--gray-600); }
.audit-details summary:hover { color: var(--gray-800); }
.audit-details pre {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  padding: 6px 8px;
  margin-top: 4px;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
}

/* ---- Payroll drill-down modal ---- */
.payroll-drill-link { color: var(--blue); text-decoration: none; font-weight: 500; }
.payroll-drill-link:hover { text-decoration: underline; }
.payroll-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 24px;
}
.payroll-modal {
  background: var(--white);
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.payroll-modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--gray-200);
  font-size: 15px;
}
.payroll-modal-month { color: var(--gray-400); font-size: 13px; }
.payroll-modal-close {
  margin-left: auto;
  background: none; border: none; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--gray-400);
  width: 32px; height: 32px; border-radius: 6px;
}
.payroll-modal-close:hover { background: var(--gray-100); color: var(--gray-800); }
.payroll-modal-body { overflow-y: auto; padding: 14px 18px; flex: 1; }
.payroll-modal-loading { padding: 30px; text-align: center; color: var(--gray-400); }
.payroll-detail-table { font-size: 13px; }

/* Contact-detail modal layout (reuses .payroll-modal* base). */
.contact-modal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 13px;
}
.contact-modal-label {
  flex-shrink: 0;
  width: 80px;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-400);
  text-transform: uppercase;
}
.contact-modal-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  text-decoration: none;
  font-size: 14px;
  color: var(--gray-600);
  background: var(--gray-100);
}
.contact-modal-action:hover { background: var(--gray-200); }
.contact-modal-related {
  margin: 6px 0 0 4px;
  list-style: none;
}
.contact-modal-related li {
  padding: 3px 0;
  font-size: 13px;
}
.contact-name-link {
  color: var(--gray-800);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px dotted var(--gray-400);
}
.contact-name-link:hover { color: var(--blue); border-bottom-color: var(--blue); }

/* ---- Agent queue-membership warning ---- */
.agent-queue-warn {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: #b45309;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 6px;
  cursor: help;
}

/* ---- System health bar ---- */
[x-cloak] { display: none !important; }

.health-bar {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
  border-left: 4px solid var(--gray-200);
}
.health-bar.health-ok   { border-left-color: var(--green); }
.health-bar.health-warn { border-left-color: var(--orange); }
.health-bar.health-crit { border-left-color: var(--red); }

.health-bar-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: none;
  border: 0;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  color: var(--gray-800);
}
.health-bar-toggle:hover { background: var(--gray-50); }

.health-bar-summary { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.health-bar-summary .health-bar-label { font-size: 11px; color: var(--gray-600); margin-right: 6px; }
.health-bar-overall { flex: 1; font-weight: 500; color: var(--gray-600); }
.health-bar-chevron { font-size: 12px; color: var(--gray-400); flex-shrink: 0; }

.health-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gray-200);
  flex-shrink: 0;
}
.health-dot.health-ok   { background: #16a34a; }
.health-dot.health-warn { background: #d97706; }
.health-dot.health-crit { background: #dc2626; }

.health-bar-detail {
  border-top: 1px solid var(--gray-200);
  padding: 4px 0;
}
.health-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  font-size: 13px;
}
.health-row + .health-row { border-top: 1px solid var(--gray-100); }
.health-row-label { font-weight: 600; flex-shrink: 0; min-width: 140px; }
.health-row-detail { color: var(--gray-600); flex: 1; }
.health-row-warn { background: #fffbeb; }
.health-row-crit { background: #fef2f2; }

/* ---- Empty state ---- */
.empty-state { color: var(--gray-400); padding: 24px; text-align: center; font-style: italic; }

/* ---- Actions cell ---- */
.actions { white-space: nowrap; }

/* ---- Pagination ---- */
.pagination { display: flex; gap: 4px; padding: 16px; justify-content: center; }
.pagination a {
  padding: 5px 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--blue);
  font-size: 13px;
}
.pagination a.current { background: var(--blue); color: var(--white); border-color: var(--blue); }

/* ---- Login ---- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--navy); }
.login-card {
  background: var(--white);
  border-radius: 10px;
  padding: 40px;
  width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,.35);
}
.login-header { text-align: center; margin-bottom: 28px; }
.login-icon { font-size: 40px; display: block; margin-bottom: 8px; }
.login-header h1 { font-size: 22px; font-weight: 700; color: var(--navy); }
.login-header p  { color: var(--gray-400); font-size: 13px; margin-top: 4px; }

/* ---- Agent live table ---- */
.agent-live-table {
  table-layout: fixed;
}
.agent-live-table th {
  font-size: 11px;
  letter-spacing: .5px;
  overflow: hidden;
}
.agent-live-table td {
  overflow: hidden;
}

.agent-name-cell {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
}
.agent-name-cell strong { font-size: 14px; line-height: 1.3; }
.agent-ext { font-size: 12px; color: var(--gray-400); line-height: 1; }

/* Row tints for live states */
.row-on-shift { background: #f8fffe; }
.row-ring     { background: #fffbeb; }
.row-busy     { background: #fff5f5; }

/* Status badge */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  border: 1px solid transparent;
}
.status-ready { background: #dcfce7; color: #15803d; border-color: #86efac; }
.status-ring  { background: #fef9c3; color: #b45309; border-color: #fde68a; }
.status-busy  { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }
.status-off   { background: var(--gray-100); color: var(--gray-400); border-color: var(--gray-200); }

.status-cell  { white-space: nowrap; }

.shift-time-detail {
  margin-top: 3px;
  font-size: 11px;
  color: var(--gray-400);
  line-height: 1.4;
}

/* Last caller link */
.last-caller-cell { white-space: nowrap; }
.caller-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
}
.caller-link:hover { text-decoration: underline; }

/* Start / Stop action buttons */
.btn-outline-action {
  background: transparent;
  border: 1px solid var(--gray-400);
  color: var(--gray-800);
  padding: 5px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-outline-action:hover { background: var(--gray-100); border-color: var(--gray-600); }

.btn-stop {
  background: transparent;
  border: 1px solid var(--red);
  color: var(--red);
  padding: 5px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn-stop:hover { background: #fee2e2; }

/* ---- Tab bar (shared across all sub-menus) ---- */
.tab-bar {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: 20px;
}
.tab-item {
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-600);
  text-decoration: none;
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  transition: background .12s, color .12s;
}
.tab-item:hover { background: var(--gray-50); color: var(--gray-800); }
.tab-item.active {
  background: var(--white);
  color: var(--blue);
  font-weight: 600;
  border-color: var(--gray-200);
  border-bottom: 2px solid var(--white);
  margin-bottom: -2px;
}

/* ---- Directory ---- */
.dir-group-icon { font-size: 14px; color: var(--gray-400); }
.dir-group-tag {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .3px; color: var(--blue);
  background: #eff6ff; border-radius: 4px; padding: 1px 6px;
}
.dir-company-notes {
  font-size: 13px; color: var(--gray-500);
  padding: 4px 16px 8px; margin: 0;
}
.dir-member-row td { padding-left: 24px; }
.text-muted { color: var(--gray-400); font-size: 13px; }
.dir-company-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.dir-company-name { display: flex; align-items: center; gap: 10px; }
.dir-contact-count {
  font-size: 12px;
  color: var(--gray-400);
  font-weight: 400;
}
.dir-company-actions { display: flex; gap: 6px; }

/* ---- Search bar ---- */
.search-bar { display: flex; gap: 8px; padding: 12px 16px; }
.search-bar .form-control { flex: 1; }

/* ---- Table actions cell ---- */
.table-actions { white-space: nowrap; text-align: right; }

/* ---- Sortable column headers ---- */
.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
.sort-link:hover { color: var(--blue); }
.sort-active { color: var(--gray-800); }

/* ---- Nav badge (unread count) ---- */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 4px;
  background: var(--red);
  color: var(--white);
  font-size: 10px;
  font-weight: 700;
  border-radius: 9px;
  line-height: 1;
}

@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { flex-direction: column; }
  .topnav-links a { padding: 6px 8px; font-size: 13px; }
  .agent-live-table { font-size: 12px; }
  .agent-live-table th, .agent-live-table td { padding: 8px 6px; }
}
