:root {
  --navy: #12232e;
  --navy-soft: #1c3444;
  --teal: #1c7c74;
  --teal-soft: #eef6f5;
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-muted: #f8fafb;
  --border: #dfe4ea;
  --text: #16202a;
  --muted: #66707c;
  --danger: #b3261e;
  --danger-bg: #fbeceb;
  --success: #1a7a3d;
  --success-bg: #e9f6ee;
  --warn: #8a5a00;
  --warn-bg: #f6ecd6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 32, 0.05), 0 8px 24px -16px rgba(16, 24, 32, 0.25);
  --bottomnav-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --navy: #eef3f6;
    --navy-soft: #c8d3db;
    --teal: #4fd0c4;
    --teal-soft: #103430;
    --bg: #0d1418;
    --surface: #141d23;
    --surface-muted: #101820;
    --border: #253038;
    --text: #eaeff2;
    --muted: #93a0ab;
    --danger: #ff8a80;
    --danger-bg: #3a1a17;
    --success: #6fdf9a;
    --success-bg: #123322;
    --warn: #f0c064;
    --warn-bg: #3a2c0e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px -18px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

html { scroll-padding-top: 96px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

input, textarea, button { font-size: 16px; }

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0 16px;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--navy);
  color: var(--teal);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-name {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
}

.brand-sub {
  margin: 1px 0 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.env-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--muted);
}

.env-badge.prod {
  background: var(--teal-soft);
  color: var(--teal);
  border-color: transparent;
}

/* ---------- Tabbar ---------- */

.tabbar {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 8px;
  border-radius: 9px;
  cursor: pointer;
}

.tab svg { width: 17px; height: 17px; flex-shrink: 0; }

.tab.active {
  background: var(--navy);
  color: var(--surface);
}

@media (max-width: 780px) {
  .tabbar {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 40;
    margin-bottom: 0;
    box-shadow: 0 8px 28px -10px rgba(16, 24, 32, 0.4);
  }
  .tab { flex-direction: column; gap: 3px; padding: 8px 4px; font-size: 10.5px; }
  .app { padding-bottom: calc(var(--bottomnav-h) + 28px); }
}

/* ---------- Views ---------- */

.view { display: none; }
.view.active { display: block; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0 0 16px 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* ---------- Composer layout ---------- */

.composer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .composer-grid { grid-template-columns: 1fr; }
  .composer-preview { display: none; }
  .composer-preview.mobile-active { display: block; }
  .composer-editor.mobile-hidden { display: none; }
}

.segmented {
  display: flex;
  gap: 4px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

#mobile-segmented { display: none; }

@media (max-width: 900px) {
  #mobile-segmented { display: flex; }
}

.seg-btn {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--navy);
  color: var(--surface);
}

.panel-preview { height: 100%; }

.preview-frame-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-muted);
  height: 640px;
}

#preview-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
}

/* ---------- Fields ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span {
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
}

.field span em {
  font-weight: 500;
  font-style: normal;
  color: var(--muted);
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.field-error {
  font-size: 12px;
  color: var(--danger);
  min-height: 14px;
}

input[type="text"],
input[type="password"],
textarea,
input[type="file"] {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-muted);
  color: var(--text);
  width: 100%;
}

textarea {
  resize: vertical;
  min-height: 220px;
  font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
}

input.invalid {
  border-color: var(--danger);
  background: var(--danger-bg);
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--teal);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 18%, transparent);
}

.hint-link {
  font-size: 12px;
  color: var(--teal);
  text-decoration: none;
  font-weight: 600;
}

.hint-link:hover { text-decoration: underline; }

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.draft-status {
  font-size: 12px;
  color: var(--muted);
  min-height: 14px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 700;
  font-size: 13.5px;
  padding: 11px 18px;
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn-primary {
  background: var(--navy);
  color: var(--surface);
}

.btn-primary:hover:not(:disabled) { opacity: 0.9; }

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--teal);
  color: var(--teal);
}

.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn-block { width: 100%; }

.btn-danger-outline {
  background: transparent;
  border-color: var(--danger-bg);
  color: var(--danger);
}
.btn-danger-outline:hover { border-color: var(--danger); }

.btn-row {
  display: flex;
  gap: 10px;
}

.btn-row-end {
  justify-content: flex-end;
}

/* ---------- Status pills / inline status ---------- */

.status-pill {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn);
}

.status-pill.ok {
  background: var(--success-bg);
  color: var(--success);
}

.status-pill.bad {
  background: var(--danger-bg);
  color: var(--danger);
}

.inline-status {
  font-size: 13px;
  min-height: 18px;
  line-height: 1.5;
}

.inline-status.success { color: var(--success); }
.inline-status.error { color: var(--danger); }
.inline-status.pending { color: var(--muted); }

/* ---------- Lists (templates / history) ---------- */

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-empty {
  font-size: 13.5px;
  color: var(--muted);
  padding: 12px 0;
}

.list-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--surface-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.list-item-main { min-width: 0; flex: 1; }

.list-item-title {
  margin: 0 0 3px 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-meta {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

