:root {
  --bg: #f5f4f1;
  --panel: #ffffff;
  --ink: #1f1f22;
  --muted: #7a7672;
  --line: #ece8e3;
  --soft: #faf9f7;
  --rose: #c94f64;
  --teal: #3c8c7c;
  --gold: #9a6d24;
  --danger: #a33b45;
  --shadow: 0 2px 16px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }

body {
  margin: 0; min-height: 100vh;
  display: grid; grid-template-columns: 232px minmax(0, 1fr);
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

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

button {
  min-height: 32px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--ink); padding: 0 12px; cursor: pointer;
  white-space: nowrap; font-size: 13px;
}
button:hover { border-color: #ccc; background: var(--soft); }
button:disabled { opacity: .4; cursor: default; }

.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.primary:hover { background: #333; color: #fff; }
.danger  { background: rgba(186,86,96,.08); border-color: rgba(186,86,96,.2); color: var(--danger); }

/* ---- Sidebar ---- */
.sidebar {
  min-height: 100vh; padding: 20px 14px;
  background: #1f1f22; color: #fff; position: sticky; top: 0;
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 16px; margin-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
  width: 38px; height: 38px; border-radius: 8px;
  display: grid; place-items: center; background: var(--rose);
  font-weight: 800; font-size: 14px;
}
.brand strong { display: block; font-size: 15px; }
.brand small { display: block; margin-top: 2px; color: rgba(255,255,255,.5); font-size: 12px; }

nav { margin-top: 8px; }
.nav-section { margin-bottom: 6px; }
.nav-section-title {
  font-size: 11px; letter-spacing: .5px; color: rgba(255,255,255,.3);
  text-transform: uppercase; padding: 10px 10px 6px; font-weight: 600;
}
.nav-btn {
  min-height: 38px; border: 0; width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  background: transparent; color: rgba(255,255,255,.7); text-align: left;
  font-size: 14px; border-radius: 6px; padding: 0 10px;
}
.nav-btn:hover, .nav-btn.active { background: rgba(255,255,255,.1); color: #fff; }
.nav-btn.locked { opacity: .4; }

/* ---- Shell ---- */
.shell { min-width: 0; padding: 24px 28px 48px; }

.topbar {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 20px; margin-bottom: 20px;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; line-height: 1.2; }
h2 { font-size: 16px; }
.topbar p { margin-top: 4px; color: var(--muted); font-size: 14px; }

.operator { display: flex; align-items: center; gap: 12px; }
.role-switch { display: flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; font-size: 13px; }

select, input, textarea {
  min-height: 36px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--ink); padding: 0 10px; outline: none; font-size: 14px;
}
textarea { min-height: 90px; padding-top: 8px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--rose); box-shadow: 0 0 0 3px rgba(201,79,100,.08); }

/* ---- Grid / Columns ---- */
.grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, .7fr); gap: 14px; margin-bottom: 14px; }

.card, .panel, .table-card {
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); box-shadow: var(--shadow);
}
.metric-card { padding: 16px 18px; }
.metric-card span, .metric-card small { display: block; color: var(--muted); font-size: 13px; }
.metric-card strong { display: block; margin: 6px 0 2px; font-size: 26px; }
.metric-card.warn strong { color: var(--rose); }
.metric-card.ok strong { color: var(--teal); }
.metric-card.gold strong { color: var(--gold); }

.panel, .table-card { padding: 16px; overflow: hidden; }

.section-title {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px;
}
.section-title span { color: var(--muted); font-size: 13px; }

/* ---- Toolbar ---- */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px;
}
.quick-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.quick-tags button { background: #fff; font-size: 13px; }
.toolbar input { width: min(480px, 100%); }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { border-bottom: 1px solid var(--line); padding: 10px 8px; text-align: left; vertical-align: middle; font-size: 13px; }
th { color: var(--muted); font-weight: 600; background: var(--soft); font-size: 12px; }
td:last-child { min-width: 160px; white-space: nowrap; }
td button { margin: 1px 2px; font-size: 12px; }

/* ---- Pill / Tag ---- */
.pill, .tag {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 22px; border-radius: 999px; padding: 0 8px;
  font-size: 12px; background: #ece6de; color: var(--ink); margin: 1px;
}
.pill.ok   { background: rgba(60,140,124,.1); color: var(--teal); }
.pill.warn { background: rgba(201,79,100,.1);  color: var(--rose); }
.pill.gold { background: rgba(154,109,36,.14); color: var(--gold); }
.pill.rose { background: rgba(201,79,100,.1);  color: var(--rose); }
.pill.mute { color: var(--muted); background: #f4f2ef; }
.tag { background: #f0ebe4; }

.product-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background: #f8edf1;
  display: block;
}

.product-detail-head {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.product-detail-img {
  width: 120px;
  height: 120px;
  border-radius: 12px;
  object-fit: cover;
  background: #f8edf1;
}

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

/* ---- Lines ---- */
.todo, .row-line {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; min-height: 44px; border-bottom: 1px solid var(--line);
}
.todo:last-child, .row-line:last-child { border-bottom: 0; }
.todo strong { font-size: 22px; color: var(--rose); min-width: 32px; }
.todo span { flex: 1; font-size: 14px; }
.todo button { font-size: 12px; }

.permission-list { display: flex; flex-wrap: wrap; gap: 8px; }
.permission-list span {
  min-height: 32px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--soft); padding: 6px 12px; font-size: 13px;
}
.hint { margin-top: 10px; color: var(--muted); line-height: 1.6; font-size: 13px; }
.empty {
  min-height: 240px; border: 1px dashed var(--line); border-radius: 8px;
  background: rgba(255,255,255,.5); display: grid; place-content: center;
  text-align: center; gap: 6px;
}
.empty strong { font-size: 18px; }
.empty p { color: var(--muted); }

/* ---- Toast ---- */
.toast {
  position: fixed; right: 24px; bottom: 24px; z-index: 10;
  min-height: 40px; display: flex; align-items: center;
  max-width: min(400px, calc(100vw - 40px));
  border-radius: 8px; background: var(--ink); color: #fff;
  padding: 0 14px; font-size: 14px;
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: .15s ease; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ---- Responsive ---- */
@media (max-width: 1080px) {
  body { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; position: static; }
  nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-section { margin: 0; }
  .nav-section-title { display: none; }
  .grid, .columns { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .shell { padding: 16px 12px 32px; }
  .grid, .columns { grid-template-columns: 1fr; }
  .topbar, .toolbar, .operator { flex-direction: column; align-items: stretch; }
  .toolbar-actions { justify-content: flex-start; }
}

/* ========== Modal / Dialog ========== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .15s;
}
.modal-box {
  background: #fff; border-radius: 12px;
  min-width: 380px; max-width: 520px; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close, .modal-header button { border: none; background: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 20px; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 20px; border-top: 1px solid var(--line);
}
.modal-footer button { min-width: 80px; }
.modal-body label { display: block; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.modal-body input, .modal-body select, .modal-body textarea {
  display: block; width: 100%; margin-top: 4px;
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px;
}
.modal-body textarea { min-height: 50px; resize: vertical; }

.dlg-row { display: flex; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.dlg-key { flex: 0 0 100px; color: var(--muted); }
.dlg-val { flex: 1; font-weight: 500; }
.dlg-reason { margin-top: 10px; }

.btn-muted { background: var(--soft); color: var(--muted); }
.btn-primary { background: var(--rose); color: #fff; border-color: var(--rose); font-weight: 600; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }

.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.edit-grid label { margin-bottom: 0; }

/* ========== Order Detail ========== */
.order-detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.detail-row { display: flex; padding: 4px 0; border-bottom: 1px solid var(--line); }
.detail-label { flex: 0 0 70px; color: var(--muted); font-size: 12px; }
.detail-value { flex: 1; font-size: 13px; }

/* ========== Timeline ========== */
.timeline { padding: 4px 0; }
.timeline-item {
  position: relative; padding: 10px 0 10px 20px;
  border-left: 2px solid var(--line);
}
.timeline-item:last-child { border-left-color: transparent; }
.timeline-meta { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.timeline-content { font-size: 13px; color: var(--ink); }
.timeline-detail { margin-top: 2px; }

/* Alert */
.alert-warn { padding: 10px 14px; border-radius: 8px; background: #fff8e1; border: 1px solid #ffe082; color: #8d6e00; }

/* Animate */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
