:root {
  color-scheme: light;
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-2: #f3f6f9;
  --text: #172b4d;
  --muted: #667085;
  --line: #d7e0ea;
  --brand: #1769aa;
  --brand-dark: #0f4774;
  --danger: #b42318;
  --ok: #15803d;
  --warn: #b45309;
  --shadow: 0 12px 30px rgba(25, 39, 52, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a {
  color: inherit;
  text-decoration: none;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background: #e8f0f7;
}

.login-panel {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
  border-top: 4px solid var(--brand);
}

.login-brand {
  color: var(--brand-dark);
  margin-bottom: 24px;
}

.login-panel h1 {
  margin-bottom: 8px;
}

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

.sidebar {
  background: #14213d;
  color: #f8fafc;
  padding: 24px 18px;
  min-height: 100vh;
  position: sticky;
  top: 0;
  align-self: start;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
  margin-bottom: 26px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #fca311;
  color: #14213d;
  font-weight: 900;
  box-shadow: 0 4px 12px rgba(252, 163, 17, 0.25);
}

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

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 9px 10px;
  border-radius: 8px;
  color: #dbeafe;
  transition: background 140ms ease, color 140ms ease, transform 140ms ease;
}

.nav a.active,
.nav a:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.nav a:hover {
  transform: translateX(2px);
}

.nav-indicator {
  width: 7px;
  height: 7px;
  border: 1px solid currentColor;
  border-radius: 50%;
  opacity: 0.65;
}

.nav a.active .nav-indicator {
  background: #fca311;
  border-color: #fca311;
  opacity: 1;
}

.nav-exit {
  margin-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0 !important;
  padding-top: 18px !important;
}

.sidebar-footer {
  display: grid;
  gap: 3px;
  margin-top: 34px;
  padding: 16px 10px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  color: #dbeafe;
  font-size: 13px;
}

.sidebar-footer strong {
  color: #ffffff;
  font-size: 14px;
}

.eyebrow {
  color: #93c5fd;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.main {
  padding: 28px clamp(18px, 3vw, 42px);
  min-width: 0;
  max-width: 1600px;
  width: 100%;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

.muted {
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 16px;
}

.stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.cards-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.stat-card {
  min-height: 118px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-accent {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fca311;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  margin-top: 8px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 14px;
}

.search-form {
  flex: 1 1 320px;
  justify-content: flex-end;
}

.search-form input {
  min-width: min(280px, 100%);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.form-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 6px;
}

.field-wide {
  grid-column: 1 / -1;
}

.token-control {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.token-control input {
  flex: 1 1 auto;
  min-width: 0;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  background: var(--surface-2);
}

.token-control button {
  flex: 0 0 auto;
}

.field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
  font: inherit;
}

input::placeholder {
  color: #98a2b3;
}

input:focus,
select:focus {
  outline: 3px solid rgba(23, 105, 170, 0.16);
  border-color: var(--brand);
}

.button,
button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  padding: 9px 13px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.button:hover,
button:hover {
  background: var(--brand-dark);
}

.button:active,
button:active {
  transform: translateY(1px);
}

.button:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(252, 163, 17, 0.45);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.button.secondary,
button.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.button.secondary:hover,
button.secondary:hover {
  background: #e4ebf2;
  color: var(--brand-dark);
}

.button.danger,
button.danger {
  background: var(--danger);
}

.icon-button {
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
}

.icon-button .icon {
  pointer-events: none;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.table-wrap {
  overflow-x: auto;
  max-height: 620px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: var(--surface);
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

tbody tr:hover {
  background: #f8fbfd;
}

tbody tr:last-child td {
  border-bottom: 0;
}

th {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  background: #f8fafc;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
  background: var(--surface-2);
  white-space: nowrap;
}

.badge.active,
.badge.ok {
  color: var(--ok);
  background: #dcfce7;
}

.badge.inactive {
  color: var(--muted);
}

.badge.suspended,
.badge.warn {
  color: var(--warn);
  background: #fef3c7;
}

.badge.pending,
.badge.exported,
.badge.received {
  color: var(--warn);
  background: #fef3c7;
}

.badge.integrated,
.badge.synced,
.badge.status_update {
  color: var(--ok);
  background: #dcfce7;
}

.badge.rejected {
  color: #991b1b;
  background: #fee2e2;
}

code {
  display: inline-block;
  max-width: 360px;
  white-space: normal;
  word-break: break-word;
  font-size: 12px;
  color: #334155;
}

.flash {
  margin-bottom: 14px;
  border-radius: 8px;
  padding: 11px 13px;
  font-weight: 700;
  background: #dcfce7;
  color: #166534;
}

.flash.error {
  background: #fee2e2;
  color: #991b1b;
}

.inline-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.compact-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.compact-form input,
.compact-form select {
  min-width: 130px;
}

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

dialog.edit-dialog {
  width: min(620px, calc(100% - 32px));
  max-height: min(760px, calc(100vh - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--brand);
  border-radius: 8px;
  color: var(--text);
  box-shadow: 0 24px 70px rgba(15, 35, 55, 0.24);
}

dialog.edit-dialog-small {
  width: min(440px, calc(100% - 32px));
}

dialog.edit-dialog::backdrop {
  background: rgba(20, 33, 61, 0.48);
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  grid-column: 1 / -1;
  padding-bottom: 4px;
}

.dialog-close {
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.dialog-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  grid-column: 1 / -1;
  padding-top: 8px;
}

.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.card > h2 {
  color: var(--brand-dark);
}

strong {
  font-weight: 750;
}

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

  .sidebar {
    position: static;
    min-height: auto;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats,
  .cards-2,
  .form-grid,
  .form-grid.three {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 20px 14px 28px;
  }

  .sidebar {
    padding: 18px 14px;
  }

  .brand {
    margin-bottom: 18px;
  }

  .sidebar-footer {
    display: none;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    gap: 10px;
    padding-bottom: 14px;
  }

  h1 {
    font-size: 23px;
  }

  .card {
    padding: 16px;
  }

  .toolbar,
  .toolbar .compact-form {
    align-items: stretch;
  }

  .toolbar > *,
  .toolbar .compact-form > * {
    width: 100%;
  }

  .inline-actions,
  .compact-form {
    align-items: stretch;
  }

  .inline-actions > *,
  .compact-form > * {
    flex: 1 1 100%;
  }

  .login-panel {
    padding: 24px 20px;
  }
}
