:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f9fbfd;
  --ink: #172033;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #dbe3ee;
  --line-strong: #cbd5e1;
  --blue: #1d64d8;
  --blue-dark: #164da6;
  --blue-soft: #e9f1ff;
  --green: #15803d;
  --green-soft: #e8f7ee;
  --amber: #b45309;
  --amber-soft: #fff4df;
  --red: #b91c1c;
  --red-soft: #feecec;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
  --radius: 8px;
  --sidebar: 248px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-frame {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.side-nav {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 20px 16px;
  background: #101827;
  color: #e2e8f0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #2563eb;
  color: white;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 2px;
  color: #94a3b8;
  font-size: 12px;
}

.nav-stack {
  display: grid;
  gap: 6px;
}

.nav-button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: var(--radius);
  padding: 10px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  font-weight: 650;
}

.nav-button:hover,
.nav-button.active {
  background: #1e293b;
  color: #ffffff;
}

.nav-glyph {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: rgba(148, 163, 184, 0.14);
  color: #93c5fd;
  font-size: 11px;
  font-weight: 800;
}

.side-note {
  margin-top: auto;
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.54);
}

.side-note span {
  color: #aab6c7;
  font-size: 12px;
  line-height: 1.45;
}

.main-shell {
  min-width: 0;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto auto;
  gap: 14px;
  align-items: center;
  min-height: 72px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.top-title h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.top-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-metrics,
.top-actions,
.inline-actions,
.log-filters,
.group-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-chip,
.dirty-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-chip.ok {
  border-color: #b7e3c5;
  background: var(--green-soft);
  color: var(--green);
}

.status-chip.warn,
.dirty-chip {
  border-color: #f5d39b;
  background: var(--amber-soft);
  color: var(--amber);
}

.status-chip.error {
  border-color: #fecaca;
  background: var(--red-soft);
  color: var(--red);
}

.primary-button,
.secondary-button,
.danger-button,
.text-button,
.icon-button {
  min-height: 36px;
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 750;
}

.primary-button {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: white;
}

.primary-button:hover {
  background: var(--blue-dark);
}

.secondary-button,
.icon-button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.secondary-button:hover,
.icon-button:hover {
  border-color: #9eb4d3;
  background: #f8fbff;
}

.danger-button {
  border: 1px solid #fecaca;
  background: var(--red-soft);
  color: var(--red);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  padding-inline: 0;
}

.account-menu {
  position: relative;
}

.account-menu summary {
  list-style: none;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 8px 12px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.account-menu summary::-webkit-details-marker {
  display: none;
}

.account-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 240px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.account-popover p {
  margin: 0 0 8px;
  color: var(--muted);
  word-break: break-word;
}

.workspace {
  padding: 22px;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head h2,
.panel h3 {
  margin: 0;
  line-height: 1.2;
}

.section-head h2 {
  font-size: 22px;
}

.section-head p,
.panel p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.setup-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(320px, 1.1fr);
  gap: 16px;
}

.checklist-panel {
  grid-row: span 2;
  padding: 10px;
}

.checklist {
  display: grid;
  gap: 8px;
}

.check-item {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.check-dot {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--faint);
  font-size: 13px;
  font-weight: 800;
}

.check-item.done .check-dot {
  border-color: #a7dcbc;
  background: var(--green-soft);
  color: var(--green);
}

.check-item.warn .check-dot {
  border-color: #f5d39b;
  background: var(--amber-soft);
  color: var(--amber);
}

.check-item strong {
  display: block;
  margin-bottom: 3px;
}

.check-item span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.qr-status {
  min-height: 330px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding: 18px;
  text-align: center;
}

.account-control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  padding: 16px 18px 0;
}

.empty-qr,
.qr-status img {
  width: min(260px, 100%);
  aspect-ratio: 1;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-soft);
}

.empty-qr {
  display: grid;
  place-items: center;
  color: var(--faint);
  font-size: 38px;
  font-weight: 850;
}

.setup-action-panel {
  padding-bottom: 16px;
}

.test-mode-banner {
  display: grid;
  gap: 4px;
  margin: 14px 16px 0;
  border: 1px solid #b9d2fb;
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--blue-soft);
  color: #17417f;
}

.test-mode-banner strong {
  color: var(--blue-dark);
}

.test-mode-banner span {
  line-height: 1.4;
}

.test-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 16px;
  margin-top: 10px;
}

.live-test-results {
  display: grid;
  gap: 8px;
  padding: 0 16px;
  margin-top: 10px;
}

.live-results-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.live-result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--surface-soft);
  color: var(--ink);
  text-align: left;
}

.live-result-row:hover {
  border-color: #92b5ed;
  background: #f3f8ff;
}

.live-result-row strong,
.live-result-row small {
  display: block;
}

.live-result-row small {
  margin-top: 2px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.test-attachment-list {
  display: grid;
  gap: 8px;
  padding: 0 16px;
  margin-top: 10px;
}

.field,
.search-field,
.compact-select {
  display: grid;
  gap: 6px;
}

.field {
  padding: 0 16px;
  margin-top: 14px;
}

.field span,
.search-field span,
.compact-select span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 94px;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #7aa4e8;
  box-shadow: 0 0 0 3px rgba(29, 100, 216, 0.12);
}

.form-status {
  min-height: 20px;
  padding: 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.field-hint {
  min-height: 18px;
  margin: 8px 16px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.field-hint.error {
  color: var(--red);
}

.form-status.ok {
  color: var(--green);
}

.form-status.error {
  color: var(--red);
}

.schedule-grid {
  display: grid;
  grid-template-columns: 300px minmax(420px, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.schedule-list-panel,
.message-table-panel,
.composer-panel {
  min-height: 540px;
}

.schedule-list-panel {
  padding: 14px;
}

.schedule-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: 680px;
  overflow: auto;
}

.schedule-card {
  width: 100%;
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 11px;
  text-align: left;
}

.schedule-card:hover,
.schedule-card.active {
  border-color: #92b5ed;
  background: #f7fbff;
}

.schedule-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.schedule-card .meta-line,
.message-preview,
.small-muted {
  color: var(--muted);
  font-size: 12px;
}

.schedule-editor {
  padding: 10px;
}

.schedule-fields {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 150px 110px;
  gap: 10px;
  padding: 6px;
  margin-bottom: 8px;
}

.message-bulk-actions,
.schedule-group-actions,
.group-bulk-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0 6px 10px;
  padding: 8px;
  background: var(--surface-soft);
}

.message-bulk-actions span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-right: auto;
}

.message-list {
  display: grid;
  gap: 6px;
}

.message-row {
  display: grid;
  grid-template-columns: 34px 78px minmax(120px, 1fr) 86px;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  background: var(--surface-soft);
}

.message-row.active {
  border-color: #92b5ed;
  background: #f3f8ff;
}

.message-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.message-status {
  justify-self: end;
  border-radius: 999px;
  padding: 5px 8px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.message-detail {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.attachment-list,
.selected-groups {
  display: grid;
  gap: 8px;
}

.attachment-item,
.selected-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--surface-soft);
}

.selected-group.warn {
  border-color: #f5d39b;
  background: var(--amber-soft);
}

.selected-group strong,
.selected-group small {
  display: block;
}

.selected-group small {
  margin-top: 2px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

.schedule-group-head {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(160px, 1fr) 140px auto;
  align-items: end;
}

.toolbar-note {
  margin: 10px 14px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.group-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  align-items: flex-start;
}

.group-toolbar .search-field {
  flex: 1 1 320px;
}

.group-filter-tabs {
  display: inline-flex;
  gap: 2px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 3px;
  background: var(--surface-soft);
}

.group-filter-button {
  min-height: 30px;
  border-radius: calc(var(--radius) - 2px);
  padding: 6px 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.group-filter-button.active {
  background: #ffffff;
  color: var(--blue);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.group-bulk-actions {
  margin: 10px 14px 0;
  border-color: var(--line);
}

.result-count {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.advanced-box {
  min-width: 260px;
}

.advanced-box summary {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 9px 10px;
  color: var(--muted);
  font-weight: 750;
  cursor: pointer;
}

.advanced-box .field {
  padding: 0;
  margin-top: 10px;
}

.groups-table {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.group-row {
  display: grid;
  grid-template-columns: 34px minmax(180px, 1fr) minmax(180px, 0.8fr) 86px 86px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--surface-soft);
}

.group-row.hidden-group {
  background: #f8fafc;
  opacity: 0.82;
}

.group-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.thread-cell {
  display: grid;
  gap: 4px;
}

.thread-cell input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.status-label {
  justify-self: end;
  border-radius: 999px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 800;
  background: var(--amber-soft);
  color: var(--amber);
}

.status-label.ok {
  background: var(--green-soft);
  color: var(--green);
}

.log-filters {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.log-filters select,
.log-filters input {
  width: auto;
  min-width: 170px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

td {
  color: #263448;
  font-size: 13px;
}

.status-pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 8px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-pill.sent,
.status-pill.queued,
.status-pill.running {
  background: var(--green-soft);
  color: var(--green);
}

.status-pill.failed,
.status-pill.error {
  background: var(--red-soft);
  color: var(--red);
}

.status-pill.retrying,
.status-pill.missed {
  background: var(--amber-soft);
  color: var(--amber);
}

.empty-row,
.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.mobile-only {
  display: none;
}

@media (max-width: 1180px) {
  .top-bar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .schedule-grid,
  .setup-grid {
    grid-template-columns: 1fr;
  }

  .schedule-list-panel,
  .message-table-panel,
  .composer-panel {
    min-height: auto;
  }
}

@media (max-width: 820px) {
  .app-frame {
    grid-template-columns: 1fr;
  }

  .side-nav {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(82vw, 300px);
    transform: translateX(-102%);
    transition: transform 160ms ease;
  }

  body.nav-open .side-nav {
    transform: translateX(0);
  }

  .mobile-only {
    display: inline-flex;
  }

  .top-bar {
    grid-template-columns: auto 1fr;
    padding: 12px;
  }

  .top-title,
  .top-metrics,
  .top-actions,
  .account-menu {
    grid-column: 1 / -1;
  }

  .workspace {
    padding: 14px;
  }

  .section-head,
  .panel-head {
    display: grid;
  }

  .schedule-fields,
  .schedule-group-head,
  .message-row,
  .group-row {
    grid-template-columns: 1fr;
  }

  .message-status,
  .status-label {
    justify-self: start;
  }
}
