:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --surface-tint: #eef5f2;
  --ink: #19221f;
  --muted: #68736e;
  --line: #dbe3df;
  --line-strong: #b9c7c1;
  --accent: #1f7a70;
  --accent-strong: #14574f;
  --accent-soft: #dff1ed;
  --accent-warm: #b96543;
  --gold: #b88b32;
  --warn: #a36512;
  --warn-soft: #fff0d7;
  --danger: #b6423a;
  --danger-soft: #ffe8e5;
  --ok: #2f7b50;
  --ok-soft: #e4f4eb;
  --shadow-sm: 0 5px 16px rgba(24, 34, 31, 0.06);
  --shadow: 0 14px 36px rgba(24, 34, 31, 0.08);
  --shadow-strong: 0 22px 58px rgba(24, 34, 31, 0.16);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1120px;
  background:
    linear-gradient(135deg, rgba(31, 122, 112, 0.08) 0 22%, transparent 22% 100%),
    linear-gradient(180deg, #f9fbfa 0, var(--bg) 260px, #eef2f0 100%);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 18px;
  background:
    linear-gradient(180deg, #17211d, #223029 58%, #19241f),
    #17211d;
  color: #fbfffc;
  box-shadow: inset -1px 0 rgba(255, 255, 255, 0.06);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 54px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.26), rgba(255, 255, 255, 0)),
    repeating-linear-gradient(90deg, #3d9a8d 0 6px, #d7b66f 6px 12px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.brand p {
  margin: 4px 0 0;
  color: rgba(251, 255, 252, 0.66);
  font-size: 12px;
}

.side-nav {
  display: grid;
  gap: 7px;
}

.nav-button,
.quiet-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  background: transparent;
  color: rgba(251, 255, 252, 0.76);
  text-align: left;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-button svg,
.quiet-button svg,
button svg,
.search-box svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.nav-button:hover,
.quiet-button:hover {
  transform: translateX(2px);
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.nav-button.active {
  background: #f9fffc;
  color: var(--ink);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.18);
}

.nav-button.active svg {
  color: var(--accent);
}

.sidebar-footer {
  display: grid;
  gap: 6px;
  margin-top: auto;
}

.quiet-button.danger {
  color: #ffd5cf;
}

.main {
  min-width: 0;
  padding: 24px 28px 42px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: -24px -28px 18px;
  padding: 20px 28px 14px;
  border-bottom: 1px solid rgba(219, 227, 223, 0.72);
  background: rgba(248, 250, 249, 0.88);
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.topbar h2 {
  margin: 0;
  font-size: 27px;
  line-height: 1.15;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 360px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--muted);
  box-shadow: var(--shadow-sm);
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 112, 0.12), var(--shadow-sm);
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.save-state {
  min-width: 64px;
  color: var(--muted);
  font-size: 13px;
}

.user-menu {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 6px 0 12px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.current-user {
  max-width: 130px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.metric-card {
  position: relative;
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 92px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--accent), var(--gold));
}

.metric-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}

.metric-card strong {
  display: block;
  font-size: 26px;
  line-height: 1;
}

.metric-card span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.work-section {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 70px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #fbfcfb);
}

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

.operation-launcher .section-heading {
  min-height: 64px;
  border-bottom: 0;
}

.entry-panel.is-collapsed {
  display: none;
}

.entry-panel:not(.is-collapsed) {
  animation: panelReveal 160ms ease;
}

@keyframes panelReveal {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-heading h3 {
  margin: 0;
  font-size: 17px;
}

.section-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select,
.filter-group input,
.filter-group select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--surface-soft);
  color: var(--ink);
  outline: 0;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.field input:hover,
.field select:hover,
.filter-group input:hover,
.filter-group select:hover,
.table-input:hover {
  border-color: var(--line-strong);
  background: #fff;
}

.field input:focus,
.field select:focus,
.filter-group input:focus,
.filter-group select:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(31, 122, 112, 0.12);
}

.span-2 {
  grid-column: span 2;
}

.option-add-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
}

.option-add-field .icon-button {
  min-height: 40px;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  padding-top: 2px;
}

.primary-button,
.secondary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease, background 150ms ease;
}

.primary-button {
  background: linear-gradient(180deg, #23877b, var(--accent));
  color: #fff;
  box-shadow: 0 9px 18px rgba(31, 122, 112, 0.2);
}

.primary-button:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, #1e746b, var(--accent-strong));
  box-shadow: 0 12px 24px rgba(31, 122, 112, 0.26);
}

.secondary-button,
.icon-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.secondary-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.secondary-button.is-active {
  border-color: rgba(31, 122, 112, 0.36);
  background: #e9f4f1;
  color: var(--accent-strong);
}

.icon-button {
  width: 40px;
  padding: 0;
}

.filter-group {
  display: flex;
  gap: 8px;
}

.wide-filter-group {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filter-group select {
  width: 132px;
}

.filter-group input[type="date"] {
  width: 150px;
}

.table-wrap {
  overflow: auto;
}

.table-wrap.compact {
  max-height: 330px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  height: 48px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef4f1;
  color: #4f5f58;
  font-weight: 700;
}

tbody tr {
  transition: background 120ms ease;
}

tbody tr:hover {
  background: #f7fbf9;
}

tbody tr.is-voided-row {
  color: var(--muted);
  background: #fafafa;
}

tbody tr.is-voided-row td {
  text-decoration-color: rgba(104, 115, 110, 0.38);
}

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

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

.mono {
  font-family: "Cascadia Mono", Consolas, monospace;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.row-actions {
  display: inline-flex;
  gap: 6px;
}

.row-actions button {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.row-actions button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

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

.line-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

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

.line-editor h4 {
  margin: 0;
  font-size: 14px;
}

.line-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.purchase-line {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) minmax(110px, 0.75fr) minmax(110px, 0.75fr) minmax(170px, 1fr) 40px;
  gap: 8px;
  align-items: end;
}

.style-material-line {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) minmax(110px, 0.8fr) minmax(110px, 0.8fr) 40px;
  gap: 8px;
  align-items: end;
}

.purchase-line button,
.style-material-line button {
  width: 40px;
  height: 40px;
}

.style-purchase-panel {
  display: grid;
  grid-template-columns: 1.4fr minmax(220px, 1fr) minmax(130px, 0.7fr) auto;
  gap: 12px;
  align-items: end;
  border: 1px solid #b9d6cf;
  border-radius: 8px;
  padding: 14px;
  background: linear-gradient(180deg, #edf8f5, var(--accent-soft));
}

.style-purchase-panel h4 {
  margin: 0;
  font-size: 14px;
}

.style-purchase-panel p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.ai-style-workflow {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.ai-paste-zone {
  display: grid;
  min-height: 220px;
  place-items: center;
  gap: 8px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background:
    repeating-linear-gradient(45deg, rgba(31, 122, 112, 0.05) 0 10px, transparent 10px 20px),
    var(--surface-soft);
  color: var(--ink);
}

.ai-paste-zone svg {
  width: 34px;
  height: 34px;
  color: var(--accent);
}

.ai-paste-zone strong {
  font-size: 18px;
}

.ai-paste-zone span {
  color: var(--muted);
  font-size: 13px;
}

.ai-paste-zone.is-dragover {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(31, 122, 112, 0.12);
}

.ai-image-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 10px;
}

.ai-image-preview img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
}

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

.ai-result-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.ai-result-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ai-style-fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 14px 18px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.ai-note-field {
  grid-column: 1 / -1;
}

.table-input {
  width: 100%;
  min-width: 130px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  background: var(--surface);
  color: var(--ink);
  outline: 0;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.table-input.compact {
  min-width: 82px;
}

.receiver-line-select {
  min-width: 118px;
}

.table-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 112, 0.12);
}

.table-action-button {
  min-height: 34px;
  padding: 0 10px;
  white-space: nowrap;
}

.compact-heading {
  min-height: 62px;
}

.empty-state {
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  min-width: 220px;
  max-width: 360px;
  transform: translateY(20px);
  border-radius: 8px;
  padding: 12px 14px;
  background: #17211d;
  color: #fff;
  box-shadow: var(--shadow-strong);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(25, 34, 31, 0.46);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: min(760px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-strong);
}

.modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-heading h3 {
  margin: 0;
  font-size: 18px;
}

.modal-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.modal-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.modal-span-2 {
  grid-column: span 2;
}

.modal-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(31, 122, 112, 0.16), transparent 42%),
    linear-gradient(180deg, #f9fbfa, #eef2f0);
}

.login-screen[hidden] {
  display: none;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-strong);
}

.login-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px;
  border-bottom: 1px solid var(--line);
}

.login-heading h1 {
  margin: 0;
  font-size: 22px;
}

.login-heading p,
.login-hint {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.login-form {
  display: grid;
  gap: 14px;
  padding: 20px 22px 22px;
}

.permission-form .form-actions {
  gap: 10px;
}

.toggle-field {
  align-content: start;
}

.switch-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  color: var(--ink);
}

.switch-line input {
  width: 18px;
  height: 18px;
}

.permission-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.permission-block h4 {
  margin: 0 0 10px;
  font-size: 14px;
}

.permission-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.permission-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
}

.permission-check input {
  width: 16px;
  height: 16px;
}

.permission-tags {
  display: flex;
  max-width: 360px;
  flex-wrap: wrap;
  gap: 5px;
}

.permission-tag {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--surface-tint);
  color: var(--accent-strong);
  font-size: 12px;
}

.is-permission-hidden {
  display: none !important;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

@media (max-width: 900px) {
  body {
    min-width: 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

  .main {
    padding: 18px;
  }

  .topbar {
    position: static;
    margin: -18px -18px 18px;
    padding: 18px;
  }

  .topbar,
  .topbar-actions,
  .split-layout {
    display: grid;
    grid-template-columns: 1fr;
  }

  .user-menu {
    width: 100%;
    justify-content: space-between;
  }

  .search-box {
    width: 100%;
  }

  .metric-grid,
  .form-grid,
  .ai-style-fields {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .purchase-line,
  .style-material-line,
  .style-purchase-panel {
    grid-template-columns: 1fr;
  }

  .line-editor-head,
  .line-editor-actions,
  .section-actions,
  .modal-actions,
  .ai-result-actions {
    align-items: stretch;
    flex-direction: column;
  }

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

  .modal-span-2 {
    grid-column: span 1;
  }
}
