:root {
  --bg: #eef2f8;
  --bg-deep: #dfe7f3;
  --surface: #ffffff;
  --surface-2: #f7f9fd;
  --surface-3: #eef3fb;
  --text: #122032;
  --muted: #50657d;
  --border: #d6e0ef;
  --accent: #1452cc;
  --accent-strong: #0c3ea0;
  --accent-soft: #d8e6ff;
  --success: #157347;
  --warn: #a15a05;
  --danger: #b42318;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(11, 41, 78, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 500px at 8% -10%, #d8e6ff 0%, transparent 65%),
    radial-gradient(800px 420px at 95% 0%, #dceadf 0%, transparent 60%),
    linear-gradient(180deg, #eef3fb 0%, #edf2f8 100%);
}

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

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

h2 {
  font-size: 1.18rem;
}

h3 {
  font-size: 1rem;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.86rem;
  color: var(--muted);
}

label > span:first-child {
  color: #2f425a;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #84a8ef;
  box-shadow: 0 0 0 4px rgba(20, 82, 204, 0.12);
}

textarea {
  background: var(--surface-2);
  resize: vertical;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #667f9e 50%),
    linear-gradient(135deg, #667f9e 50%, transparent 50%);
  background-position:
    calc(100% - 16px) calc(1em + 2px),
    calc(100% - 11px) calc(1em + 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

.select-wrap {
  position: relative;
  display: block;
}

.select-wrap svg {
  width: 15px;
  height: 15px;
  fill: #5c7699;
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.select-wrap select {
  padding-left: 32px;
}

.hidden {
  display: none !important;
}

.small-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.msg {
  min-height: 1.3em;
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: #2d4d72;
}

.tag {
  display: inline-flex;
  align-items: center;
  border: 1px solid #bfd3f4;
  background: #e8f0ff;
  color: #17438a;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.btn:hover {
  filter: brightness(0.98);
}

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

.btn.primary {
  background: linear-gradient(120deg, var(--accent), var(--accent-strong));
  color: #fff;
  box-shadow: 0 5px 14px rgba(20, 82, 204, 0.25);
}

.btn.ghost {
  background: var(--surface-3);
  color: #27405d;
  border-color: #cfe0fa;
}

.btn.full {
  width: 100%;
}

.btn.icon-left svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-view {
  min-height: 100vh;
  position: relative;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(500px 250px at 15% 15%, rgba(78, 129, 216, 0.2), transparent 70%),
    radial-gradient(480px 280px at 85% 10%, rgba(78, 180, 134, 0.18), transparent 70%);
}

.auth-content {
  width: min(1080px, 100%);
  position: relative;
  z-index: 1;
}

.auth-header {
  margin-bottom: 14px;
}

.auth-header h1 {
  font-size: clamp(1.8rem, 3vw, 2.5rem);
}

.auth-header p {
  margin: 8px 0 0;
  color: #41556f;
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.auth-panel {
  padding: 18px;
  display: grid;
  gap: 10px;
}

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

.sidebar {
  border-right: 1px solid #cbd8ee;
  background:
    linear-gradient(180deg, rgba(250, 252, 255, 0.95) 0%, rgba(239, 245, 255, 0.95) 100%),
    radial-gradient(600px 300px at -10% 10%, rgba(130, 172, 240, 0.25), transparent 65%);
  padding: 16px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
}

.brand-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  background: linear-gradient(145deg, #1857ce, #113f9a);
}

.brand-title {
  font-weight: 700;
  font-size: 1.02rem;
}

.brand-subtitle {
  color: #516681;
  font-size: 0.79rem;
}

.nav-list {
  display: grid;
  gap: 8px;
  align-content: start;
}

.nav-btn {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: #204066;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.nav-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

.nav-btn:hover {
  background: #eaf1ff;
  border-color: #c9dbf7;
}

.nav-btn.active {
  background: linear-gradient(115deg, #e0ebff, #edf4ff);
  border-color: #abc4ec;
  color: #153f86;
  font-weight: 700;
}

.sidebar-footer {
  display: grid;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid #cfe0fa;
  background: rgba(255, 255, 255, 0.78);
}

.session-summary {
  font-size: 0.82rem;
  color: #324d6e;
  line-height: 1.35;
}

.main {
  padding: 18px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
}

.topbar {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.topbar h1 {
  font-size: 1.38rem;
}

.page {
  display: none;
  gap: 14px;
}

.page.active {
  display: grid;
}

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

.stat-card {
  padding: 14px;
  background: linear-gradient(160deg, #ffffff 0%, #f0f6ff 100%);
}

.stat-label {
  color: #4f6681;
  font-size: 0.84rem;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.panel {
  padding: 15px;
}

.panel-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-header-row.wrap {
  flex-wrap: wrap;
}

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

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

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

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

.span-full {
  grid-column: 1 / -1;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

.checkbox-label input {
  width: 18px;
  height: 18px;
}

.split-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.side-card {
  border: 1px solid var(--border);
  background: #f8fbff;
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

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

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

.manual-fields {
  grid-template-columns: 1fr 1fr;
}

.cards-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.card-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f9fbff;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.card-item h3 {
  font-size: 0.98rem;
}

.kv {
  display: grid;
  gap: 2px;
}

.kv-label {
  color: #607997;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kv-value {
  color: #1f3550;
  font-size: 0.86rem;
  word-break: break-word;
}

.candidate-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.candidate-item {
  border: 1px solid #c9daf7;
  border-radius: 10px;
  background: #edf4ff;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.candidate-item code {
  font-size: 0.8rem;
  background: #fff;
  border: 1px solid #d0def4;
  border-radius: 7px;
  padding: 1px 6px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid #dce5f3;
  vertical-align: top;
  font-size: 0.86rem;
}

thead th {
  position: sticky;
  top: 0;
  background: #f0f5fd;
  color: #1f3857;
  z-index: 1;
}

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 9px;
  text-transform: uppercase;
}

.status.queued {
  background: #e3ebf8;
  color: #35567d;
}

.status.running {
  background: #dff4e8;
  color: #1b6d43;
}

.status.done {
  background: #daf4dd;
  color: #135e39;
}

.status.failed {
  background: #fde5e4;
  color: #9f261a;
}

.status.cancelled {
  background: #eceff4;
  color: #4f6481;
}

.profiles-grid {
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

.profile-card .flow-line {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.86rem;
}

.flow-badge {
  border-radius: 999px;
  padding: 2px 8px;
  border: 1px solid #c3d8f7;
  background: #edf4ff;
  color: #1d4f95;
  font-size: 0.74rem;
  text-transform: uppercase;
  font-weight: 700;
}

.profile-stats {
  display: grid;
  gap: 4px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid #d5e2f6;
  background: #f3f8ff;
}

.dns-editor-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 0;
}

.dns-ocr-box {
  margin-top: 12px;
  border: 1px solid #d2dff3;
  border-radius: 12px;
  background: #f6f9ff;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid #bfd3f4;
  background: #eaf2ff;
  color: #1e4e95;
  padding: 4px 9px;
  font-size: 0.78rem;
  font-weight: 600;
}

.chip button {
  border: 0;
  background: transparent;
  color: #1e4e95;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 999px;
  line-height: 1;
}

.chip button:hover {
  background: rgba(20, 82, 204, 0.12);
}

.ip-replace-wrap {
  position: relative;
}

.ip-replace-dropdown {
  position: absolute;
  right: 0;
  top: 44px;
  width: min(460px, calc(100vw - 48px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(16, 44, 76, 0.16);
  padding: 12px;
  z-index: 10;
}

.ip-replace-list {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.ip-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 37, 0.42);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}

.modal[hidden] {
  display: none !important;
}

.modal-card {
  width: min(540px, 100%);
  border: 1px solid #cad8ed;
  border-radius: 14px;
  background: #fff;
  padding: 15px;
  box-shadow: 0 20px 44px rgba(15, 41, 70, 0.26);
}

@media (max-width: 1140px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid #cbd8ee;
    grid-template-rows: auto auto auto;
  }

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

  .nav-btn {
    justify-content: center;
  }

  .nav-btn span {
    display: none;
  }

  .main {
    padding-top: 12px;
  }
}

@media (max-width: 900px) {
  .auth-grid,
  .split-grid,
  .form-grid,
  .form-grid.two-col,
  .form-grid.three-col {
    grid-template-columns: 1fr;
  }

  .manual-fields {
    grid-template-columns: 1fr;
  }

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

  .dns-editor-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .ip-replace-dropdown {
    position: static;
    width: 100%;
    margin-top: 8px;
  }

  .sidebar {
    padding: 12px;
  }

  .nav-list {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    overflow: auto;
  }

  .nav-btn {
    min-width: 48px;
  }
}
