:root {
  --kx-ink: #142033;
  --kx-muted: #607086;
  --kx-line: #dbe3ec;
  --kx-soft: #f3f6f9;
  --kx-surface: #ffffff;
  --kx-blue: #1769e0;
  --kx-blue-dark: #0d4da8;
  --kx-teal: #078477;
  --kx-amber: #b45309;
  --kx-red: #c83b3b;
  --kx-green: #16805a;
  --kx-sidebar: #172334;
  --kx-shadow: 0 12px 34px rgba(20, 32, 51, 0.1);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  color: var(--kx-ink);
  background: var(--kx-soft);
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: 0;
}

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

button,
a { -webkit-tap-highlight-color: transparent; }

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

button { border: 0; }

.is-hidden { display: none !important; }
.cluster-row { display: flex; align-items: center; gap: 10px; }
.actions-end { display: flex; justify-content: flex-end; gap: 8px; }
.nav-external-icon { width: 14px; margin-left: auto; }
.notice-body { min-width: 0; }
.spacer-top-sm { margin-top: 8px; }
.redirect-shell { min-height: 100vh; }
.redirect-title { margin: 0; font-size: 20px; }

.app-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  stroke: currentColor;
  fill: none;
}

.app-icon-lg { width: 24px; height: 24px; flex-basis: 24px; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
  color: var(--kx-ink);
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--kx-blue);
  font-weight: 800;
}

.brand-copy { display: grid; line-height: 1.2; }
.brand-copy small { color: var(--kx-muted); font-size: 11px; font-weight: 500; }

.btn {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 650;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.btn:disabled { cursor: not-allowed; opacity: 0.55; }
.btn-primary { color: #fff; background: var(--kx-blue); }
.btn-primary:hover:not(:disabled) { background: var(--kx-blue-dark); }
.btn-secondary { color: var(--kx-ink); background: #fff; border-color: var(--kx-line); }
.btn-secondary:hover:not(:disabled) { background: #f8fafc; border-color: #b7c4d2; }
.btn-danger { color: var(--kx-red); background: #fff; border-color: #efc9c9; }
.btn-danger:hover:not(:disabled) { background: #fff5f5; }
.btn-quiet { min-height: 34px; padding: 6px 9px; color: var(--kx-muted); background: transparent; }
.btn-quiet:hover { color: var(--kx-ink); background: #edf2f7; }
.btn-block { width: 100%; }
.icon-btn { width: 38px; padding: 0; }

.field { display: grid; gap: 6px; }
.field label { color: #344357; font-size: 13px; font-weight: 650; }
.field-hint { margin: 0; color: var(--kx-muted); font-size: 12px; }
.input,
.select,
.textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--kx-ink);
  background: #fff;
  border: 1px solid #cbd6e2;
  border-radius: 7px;
  outline: 0;
}
.textarea { min-height: 92px; resize: vertical; }
.input:focus,
.select:focus,
.textarea:focus { border-color: var(--kx-blue); box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.13); }
.input[aria-invalid="true"] { border-color: var(--kx-red); }
.password-wrap { position: relative; }
.password-wrap .input { padding-right: 44px; }
.password-toggle { position: absolute; top: 2px; right: 2px; width: 38px; height: 38px; color: var(--kx-muted); background: transparent; cursor: pointer; }

.notice {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 12px;
  border: 1px solid var(--kx-line);
  border-radius: 7px;
  color: #344357;
  background: #fff;
}
.notice-info { border-color: #bed4f4; background: #f3f8ff; }
.notice-success { border-color: #b9dfd0; background: #f0faf6; color: #0f6648; }
.notice-warning { border-color: #ead4a9; background: #fff9ed; color: #85500e; }
.notice-error { border-color: #efc5c5; background: #fff5f5; color: #9f2929; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--kx-green); }
.spinner { animation: kx-spin 0.8s linear infinite; }
@keyframes kx-spin { to { transform: rotate(360deg); } }

/* Authentication */
.auth-body { min-height: 100vh; background: #eef3f8; }
.auth-header {
  display: flex;
  height: 64px;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(18px, 4vw, 56px);
  background: #fff;
  border-bottom: 1px solid var(--kx-line);
}
.auth-header-links { display: flex; align-items: center; gap: 18px; color: var(--kx-muted); font-size: 13px; }
.auth-main {
  display: grid;
  min-height: calc(100vh - 64px);
  grid-template-columns: minmax(260px, 0.85fr) minmax(360px, 1.15fr);
}
.auth-context {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(36px, 7vw, 92px);
  color: #e8eef6;
  background: var(--kx-sidebar);
}
.auth-context h1 { max-width: 560px; margin: 0 0 14px; color: #fff; font-size: clamp(30px, 4vw, 46px); line-height: 1.14; }
.auth-context > p { max-width: 540px; margin: 0; color: #b9c5d4; font-size: 16px; }
.auth-points { display: grid; gap: 14px; margin-top: 34px; }
.auth-point { display: flex; gap: 11px; align-items: flex-start; max-width: 520px; }
.auth-point strong { display: block; color: #fff; }
.auth-point span { color: #aebccd; font-size: 13px; }
.auth-panel-wrap { display: grid; place-items: center; padding: 32px 18px; }
.auth-panel { width: min(100%, 440px); padding: clamp(24px, 4vw, 38px); background: #fff; border: 1px solid var(--kx-line); border-radius: 8px; box-shadow: var(--kx-shadow); }
.auth-panel h2 { margin: 0; font-size: 25px; }
.auth-panel > p { margin: 6px 0 24px; color: var(--kx-muted); }
.auth-form { display: grid; gap: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--kx-muted); font-size: 12px; }
.form-meta label { display: flex; align-items: flex-start; gap: 8px; }
.auth-switch { margin: 19px 0 0; text-align: center; color: var(--kx-muted); font-size: 13px; }
.auth-switch a, .text-link { color: var(--kx-blue); font-weight: 650; }

/* Console */
.console-body { min-height: 100vh; overflow-x: hidden; }
.console-shell { display: grid; min-height: 100vh; grid-template-columns: 236px minmax(0, 1fr); }
.console-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  padding: 20px 14px;
  color: #c4cedb;
  background: var(--kx-sidebar);
}
.console-sidebar .brand { color: #fff; padding: 0 6px 18px; }
.console-sidebar .brand-copy small { color: #91a0b2; }
.nav-label { margin: 12px 9px 7px; color: #8190a3; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.console-nav { display: grid; gap: 3px; }
.console-nav button,
.console-nav a {
  display: flex;
  width: 100%;
  min-height: 40px;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 6px;
  color: #b5c1cf;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.console-nav button:hover,
.console-nav a:hover { color: #fff; background: #223248; }
.console-nav .active { color: #fff; background: #294568; }
.sidebar-footer { margin-top: auto; padding-top: 14px; border-top: 1px solid #2b3a4e; }
.console-main { min-width: 0; }
.console-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px clamp(18px, 3vw, 36px);
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--kx-line);
}
.console-title h1 { margin: 0; font-size: 19px; }
.console-title p { margin: 2px 0 0; color: var(--kx-muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-chip { display: grid; text-align: right; line-height: 1.25; }
.user-chip strong { font-size: 12px; }
.user-chip span { color: var(--kx-muted); font-size: 11px; }
.mobile-menu { display: none; }
.console-content { display: grid; gap: 18px; padding: clamp(18px, 3vw, 36px); }
.panel { display: grid; gap: 16px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.panel-heading h2 { margin: 0; font-size: 18px; }
.panel-heading p { margin: 4px 0 0; color: var(--kx-muted); }
.card {
  background: var(--kx-surface);
  border: 1px solid var(--kx-line);
  border-radius: 8px;
  box-shadow: 0 2px 7px rgba(20, 32, 51, 0.035);
}
.card-pad { padding: 18px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric { min-height: 112px; padding: 16px; }
.metric-head { display: flex; align-items: center; justify-content: space-between; color: var(--kx-muted); font-size: 12px; }
.metric-value { margin-top: 12px; font-size: 27px; font-weight: 760; line-height: 1; }
.metric-foot { margin-top: 9px; color: var(--kx-muted); font-size: 11px; }
.section-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr); gap: 14px; }
.card-title { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; font-size: 14px; }
.list { display: grid; }
.list-row { display: grid; min-height: 50px; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid #edf1f5; }
.list-row:first-child { border-top: 0; }
.list-row strong { display: block; font-size: 13px; }
.list-row small { color: var(--kx-muted); }
.badge { display: inline-flex; align-items: center; min-height: 23px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-green { color: #0f6849; background: #e8f6f0; }
.badge-blue { color: #124f9e; background: #eaf3ff; }
.badge-amber { color: #84500e; background: #fff3d9; }
.badge-red { color: #9d2929; background: #fdeaea; }
.badge-gray { color: #59687a; background: #edf1f5; }
.table-wrap { overflow: auto; }
.data-table { width: 100%; min-width: 720px; border-collapse: collapse; }
.data-table th { padding: 10px 12px; color: var(--kx-muted); background: #f7f9fb; border-bottom: 1px solid var(--kx-line); font-size: 11px; text-align: left; }
.data-table td { padding: 11px 12px; border-bottom: 1px solid #edf1f5; vertical-align: middle; }
.data-table tbody tr:hover { background: #fafbfd; }
.table-actions { display: flex; align-items: center; gap: 6px; }
.empty-state { padding: 38px 18px; color: var(--kx-muted); text-align: center; }
.empty-state .app-icon { width: 30px; height: 30px; margin-bottom: 8px; color: #8ea0b4; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.toolbar .input, .toolbar .select { width: auto; min-width: 170px; }
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--kx-line); border-radius: 7px; background: #fff; }
.segmented button { min-height: 32px; padding: 5px 10px; color: var(--kx-muted); background: transparent; border-radius: 5px; cursor: pointer; }
.segmented button.active { color: #fff; background: var(--kx-blue); }
.progress { height: 7px; overflow: hidden; background: #e9eef3; border-radius: 999px; }
.progress > span { display: block; height: 100%; background: var(--kx-teal); }
.code-box { padding: 12px; overflow: auto; color: #d7e2ed; background: #152233; border-radius: 7px; font: 12px/1.65 Consolas, monospace; }
.modal-backdrop { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 18px; background: rgba(13, 24, 39, 0.56); }
.modal { width: min(100%, 620px); max-height: calc(100vh - 36px); overflow: auto; padding: 22px; background: #fff; border-radius: 8px; box-shadow: var(--kx-shadow); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.toast-stack { position: fixed; right: 18px; bottom: 18px; z-index: 90; display: grid; gap: 8px; }
.toast { max-width: 360px; padding: 11px 13px; color: #fff; background: #172334; border-radius: 7px; box-shadow: var(--kx-shadow); }
.toast.error { background: #9f2929; }
.toast.success { background: #126548; }

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

@media (max-width: 820px) {
  .auth-main { grid-template-columns: 1fr; }
  .auth-context { display: none; }
  .auth-header-links { display: none; }
  .console-shell { grid-template-columns: 1fr; }
  .console-sidebar {
    position: fixed;
    z-index: 60;
    width: 236px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .console-sidebar.open { transform: translateX(0); }
  .mobile-menu { display: inline-flex; }
  .console-topbar { padding-inline: 14px; }
  .console-content { padding: 16px; }
  .user-chip { display: none; }
}

@media (max-width: 560px) {
  .auth-header { height: 58px; }
  .auth-main { min-height: calc(100vh - 58px); }
  .auth-panel-wrap { padding: 18px 12px; }
  .auth-panel { padding: 22px 18px; }
  .form-row, .modal-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric { min-height: 102px; padding: 13px; }
  .metric-value { font-size: 22px; }
  .panel-heading { display: grid; }
  .toolbar .input, .toolbar .select { width: 100%; }
}

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