/* ============================================================
   Ghost Postman UI — Phantom Signal theme
   ============================================================ */
:root {
  --bg:            #071520;
  --bg-soft:       #091c2e;
  --panel:         #0a2030;
  --panel-2:       #0d2840;
  --panel-3:       #173550;
  --border:        #1a4060;
  --border-strong: #1e5575;
  --text:          #c8ede5;
  --muted:         #4d8a9c;
  --accent:        #00d4aa;
  --accent-2:      #00b891;
  --accent-glow:   rgba(0,212,170,.18);
  --good:  #00d4aa;
  --bad:   #f87171;
  --warn:  #f5a623;
  --info:  #38bdf8;
  --shadow: 0 10px 30px rgba(0,0,0,.5);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
}
:root[data-theme="light"] {
  --bg:            #edf6f4;
  --bg-soft:       #ffffff;
  --panel:         #ffffff;
  --panel-2:       #f0faf7;
  --panel-3:       #d9f2ec;
  --border:        #b2ddd4;
  --border-strong: #89c8bc;
  --text:          #0a2030;
  --muted:         #4d8a9c;
  --accent:        #00997a;
  --accent-2:      #007d65;
  --accent-glow:   rgba(0,153,122,.15);
  --shadow: 0 6px 18px rgba(7,21,32,.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Layout ===== */
#app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--bg-soft);
  background-image:
    linear-gradient(rgba(0,212,170,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,212,170,.025) 1px, transparent 1px);
  background-size: 28px 28px;
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 10px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.logo {
  width: 36px; height: 36px;
  background: rgba(0,212,170,.1);
  border: 1px solid rgba(0,212,170,.35);
  border-radius: 10px;
  display: grid; place-items: center;
  box-shadow: 0 0 14px rgba(0,212,170,.15);
  flex-shrink: 0;
}
.brand-title {
  font-weight: 700; font-size: 14px;
  color: var(--text);
  letter-spacing: .3px;
}
.brand-sub { font-size: 11px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--muted);
  cursor: pointer; user-select: none;
  font-size: 13.5px; font-weight: 500;
  transition: background .12s, color .12s;
  border-left: 2px solid transparent;
}
.nav-item:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav-item.active {
  background: rgba(0,212,170,.08);
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
  box-shadow: inset 0 0 16px rgba(0,212,170,.04);
}
.nav-item .ic { width: 18px; text-align: center; font-size: 14px; flex-shrink: 0; }

.sidebar-footer {
  padding-top: 12px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.theme-btn {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; cursor: pointer;
  color: var(--text); font-size: 14px;
}
.theme-btn:hover { background: var(--panel-2); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(7,21,32,.9);
  position: sticky; top: 0; z-index: 4;
  backdrop-filter: blur(12px);
}
.crumbs { font-size: 16px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 12px; }
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
}
.live-dot.on {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(0,212,170,.18);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 4px rgba(0,212,170,.18); }
  50%      { box-shadow: 0 0 0 7px rgba(0,212,170,.05); }
}
.muted { color: var(--muted); }

#view {
  padding: 28px;
  max-width: 1280px;
  width: 100%;
}

/* ===== Cards ===== */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  transition: border-color .2s;
}
.card:hover { border-color: var(--border-strong); }
.card + .card { margin-top: 18px; }
.card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.card .helper { font-size: 12px; color: var(--muted); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; }
@media (max-width: 1080px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ===== Forms ===== */
label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; font-weight: 500; }
label:first-child { margin-top: 0; }
input, textarea, select {
  width: 100%; padding: 10px 13px; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid var(--border-strong);
  color: var(--text); font-family: inherit; font-size: 13.5px;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
textarea {
  font-family: var(--mono);
  min-height: 130px; resize: vertical;
  line-height: 1.5;
}
textarea.html-editor { min-height: 240px; }
button, .btn {
  background: var(--accent-2); color: #071520; border: 0;
  padding: 9px 16px; border-radius: var(--radius-sm);
  font-weight: 700; font-size: 13.5px; cursor: pointer;
  transition: background .12s, transform .06s, box-shadow .12s;
  font-family: inherit;
}
button:hover, .btn:hover {
  background: var(--accent);
  box-shadow: 0 0 12px rgba(0,212,170,.3);
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.ghost {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border);
}
button.ghost:hover { background: var(--panel-3); box-shadow: none; }
button.danger { background: var(--bad); color: #fff; }
button.danger:hover { background: #dc2626; box-shadow: 0 0 10px rgba(248,113,113,.3); }
.icon-btn {
  background: none; border: 0; color: var(--muted);
  padding: 4px 8px; cursor: pointer; font-size: 16px;
}
.icon-btn:hover { color: var(--text); background: var(--panel-2); }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.gap-sm { gap: 6px; }

/* ===== Stats cards ===== */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 14px; margin-bottom: 18px;
}
@media (max-width: 1080px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}
.stat::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
  border-radius: var(--radius) var(--radius) 0 0;
}
.stat::after {
  content: ""; position: absolute; right: -20px; top: -20px;
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--accent-glow); filter: blur(20px);
}
.stat .stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.stat .stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; line-height: 1.1; }
.stat .stat-delta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.stat.good .stat-value { color: var(--good); }
.stat.bad  .stat-value { color: var(--bad); }
.stat.warn .stat-value { color: var(--warn); }
.stat.info .stat-value { color: var(--info); }

/* ===== Tables ===== */
.table-wrap { overflow: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background: var(--panel-2); position: sticky; top: 0; z-index: 1; }
th { padding: 10px 12px; text-align: left; color: var(--muted);
     font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
td { padding: 11px 12px; border-top: 1px solid var(--border); }
tbody tr { transition: background .08s; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--panel-2); }
td.right, th.right { text-align: right; }
td.muted { color: var(--muted); }

/* ===== Badges ===== */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px;
}
.badge.sent      { background: rgba(0,212,170,.15);   color: var(--good); }
.badge.failed    { background: rgba(248,113,113,.15);  color: var(--bad); }
.badge.queued    { background: rgba(245,166,35,.15);   color: var(--warn); }
.badge.sending   { background: rgba(56,189,248,.15);   color: var(--info); }
.badge.suppressed{ background: rgba(0,212,170,.1);     color: var(--accent); }
.badge.delivered { background: rgba(0,212,170,.15);    color: var(--good); }
.badge.bounced   { background: rgba(248,113,113,.15);  color: var(--bad); }
.badge.complained{ background: rgba(245,166,35,.2);    color: var(--warn); }
.badge.dot {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border);
  text-transform: none; font-weight: 500; font-size: 11px;
}
.badge.dot::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
}
.badge.dot.good::before { background: var(--good); box-shadow: 0 0 5px rgba(0,212,170,.4); }
.badge.dot.bad::before  { background: var(--bad); }
.badge.dot.warn::before { background: var(--warn); }

/* ===== Toast ===== */
#toast-host {
  position: fixed; right: 20px; bottom: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  padding: 12px 16px; border-radius: 8px; min-width: 240px;
  box-shadow: var(--shadow), 0 0 20px rgba(0,212,170,.08); font-size: 13px;
  animation: toastIn .2s ease-out;
}
.toast.good { border-left-color: var(--good); }
.toast.bad  { border-left-color: var(--bad); }
@keyframes toastIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* ===== Drawer ===== */
.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50;
  backdrop-filter: blur(3px);
}
.backdrop.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 580px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform .25s ease;
  z-index: 51; display: flex; flex-direction: column;
  box-shadow: -10px 0 40px rgba(0,0,0,.4);
}
.drawer.show { transform: translateX(0); }
.drawer-head {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.drawer-body { padding: 22px; overflow: auto; flex: 1; }

/* ===== Timeline ===== */
.timeline { list-style: none; padding: 0; margin: 18px 0 0; }
.timeline li {
  padding: 8px 0 14px 22px;
  border-left: 2px solid var(--border-strong);
  position: relative; font-size: 12.5px;
  margin-left: 6px;
}
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: 12px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
  box-shadow: 0 0 8px rgba(0,212,170,.4);
}
.timeline .ev-type { font-weight: 600; text-transform: capitalize; color: var(--text); }
.timeline .ev-time { color: var(--muted); font-size: 11px; }
.timeline pre { background: var(--panel-2); padding: 8px 10px; border-radius: 6px; margin-top: 6px; font-size: 11px; max-height: 200px; overflow: auto; }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 16px; font-size: 13px; }
.kv .k { color: var(--muted); }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
pre  { background: var(--panel-2); padding: 12px; border-radius: 8px; overflow: auto; font-size: 12px; }

/* ===== Health pills ===== */
.health-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.health-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px; background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px; font-size: 12px;
}

/* ===== Template editor ===== */
.editor-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 14px; min-height: 480px;
}
@media (max-width: 1080px) { .editor-grid { grid-template-columns: 1fr; } }
.editor-pane, .preview-pane {
  display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--panel-2);
}
.editor-pane textarea {
  border: 0; border-radius: 0; flex: 1; min-height: 460px;
  background: transparent;
}
.preview-pane iframe {
  flex: 1; width: 100%; border: 0; background: #fff; min-height: 460px;
}

/* ===== Pagination & filters ===== */
.filter-row {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin-bottom: 14px; align-items: center;
}
.filter-row input, .filter-row select {
  width: auto; min-width: 160px;
}
.pager {
  display: flex; gap: 6px; justify-content: flex-end;
  align-items: center; margin-top: 14px; font-size: 12px; color: var(--muted);
}
.pager button { padding: 5px 10px; }

/* ===== Charts ===== */
.chart-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.chart-card h3 { margin: 0 0 12px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }

/* ===== Empty state ===== */
.empty {
  text-align: center; padding: 60px 20px; color: var(--muted);
}
.empty-icon { font-size: 40px; opacity: .4; margin-bottom: 12px; }
