:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-subtle: #f7f8fa;
  --surface-strong: #eef1f4;
  --text: #17191c;
  --muted: #667085;
  --line: #dfe3e8;
  --line-strong: #c7cdd4;
  --primary: #1769e0;
  --primary-hover: #0f57c2;
  --primary-soft: #eaf2ff;
  --success: #17875d;
  --success-soft: #e8f6f0;
  --warning: #9a6700;
  --warning-soft: #fff4d6;
  --danger: #c93636;
  --danger-hover: #a92929;
  --danger-soft: #fff0f0;
  --shadow-sm: 0 1px 2px rgba(20, 24, 31, 0.06);
  --shadow-lg: 0 18px 48px rgba(20, 24, 31, 0.16);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

a {
  color: inherit;
}

.button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  font-weight: 650;
  white-space: nowrap;
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.button:hover {
  background: var(--primary-hover);
}

.button:active {
  transform: translateY(1px);
}

.button.secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.button.secondary:hover {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
}

.button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.button.ghost:hover {
  background: var(--surface-strong);
  color: var(--text);
}

.button.danger {
  background: var(--danger);
}

.button.danger:hover {
  background: var(--danger-hover);
}

.button.warning {
  border-color: #f0d58d;
  background: var(--warning-soft);
  color: #6d4800;
}

.button.success {
  background: var(--success);
}

.button.small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 17px;
}

.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
}

.field {
  display: grid;
  gap: 6px;
}

.field > span,
.field-label {
  color: #475467;
  font-size: 12px;
  font-weight: 650;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.textarea {
  min-height: 92px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.13);
}

.muted {
  color: var(--muted);
}

.error-text {
  color: var(--danger);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: #475467;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.primary {
  background: var(--primary-soft);
  color: #0d55bd;
}

.badge.success {
  background: var(--success-soft);
  color: #0f6d4a;
}

.badge.warning {
  background: var(--warning-soft);
  color: #7a5200;
}

.badge.danger {
  background: var(--danger-soft);
  color: #a52d2d;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-line,
.empty-state {
  min-height: 180px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.loading-line > div {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

dialog::backdrop {
  background: rgba(18, 22, 28, 0.52);
  backdrop-filter: blur(2px);
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.4;
}

.dialog-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.dialog-body {
  padding: 20px;
  overflow: auto;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface-subtle);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid .span-2 {
  grid-column: 1 / -1;
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1000;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 36px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(20, 24, 31, 0.14);
  animation: toast-in 180ms ease-out;
}

.toast.error {
  border-left-color: var(--danger);
}

.toast.success {
  border-left-color: var(--success);
}

.toast.warning {
  border-left-color: var(--warning);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

@media (max-width: 680px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .span-2 {
    grid-column: auto;
  }

  .dialog-actions {
    flex-wrap: wrap;
  }

  .dialog-actions .button {
    flex: 1;
  }
}
