:root {
  --navy: #101d38;
  --navy-2: #16264a;
  --ink: #172033;
  --muted: #66738b;
  --line: #e2e7f0;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --orange: #ff8a00;
  --orange-600: #d96c00;
  --green: #16794c;
  --red: #b3261e;
  --radius: 14px;
  --shadow: 0 18px 50px -28px rgba(16, 29, 56, 0.45);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.02em; }
p { margin: 0 0 12px; }
a { color: #0b5cad; }
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 3px solid rgba(255, 138, 0, 0.55); outline-offset: 2px; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 200;
  padding: 10px 14px;
  background: var(--navy);
  color: #fff;
  border-radius: 8px;
}
.skip-link:focus { left: 8px; }

.eyebrow {
  margin: 0 0 6px;
  color: var(--orange-600);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* Brand */
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand__mark { display: inline-flex; flex: none; }
.brand strong { display: block; font-size: 14px; letter-spacing: 0.08em; }
.brand small { display: block; color: rgba(255, 255, 255, 0.62); font-size: 11px; letter-spacing: 0.06em; }
.brand--side { padding: 0 6px 20px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }

/* Gate */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px 18px;
  background:
    radial-gradient(80% 120% at 15% 0%, #1e3560 0%, transparent 55%),
    radial-gradient(90% 100% at 100% 100%, #2b1a05 0%, transparent 50%),
    var(--navy);
}
.gate__panel {
  width: min(460px, 100%);
  padding: clamp(24px, 5vw, 40px);
  background: var(--surface);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.gate__panel .brand { color: var(--ink); margin-bottom: 24px; }
.gate__panel .brand small { color: var(--muted); }
.gate h1 { font-size: clamp(24px, 4vw, 30px); margin-bottom: 8px; }
.gate__copy { color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.gate label { display: block; margin: 14px 0 6px; font-size: 13px; font-weight: 700; }
.gate input { width: 100%; }
.gate .btn { margin-top: 18px; }
.gate__recovery { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.gate__recovery summary { cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 600; }
.gate__recovery summary:hover { color: var(--ink); }
.gate__recovery .btn { margin-top: 14px; }

/* Inputs */
input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid #ccd4e2;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--orange); outline: none; box-shadow: 0 0 0 3px rgba(255, 138, 0, 0.18); }
input[type="checkbox"] { width: 18px; min-height: 18px; accent-color: var(--orange-600); }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #e8edf6;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: #dde5f2; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn--primary { background: var(--orange-600); color: #fff; }
.btn--primary:hover { background: #bf5f00; }
.btn--dark { background: var(--navy); color: #fff; }
.btn--dark:hover { background: var(--navy-2); }
.btn--ghost { background: transparent; border-color: #ccd4e2; }
.btn--ghost:hover { background: #eef2f9; }
.btn--danger { background: #fbe9e7; color: var(--red); border-color: #f3c9c5; }
.btn--danger:hover { background: #f7d8d5; }
.btn--sm { min-height: 34px; padding: 6px 11px; font-size: 12.5px; }
.btn--block { width: 100%; }
.iconbtn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: #eef2f9;
  color: var(--ink);
  font-size: 22px;
  cursor: pointer;
}
.iconbtn:hover { background: #e1e8f4; }
.linkbtn {
  border: 0;
  background: none;
  padding: 0;
  color: inherit;
  font-size: 13px;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* App shell */
.app { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  background: var(--navy);
  color: #fff;
  overflow-y: auto;
}
.nav { display: grid; gap: 2px; margin-top: 16px; }
.nav button {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.nav button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav button.is-active { background: rgba(255, 138, 0, 0.16); color: #ffb45c; box-shadow: inset 3px 0 0 var(--orange); }
.sidebar__foot {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: rgba(255, 255, 255, 0.66);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.main { min-width: 0; padding: clamp(18px, 3vw, 34px); }
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.topbar h1 { font-size: clamp(24px, 3vw, 34px); }
.topbar__actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.status { min-height: 20px; color: var(--muted); font-size: 12.5px; }
.status.is-error { color: var(--red); }
.status.is-ok { color: var(--green); }

/* Cards and layout */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(16, 29, 56, 0.04);
  padding: clamp(16px, 2.4vw, 22px);
  margin-bottom: 18px;
  min-width: 0;
}
.card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.card h2 { font-size: 17px; }
.card h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fbfcfe; }
.stat__label { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.stat__value { display: block; margin-top: 4px; font-size: 30px; font-weight: 800; letter-spacing: -0.03em; }
.stat__hint { color: var(--muted); font-size: 12px; }
.cols { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 18px; align-items: start; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eef2f9;
  color: #39465d;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge--ok { background: #e4f5ec; color: var(--green); }
.badge--warn { background: #fff2dc; color: #925200; }
.badge--draft { background: #eef2f9; color: #4a5872; }
.badge--danger { background: #fbe9e7; color: var(--red); }
.badge--off { background: #f1f3f7; color: #7a8599; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 620px; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f7f9fd; color: var(--muted); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td .actions { display: flex; gap: 6px; flex-wrap: nowrap; }
td.nowrap { white-space: nowrap; }
td .title { font-weight: 700; }
td .sub { color: var(--muted); font-size: 12px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* Toolbar */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .search { flex: 1 1 220px; }
.toolbar select { flex: 0 1 170px; }
.toolbar .spacer { flex: 1; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field label, .field > label { display: block; margin-bottom: 5px; font-size: 12.5px; font-weight: 700; }
.field .hint { margin: 4px 0 0; color: var(--muted); font-size: 11.5px; }
.form-error { min-height: 18px; margin: 10px 0 0; color: var(--red); font-size: 12.5px; }
.codebox {
  display: block;
  margin: 10px 0;
  padding: 12px 14px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #f7f9fc;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
  user-select: all;
}
fieldset { margin: 0 0 18px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; }
legend { padding: 0 6px; font-size: 13px; font-weight: 800; }

/* Offers */
.offers { display: grid; gap: 12px; }
.offer-row {
  display: grid;
  grid-template-columns: 1.1fr 2fr 0.7fr 0.7fr 0.8fr auto auto;
  gap: 8px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcfe;
}
.offer-row .field label { font-size: 11px; }
.offer-row .check { align-self: center; min-height: 42px; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 120; display: grid; place-items: center; padding: 18px; }
.modal__scrim { position: absolute; inset: 0; background: rgba(8, 15, 29, 0.62); backdrop-filter: blur(2px); }
.modal__panel {
  position: relative;
  width: min(820px, 100%);
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.modal__head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.modal__head h2 { font-size: 19px; }
.modal__body { padding: 20px 22px 24px; }
.modal__foot { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }

/* Integrations */
.integrations { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.integration { padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.integration strong { display: block; font-size: 13px; }
.integration span { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

/* Activity */
.activity { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.activity li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.activity li:last-child { border-bottom: 0; }
.activity .when { color: var(--muted); font-size: 11.5px; white-space: nowrap; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 160;
  transform: translate(-50%, 20px);
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--navy);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: #7f1d1d; }

/* Media library */
.media-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  margin-top: 14px;
}
.media-item { margin: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fbfcfe; }
.media-item img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #eef1f7; }
.media-item figcaption { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px 12px; }
.media-item .sub { color: var(--muted); font-size: 11.5px; word-break: break-word; }
.media-item .btn { align-self: flex-start; margin-top: 4px; }
.media-item.is-broken img { display: none; }
.media-item.is-broken::before {
  content: "Preview unavailable";
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  color: var(--muted);
  font-size: 12px;
  background: #eef1f7;
}

/* Responsive */
@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols { grid-template-columns: minmax(0, 1fr); }
  .integrations { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
    gap: 12px;
  }
  .brand--side { padding-bottom: 12px; }
  .nav { display: flex; gap: 6px; overflow-x: auto; margin: 0; padding-bottom: 4px; }
  .nav button { width: auto; white-space: nowrap; padding: 8px 12px; }
  .nav button.is-active { box-shadow: inset 0 -3px 0 var(--orange); }
  .sidebar__foot { flex-direction: row; justify-content: space-between; gap: 12px; padding-top: 10px; }
  .main { padding: 18px 14px 40px; }
  .topbar { flex-direction: column; }
  .topbar__actions { justify-content: flex-start; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .offer-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .offer-row .field:nth-child(2) { grid-column: 1 / -1; }
  .integrations { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 520px) {
  .stats { grid-template-columns: minmax(0, 1fr); }
  .modal { padding: 0; place-items: end center; }
  .modal__panel { max-height: 94dvh; border-radius: 18px 18px 0 0; }
  .gate { padding: 14px; }
  .gate__panel { padding: 22px; }
}

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