/* Console look inspired by the AWS (Pinpoint) console. */
:root {
  --bg: #f2f3f3;
  --panel: #ffffff;
  --text: #16191f;
  --muted: #5f6b7a;
  --border: #d5dbdb;
  --topbar: #232f3e;
  --primary: #0972d3;
  --primary-dark: #033160;
  --nav-active: #0972d3;
  --success: #037f0c;
  --warning: #8d6605;
  --danger: #d91515;
}

html, body { height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  height: 48px; padding: 0 16px; background: var(--topbar); color: #fff;
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; text-decoration: none; }
.brand img { border-radius: 6px; background: #fff; }
.brand:hover { color: #fff; }
.topbar-sub { color: #d1d5db; font-size: 13px; }
.topbar-user { color: #d1d5db; font-size: 13px; }
.spacer { flex: 1; }

.layout { display: flex; min-height: calc(100vh - 48px); }
.sidenav {
  width: 220px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border);
  padding: 16px 0;
}
.sidenav a {
  display: block; padding: 6px 20px; color: var(--text); text-decoration: none;
  border-left: 3px solid transparent;
}
.sidenav a:hover { color: var(--primary); }
.sidenav a.active { color: var(--nav-active); font-weight: 700; border-left-color: var(--nav-active); }
.content { flex: 1; padding: 20px 28px 60px; min-width: 0; }

.breadcrumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.breadcrumbs a { color: var(--primary); text-decoration: none; }

.page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 24px; font-weight: 700; margin: 0; }
.page-header .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.panel {
  background: var(--panel); border-radius: 12px; box-shadow: 0 1px 1px rgba(0,28,36,.3), 0 1px 4px rgba(0,28,36,.12);
  margin-bottom: 20px;
}
.panel-header {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 20px; border-bottom: 1px solid #eaeded;
}
.panel-header h2 { font-size: 18px; font-weight: 700; margin: 0; }
.panel-header .actions { margin-left: auto; display: flex; gap: 8px; }
.panel-body { padding: 16px 20px; }
.panel-body.flush { padding: 0; }
.hint { color: var(--muted); font-size: 12px; }

.btn { border-radius: 20px; font-weight: 700; padding: 4px 18px; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }

table.list { width: 100%; margin: 0; }
table.list th {
  background: #fafafa; font-weight: 700; color: var(--muted); font-size: 13px;
  border-bottom: 1px solid var(--border); padding: 8px 16px; white-space: nowrap;
}
table.list td { padding: 8px 16px; border-bottom: 1px solid #eaeded; vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list a { color: var(--primary); text-decoration: none; font-weight: 600; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

.status { font-weight: 600; white-space: nowrap; }
.status::before { content: "●"; margin-right: 6px; }
.status-draft, .status-unsubscribed { color: var(--muted); }
.status-scheduled { color: var(--primary); }
.status-sending { color: var(--warning); }
.status-sent, .status-subscribed { color: var(--success); }
.status-failed, .status-cancelled, .status-bounced, .status-complained { color: var(--danger); }

/* Wizard */
.wizard { display: flex; gap: 28px; align-items: flex-start; }
.steps { width: 200px; flex-shrink: 0; list-style: none; padding: 0; margin: 0; }
.steps li { margin-bottom: 14px; }
.steps small { display: block; color: var(--muted); font-size: 12px; }
.steps a { color: var(--muted); text-decoration: none; }
.steps li.active a { color: var(--text); font-weight: 700; }
.steps li.done a { color: var(--primary); }
.wizard-main { flex: 1; min-width: 0; }
.wizard-footer { display: flex; justify-content: flex-end; gap: 8px; }

/* Template editor */
/* Source and preview side by side; the header row aligns their tops and both are the
   same height. */
.editor-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; align-items: end;
  grid-template-areas: "source-head preview-head" "source preview" "layout error";
}
.editor-grid > * { min-width: 0; }
.ed-source-head { grid-area: source-head; }
.ed-preview-head { grid-area: preview-head; }
.ed-source { grid-area: source; }
.ed-preview { grid-area: preview; }
.ed-layout { grid-area: layout; align-self: start; }
.ed-error { grid-area: error; align-self: start; }
.editor-grid .ed-source, .editor-grid .ed-preview { height: 560px; min-height: 0; align-self: stretch; }
.editor-grid .ed-source { resize: none; white-space: pre-wrap; }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px;
  min-height: 460px; resize: vertical; tab-size: 2; white-space: pre;
}
.preview-frame { width: 100%; height: 520px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.preview-frame.small { height: 420px; }
.mode-switch .btn { border-radius: 0; padding: 4px 14px; }
.mode-switch .btn:first-child { border-radius: 20px 0 0 20px; }
.mode-switch .btn:last-child { border-radius: 0 20px 20px 0; }
.attr-chip {
  display: inline-block; font-family: ui-monospace, monospace; font-size: 12px; background: #f1faff;
  border: 1px solid #b5d6f4; border-radius: 12px; padding: 1px 8px; margin: 0 4px 4px 0; cursor: pointer;
}
.attr-chip:hover { background: #d3e7f9; }
.render-error { color: var(--danger); font-size: 12px; white-space: pre-wrap; }

.kv { display: grid; grid-template-columns: 200px 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.metric small { color: var(--muted); display: block; }
.metric strong { font-size: 26px; font-weight: 300; }

.login { display: flex; justify-content: center; padding: 10vh 16px; }
.login-panel { width: 100%; max-width: 380px; padding: 28px; }
.login-panel h1 { font-size: 22px; margin-bottom: 20px; }

.toast-msg {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100;
  background: var(--topbar); color: #fff; padding: 10px 20px; border-radius: 8px; max-width: 90vw;
}
.toast-msg.error { background: var(--danger); }

/* QueryBuilder ships Bootstrap 3 markup; adapt it to Bootstrap 5. */
.query-builder .rules-group-container { background: #fafafa; border-color: var(--border); }
.query-builder .btn { border-radius: 4px; padding: 2px 10px; font-weight: 600; font-size: 12px; }
.query-builder .pull-right { float: right; }
.query-builder .rule-container { padding: 8px 10px; }
.query-builder .rule-container::after { content: ""; display: block; clear: both; }
.query-builder .form-control { display: inline-block; width: auto; max-width: 100%; font-size: 13px; padding: 3px 8px; }
.query-builder .rule-value-container input.form-control { min-width: 180px; }
.query-builder .error-container { display: none; }
.query-builder .has-error .error-container { display: inline-block; color: var(--danger); }
.query-builder .has-error .error-container::before { content: "!"; font-weight: 700; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidenav { width: auto; display: flex; padding: 0; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .sidenav a { border-left: 0; border-bottom: 3px solid transparent; white-space: nowrap; padding: 10px 16px; }
  .sidenav a.active { border-bottom-color: var(--nav-active); }
  .content { padding: 16px; }
  .editor-grid {
    grid-template-columns: 1fr;
    grid-template-areas: "source-head" "source" "layout" "preview-head" "preview" "error";
  }
  .editor-grid .ed-source, .editor-grid .ed-preview { height: 420px; }
  .wizard { flex-direction: column; }
  .steps { width: auto; display: flex; gap: 16px; overflow-x: auto; }
  .kv { grid-template-columns: 1fr; }
  .topbar-sub { display: none; }
}
