:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #6b7688;
  --line: #e2e7ef;
  --blue: #2c89d9;
  --blue-weak: #eaf1ff;
  --teal: #0e9a9a;
  --green: #16865f;
  --red: #dc4458;
  --amber: #b76f0b;
  --sidebar: #111827;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

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

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 16px;
  background: var(--sidebar);
  color: #fff;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--blue);
  font-weight: 800;
}

.brand strong, .brand span { display: block; }
.brand span, .sidebar-card small {
  margin-top: 4px;
  color: #b5c0d2;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 7px;
  overflow-y: auto;
  padding-right: 2px;
}

.nav-item {
  height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  text-align: left;
  color: #dbe4f3;
  background: transparent;
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.nav-item.active, .nav-item:hover {
  color: #fff;
  background: #263756;
}

.nav-item:hover {
  transform: translateX(2px);
}

.sidebar-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid #344763;
  border-radius: 8px;
  background: #21304b;
}

.sidebar-card strong {
  display: block;
  margin: 8px 0;
}

.main {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 700;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 28px; }
h2 { margin-bottom: 0; font-size: 17px; }
h3 { margin-bottom: 8px; font-size: 15px; }

.top-actions, .button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button, .ghost-button, .text-button, .danger-button, .icon-button {
  min-height: 38px;
  border-radius: 6px;
  padding: 0 14px;
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.primary-button { border: 0; color: #fff; background: var(--blue); }
.danger-button { border: 0; color: #fff; background: var(--red); }
.ghost-button { border: 1px solid var(--line); color: var(--ink); background: #fff; }
.text-button { border: 0; color: var(--blue); background: transparent; }

.primary-button:hover, .danger-button:hover, .ghost-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(24, 35, 59, 0.12);
}
.text-link {
  color: var(--blue);
  font-size: 12px;
  text-decoration: none;
}
.text-link:hover { text-decoration: underline; }
.icon-button {
  width: 38px;
  border: 1px solid var(--line);
  padding: 0;
  color: var(--ink);
  background: #fff;
  font-size: 20px;
}

.metrics-grid, .content-grid, .three-grid, .two-grid, .board-grid, .settings-grid {
  display: grid;
  gap: 16px;
}

.metrics-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.content-grid { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.three-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.two-grid, .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.board-grid {
  grid-template-columns: repeat(5, minmax(190px, 1fr));
  overflow-x: auto;
  padding-bottom: 4px;
}

.login-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(440px, 1fr);
  min-height: 100vh;
  gap: 0;
  align-items: stretch;
  background: #fff;
}

.login-panel {
  width: min(100%, 560px);
  align-self: center;
  justify-self: center;
  padding: 0 54px;
  background: #fff;
}

.login-visual {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(8, 13, 22, 0.46), rgba(8, 13, 22, 0.16)),
    url("./assets/login-hero-premium.png") center / cover no-repeat;
}

.login-visual::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0.42));
}

.login-brand-lockup {
  position: absolute;
  z-index: 1;
  left: 44px;
  top: 34px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: #fff;
  letter-spacing: 0;
}

.login-brand-lockup strong {
  font-size: 15px;
  font-weight: 700;
}

.login-brand-lockup span {
  color: #ff5b4d;
  font-size: 13px;
  font-weight: 700;
}

.login-title {
  margin-bottom: 52px;
}

.login-title h2 {
  margin: 0 0 10px;
  color: #445166;
  font-size: 24px;
  font-weight: 400;
}

.login-title span {
  color: #9aa5b5;
  font-size: 13px;
}

.login-panel label {
  margin-bottom: 28px;
  color: #7b8797;
}

.login-panel input {
  border: 0;
  border-bottom: 1px solid #aeb7c4;
  border-radius: 0;
  padding: 11px 0;
  background: transparent;
}

.login-panel input:focus {
  outline: 0;
  border-bottom-color: var(--blue);
  box-shadow: none;
}

.login-panel .primary-button {
  width: 100%;
  height: 40px;
  border-radius: 2px;
  background: #2f9be6;
}

.recovery-drawer {
  margin-top: 34px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.recovery-drawer summary {
  width: max-content;
  color: #8b98aa;
  cursor: pointer;
  font-size: 13px;
}

.login-mode .app-shell {
  display: block;
}

.login-mode .sidebar,
.login-mode .topbar {
  display: none;
}

.login-mode .main {
  min-height: 100vh;
  padding: 0;
}

.panel, .metric, .board-column, .record-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(24, 35, 59, 0.045);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.panel { padding: 18px; }
.metric { padding: 18px; }
.panel:hover, .metric:hover {
  border-color: #d5deeb;
  box-shadow: 0 12px 30px rgba(24, 35, 59, 0.07);
}
.metric span, .metric small { color: var(--muted); }
.metric strong {
  display: block;
  margin: 10px 0 6px;
  font-size: 27px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.dashboard-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 108px;
  background: #fff;
}

.dashboard-hero p {
  max-width: 680px;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.command-hero h2 {
  font-size: 22px;
}

.single-form {
  grid-template-columns: 1fr;
  margin-bottom: 12px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 160px 160px 120px;
  gap: 12px;
  margin-bottom: 16px;
}

.customer-toolbar {
  grid-template-columns: minmax(260px, 1fr) 150px 150px 130px;
}

.material-toolbar {
  grid-template-columns: 180px 140px 170px 150px;
}

.sales-toolbar {
  grid-template-columns: 180px 140px 160px 140px;
}

.finance-toolbar {
  grid-template-columns: 150px 150px 150px 150px minmax(220px, 1fr);
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  transition: border-color 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

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

input:focus, select:focus, textarea:focus {
  outline: 0;
  border-color: rgba(44, 137, 217, 0.72);
  box-shadow: 0 0 0 3px rgba(44, 137, 217, 0.12);
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
  color: var(--muted);
  font-size: 13px;
}

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

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

th {
  color: var(--muted);
  background: #f8fafc;
  font-weight: 700;
}

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

tbody tr {
  transition: background 0.14s ease;
}

tbody tr:hover {
  background: #f9fbff;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.tag.red { color: var(--red); background: #ffe9ed; }
.tag.blue { color: var(--blue); background: var(--blue-weak); }
.tag.green { color: var(--green); background: #e7f7ef; }
.tag.amber { color: var(--amber); background: #fff4dc; }
.tag.gray { color: #566176; background: #edf1f7; }

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.log-mini {
  display: grid;
  gap: 5px;
  min-width: 220px;
  margin: 0;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  list-style: none;
  white-space: normal;
}

.task-list, .plain-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.task-list li, .plain-list li {
  display: flex;
  gap: 10px;
  align-items: center;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.dot.red { background: var(--red); }
.dot.amber { background: var(--amber); }
.dot.green { background: var(--green); }
.dot.blue { background: var(--blue); }

.board-column { padding: 12px; }
.board-column h3 {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.record-card {
  margin-top: 10px;
  padding: 12px;
  box-shadow: none;
}

.record-card strong {
  display: block;
  margin-bottom: 6px;
}

.record-card small {
  display: block;
  color: var(--muted);
  line-height: 1.5;
}

.check-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 13px 0;
}

.check-row span { color: var(--muted); }

.check-list {
  margin-bottom: 18px;
}

.rule-meta {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
  background: #f8fafc;
}

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

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 18px;
  color: var(--muted);
  background: #fbfcfe;
}

.mini-section + .mini-section {
  margin-top: 16px;
}

.bar-list {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  gap: 7px;
}

.bar-row div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

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

.bar-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1f7;
}

.bar-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.summary-strip div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}

.summary-strip span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.summary-strip strong { font-size: 23px; }

.notice {
  border: 1px solid #ffe0a3;
  border-radius: 8px;
  padding: 13px 14px;
  color: #754400;
  background: #fff8e8;
  line-height: 1.6;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.45);
  z-index: 20;
}

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

.modal {
  width: min(980px, 100%);
  max-height: 90vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

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

.modal-foot {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.modal-body {
  padding: 18px;
  overflow: auto;
}

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

.form-grid .full { grid-column: 1 / -1; }

.form-message {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.form-message.error {
  color: var(--red);
}

.form-message.success {
  color: var(--green);
}

.ledger-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.ledger-summary article {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fbfcfe;
}

.ledger-summary span, .ledger-summary small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.ledger-summary strong {
  display: block;
  margin: 6px 0;
  font-size: 20px;
}

.ledger-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.ledger-tabs button {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  background: #fff;
  cursor: pointer;
}

.ledger-tabs button.active {
  border-color: var(--blue);
  color: var(--blue);
  background: #eef5ff;
}

.ledger-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 14px;
}

.ledger-form-grid .full { grid-column: 1 / -1; }

.ledger-warning {
  margin-top: 14px;
}

.ledger-table table {
  min-width: 860px;
}

.compact-table table {
  min-width: 680px;
  font-size: 13px;
}

.finance-detail-table table {
  min-width: 1120px;
}

.xhs-table table {
  min-width: 980px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  border-radius: 8px;
  padding: 12px 14px;
  color: #fff;
  background: #172033;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  z-index: 30;
}

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { grid-template-columns: repeat(3, 1fr); }
  .metrics-grid, .content-grid, .three-grid, .two-grid, .settings-grid, .summary-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .login-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .main { padding: 18px; }
  .topbar, .top-actions, .button-row {
    align-items: stretch;
    flex-direction: column;
  }
  .nav, .metrics-grid, .content-grid, .three-grid, .two-grid, .settings-grid, .summary-strip, .toolbar, .form-grid, .ledger-summary, .ledger-form-grid {
    grid-template-columns: 1fr;
  }
}
