:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #d9e0e7;
  --line-strong: #bdc8d3;
  --text: #15202b;
  --muted: #647487;
  --primary: #175cd3;
  --primary-dark: #1249a7;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b42318;
  --shadow: 0 12px 32px rgba(20, 34, 50, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  color: var(--primary-dark);
}

button,
input,
select {
  font: inherit;
}

.app-header {
  min-height: 68px;
  padding: 12px 28px;
  background: #14213d;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand:hover {
  color: #ffffff;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #bfccdc;
  margin-top: 2px;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.app-nav > a {
  color: #dbe6f4;
  padding: 8px 10px;
  border-radius: 6px;
}

.app-nav > a:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.identity {
  padding: 0 10px;
  border-left: 1px solid rgba(255, 255, 255, 0.2);
}

.identity strong,
.identity small {
  display: block;
}

.identity small {
  color: #bfccdc;
  margin-top: 2px;
}

.app-main {
  padding: 28px;
}

.content-wide,
.content-narrow {
  margin: 0 auto;
}

.content-wide {
  max-width: 1440px;
}

.content-narrow {
  max-width: 760px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.page-title h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.25;
}

.page-title p:not(.eyebrow) {
  color: var(--muted);
  margin: 8px 0 0;
}

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

.panel {
  padding: 20px;
  margin-bottom: 20px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel h2 {
  margin: 0;
  font-size: 16px;
}

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

.button {
  min-height: 36px;
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.button:hover {
  background: #f1f5f9;
}

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

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

.button.ghost {
  color: #ffffff;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.3);
}

.button.ghost:hover {
  background: rgba(255, 255, 255, 0.1);
}

.button.subtle {
  color: var(--primary);
}

.button.danger {
  color: var(--danger);
  border-color: #efb2ad;
}

.button.danger:hover {
  background: #fff5f4;
}

.button.compact {
  min-height: 30px;
  padding: 5px 10px;
  font-size: 12px;
}

.button.wide {
  width: 100%;
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-weight: 700;
}

.field {
  display: grid;
  gap: 6px;
  color: #344054;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--text);
  background: #ffffff;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 92, 211, 0.12);
}

.auth-layout {
  min-height: calc(100vh - 124px);
  max-width: 1080px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(340px, 0.8fr);
  align-items: center;
  gap: 64px;
}

.auth-intro h1 {
  margin: 0;
  max-width: 620px;
  font-size: 42px;
  line-height: 1.16;
}

.auth-intro > p:not(.eyebrow) {
  max-width: 600px;
  color: var(--muted);
  margin: 18px 0 0;
  font-size: 16px;
  line-height: 1.8;
}

.auth-card,
.form-panel {
  padding: 28px;
}

.auth-card {
  display: grid;
  gap: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-card h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.form-panel {
  display: grid;
  gap: 18px;
}

.flash-stack {
  max-width: 1440px;
  margin: 0 auto 18px;
  display: grid;
  gap: 8px;
}

.flash {
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.flash.error {
  color: var(--danger);
  border-color: #f3b8b2;
  background: #fff5f4;
}

.flash.success {
  color: var(--success);
  border-color: #a9d8b8;
  background: #f1fbf4;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr)) minmax(210px, 1.4fr) auto;
  align-items: end;
  gap: 12px;
}

.table-scroll {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1180px;
}

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

.admin-table th {
  color: #475467;
  background: var(--surface-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.admin-table tr:last-child td {
  border-bottom: 0;
}

.compact-table td,
.compact-table th {
  padding: 9px 10px;
  font-size: 12px;
}

.compact-select {
  min-height: 32px;
  width: 150px;
}

.region-editor {
  min-height: 40px;
  display: grid;
  gap: 6px;
}

.region-checkbox-grid {
  max-height: 112px;
  padding: 7px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
}

.region-checkbox-grid.is-disabled {
  color: #98a2b3;
  background: #f2f4f7;
}

.region-option {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 5px;
  min-width: 0;
  color: inherit;
  font-weight: 500;
  white-space: nowrap;
}

.region-option input {
  width: 15px;
  min-height: 15px;
  margin: 0;
}

.compact-region-editor {
  width: 250px;
}

.compact-region-grid {
  max-height: 126px;
  grid-template-columns: repeat(2, minmax(76px, 1fr));
  font-size: 12px;
}

.permission-summary {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

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

.actions form {
  display: none;
}

.toggle {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.toggle input {
  width: 16px;
  min-height: 16px;
}

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}

.tag.warn {
  color: var(--warning);
  background: #fff4df;
}

.status-strip {
  padding: 18px 20px;
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-left: 4px solid #98a2b3;
  border-radius: 8px;
  background: var(--surface);
}

.status-strip[data-state="running"] {
  border-left-color: var(--primary);
}

.status-strip[data-state="success"] {
  border-left-color: var(--success);
}

.status-strip[data-state="failed"] {
  border-left-color: var(--danger);
}

.status-strip > div:first-child {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #98a2b3;
}

.status-strip[data-state="running"] .status-dot {
  background: var(--primary);
}

.status-strip[data-state="success"] .status-dot {
  background: var(--success);
}

.status-strip[data-state="failed"] .status-dot {
  background: var(--danger);
}

.status-meta {
  margin: 16px 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 12px;
}

.status-meta div {
  min-width: 0;
}

.status-meta dt {
  color: var(--muted);
  font-size: 12px;
}

.status-meta dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.log-view {
  min-height: 300px;
  max-height: 540px;
  margin: 0;
  padding: 16px;
  overflow: auto;
  color: #dce7f5;
  background: #111c2e;
  border-radius: 6px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.empty-state {
  padding: 52px 32px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.empty-state h1 {
  margin: 0;
}

.empty-state p:not(.eyebrow) {
  color: var(--muted);
  margin: 14px auto 22px;
  overflow-wrap: anywhere;
}

@media (max-width: 1100px) {
  .inline-form {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .inline-form .button {
    width: max-content;
  }
}

@media (max-width: 820px) {
  .app-header {
    padding: 14px 18px;
    align-items: flex-start;
  }

  .app-nav {
    justify-content: flex-start;
  }

  .identity {
    border-left: 0;
    padding-left: 0;
  }

  .app-main {
    padding: 20px 14px;
  }

  .auth-layout {
    min-height: auto;
    grid-template-columns: 1fr;
    gap: 28px;
  }

  .auth-intro h1 {
    font-size: 30px;
  }

  .page-title {
    flex-direction: column;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }
}
