:root {
  --ink: #172126;
  --muted: #68767c;
  --line: #dce4e4;
  --soft: #f3f6f5;
  --paper: #fff;
  --teal: #087f78;
  --teal-dark: #05635e;
  --teal-soft: #e3f3f0;
  --orange: #d97628;
  --red: #b23a36;
  --shadow: 0 12px 34px rgba(23, 33, 38, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--soft);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--soft); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid rgba(8, 127, 120, .25); outline-offset: 2px;
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.45rem, 2vw, 2rem); letter-spacing: -.035em; }
h2 { margin-bottom: .35rem; font-size: 1.05rem; letter-spacing: -.015em; }
.muted { color: var(--muted); line-height: 1.55; }
.eyebrow { margin-bottom: .4rem; color: var(--teal); font-size: .68rem; font-weight: 800; letter-spacing: .14em; }
[hidden] { display: none !important; }

.notice { position: fixed; top: 1rem; right: 1rem; z-index: 20; max-width: 28rem; padding: .85rem 1rem; border: 1px solid #bfddd8; border-radius: .65rem; background: #f1fbf9; box-shadow: var(--shadow); font-size: .88rem; }
.notice.error { border-color: #e8bbb8; background: #fff3f2; color: #842e2b; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(circle at top right, #d8eeea, transparent 42%), var(--soft); }
.login-card { width: min(100%, 29rem); padding: clamp(2rem, 6vw, 3.5rem); border: 1px solid var(--line); border-radius: 1rem; background: var(--paper); box-shadow: var(--shadow); }
.login-card h1 { margin-bottom: 1rem; font-size: 2rem; }
.brand-mark { display: grid; place-items: center; width: 3.5rem; height: 3.5rem; margin-bottom: 1.5rem; border-radius: .75rem; background: var(--teal); color: #fff; font-family: Georgia, serif; font-size: 1.8rem; font-weight: 700; }
.brand-mark.small { width: 2.25rem; height: 2.25rem; margin: 0; border-radius: .5rem; font-size: 1.15rem; }
.security-note { margin: 1rem 0 0; color: var(--muted); font-size: .78rem; text-align: center; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; display: flex; flex-direction: column; width: 15rem; padding: 1.5rem 1rem; border-right: 1px solid #26353a; background: #17262b; color: #fff; }
.brand { display: flex; align-items: center; gap: .75rem; margin: 0 .5rem 2rem; color: #fff; text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand small { margin-top: .12rem; color: #9db0b5; font-size: .7rem; }
.sidebar nav { display: grid; gap: .3rem; }
.sidebar nav a { display: flex; align-items: center; gap: .75rem; padding: .8rem .85rem; border-radius: .5rem; color: #afbec2; font-size: .88rem; font-weight: 650; text-decoration: none; }
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(255,255,255,.08); color: #fff; }
.sidebar nav a.active { box-shadow: inset 3px 0 var(--teal); }
.sidebar-footer { display: flex; align-items: center; gap: .5rem; margin-top: auto; padding: .8rem; color: #9db0b5; font-size: .72rem; }
.status-dot { width: .45rem; height: .45rem; border-radius: 50%; background: #48c49a; box-shadow: 0 0 0 4px rgba(72,196,154,.1); }

.workspace { min-width: 0; margin-left: 15rem; min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 8; display: flex; align-items: center; min-height: 5.5rem; padding: 1rem clamp(1.25rem, 4vw, 3rem); border-bottom: 1px solid var(--line); background: rgba(255,255,255,.94); backdrop-filter: blur(10px); }
.topbar .eyebrow { margin-bottom: .2rem; }
.account { display: flex; align-items: center; gap: 1rem; margin-left: auto; }
.account-email { color: var(--muted); font-size: .8rem; }
.content { min-width: 0; max-width: 92rem; margin: 0 auto; padding: clamp(1.25rem, 4vw, 3rem); }
.page { display: grid; min-width: 0; gap: 1.5rem; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.section-heading p { margin-bottom: 0; }
.section-heading.compact { margin-bottom: 1rem; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 2.55rem; padding: .65rem 1rem; border: 1px solid transparent; border-radius: .5rem; cursor: pointer; font-size: .8rem; font-weight: 750; text-decoration: none; transition: background .15s, border .15s, transform .15s; }
.button:active { transform: translateY(1px); }
.button:disabled { cursor: wait; opacity: .55; }
.button.primary { background: var(--teal); color: #fff; }
.button.primary:hover { background: var(--teal-dark); }
.button.secondary, .button.ghost { border-color: var(--line); background: #fff; color: var(--ink); }
.button.secondary:hover, .button.ghost:hover { border-color: #b9c9c8; background: #f9fbfb; }
.button.danger { background: var(--red); color: #fff; }
.button.wide { width: 100%; margin-top: 1rem; }
.button.centered { margin: 0 auto; }
.icon-button { display: grid; place-items: center; width: 2.5rem; height: 2.5rem; border: 0; border-radius: .45rem; background: transparent; cursor: pointer; font-size: 1.3rem; }
.menu-button { display: none; margin-right: .75rem; }
.text-link { color: var(--teal); font-size: .8rem; font-weight: 750; text-decoration: none; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.stat-card, .panel, .template-card { min-width: 0; border: 1px solid var(--line); border-radius: .75rem; background: var(--paper); box-shadow: 0 3px 12px rgba(23,33,38,.035); }
.stat-card { padding: 1.25rem; }
.stat-card .label { color: var(--muted); font-size: .73rem; font-weight: 700; }
.stat-card strong { display: block; margin-top: .55rem; font-size: 1.85rem; letter-spacing: -.04em; }
.stat-card.submitted { border-top: 3px solid var(--teal); }
.stat-card.failed { border-top: 3px solid var(--red); }
.stat-card.unknown { border-top: 3px solid var(--orange); }
.stat-card.skipped { border-top: 3px solid #84979c; }
.panel { padding: clamp(1.25rem, 3vw, 1.75rem); }
.two-column { display: grid; grid-template-columns: minmax(15rem,.75fr) minmax(18rem,1.25fr); gap: 2rem; align-items: center; }
.module-health { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; }
.health-item { padding: .75rem; border: 1px solid var(--line); border-radius: .55rem; background: #fbfcfc; }
.health-item strong, .health-item span { display: block; }
.health-item strong { font-size: .78rem; }
.health-item span { margin-top: .3rem; color: var(--muted); font-size: .7rem; }
.health-item .on { color: var(--teal); }

.template-list { display: grid; gap: 1.25rem; }
.template-card { overflow: hidden; }
.template-card > header, .template-card > footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.2rem 1.4rem; }
.template-card > header { border-bottom: 1px solid var(--line); }
.template-card > footer { border-top: 1px solid var(--line); background: #fafcfc; }
.template-card .module-name { margin-bottom: .25rem; }
.template-card .module-trigger { margin-bottom: 0; font-size: .78rem; }
.editor-grid { display: grid; grid-template-columns: minmax(0,1.25fr) minmax(18rem,.75fr); gap: 1.5rem; padding: 1.4rem; }
.field-label { display: grid; gap: .5rem; font-size: .78rem; font-weight: 750; }
textarea, select { width: 100%; border: 1px solid #cbd7d7; border-radius: .5rem; background: #fff; color: var(--ink); }
textarea { min-height: 9rem; padding: .8rem; resize: vertical; line-height: 1.55; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .82rem; }
select { padding: .58rem 2rem .58rem .7rem; }
.field-help { margin: .6rem 0; color: var(--muted); font-size: .7rem; }
.placeholder-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.placeholder-chip { padding: .36rem .55rem; border: 1px solid #b9d8d3; border-radius: 999px; background: var(--teal-soft); color: var(--teal-dark); cursor: pointer; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .66rem; }
.preview-panel { padding: 1rem; border-radius: .65rem; background: #edf1f0; }
.phone-preview { min-height: 10rem; padding: 1.2rem; border: 6px solid #26353a; border-radius: 1.35rem; background: #fff; box-shadow: 0 7px 15px rgba(23,33,38,.12); }
.preview-message { max-width: 92%; margin-left: auto; padding: .75rem .85rem; border-radius: .85rem .85rem .18rem .85rem; background: #d9f1ec; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .77rem; line-height: 1.45; }
.message-meter { display: flex; justify-content: space-between; margin-top: .9rem; color: var(--muted); font-size: .68rem; }
.meter-track { height: .35rem; margin-top: .4rem; overflow: hidden; border-radius: 1rem; background: #d3dedd; }
.meter-track span { display: block; width: 0; height: 100%; background: var(--teal); transition: width .2s; }
.validation-message { min-height: 1rem; margin: .6rem 0 0; color: var(--muted); font-size: .7rem; }
.validation-message.error { color: var(--red); }
.version-label { color: var(--muted); font-size: .7rem; }
.switch { display: flex; align-items: center; gap: .55rem; cursor: pointer; font-size: .75rem; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: relative; width: 2.5rem; height: 1.35rem; border-radius: 2rem; background: #b9c5c6; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: .18rem; left: .2rem; width: .98rem; height: .98rem; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked + span { background: var(--teal); }
.switch input:checked + span::after { transform: translateX(1.12rem); }

.filter-bar { display: flex; align-items: end; gap: .75rem; padding: 1rem; border: 1px solid var(--line); border-radius: .65rem; background: #fff; }
.filter-bar label { display: grid; gap: .35rem; min-width: 11rem; color: var(--muted); font-size: .7rem; font-weight: 700; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: .65rem; background: #fff; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; font-size: .76rem; }
th { padding: .8rem 1rem; background: #f8fafa; color: var(--muted); font-size: .65rem; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
td { padding: .9rem 1rem; border-top: 1px solid #e8eeee; }
.status-badge { display: inline-flex; padding: .25rem .48rem; border-radius: 999px; background: #edf1f1; color: #58686c; font-size: .65rem; font-weight: 800; text-transform: capitalize; }
.status-badge.submitted { background: #def4ed; color: #086a55; }
.status-badge.failed { background: #f9e4e2; color: #9c302c; }
.status-badge.unknown { background: #fbead9; color: #9b551e; }
.row-button { padding: .35rem .5rem; border: 0; background: transparent; color: var(--teal); cursor: pointer; font-size: .72rem; font-weight: 800; }
.empty-state { padding: 1.5rem; border: 1px dashed #c7d2d2; border-radius: .55rem; color: var(--muted); font-size: .8rem; text-align: center; }
#dashboard-exceptions { max-width: 100%; overflow-x: auto; }

dialog { width: min(94vw, 43rem); max-height: 88vh; padding: 0; border: 1px solid var(--line); border-radius: .85rem; box-shadow: 0 24px 70px rgba(11,24,28,.25); }
dialog::backdrop { background: rgba(10,23,27,.55); backdrop-filter: blur(2px); }
.dialog-header, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.15rem 1.4rem; }
.dialog-header { border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; }
.dialog-actions { justify-content: flex-end; border-top: 1px solid var(--line); background: #fafcfc; }
.detail-content { max-height: 60vh; padding: 1.4rem; overflow: auto; }
.detail-grid { display: grid; grid-template-columns: 9rem 1fr; gap: .7rem 1rem; margin: 0; font-size: .78rem; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.detail-block { margin-top: 1.25rem; }
.detail-block pre { max-height: 13rem; padding: .9rem; overflow: auto; border-radius: .5rem; background: #18272c; color: #dce8e7; font-size: .7rem; white-space: pre-wrap; }

@media (max-width: 980px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .editor-grid { grid-template-columns: 1fr; }
  .two-column { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .workspace { margin-left: 0; }
  .menu-button { display: grid; }
  .account-email { display: none; }
  .content { padding: 1rem; }
  .topbar { padding: .8rem 1rem; }
  .module-health { grid-template-columns: repeat(2, 1fr); }
  .filter-bar { align-items: stretch; flex-direction: column; }
  .filter-bar label { min-width: 0; }
}

@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; }
  .template-card > header { align-items: flex-start; }
  .template-card > footer { align-items: stretch; flex-direction: column; }
  .editor-grid { padding: 1rem; }
  .module-health { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; gap: .2rem; }
  .detail-grid dd { margin-bottom: .7rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
