:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-muted: #f9fbff;
  --border: #d9e2ef;
  --text: #162033;
  --subtle: #5e6d82;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #0f9f62;
  --warning: #c97710;
  --danger: #d14343;
  --shadow: 0 20px 45px rgba(31, 55, 90, 0.08);
}

* {
  box-sizing: border-box;
}

/* 显式 display 规则（如 .form-status 的 flex）会覆盖 hidden 属性的默认样式，这里统一兜底 */
[hidden] {
  display: none !important;
}

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

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

a:hover {
  text-decoration: underline;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 0.95rem;
  background: #fff;
  color: var(--text);
}

.file-input-native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

textarea {
  resize: vertical;
  min-height: 100px;
}

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

.sidebar {
  background: #0f172a;
  color: #dbe7ff;
  padding: 1.5rem;
}

.brand {
  padding-bottom: 1.5rem;
  border-bottom: 1px solid rgba(219, 231, 255, 0.15);
  margin-bottom: 1.5rem;
}

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

.brand-subtitle {
  margin-top: 0.35rem;
  color: #93a7c7;
  font-size: 0.92rem;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-link {
  display: block;
  padding: 0.82rem 0.95rem;
  border-radius: 12px;
  color: #dbe7ff;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(37, 99, 235, 0.18);
  text-decoration: none;
}

.main-shell {
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 1.5rem 2rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.language-switcher {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--subtle);
  font-size: 0.92rem;
}

.language-link {
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
}

.language-link.active {
  background: #e7eefc;
  color: #17315c;
  font-weight: 600;
}

.login-language-switcher {
  justify-content: flex-end;
  margin-bottom: 0.9rem;
}

.page-title {
  margin: 0;
  font-size: 1.75rem;
}

.page-subtitle {
  margin: 0.35rem 0 0;
  color: var(--subtle);
}

.page-content {
  padding: 1.5rem 2rem 2rem;
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-panel {
  width: min(100%, 460px);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 2rem;
}

.login-header h1 {
  margin: 0;
  font-size: 2rem;
}

.login-header p,
.login-note,
.field-hint {
  color: var(--subtle);
}

.login-note {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.92rem;
}

.field-hint {
  font-size: 0.84rem;
}

.card,
.metric-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.card {
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  padding: 1.4rem;
}

.metric-label {
  display: block;
  color: var(--subtle);
  margin-bottom: 0.65rem;
}

.metric-value {
  font-size: 2rem;
}

.card-header {
  margin-bottom: 1.25rem;
}

.card-header h2,
.detail-section h3 {
  margin: 0;
}

.card-header p,
.detail-section p {
  color: var(--subtle);
}

.card-header-inline {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.95rem 0.8rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--subtle);
  font-weight: 600;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.field span,
.detail-label {
  display: inline-block;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--subtle);
  margin-bottom: 0.45rem;
}

.password-input-row {
  display: flex;
  gap: 0.65rem;
  align-items: center;
}

.password-input-row input {
  flex: 1;
}

.password-toggle-button {
  min-width: 64px;
  padding: 0.72rem 0.95rem;
}

.radio-choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.4rem;
  align-items: center;
  margin-top: 0.55rem;
  margin-bottom: 0.65rem;
}

.radio-choice {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
}

.radio-choice input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

.radio-choice span {
  line-height: 1.2;
}

.radio-choice-group + .button {
  margin-top: 0.55rem;
}

.form-status {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  border-radius: 12px;
  padding: 0.9rem 1rem;
  font-weight: 500;
  /* 上下间距由 .stack-form 的 gap 统一控制 */
}

.form-status.is-loading {
  background: #e7eefc;
  color: #17315c;
}

.form-status-spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(23, 49, 92, 0.2);
  border-top-color: #17315c;
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

/* 登录等堆叠式表单：控件之间保持统一的垂直间距 */
.stack-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.stack-form.is-submitting {
  pointer-events: none;
}

.button[disabled] {
  opacity: 0.72;
  cursor: not-allowed;
}

.button.is-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.button.is-loading::before {
  content: '';
  width: 0.95rem;
  height: 0.95rem;
  margin-right: 0.55rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

.tech-meta-grid {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 1.15rem 1rem;
}

.button-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.button {
  border: none;
  border-radius: 12px;
  padding: 0.82rem 1.2rem;
  cursor: pointer;
  font-weight: 600;
}

.button-block {
  width: 100%;
}

.button-inline {
  white-space: nowrap;
}

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

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

.button-secondary {
  background: #e7eefc;
  color: #17315c;
}

.button-danger {
  background: #fee2e2;
  color: #9f1d1d;
}

.filter-bar {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 1fr auto;
  gap: 0.75rem;
  margin-bottom: 1.2rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
}

.status-draft { background: #e5e7eb; color: #334155; }
.status-pending { background: #dbeafe; color: #1d4ed8; }
.status-processed { background: #dcfce7; color: #166534; }
.status-rejected { background: #fee2e2; color: #b91c1c; }
.status-closed { background: #e2e8f0; color: #0f172a; }
.status-hold { background: #fef3c7; color: #92400e; }

.flash-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.login-card .flash-stack {
  margin-top: 1rem;
  margin-bottom: 1.15rem;
}

.flash {
  border-radius: 12px;
  padding: 0.9rem 1rem;
  font-weight: 500;
}

.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #b91c1c; }

.empty-state,
.form-errors {
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: var(--panel-muted);
  padding: 1rem;
  color: var(--subtle);
}

.form-errors {
  border-style: solid;
  border-color: #f5c6c6;
  background: #fff7f7;
  color: #b91c1c;
  /* 错误条比空状态框更紧凑：小内边距 + 小圆角 + 左侧红色强调线 */
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  border-left: 4px solid #d14343;
  font-size: 0.92rem;
  line-height: 1.5;
}

.form-errors ul {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.25rem;
}

.detail-card,
.detail-section {
  margin-bottom: 1.5rem;
}

.detail-grid {
  margin-top: 1.15rem;
  gap: 1.2rem 1rem;
}

.detail-grid > div {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.detail-section {
  margin-top: 1.3rem;
}

.detail-section .detail-label {
  margin-bottom: 0.55rem;
}

.detail-section h3 {
  margin-bottom: 0.85rem;
}

.detail-text {
  margin-top: 0.15rem;
  line-height: 1.65;
  white-space: pre-wrap;
  color: var(--text);
}

.attachment-section.compact {
  margin-top: 0.4rem;
}

.file-picker {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.file-picker-button {
  min-width: 132px;
  padding: 0.8rem 1.1rem;
  border: 1px solid #c7d7f4;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.08);
}

.file-picker-button:hover {
  background: #dbe7ff;
  text-decoration: none;
}

.file-picker-status {
  flex: 1;
  min-width: 240px;
  padding: 0.82rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--subtle);
  line-height: 1.4;
  word-break: break-all;
}

.file-picker-status.has-file {
  color: var(--text);
  background: #f8fbff;
}

.attachment-list {
  display: grid;
  gap: 0.85rem;
}

.attachment-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.95rem 1rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-muted);
}

.attachment-name {
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}

.attachment-meta {
  margin-top: 0.25rem;
  color: var(--subtle);
  font-size: 0.86rem;
}

.attachment-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}

.attachment-actions form {
  margin: 0;
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.timeline-item {
  padding-left: 1rem;
  border-left: 3px solid var(--border);
}

.timeline-meta {
  font-size: 0.86rem;
  color: var(--subtle);
  margin-bottom: 0.35rem;
}

.timeline-content {
  white-space: pre-wrap;
}

.inline-form {
  margin-top: 1rem;
}

code {
  background: #eff3f8;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}

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

  .sidebar {
    padding-bottom: 0.75rem;
  }

  .card-grid,
  .form-grid,
  .detail-grid,
  .action-grid,
  .filter-bar {
    grid-template-columns: 1fr;
  }

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

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

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

  .password-input-row,
  .attachment-item,
  .file-picker {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 640px) {
  .detail-grid-compact,
  .tech-meta-grid {
    grid-template-columns: 1fr;
  }
}
