:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #111827;
  --ink-soft: #5b6472;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eaf2ff;
  --success-bg: #eaf7ef;
  --success-ink: #17633a;
  --warning-bg: #fff7d6;
  --warning-ink: #7a5400;
  --danger-bg: #feecec;
  --danger-ink: #a52323;
  --line: #dbe3ef;
  --shadow: 0 18px 38px rgba(15, 23, 42, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  background: linear-gradient(180deg, #f8fafc 0%, #eef4fb 100%);
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.08), transparent 42%),
    linear-gradient(180deg, #fbfdff 0%, #eef4fb 100%);
}

.auth-card {
  width: min(720px, 92vw);
  background: var(--surface);
  padding: 36px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  animation: rise 0.35s ease-out;
}

.brand {
  display: flex;
  gap: 18px;
  align-items: center;
  margin-bottom: 20px;
}

.brand img {
  width: 64px;
  height: 64px;
  object-fit: contain;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.68rem;
  color: var(--accent);
  margin: 0;
  font-weight: 800;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--ink-soft);
}

.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-dark);
  margin-bottom: 16px;
  border: 1px solid #c7d8ff;
}

.auth-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 650;
}

input,
select,
textarea {
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
}

textarea {
  resize: vertical;
}

.password-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.password-wrap input[type="password"],
.password-wrap input[type="text"] {
  flex: 1;
}

.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius);
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.icon-eye,
.icon-eye-off {
  width: 20px;
  height: 20px;
  fill: var(--ink-soft);
}

.icon-eye-off {
  display: none;
}

.icon-btn.is-visible .icon-eye {
  display: none;
}

.icon-btn.is-visible .icon-eye-off {
  display: block;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(37, 99, 235, 0.16);
  border-color: var(--accent);
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 10px 16px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 750;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 18px rgba(37, 99, 235, 0.2);
}

.btn.primary:hover {
  background: var(--accent-dark);
}

.btn.ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.ghost:hover {
  background: var(--accent-soft);
  border-color: #bdd1ff;
  color: var(--accent-dark);
}

.app-body {
  min-height: 100vh;
  overflow: hidden;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
}

.sidebar {
  padding: 28px 22px;
  background: var(--surface);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  overflow: hidden;
  border-right: 1px solid var(--line);
  box-shadow: 8px 0 28px rgba(15, 23, 42, 0.04);
}

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

.logo-block img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  background: var(--surface-soft);
  border-radius: var(--radius);
  padding: 6px;
  border: 1px solid var(--line);
}

.logo-block h2 {
  margin: 4px 0 0;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-group {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.nav-label {
  margin: 0;
  font-size: 0.65rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 800;
}

.nav-sub,
.nav-btn {
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
}

.nav-sub:hover,
.nav-btn.active,
.nav-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-color: #c7d8ff;
}

.sidebar-footer {
  display: grid;
  gap: 16px;
  margin-top: auto;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip p {
  margin: 0;
  font-weight: 750;
}

.pill {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
}

.content {
  padding: 32px;
  height: 100vh;
  overflow-y: auto;
}

.panel {
  display: grid;
  gap: 24px;
  animation: rise 0.35s ease-out;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
}

.panel-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.stack-actions {
  display: grid;
  gap: 8px;
  align-items: start;
}

.stack-actions form {
  margin: 0;
}

.error-text {
  color: var(--danger-ink);
  font-weight: 800;
}

td small {
  display: block;
  color: var(--ink-soft);
  margin-top: 4px;
}

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

.inline-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.grid {
  display: grid;
  gap: 22px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

#codes-section .grid {
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  align-items: start;
}

.create-card {
  max-width: 320px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.table-wrap {
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table-wrap th,
.table-wrap td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.table-wrap th {
  background: #f1f5f9;
  color: #334155;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.table-wrap tr:last-child td {
  border-bottom: none;
}

.ops-table th,
.ops-table td {
  vertical-align: top;
}

.ops-table td {
  line-height: 1.35;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  border: 1px solid var(--line);
}

.status-chip.ok {
  background: var(--success-bg);
  color: var(--success-ink);
  border-color: #bfe6cf;
}

.status-chip.active {
  background: var(--warning-bg);
  color: var(--warning-ink);
  border-color: #f2d77a;
}

.status-chip.bad {
  background: var(--danger-bg);
  color: var(--danger-ink);
  border-color: #f4bcbc;
}

.status-chip.neutral {
  background: #eef2f7;
  color: #475569;
}

.technical-details {
  margin-top: 8px;
}

.technical-details summary {
  font-size: 0.82rem;
}

.technical-details code {
  display: block;
  max-width: 420px;
  max-height: 90px;
  overflow: auto;
  margin-top: 6px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--surface-soft);
  font-size: 0.78rem;
}

.technical-details pre {
  max-width: 520px;
  max-height: 140px;
}

.form {
  display: grid;
  gap: 12px;
}

.link-row {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
  align-items: end;
}

.link-row input {
  width: 100%;
}

.field-group {
  display: grid;
  gap: 12px;
}

.field-block {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.field-title {
  margin: 0;
  font-weight: 800;
}

.field-group.hidden {
  display: none;
}

.muted {
  color: var(--ink-soft);
  margin: 0;
}

.search {
  min-width: 220px;
}

.form-feedback {
  margin: 0;
  font-size: 0.85rem;
  color: var(--accent-dark);
}

.pagination {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.page-jump input {
  width: 90px;
}

.pagination .btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-empty {
  padding: 18px;
  border: 1px dashed #c5d1e0;
  border-radius: var(--radius);
  color: var(--ink-soft);
  background: var(--surface-soft);
}

.preview-list {
  display: grid;
  gap: 14px;
}

.preview-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
}

.preview-card h4 {
  margin: 0 0 6px;
}

.preview-card pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 12px 0 0;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface-soft);
  font-family: inherit;
  line-height: 1.4;
}

.audience-count {
  margin: 10px 0 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: #111827;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
}

.preview-card .table-wrap {
  max-height: 360px;
}

.preview-card table {
  table-layout: auto;
}

.preview-card th,
.preview-card td {
  white-space: nowrap;
}

.preview-card td:nth-child(1),
.preview-card td:nth-child(3),
.preview-card td:nth-child(5) {
  white-space: normal;
  min-width: 140px;
}

code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

details summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 800;
}

details pre {
  max-width: 520px;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 8px 0 0;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-card {
  width: min(560px, 92vw);
  background: var(--surface);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.hidden {
  display: none;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 16px;
    height: auto;
    overflow: visible;
  }

  .sidebar-footer {
    margin-top: 0;
  }

  .content {
    height: auto;
    overflow: visible;
  }

  .nav {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

  .nav-group {
    grid-column: 1 / -1;
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .panel-actions {
    width: 100%;
  }

  #codes-section .grid {
    grid-template-columns: 1fr;
  }

  .create-card {
    max-width: none;
  }
}

@media (max-width: 600px) {
  .content {
    padding: 20px;
  }

  .sidebar {
    padding: 20px 16px;
  }

  .logo-block {
    width: 100%;
  }

  .logo-block h2 {
    font-size: 1.1rem;
  }

  .card {
    padding: 18px;
  }

  .search {
    min-width: 100%;
  }

  .filters {
    flex-direction: column;
    align-items: stretch;
  }

  .table-wrap table {
    font-size: 0.85rem;
  }

  .table-wrap thead {
    display: none;
  }

  .table-wrap table,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td {
    display: block;
    width: 100%;
  }

  .table-wrap tr {
    border-bottom: 1px solid var(--line);
    padding: 8px 0;
  }

  .table-wrap td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: none;
  }

  .table-wrap td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--ink-soft);
  }
}
