:root {
  color-scheme: light;
  --bg: #f3f0eb;
  --panel: #fffdfa;
  --panel-strong: #ffffff;
  --ink: #181817;
  --ink-soft: #4b4641;
  --muted: #7f7871;
  --line: #e5ded5;
  --line-strong: #d5cbc0;
  --accent: #d66f2f;
  --accent-deep: #a84a18;
  --accent-soft: #fff0e4;
  --charcoal: #191a1a;
  --success: #287450;
  --success-soft: #eaf5ef;
  --warning: #9a5b1a;
  --warning-soft: #fff2dc;
  --danger: #a33c34;
  --danger-soft: #fbecea;
  --shadow: 0 18px 48px rgba(52, 41, 30, 0.08);
  --radius: 18px;
  --font: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 9% -8%, rgba(214, 111, 47, 0.12), transparent 28rem),
    linear-gradient(180deg, #f8f5f0 0, var(--bg) 26rem);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }

.topbar {
  height: 74px;
  padding: 0 clamp(18px, 4vw, 58px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: #fff;
  background:
    linear-gradient(115deg, rgba(255,255,255,0.04), transparent 45%),
    var(--charcoal);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 38px; height: 38px; color: #fff; }
.brand-cn { font-size: 20px; font-weight: 800; letter-spacing: 0.18em; line-height: 1.05; }
.brand-en { margin-top: 3px; color: rgba(255,255,255,0.56); font-size: 9px; font-weight: 700; letter-spacing: 0.18em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.db-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 280px;
  color: rgba(255,255,255,0.72);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #ad8b68; box-shadow: 0 0 0 4px rgba(173,139,104,.12); }
.status-dot.is-connected { background: #66c596; box-shadow: 0 0 0 4px rgba(102,197,150,.12); }
.status-dot.is-error { background: #ef8179; box-shadow: 0 0 0 4px rgba(239,129,121,.12); }

main { width: min(1540px, calc(100% - clamp(24px, 5vw, 80px))); margin: 0 auto; padding: 36px 0 58px; }

.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: 0.2em; }
.hero h1 { margin: 0; font-size: clamp(30px, 4vw, 48px); line-height: 1.08; letter-spacing: -0.04em; }
.hero-copy { max-width: 620px; margin: 11px 0 0; color: var(--muted); line-height: 1.7; }
.hero-note { display: grid; gap: 4px; min-width: 210px; padding: 13px 17px; color: var(--ink-soft); background: rgba(255,253,250,.72); border: 1px solid var(--line); border-radius: 12px; }
.hero-note span { color: var(--accent); font-size: 11px; font-weight: 700; }
.hero-note strong { font-size: 13px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { position: relative; overflow: hidden; padding: 18px 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 24px rgba(60,47,34,.035); }
.stat-card::after { content: ""; position: absolute; right: -20px; bottom: -35px; width: 90px; height: 90px; border-radius: 50%; background: var(--accent-soft); opacity: .55; }
.stat-card span { position: relative; z-index: 1; display: block; color: var(--muted); font-size: 12px; }
.stat-card strong { position: relative; z-index: 1; display: block; margin-top: 8px; font-size: clamp(21px, 2.4vw, 29px); font-variant-numeric: tabular-nums; }
.stat-warning strong { color: var(--warning); }

.workspace { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.toolbar { display: grid; grid-template-columns: minmax(280px, 1fr) auto auto; align-items: center; gap: 14px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.search-box { display: flex; align-items: center; gap: 9px; min-width: 0; height: 40px; padding: 0 13px; background: #f8f5f1; border: 1px solid transparent; border-radius: 10px; transition: .2s ease; }
.search-box:focus-within { background: #fff; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(214,111,47,.1); }
.search-icon { color: var(--muted); font-size: 23px; line-height: 1; transform: rotate(-15deg); }
.search-box input { width: 100%; min-width: 0; padding: 0; color: var(--ink); background: transparent; border: 0; outline: 0; }
.search-box input::placeholder { color: #aaa199; }
.filter-row { display: flex; gap: 5px; }
.filter-chip { padding: 8px 11px; color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: 8px; font-size: 12px; }
.filter-chip:hover { color: var(--ink); background: #f7f3ef; }
.filter-chip.is-active { color: var(--accent-deep); background: var(--accent-soft); border-color: #f2cdb3; font-weight: 700; }
.toolbar-actions { display: flex; gap: 7px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; padding: 0 16px; border: 1px solid transparent; border-radius: 9px; font-weight: 700; white-space: nowrap; transition: transform .16s ease, background .16s ease, border-color .16s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { cursor: not-allowed; opacity: .48; transform: none; }
.btn-primary { color: #fff; background: var(--accent); border-color: var(--accent); box-shadow: 0 7px 16px rgba(214,111,47,.19); }
.btn-primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
.btn-ghost { color: var(--ink-soft); background: #fff; border-color: var(--line-strong); }
.btn-ghost:hover { background: #f8f4ef; border-color: #c6b9ab; }
.topbar .btn-ghost { color: rgba(255,255,255,.82); background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.17); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-small { min-height: 34px; padding: 0 11px; font-size: 12px; }

.table-wrap { overflow: auto; max-height: calc(100vh - 330px); min-height: 255px; }
table { width: 100%; min-width: 1350px; border-collapse: separate; border-spacing: 0; }
th { position: sticky; top: 0; z-index: 2; padding: 13px 12px; color: #7b7167; background: #faf7f3; border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 800; text-align: left; white-space: nowrap; }
td { padding: 14px 12px; color: var(--ink-soft); border-bottom: 1px solid #eee8e1; vertical-align: top; }
td:nth-child(2) { white-space: nowrap; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #fffaf5; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.wide-cell { min-width: 205px; max-width: 280px; white-space: pre-wrap; line-height: 1.55; }
.actions-col { min-width: 112px; width: 112px; white-space: nowrap; }
.actions { display: flex; flex-wrap: nowrap; gap: 4px; }
.link-button { padding: 3px 4px; color: var(--accent-deep); background: transparent; border: 0; font-weight: 700; white-space: nowrap; }
.link-button:hover { text-decoration: underline; }
.link-button.danger { color: var(--danger); }
.order-no { color: var(--ink); font-weight: 800; letter-spacing: .02em; }
.price { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money-strong { color: var(--ink); font-weight: 800; }
.money-muted { color: var(--muted); }
.type-tag { display: inline-flex; padding: 5px 8px; color: var(--ink-soft); background: #f4f0eb; border-radius: 6px; white-space: nowrap; font-size: 11px; }
.status-chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.status-chip::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status-unpaid { color: var(--danger); background: var(--danger-soft); }
.status-partial { color: var(--warning); background: var(--warning-soft); }
.status-toship { color: var(--warning); background: var(--warning-soft); }
.status-shipped { color: var(--success); background: var(--success-soft); }
.status-overpaid { color: #733b80; background: #f5eafa; }
.muted-dash { color: #bbb2a9; }

.empty-state { display: grid; place-items: center; padding: 56px 20px 64px; text-align: center; }
.empty-state[hidden] { display: none; }
.empty-mark { display: grid; place-items: center; width: 46px; height: 46px; margin-bottom: 14px; color: var(--accent); background: var(--accent-soft); border-radius: 50%; font-size: 26px; font-weight: 300; }
.empty-state h2 { margin: 0 0 7px; font-size: 18px; }
.empty-state p { margin: 0; color: var(--muted); }
.table-footer { display: flex; justify-content: space-between; gap: 15px; padding: 12px 18px; color: var(--muted); background: #fcfaf7; border-top: 1px solid var(--line); font-size: 11px; }

dialog { color: var(--ink); border: 0; }
dialog::backdrop { background: rgba(25, 24, 22, .52); backdrop-filter: blur(4px); }
.order-dialog { width: min(790px, calc(100% - 30px)); max-height: calc(100vh - 40px); padding: 0; background: var(--panel-strong); border-radius: 18px; box-shadow: 0 26px 90px rgba(0,0,0,.26); overflow: auto; }
.order-dialog form { padding: 24px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.dialog-head h2 { margin: 0; font-size: 27px; letter-spacing: -.03em; }
.icon-button { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 9px; font-size: 24px; line-height: 1; }
.icon-button:hover { color: var(--ink); background: #f7f3ee; }
.form-grid { display: grid; gap: 15px; }
.form-section { min-width: 0; margin: 0; padding: 16px; background: #fcfaf7; border: 1px solid var(--line); border-radius: 12px; }
.form-section legend { padding: 0 7px; color: var(--ink-soft); font-size: 12px; font-weight: 800; }
.date-row { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
label { display: grid; gap: 7px; min-width: 0; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
label span { display: block; }
input, select, textarea { width: 100%; min-width: 0; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 8px; outline: 0; transition: border .18s ease, box-shadow .18s ease; }
input, select { height: 39px; padding: 0 11px; }
textarea { min-height: 74px; padding: 10px 11px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(214,111,47,.1); }
input::placeholder, textarea::placeholder { color: #b5aca4; }
label small { color: var(--muted); font-size: 10px; font-weight: 400; line-height: 1.4; }
.full-field { margin-top: 12px; }
.order-total { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 30px; margin-top: 16px; padding: 14px 17px; color: #fff; background: var(--charcoal); border-radius: 12px; }
.order-total div { display: grid; gap: 4px; }
.order-total span { color: rgba(255,255,255,.58); font-size: 11px; }
.order-total strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.order-total p { margin: 0; color: rgba(255,255,255,.48); text-align: right; font-size: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

.connect-dialog { width: min(470px, calc(100% - 30px)); padding: 0; background: transparent; overflow: visible; }
.connect-card { position: relative; padding: 28px; background: var(--panel-strong); border-radius: 18px; box-shadow: 0 28px 95px rgba(0,0,0,.28); }
.connect-close { position: absolute; top: 15px; right: 15px; }
.database-icon { display: flex; align-items: flex-end; gap: 5px; width: 54px; height: 54px; margin-bottom: 18px; padding: 12px; background: var(--charcoal); border-radius: 13px; }
.database-icon span { display: block; width: 8px; background: var(--accent); border-radius: 5px 5px 2px 2px; }
.database-icon span:nth-child(1) { height: 13px; opacity: .6; }
.database-icon span:nth-child(2) { height: 20px; opacity: .8; }
.database-icon span:nth-child(3) { height: 28px; }
.connect-card h2 { margin: 0 0 10px; font-size: 28px; letter-spacing: -.03em; }
.connect-copy { margin: 0; color: var(--muted); line-height: 1.75; }
code { padding: 1px 5px; color: var(--accent-deep); background: var(--accent-soft); border-radius: 4px; }
.connect-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 20px; }
.connect-status { min-height: 18px; margin: 14px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.login-field { margin-top: 20px; }
.login-field input { height: 44px; }
.login-submit { width: 100%; min-height: 44px; margin-top: 12px; }
.login-status-error { color: var(--danger); }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 100; max-width: calc(100% - 32px); padding: 11px 16px; color: #fff; background: rgba(25,26,26,.94); border-radius: 9px; box-shadow: 0 12px 30px rgba(0,0,0,.18); font-size: 13px; opacity: 0; transform: translate(-50%, 12px); pointer-events: none; transition: .2s ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: #8f342e; }

@media (max-width: 1050px) {
  .toolbar { grid-template-columns: 1fr auto; }
  .filter-row { grid-column: 1 / -1; grid-row: 2; }
  .table-wrap { max-height: none; }
}

@media (max-width: 720px) {
  .topbar { height: auto; min-height: 68px; padding: 12px 16px; }
  .db-status { display: none; }
  .topbar-actions { gap: 7px; }
  .topbar-actions .btn { min-height: 34px; padding: 0 11px; font-size: 12px; }
  .brand-en { display: none; }
  main { width: calc(100% - 24px); padding-top: 24px; }
  .hero { align-items: flex-start; flex-direction: column; }
  .hero-note { width: 100%; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card { padding: 14px 15px; }
  .toolbar { grid-template-columns: 1fr; padding: 13px; }
  .filter-row { grid-column: auto; grid-row: auto; overflow-x: auto; padding-bottom: 2px; }
  .toolbar-actions { justify-content: flex-end; }
  .table-footer { flex-direction: column; gap: 4px; }
  .date-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
  .order-dialog form { padding: 18px; }
  .order-total { grid-template-columns: 1fr 1fr; gap: 14px; }
  .order-total p { grid-column: 1 / -1; text-align: left; }
  .dialog-actions .btn { flex: 1; }
}

