:root {
  --ink: #182028;
  --muted: #66717c;
  --line: #dbe1e5;
  --surface: #ffffff;
  --canvas: #f3f5f6;
  --teal: #08766d;
  --teal-dark: #075f58;
  --teal-soft: #e7f4f2;
  --amber: #9a5b00;
  --amber-soft: #fff3d5;
  --red: #b42318;
  --red-soft: #fff0ee;
  --green: #237a45;
  --green-soft: #e8f5ec;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
label { display: grid; gap: 6px; color: #39434d; font-size: 13px; font-weight: 600; }
input, select, textarea {
  width: 100%; min-height: 40px; border: 1px solid #cbd3d8; border-radius: 6px;
  background: #fff; color: var(--ink); padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(8,118,109,.12); }
textarea { resize: vertical; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(380px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 18px 44px rgba(29,46,56,.1); }
.login-panel h1 { margin: 12px 0 24px; font-size: 24px; }
.login-panel label { margin-top: 14px; }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 8px; background: var(--teal); color: white; font-size: 20px; font-weight: 800; }
.brand-mark.small { width: 34px; height: 34px; font-size: 16px; }
.form-error { min-height: 20px; margin: 12px 0 0; color: var(--red); font-size: 13px; }

.app-view { min-height: 100vh; }
.topbar { height: 64px; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; border-bottom: 1px solid var(--line); background: #fff; }
.product-title, .topbar-actions, .section-heading, .agent-heading, .modal-header, .modal-actions, .action-bar { display: flex; align-items: center; }
.product-title { gap: 11px; }
.product-title h1 { margin: 0; font-size: 18px; }
.version-text { color: var(--muted); font-size: 11px; }
.topbar-actions { gap: 16px; color: var(--muted); font-size: 13px; }
.text-button { border: 0; background: transparent; color: var(--teal); padding: 6px; }

.workspace { width: min(1440px, 100%); margin: 0 auto; padding: 20px 24px 40px; }
.period-toolbar { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.period-toolbar label { width: 210px; }
.dirty-badge { align-self: center; border-radius: 4px; background: var(--amber-soft); color: var(--amber); padding: 6px 9px; font-size: 12px; font-weight: 700; }

.metric-strip { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)); border: 1px solid var(--line); border-radius: 8px; background: #fff; overflow: hidden; }
.metric { min-height: 84px; padding: 15px 17px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 9px; font-size: 21px; }
.metric.warning strong { color: var(--amber); }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; margin-top: 18px; align-items: start; }
.main-column { min-width: 0; display: grid; gap: 14px; }
.main-column > *, .workspace-grid > * { min-width: 0; }
.section-band, .agent-panel, .action-bar { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.section-band { padding: 18px; }
.section-heading { justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.section-heading h2, .agent-heading h2, .modal-header h2 { margin: 0; font-size: 16px; }
.section-heading p, .modal-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.business-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 220px)) minmax(240px, 1fr); gap: 14px; }
.source-heading { align-items: start; }
.source-status { border-radius: 4px; padding: 5px 8px; background: #eef1f3; color: var(--muted); font-size: 11px; font-weight: 800; }
.source-status.ready { background: var(--green-soft); color: var(--green); }
.source-status.pending { background: var(--amber-soft); color: var(--amber); }
.source-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.source-layout { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.source-layout strong { font-size: 14px; }
.source-layout p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }

.primary-button, .secondary-button, .success-button, .danger-button {
  min-height: 38px; border-radius: 6px; padding: 8px 14px; font-weight: 700; border: 1px solid transparent;
}
.primary-button { background: var(--teal); color: #fff; }
.primary-button:hover { background: var(--teal-dark); }
.secondary-button { border-color: #c8d0d5; background: #fff; color: #35404a; }
.success-button { background: var(--green); color: #fff; }
.danger-button { border-color: #e7b5b0; background: #fff; color: var(--red); }
.full-width { width: 100%; margin-top: 20px; }

.table-wrap { width: 100%; min-width: 0; max-width: 100%; overflow-x: auto; }
table { width: 100%; min-width: 780px; border-collapse: collapse; font-size: 13px; }
th { color: var(--muted); font-size: 12px; text-align: left; font-weight: 700; background: #f7f8f8; }
th, td { padding: 11px 10px; border-bottom: 1px solid #e6eaec; white-space: nowrap; }
tbody tr:hover { background: #fafcfc; }
.actions-column { width: 118px; }
.row-actions { display: flex; gap: 6px; }
.row-actions button { border: 0; background: transparent; color: var(--teal); padding: 4px; }
.row-actions button.remove { color: var(--red); }
.empty-state { padding: 30px 12px; color: var(--muted); text-align: center; font-size: 13px; }
.blocker-band { border-color: #efc4bf; background: #fffafa; }
.blocker-list { margin: 0; padding-left: 20px; color: var(--red); font-size: 13px; line-height: 1.8; }
.action-bar { gap: 10px; flex-wrap: wrap; padding: 14px 18px; }

.agent-panel { position: sticky; top: 18px; overflow: hidden; }
.agent-heading { gap: 10px; padding: 16px; border-bottom: 1px solid var(--line); }
.agent-heading span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.agent-avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 6px; background: var(--teal-soft); color: var(--teal); font-weight: 800; }
.agent-messages { height: 330px; overflow-y: auto; padding: 14px; background: #fafbfb; }
.agent-message { width: fit-content; max-width: 92%; margin-bottom: 10px; border-radius: 7px; padding: 9px 11px; white-space: pre-wrap; font-size: 13px; line-height: 1.6; }
.agent-message.assistant { border: 1px solid #d9e5e3; background: #fff; }
.agent-message.user { margin-left: auto; background: var(--teal); color: #fff; }
.agent-suggestions { display: flex; gap: 6px; flex-wrap: wrap; padding: 12px 14px 0; }
.agent-suggestions button { min-height: 30px; border: 1px solid #b9d9d5; border-radius: 5px; background: var(--teal-soft); color: var(--teal-dark); font-size: 12px; }
.agent-input { display: grid; gap: 8px; padding: 12px 14px 14px; }
.agent-input textarea { min-height: 70px; }

.modal { width: min(820px, calc(100vw - 24px)); max-height: calc(100vh - 30px); padding: 0; border: 0; border-radius: 8px; box-shadow: 0 24px 80px rgba(15,31,39,.28); }
.modal::backdrop { background: rgba(24,32,40,.48); }
.compact-modal { width: min(430px, calc(100vw - 24px)); }
.modal-header { justify-content: space-between; padding: 17px 20px; border-bottom: 1px solid var(--line); }
.modal-body { max-height: calc(100vh - 180px); overflow-y: auto; padding: 20px; }
.modal-actions { justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.icon-button { width: 34px; height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 24px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
fieldset { margin: 20px 0 0; border: 1px solid var(--line); border-radius: 6px; padding: 14px; }
legend { padding: 0 6px; font-size: 13px; font-weight: 800; }
.tax-fields { margin-top: 14px; }
.import-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.import-metric { min-height: 74px; padding: 13px; border-right: 1px solid var(--line); }
.import-metric:last-child { border-right: 0; }
.import-metric span { display: block; color: var(--muted); font-size: 11px; }
.import-metric strong { display: block; margin-top: 7px; font-size: 18px; }
.import-fields { margin-top: 18px; }
.checkbox-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; }
.checkbox-grid label { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.checkbox-grid input { width: 18px; min-height: 18px; height: 18px; margin: 0; accent-color: var(--teal); }
.import-differences { margin-top: 20px; }
.import-differences h3 { margin: 0 0 10px; font-size: 14px; }
.import-differences ul { max-height: 220px; overflow-y: auto; margin: 0; padding-left: 20px; color: #3f4a54; font-size: 13px; line-height: 1.8; }
.import-blockers { margin-top: 16px; border: 1px solid #efc4bf; border-radius: 6px; background: var(--red-soft); color: var(--red); padding: 11px 12px; font-size: 13px; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: min(420px, calc(100vw - 30px)); border-radius: 6px; background: #202a31; color: #fff; padding: 11px 14px; font-size: 13px; box-shadow: 0 10px 28px rgba(0,0,0,.2); }

@media (max-width: 980px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .agent-panel { position: static; }
  .agent-messages { height: 250px; }
}

@media (max-width: 700px) {
  .topbar { padding: 0 14px; }
  .workspace { padding: 14px 12px 30px; }
  .metric-strip { grid-template-columns: repeat(2, 1fr); }
  .metric { border-bottom: 1px solid var(--line); }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:last-child { grid-column: 1 / -1; border-bottom: 0; }
  .period-toolbar label { width: calc(50% - 6px); }
  .period-toolbar .secondary-button { order: 3; }
  .business-fields, .form-grid { grid-template-columns: 1fr; }
  .source-layout { align-items: stretch; flex-direction: column; }
  .source-layout button { width: 100%; }
  .import-metrics { grid-template-columns: repeat(2, 1fr); }
  .import-metric:nth-child(2) { border-right: 0; }
  .import-metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .checkbox-grid { grid-template-columns: 1fr; }
  .wide-field { grid-column: auto; }
  .section-band { padding: 14px; }
  .action-bar { display: grid; grid-template-columns: repeat(2, 1fr); }
  .topbar-actions #currentUser { display: none; }
}
