:root {
  color-scheme: light;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

body {
  margin: 0;
  background: #f1f5f9;
  color: #0f172a;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

h1 {
  margin-bottom: 6px;
}

.subtitle {
  margin-top: 0;
  color: #64748b;
}

.panel {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.panel.filters-panel {
  position: sticky;
  top: 16px;
  z-index: 10;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

input,
select,
button {
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
  padding: 9px 10px;
}

button {
  background: #2563eb;
  border: none;
  cursor: pointer;
  font-weight: 600;
  color: #ffffff;
}

button:hover {
  background: #1d4ed8;
}

.table-wrapper {
  overflow: auto;
}

.inactive-pkg-details {
  margin-top: 16px;
}

.inactive-pkg-details summary {
  cursor: pointer;
  font-weight: 600;
  color: #475569;
  padding: 8px 0;
}

.inactive-pkg-details summary:hover {
  color: #1d4ed8;
}

.inactive-pkg-details[open] summary {
  margin-bottom: 8px;
}

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

th,
td {
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
  padding: 10px 8px;
  vertical-align: top;
}

th {
  color: #2563eb;
  position: sticky;
  top: 0;
  background: #ffffff;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable:hover {
  color: #1d4ed8;
}

th.sort-asc::after  { content: " ▲"; font-size: 11px; }
th.sort-desc::after { content: " ▼"; font-size: 11px; }

th.price-col,
td.price-col {
  text-align: right;
}

tbody tr:hover {
  background: #eff6ff;
}

tbody tr:nth-child(even) {
  background: #f8fafc;
}

tbody tr:nth-child(even):hover {
  background: #eff6ff;
}

td.body-cell {
  max-width: 280px;
  word-break: break-word;
}

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

.contact-name {
  font-weight: 600;
}

.contact-number {
  color: #64748b;
  font-size: 12px;
}

.expand-btn {
  background: none;
  border: none;
  color: #60a5fa;
  cursor: pointer;
  font-size: 12px;
  padding: 0 4px;
  font-weight: 500;
}

.expand-btn:hover {
  color: #93c5fd;
  background: none;
}

.empty-row {
  text-align: center;
  color: #94a3b8;
  padding: 16px;
}

.table-meta {
  margin-bottom: 12px;
  color: #64748b;
}

/* Status badges */
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-delivered  { background: #14532d; color: #86efac; }
.badge-sent       { background: #172554; color: #93c5fd; }
.badge-received   { background: #1e1b4b; color: #c4b5fd; }
.badge-read       { background: #064e3b; color: #6ee7b7; }
.badge-failed     { background: #450a0a; color: #fca5a5; }
.badge-undelivered { background: #431407; color: #fdba74; }
.badge-queued     { background: #1c1917; color: #d6d3d1; }
.badge-sending    { background: #1e3a5f; color: #7dd3fc; }
.badge-accepted   { background: #1a2e05; color: #a3e635; }
.badge-scheduled  { background: #2e1065; color: #d8b4fe; }
.badge-default    { background: #1f2937; color: #94a3b8; }

.badge-clickable {
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

.status-detail {
  margin-top: 6px;
  font-size: 12px;
  color: #64748b;
  max-width: 260px;
  white-space: normal;
  line-height: 1.5;
}

.status-detail-link {
  display: inline-block;
  margin-top: 4px;
  color: #60a5fa;
  font-weight: 500;
}

.status-detail-link:hover {
  color: #93c5fd;
}

/* Direction */
.direction {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  white-space: nowrap;
}

.direction .arrow {
  font-size: 16px;
  line-height: 1;
}

.direction.inbound  .arrow { color: #86efac; }
.direction.outbound .arrow { color: #93c5fd; }

/* Tabs */
.tabs {
  display: flex;
  gap: 2px;
  margin: 16px 0;
  padding: 0 6px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  /* One row; scrolls sideways on narrow screens instead of wrapping. */
  overflow-x: auto;
  scrollbar-width: thin;
}

/* Base tab button. The admin ☰ menu items also use .tab-btn (for the tab
   switching) and restyle themselves as menu rows. */
.tab-btn {
  white-space: nowrap;
  cursor: pointer;
}

.tabs .tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 11px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: #64748b;
  font-weight: 600;
  font-size: 14px;
}

.tabs .tab-btn:hover {
  background: #f8fafc;
  color: #0f172a;
}

.tabs .tab-btn.active {
  background: transparent;
  border-bottom-color: #2563eb;
  color: #2563eb;
}

.tabs .tab-btn:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: -4px;
  border-radius: 8px;
}

.tab-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Broadcast form */
.broadcast-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.broadcast-grid .span-2 {
  grid-column: 1 / -1;
}

.field-block {
  margin-bottom: 14px;
}

.field-label {
  display: block;
  font-size: 14px;
  margin-bottom: 6px;
}

.checkbox-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
  color: #64748b;
  font-size: 14px;
}

.checkbox-item {
  flex-direction: row !important;
  align-items: center;
  gap: 6px !important;
  font-size: 14px;
  color: #0f172a;
}

.audience-toggle {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.radio-item {
  flex-direction: row !important;
  align-items: center;
  gap: 6px !important;
  font-size: 14px;
  color: #0f172a;
  cursor: pointer;
}

.people-list {
  flex-direction: column;
  flex-wrap: nowrap;
  max-height: 260px;
  overflow-y: auto;
}

.people-list .checkbox-item {
  width: 100%;
}

.hint {
  color: #64748b;
  font-size: 12px;
  font-weight: normal;
}

.hint-note {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

.error-text {
  color: #dc2626;
  font-size: 13px;
  margin-left: 10px;
}

.confirm-row {
  display: flex;
  align-items: end;
  gap: 16px;
  margin-top: 8px;
}

.confirm-row[hidden] {
  display: none;
}

.confirm-row label {
  max-width: 220px;
}

#bc-send-btn {
  white-space: nowrap;
}

button:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

details summary {
  cursor: pointer;
  color: #2563eb;
  font-weight: 600;
  margin-top: 8px;
}

#bc-skipped-list {
  color: #64748b;
  font-size: 13px;
}

.progress-bar {
  height: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: #2563eb;
  transition: width 0.3s ease;
}

/* Secondary button */
.secondary-btn {
  background: #ffffff;
  color: #2563eb;
  border: 1px solid #2563eb;
  font-weight: 600;
}

.secondary-btn:hover {
  background: #eff6ff;
}

/* WhatsApp message preview */
.whatsapp-preview {
  margin-top: 14px;
  max-width: 320px;
}

.whatsapp-preview-frame {
  background: #e5ddd5;
  border-radius: 12px;
  padding: 16px;
}

.whatsapp-bubble {
  background: #dcf8c6;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.whatsapp-preview-image {
  width: 100%;
  display: block;
  border-radius: 6px;
  margin-bottom: 6px;
  background: #f8fafc;
}

.whatsapp-preview-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.4;
  color: #111b21;
  padding: 2px 4px;
}

/* Templates tab */
.tpl-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.tpl-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#tpl-search {
  min-width: 220px;
}

.tpl-name-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tpl-sid {
  color: #64748b;
  font-size: 12px;
  font-family: "Consolas", "Courier New", monospace;
}

.tpl-actions-cell {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.badge-approved     { background: #14532d; color: #86efac; }
.badge-pending       { background: #1e3a5f; color: #7dd3fc; }
.badge-rejected      { background: #450a0a; color: #fca5a5; }
.badge-unsubmitted   { background: #1f2937; color: #94a3b8; }
.badge-noassertion   { background: #1f2937; color: #94a3b8; }

.badge-active        { background: #14532d; color: #86efac; }
.badge-needsreview   { background: #78350f; color: #fbbf24; }
.badge-closed        { background: #1f2937; color: #94a3b8; }
.badge-expired       { background: #450a0a; color: #fca5a5; }

/* Package deep-linked via ?package=<id> (e.g. from an auto-renewal alert) */
.pkg-row-focus td { background: #fef9c3; }

.pkg-name-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pkg-sub {
  color: #64748b;
  font-size: 12px;
}

.danger-btn {
  background: #ffffff;
  color: #dc2626;
  border: 1px solid #dc2626;
  font-weight: 600;
  padding: 6px 12px;
  font-size: 13px;
}

.danger-btn:hover {
  background: #fef2f2;
}

.small-btn {
  padding: 6px 12px;
  font-size: 13px;
}

/* Wake up services: a banner of its own, with the only amber button in the app */
.wake-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-left: 4px solid #f59e0b;
  border-radius: 8px;
  color: #78350f;
  font-size: 13px;
}

.wake-btn {
  background: #f59e0b;
  color: #ffffff;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(180, 83, 9, 0.35);
  white-space: nowrap;
}

.wake-btn:hover {
  background: #d97706;
}

.wake-btn:disabled {
  background: #fcd34d;
  color: #78350f;
  box-shadow: none;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-box {
  background: #ffffff;
  border-radius: 12px;
  padding: 24px;
  max-width: 480px;
  width: 100%;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: #64748b;
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
}

.modal-close:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.tpl-preview-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.tpl-preview-actions .tpl-action-chip {
  border-top: 1px solid #cde5b3;
  color: #2563eb;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 8px 4px 0;
}

.tpl-preview-vars {
  margin-top: 14px;
  font-size: 13px;
  color: #64748b;
}

.tpl-preview-vars .var-chip {
  display: inline-block;
  background: #f1f5f9;
  border-radius: 6px;
  padding: 2px 8px;
  margin: 2px 4px 2px 0;
  font-family: "Consolas", "Courier New", monospace;
}

#tpl-preview-raw-details {
  margin-top: 14px;
}

#tpl-preview-raw {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
  overflow: auto;
  max-height: 240px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Client Packages tab */
#pkg-advanced-details {
  margin: 4px 0 14px;
}

#pkg-advanced-details .broadcast-grid {
  margin-top: 12px;
}

.script-output {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 14px;
  font-size: 13px;
  font-family: "Consolas", "Courier New", monospace;
  overflow: auto;
  max-height: 480px;
  white-space: pre-wrap;
  word-break: break-word;
}

.tab-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.tab-btn-small {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  color: #475569;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 5px 12px;
  border-radius: 6px;
}

.tab-btn-small.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #ffffff;
}

.tab-btn-small:hover:not(.active) {
  background: #eff6ff;
}

.tab-btn-small:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  width: 30px;
  height: 30px;
  line-height: 1;
  font-size: 15px;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}

.icon-btn:hover {
  background: #eff6ff;
  border-color: #93c5fd;
}

.invoice-readable {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 18px 20px;
  font-size: 14px;
  line-height: 1.6;
  overflow: auto;
  max-height: 480px;
  white-space: pre-wrap;
  word-break: break-word;
}

.invoice-text-edit {
  width: 100%;
  box-sizing: border-box;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #0f172a;
  padding: 12px 14px;
  font: inherit;
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
}

#pkg-invoice-text-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin: 14px 0;
}

#pkg-invoice-text-row[hidden] {
  display: none;
}

#pkg-invoice-text-row label {
  align-self: stretch;
}

#invoice-template-panel > label {
  margin-bottom: 12px;
}

.invoice-template-help {
  margin-bottom: 14px;
}

.invoice-template-placeholders {
  list-style: none;
  padding: 0;
  margin: 10px 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 6px 16px;
  font-size: 13px;
}

.invoice-template-placeholders code {
  cursor: pointer;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  padding: 1px 6px;
  color: #1d4ed8;
}

.invoice-template-placeholders code:hover {
  background: #dbeafe;
}

.status-ok {
  color: #16a34a;
  font-weight: 600;
}

.status-fail {
  color: #dc2626;
  font-weight: 600;
}

/* Coupons tab */
#tab-coupons [hidden] {
  display: none !important;
}

#cpn-search {
  min-width: 220px;
}

.cpn-detail-row > td {
  background: #f8fafc;
}

.cpn-detail {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 6px 4px;
}

.cpn-detail-block .field-label {
  display: block;
  margin-bottom: 6px;
}

.cpn-inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.cpn-inline-form input[type="text"] {
  min-width: 200px;
}

.cpn-inline-form input[type="number"] {
  width: 110px;
}

.cpn-codes-table {
  background: #ffffff;
}

/* ── Sign-in, user bar & permissions ─────────────────────────────────────── */

/* Controls the signed-in user isn't allowed to use. !important so a script
   un-hiding its panel (el.hidden = false) can't bring them back. */
.perm-denied {
  display: none !important;
}

.header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 16px 0 8px;
}

.brand h1 {
  margin: 0;
}

/* 240x96 source, shown at half size so it stays sharp on high-DPI screens. */
.brand-logo {
  display: block;
  height: 40px;
  width: auto;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-menu {
  position: relative;
}

.admin-menu-btn {
  width: 38px;
  height: 36px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  color: #475569;
}

.admin-menu-btn:hover,
.admin-menu-btn[aria-expanded="true"] {
  background: #e2e8f0;
}

.admin-menu-btn.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #ffffff;
}

.admin-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 50;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  padding: 6px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.12);
}

.admin-menu-list[hidden] {
  display: none;
}

.admin-menu-heading {
  padding: 6px 10px 4px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #94a3b8;
}

/* Menu items reuse .tab-btn for behaviour, but look like menu rows. */
.admin-menu-list .admin-menu-item {
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: #0f172a;
  font-weight: 500;
  padding: 8px 10px;
}

.admin-menu-list .admin-menu-item:hover {
  background: #f1f5f9;
}

.admin-menu-list .admin-menu-item.active {
  background: #eff6ff;
  color: #2563eb;
  font-weight: 600;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: #475569;
}

.tab-intro {
  margin: 0 0 12px;
  font-size: 14px;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}

.login-box {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px 24px;
}

.login-box h1 {
  margin: 0;
}

.login-box .brand {
  margin: 0;
}

.login-box .subtitle,
.login-box .error-text {
  margin: 0;
}

.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.perm-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}

.perm-tab {
  font-weight: 600;
}

.perm-action {
  padding-left: 22px;
  font-size: 13px;
}

.perm-action:has(input:disabled) {
  color: #94a3b8;
}
