:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #172033;
  --muted: #667085;
  --blue: #1d64d8;
  --blue-dark: #174fa9;
  --green: #147a55;
  --amber: #9a5b00;
  --red: #c33232;
  --shadow: 0 14px 36px rgba(23, 32, 51, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

body.auth-locked .app-shell {
  display: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
  white-space: nowrap;
}

button:hover {
  border-color: #9aa8bd;
}

button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

button.primary:hover {
  background: var(--blue-dark);
}

button.danger {
  color: var(--red);
}

button.route-toggle.pause {
  border-color: #e3a328;
  background: #fff8e8;
  color: var(--amber);
}

button.route-toggle.resume {
  border-color: #6fb996;
  background: #eefbf5;
  color: var(--green);
}

button.icon-button {
  width: 40px;
  padding: 0;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
  outline: none;
}

input {
  height: 40px;
  padding: 0 12px;
}

select {
  height: 40px;
  padding: 0 10px;
}

textarea {
  resize: vertical;
  padding: 10px 12px;
  line-height: 1.55;
}

input:focus,
textarea:focus,
select:focus,
.media-panel:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 100, 216, 0.12);
}

.app-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-right: 1px solid var(--line);
  background: #fbfcfe;
  padding: 22px;
}

.brand-row,
.editor-head,
.panel-head,
.search-row,
.head-actions {
  display: flex;
  align-items: center;
}

.brand-row,
.editor-head,
.panel-head {
  justify-content: space-between;
  gap: 12px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-size: 24px;
  line-height: 1.2;
}

h3 {
  font-size: 16px;
}

.brand-row p,
.eyebrow {
  color: var(--muted);
  font-size: 13px;
  margin-top: 5px;
}

.search-row {
  gap: 8px;
}

.search-row input {
  min-width: 0;
  flex: 1 1 auto;
}

#newBtn {
  flex: 0 0 auto;
  min-width: 64px;
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 700;
}

#newBtn:hover {
  background: var(--blue-dark);
  border-color: var(--blue-dark);
}

.enterprise-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  min-height: 0;
}

.enterprise-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
  text-align: left;
}

.enterprise-item.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(29, 100, 216, 0.1);
}

.enterprise-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.enterprise-name img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.enterprise-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin-top: 7px;
  overflow-wrap: anywhere;
}

.editor {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  min-width: 0;
}

.head-actions {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 14px;
}

.config-grid label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.config-grid label.wide {
  grid-column: 1 / -1;
}

.media-grid {
  display: grid;
  grid-template-columns: minmax(240px, 340px) minmax(0, 1fr);
  gap: 14px;
}

.media-panel,
.api-preview,
.route-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  box-shadow: var(--shadow);
}

.route-panel {
  display: grid;
  gap: 14px;
}

.route-panel-head {
  align-items: flex-start;
}

.panel-note {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.route-actions,
.route-form-actions,
.route-row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ttl-field {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.ttl-field input {
  width: 92px;
}

.route-list {
  display: grid;
  gap: 8px;
}

.route-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(240px, 2fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #f8fafc;
}

.route-name {
  font-weight: 700;
}

.route-meta,
.route-endpoints {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.route-badge {
  display: inline-flex;
  margin-left: 6px;
  border-radius: 999px;
  padding: 2px 7px;
  background: #e8eef8;
  color: var(--blue-dark);
  font-size: 11px;
}

.route-badge.off {
  background: #f4e7e7;
  color: var(--red);
}

.route-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.route-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.route-form label.wide {
  grid-column: span 2;
}

.route-form .check-field {
  display: flex;
  align-items: center;
}

.check-field input {
  width: 18px;
  height: 18px;
}

.route-form-actions {
  justify-content: flex-end;
  grid-column: 1 / -1;
}

.probe-form {
  display: grid;
  grid-template-columns: 1fr 2fr 140px 180px auto;
  gap: 10px;
  align-items: end;
  margin: 14px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.probe-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.probe-form .check-field {
  display: flex;
  align-items: center;
  padding-bottom: 9px;
}

.probe-form .route-form-actions {
  grid-column: auto;
  padding-bottom: 1px;
}

.probe-health {
  font-weight: 700;
  color: var(--red);
}

.probe-health.ok {
  color: var(--green);
}

.route-history {
  display: grid;
  gap: 7px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.route-history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.media-panel.dragging {
  border-color: var(--green);
  background: #f1fbf7;
}

.hidden-input {
  display: none;
}

.logo-preview {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px dashed #a8b3c5;
  border-radius: 8px;
  margin-top: 12px;
  color: var(--muted);
  overflow: hidden;
  background: #f8fafc;
  text-align: center;
}

.logo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-preview-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  min-height: 160px;
  margin-top: 12px;
}

.image-tile {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  background: #f8fafc;
}

.image-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-tile button {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 32px;
  min-height: 32px;
  padding: 0;
  background: rgba(255, 255, 255, 0.92);
  color: var(--red);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 160px;
  border: 1px dashed #a8b3c5;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.api-preview pre {
  margin: 12px 0 0;
  min-height: 160px;
  max-height: 280px;
  overflow: auto;
  background: #111827;
  color: #e5e7eb;
  border-radius: 8px;
  padding: 14px;
  font-size: 12px;
  line-height: 1.55;
}

.login-layer {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.login-box {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  border-radius: 8px;
  background: var(--panel);
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-box label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  border-radius: 8px;
  background: #172033;
  color: #fff;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  z-index: 5;
}

.hidden {
  display: none;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 42vh;
  }

  .config-grid,
  .media-grid,
  .route-form,
  .probe-form {
    grid-template-columns: 1fr;
  }

  .route-form label.wide {
    grid-column: auto;
  }

  .probe-form .route-form-actions {
    grid-column: auto;
  }

  .route-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .editor,
  .sidebar {
    padding: 16px;
  }

  .editor-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .head-actions {
    width: 100%;
    justify-content: stretch;
  }

  .head-actions button {
    flex: 1;
  }
}
