:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #f8fafb;
  --text: #17212b;
  --text-muted: #5c6875;
  --border: #cbd3dc;
  --border-soft: #e3e8ed;
  --primary: #145b76;
  --primary-hover: #0d485f;
  --primary-soft: #e7f2f6;
  --danger: #a33131;
  --danger-soft: #fff0ef;
  --warning: #865414;
  --warning-soft: #fff5df;
  --success: #236542;
  --success-soft: #eaf6ef;
  --neutral-soft: #edf1f4;
  --focus: #2176ae;
  --shadow: 0 12px 36px rgba(23, 33, 43, 0.16);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }
button, select, label[for] { cursor: pointer; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 72%, white);
  outline-offset: 2px;
}

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

.app-header {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px clamp(16px, 3vw, 36px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.title-block h1 { margin: 0; font-size: 24px; line-height: 1.25; }
.title-block p { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }
.header-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.account-actions {
  align-items: center;
  border-left: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: 4px;
  padding-left: 12px;
}

.current-user { color: var(--text-muted); font-size: 14px; font-weight: 600; margin-right: 2px; }

.login-view {
  align-items: center;
  background: var(--surface-muted);
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.1);
  max-width: 430px;
  padding: 30px;
  width: 100%;
}

.login-panel h1 { font-size: 26px; margin: 2px 0 8px; }
.login-panel > p { color: var(--text-muted); margin: 0 0 22px; }
.login-kicker { color: var(--primary) !important; font-size: 14px; font-weight: 700; }
.login-form { display: grid; gap: 16px; }
.login-submit { min-height: 44px; width: 100%; }
.setup-note { background: var(--warning-soft); border-left: 4px solid var(--warning); color: var(--text); margin: 0; padding: 10px 12px; }
.password-hint { color: var(--text-muted); font-size: 13px; line-height: 1.55; margin: -4px 0 0; }
.form-error { background: var(--danger-soft); border-left: 4px solid var(--danger); color: var(--danger); font-size: 14px; margin: 0; padding: 9px 12px; }
.single-column { grid-template-columns: 1fr; }
.users-dialog { max-width: 900px; width: min(900px, calc(100vw - 32px)); }
.users-toolbar { align-items: center; display: flex; gap: 20px; justify-content: space-between; padding: 0 24px 16px; }
.users-toolbar p { color: var(--text-muted); font-size: 14px; margin: 0; }
.users-table-wrap { margin: 0 24px 24px; max-height: min(55vh, 520px); }
.user-identity { display: grid; gap: 2px; }
.user-identity span { color: var(--text-muted); font-size: 13px; }
.user-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.user-actions .button { min-height: 34px; padding: 5px 10px; }

.module-nav {
  min-height: 46px;
  display: flex;
  align-items: end;
  gap: 4px;
  padding: 0 clamp(16px, 3vw, 36px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.module-tab {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-weight: 700;
}
button.module-tab:hover { background: var(--surface-muted); color: var(--text); }
.module-tab.active { border-bottom-color: var(--primary); color: var(--primary); }
.planned-label { padding: 1px 6px; border-radius: 999px; background: var(--neutral-soft); color: #56616c; font-size: 12px; font-weight: 600; }

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.button-primary { background: var(--primary); color: white; border-color: var(--primary); }
.button-primary:hover { background: var(--primary-hover); }
.button-secondary { background: var(--surface); border-color: var(--border); }
.button-secondary:hover, .button-quiet:hover { background: var(--surface-muted); border-color: #aeb8c2; }
.button-quiet { border-color: transparent; color: var(--text-muted); }
.button-danger { color: var(--danger); border-color: #d8aaaa; background: var(--surface); }

.workspace { padding: 16px clamp(12px, 3vw, 36px) 32px; }

.summary-strip {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}

.summary-item {
  min-width: 135px;
  min-height: 60px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  padding: 10px 16px;
  border: 0;
  border-right: 1px solid var(--border-soft);
  background: var(--surface);
  color: var(--text);
}
button.summary-item:hover { background: var(--surface-muted); }
.summary-item strong { font-size: 23px; line-height: 1; }
.summary-label { color: var(--text-muted); white-space: nowrap; }
.summary-alert strong { color: var(--danger); }
.summary-total { margin-left: auto; border-right: 0; }

.records {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.toolbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.toolbar h2 { margin: 0; font-size: 18px; }
.filters { display: flex; justify-content: flex-start; flex-wrap: wrap; gap: 8px; }
.filters input, .filters select { min-height: 40px; }
.search-field { flex: 1 1 240px; max-width: 430px; }
.search-field input { width: 100%; }

input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #aeb8c2;
  border-radius: 5px;
  background: white;
  color: var(--text);
}
textarea { resize: vertical; min-height: 86px; }
input::placeholder, textarea::placeholder { color: #717d89; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 820px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
th { background: var(--surface-muted); color: #3d4a57; font-size: 13px; font-weight: 700; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f3f8fa; }
tbody tr:focus { outline: 3px solid var(--focus); outline-offset: -3px; }
tbody tr:last-child td { border-bottom: 0; }
.company-name { display: block; font-weight: 700; color: var(--text); }
.cell-meta { display: block; margin-top: 2px; color: var(--text-muted); font-size: 13px; }
.number-col { text-align: center; }

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--neutral-soft);
  color: #3f4b56;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.status-active { color: var(--primary); background: var(--primary-soft); }
.status-success { color: var(--success); background: var(--success-soft); }
.status-warning { color: var(--warning); background: var(--warning-soft); }
.status-muted { color: #58636e; background: var(--neutral-soft); }
.due-overdue { color: var(--danger); font-weight: 700; }
.due-today { color: var(--warning); font-weight: 700; }

.empty-state { padding: 62px 24px; text-align: center; }
.empty-state h3 { margin: 0; font-size: 19px; }
.empty-state p { margin: 8px 0 18px; color: var(--text-muted); }
.result-count { margin: 0; padding: 8px 14px; color: var(--text-muted); font-size: 13px; border-top: 1px solid var(--border-soft); }

.detail-panel {
  position: fixed;
  z-index: 20;
  inset: 0 0 0 auto;
  width: min(520px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateX(104%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 180ms ease;
}
.detail-panel.open { transform: translateX(0); visibility: visible; pointer-events: auto; }
.panel-backdrop { position: fixed; z-index: 19; inset: 0; background: rgba(20, 28, 36, 0.34); }
.panel-header, .dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-header h2, .dialog-header h2 { margin: 1px 0 0; font-size: 21px; line-height: 1.35; }
.eyebrow { margin: 0; color: var(--text-muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; }
.icon-button {
  width: 40px; height: 40px;
  flex: 0 0 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 27px;
  line-height: 1;
}
.icon-button:hover { background: var(--surface-muted); border-color: var(--border); }
.panel-content { overflow-y: auto; padding: 16px 18px 30px; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }

.detail-section { margin-top: 22px; }
.detail-section:first-child { margin-top: 0; }
.detail-section h3 { margin: 0 0 9px; font-size: 16px; }
.detail-list { display: grid; grid-template-columns: 118px 1fr; gap: 7px 12px; margin: 0; }
.detail-list dt { color: var(--text-muted); }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }
.detail-list a { color: var(--primary); }
.notes-box { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { padding: 2px 8px; background: var(--neutral-soft); border-radius: 4px; color: #46525e; font-size: 13px; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline-item { position: relative; padding: 0 0 18px 19px; border-left: 2px solid var(--border-soft); }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before { content: ""; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.timeline-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.timeline-date { font-weight: 700; }
.timeline-method { color: var(--text-muted); font-size: 13px; }
.timeline-summary { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.timeline-next { margin: 7px 0 0; padding: 7px 9px; background: var(--surface-muted); border-left: 3px solid var(--primary); }
.no-history { color: var(--text-muted); padding: 12px 0; }
.audit { color: var(--text-muted); font-size: 12px; }

dialog {
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(20, 28, 36, 0.46); }
.form-dialog-small { width: min(620px, calc(100vw - 24px)); }
.form-dialog form { max-height: calc(100vh - 34px); overflow-y: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; padding: 18px; }
.field { display: flex; flex-direction: column; gap: 5px; font-weight: 600; }
.field input, .field select, .field textarea { font-weight: 400; }
.span-2 { grid-column: span 2; }
.dialog-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; background: var(--surface); border-top: 1px solid var(--border); }

.engine-body { padding: 18px; }
.engine-body > p { margin: 0 0 14px; }
.engine-status { padding: 10px 12px; border-left: 4px solid var(--primary); background: var(--primary-soft); color: #164b61; }
.engine-flow { list-style: none; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 0; margin: 18px 0; counter-reset: flow; }
.engine-flow li { position: relative; min-height: 112px; padding: 34px 10px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-muted); counter-increment: flow; }
.engine-flow li::before { content: counter(flow); position: absolute; top: 9px; left: 10px; width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%; background: var(--primary); color: white; font-size: 12px; font-weight: 700; }
.engine-flow strong, .engine-flow span { display: block; }
.engine-flow span { margin-top: 5px; color: var(--text-muted); font-size: 13px; }
.activation-box { padding: 12px 14px; border: 1px solid var(--border); border-radius: 6px; }
.activation-box h3 { margin: 0 0 7px; font-size: 15px; }
.activation-box ul { margin: 0; padding-left: 1.4em; }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%; bottom: 26px;
  transform: translateX(-50%);
  max-width: min(460px, calc(100vw - 32px));
  padding: 11px 15px;
  border-radius: 6px;
  background: #1f2d38;
  color: white;
  box-shadow: var(--shadow);
}

@media (max-width: 900px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .header-actions { justify-content: flex-start; }
  .account-actions { border-left: 0; margin-left: 0; padding-left: 0; }
  .toolbar { grid-template-columns: 1fr auto; }
  .filters { grid-column: 1 / -1; grid-row: 2; }
  .summary-total { margin-left: 0; }
}

@media (max-width: 700px) {
  .detail-panel { width: 100vw; }
  .engine-flow { grid-template-columns: 1fr; }
  .engine-flow li { min-height: auto; }
}

@media (max-width: 620px) {
  .workspace { padding-inline: 8px; }
  .app-header { padding-inline: 12px; }
  .header-actions { width: 100%; }
  .header-actions .button { flex: 1; padding-inline: 8px; }
  .account-actions { width: 100%; }
  .login-view { padding: 12px; }
  .login-panel { padding: 22px 18px; }
  .users-toolbar { align-items: stretch; flex-direction: column; }
  .summary-item { min-width: 124px; }
  .toolbar { grid-template-columns: 1fr; }
  .toolbar > .button-primary { grid-row: 2; width: 100%; }
  .filters { grid-row: 3; flex-direction: column; }
  .filters > *, .search-field { width: 100%; max-width: none; }
  .form-grid { grid-template-columns: 1fr; padding: 14px; }
  .span-2 { grid-column: span 1; }
  .detail-list { grid-template-columns: 1fr; gap: 2px; }
  .detail-list dd { margin-bottom: 7px; }
  .module-nav { padding-inline: 8px; overflow-x: auto; }
  .module-tab { white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  .detail-panel { transition: none; }
}
