:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --line: #dcdfe6;
  --text: #303133;
  --muted: #909399;
  --primary: #409eff;
  --success: #67c23a;
  --warning: #e6a23c;
  --danger: #f56c6c;
  --sidebar: #1f2d3d;
  --sidebar-active: #409eff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; color: var(--text); background: linear-gradient(180deg, #f8fafc 0%, #f4f7fb 100%); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; }
textarea { min-height: 100px; resize: vertical; }

.app-shell { min-height: 100vh; display: flex; }
.sidebar { width: 220px; background: var(--sidebar); color: #fff; padding: 16px 0; flex: 0 0 auto; box-shadow: inset -1px 0 0 rgba(255,255,255,.04); }
.brand { padding: 0 18px 18px; font-size: 18px; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 12px; }
.nav-item { display: flex; align-items: center; padding: 11px 18px; color: rgba(255,255,255,.82); border-left: 3px solid transparent; transition: background .15s ease, color .15s ease, transform .15s ease; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.06); color: #fff; border-left-color: var(--sidebar-active); }
.main { flex: 1; min-width: 0; }
.topbar { height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.92); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 10; box-shadow: 0 1px 0 rgba(31,45,61,.02); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.content { padding: 20px; max-width: 1400px; }
.global-search { display: flex; gap: 8px; flex: 1; max-width: 560px; }
.global-search input, .field input, .field select, .field textarea, .mini-form input, .mini-form select, .items-table input, .items-table select { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; background: #fff; }
.global-search input:focus, .field input:focus, .field select:focus, .field textarea:focus, .mini-form input:focus, .mini-form select:focus, .items-table input:focus, .items-table select:focus { outline: 2px solid rgba(64,158,255,.18); border-color: var(--primary); }
.items-table { min-width: 1180px; }
.items-table .product-picker-cell { min-width: 260px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 22px; }
.head-actions, .actions, .row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.back-link { display: inline-block; margin-bottom: 4px; color: var(--muted); }
.muted { color: var(--muted); }
.flash, .notice { padding: 12px 14px; background: #ecf5ff; border: 1px solid #c6e2ff; color: #409eff; border-radius: 8px; margin-bottom: 16px; }
.error { background: #fef0f0; color: var(--danger); padding: 12px; border-radius: 8px; overflow: auto; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 16px; overflow: hidden; box-shadow: 0 4px 18px rgba(31,45,61,.04); transition: box-shadow .15s ease, transform .15s ease; }
.panel:hover { box-shadow: 0 8px 24px rgba(31,45,61,.06); transform: translateY(-1px); }
.panel > summary { list-style: none; cursor: pointer; }
.panel > summary::-webkit-details-marker { display: none; }
.panel[open] > summary { border-bottom: 1px solid var(--line); }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, #fff 0%, #fbfcfe 100%); }
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-body { padding: 16px; }
.stats-grid, .two-col, .detail-layout { display: grid; gap: 16px; }
.stats-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); margin-bottom: 16px; }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; color: inherit; display: block; box-shadow: 0 4px 14px rgba(31,45,61,.04); transition: transform .15s ease, box-shadow .15s ease; }
.stat-card:hover { box-shadow: 0 8px 20px rgba(31,45,61,.06); transform: translateY(-1px); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.detail-layout { grid-template-columns: 340px minmax(0, 1fr); align-items: start; }
.detail-aside, .detail-main { display: grid; gap: 16px; }
.detail-aside { position: sticky; top: 76px; align-self: start; max-height: calc(100vh - 92px); overflow: auto; padding-right: 4px; }
.detail-surface .table-wrap, .quote-page-surface .table-wrap, .order-page-surface .table-wrap, .reports-page-surface .table-wrap, .settings-page-surface .table-wrap { max-height: 320px; }
.reports-page-surface .scroll-box { max-height: 320px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.detail-item { padding: 10px 0; border-bottom: 1px solid #f0f2f5; }
.detail-label { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.detail-value { word-break: break-word; }

.btn, .icon-btn { border: 1px solid transparent; border-radius: 6px; padding: 9px 12px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: #fff; color: var(--text); transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(64,158,255,.18); }
.btn-ghost { border-color: var(--line); background: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.icon-btn { width: 36px; height: 36px; padding: 0; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.content > .table-wrap, .content > .panel > .table-wrap { max-height: clamp(280px, 62vh, 680px); }
.orders-list-surface .table-wrap { max-height: clamp(280px, 58vh, 640px); }
.list-table-wrap { max-height: clamp(280px, 58vh, 640px); }
.list-summary { margin: -4px 0 10px; color: var(--muted); font-size: 13px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 12px 10px; border-bottom: 1px solid #ebeef5; vertical-align: top; text-align: left; }
th { background: #f5f7fa; font-weight: 600; white-space: nowrap; position: sticky; top: 0; z-index: 1; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty-cell { text-align: center; color: var(--muted); padding: 24px 10px; }
tbody tr:nth-child(even) td { background: #fcfdff; }
tbody tr:hover td { background: #f8fbff; }
.items-wrap { max-height: 420px; }

.pill, .chip { display: inline-flex; align-items: center; border: 1px solid transparent; border-radius: 999px; padding: 3px 9px; font-size: 12px; line-height: 1.4; }
.chip { background: #f4f4f5; color: #606266; }

.form-grid, .custom-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field, .field-wide { display: grid; gap: 6px; }
.field-wide { grid-column: 1 / -1; }
.field > span { color: var(--muted); font-size: 13px; }
.company-brand-layout { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 20px; align-items: start; }
.company-logo-preview, .company-logo-placeholder { min-height: 112px; border: 1px dashed var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 12px; color: var(--muted); background: #fbfcfe; }
.company-logo-preview img { display: block; max-width: 100%; max-height: 96px; object-fit: contain; }
.filter-bar { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.filter-actions { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; grid-column: 1 / -1; }
.mini-form { margin-top: 12px; }
.mini-filters { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.mini-list { display: grid; gap: 8px; max-height: 280px; overflow: auto; padding-right: 4px; }
.mini-item { display: block; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); transition: transform .15s ease, box-shadow .15s ease; }
.mini-item:hover { box-shadow: 0 6px 16px rgba(31,45,61,.05); transform: translateY(-1px); }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.tab { padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--text); background: #fff; }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.product-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; box-shadow: 0 4px 14px rgba(31,45,61,.04); }
.product-media { display: block; aspect-ratio: 1 / 1; background: #f5f7fa; overflow: hidden; }
.product-media img, .product-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.product-placeholder { display: grid; place-items: center; height: 100%; color: var(--muted); }
.product-meta { padding: 12px; display: grid; gap: 8px; }
.product-title { font-weight: 600; color: var(--text); }
.product-price { font-size: 18px; font-variant-numeric: tabular-nums; }
.product-thumb { display: block; aspect-ratio: 1 / 1; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #f5f7fa; }

.calendar-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.calendar-weekday { text-align: center; color: var(--muted); font-size: 13px; padding: 6px 0; }
.calendar-day { min-height: 140px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 10px; display: grid; gap: 8px; align-content: start; overflow: hidden; }
.calendar-day.today { border-color: var(--primary); box-shadow: 0 0 0 1px rgba(64,158,255,.1); }
.calendar-day.muted-day { opacity: .45; }
.calendar-head { display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.calendar-body { display: grid; gap: 4px; max-height: 110px; overflow: auto; padding-right: 2px; }

.timeline-item { padding: 10px 0; border-bottom: 1px solid #f0f2f5; }
.timeline-time { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.bar-row { display: grid; grid-template-columns: 80px 1fr 90px; gap: 10px; align-items: center; margin-bottom: 10px; }
.bar-track { height: 10px; background: #ebeef5; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 999px; }
.bar-fill.alt { background: var(--success); }

.kanban-board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(280px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.kanban-col { background: #fff; border: 1px solid var(--line); border-radius: 8px; min-height: 420px; display: grid; grid-template-rows: auto 1fr; }
.kanban-head { padding: 12px 14px; border-top: 3px solid var(--primary); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.kanban-body { padding: 12px; display: grid; gap: 10px; max-height: 520px; overflow: auto; }
.multi-list { max-height: 240px; overflow: auto; padding-right: 4px; display: grid; gap: 8px; }
.kanban-card { background: #fafafa; border: 1px solid #ebeef5; border-radius: 8px; padding: 12px; display: grid; gap: 8px; }
.kanban-title { font-weight: 600; color: var(--text); }
.kanban-meta { color: var(--muted); font-size: 13px; }
.empty-inline { color: var(--muted); padding: 16px 0; text-align: center; }

.auth-shell { min-height: calc(100vh - 56px); display: grid; place-items: center; }
.auth-card { width: min(420px, calc(100vw - 24px)); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 24px; box-shadow: 0 8px 30px rgba(31,45,61,.08); }
.auth-card h1 { margin-top: 0; }

.pager { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.page-link { border: 1px solid var(--line); background: #fff; padding: 6px 10px; border-radius: 6px; color: var(--text); }
.page-link.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.mobile-toggle { display: none; }
.top-user { display: flex; align-items: center; gap: 10px; }
.bell-link { position: relative; }
.notif-badge { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 11px; display: inline-flex; align-items: center; justify-content: center; padding: 0 4px; box-shadow: 0 2px 8px rgba(245,108,108,.35); }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.dashboard-card { min-height: 240px; cursor: grab; }
.dashboard-card.dragging { opacity: .7; transform: scale(.99); }
.drag-handle { color: var(--muted); font-size: 12px; user-select: none; }
.column-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 10px 0 12px; }
.column-switch { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.column-switch input { margin: 0; }
.col-fixed { width: 42px; }

.back-link:hover, .nav-item:hover, .mini-item:hover, .tab:hover, .btn:hover, .page-link:hover { opacity: .92; }
.scroll-box { overflow: auto; padding-right: 4px; }
.shipment-editor { display: grid; gap: 10px; }
.shipment-editor-hint { font-size: 13px; }
.shipment-editor-rows { display: grid; gap: 10px; max-height: 300px; overflow: auto; padding-right: 4px; }
.shipment-editor-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 10px; align-items: end; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe; }

@media (max-width: 1199px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-layout { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .company-brand-layout { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-aside { position: static; max-height: none; overflow: visible; padding-right: 0; }
  .detail-surface .table-wrap, .quote-page-surface .table-wrap, .order-page-surface .table-wrap, .reports-page-surface .table-wrap, .settings-page-surface .table-wrap { max-height: 280px; }
  .content > .table-wrap, .content > .panel > .table-wrap { max-height: 320px; }
  .reports-page-surface .scroll-box { max-height: 280px; }
  .items-wrap { max-height: 340px; }
  .mini-list, .multi-list, .kanban-body { max-height: 320px; }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 767px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 56px auto 0 0; width: 220px; transform: translateX(-100%); transition: transform .2s ease; z-index: 20; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .mobile-toggle { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 0 12px; }
  .global-search { max-width: none; }
  .stats-grid, .form-grid, .custom-grid, .filter-bar, .form-grid.compact { grid-template-columns: 1fr; }
  .detail-surface .table-wrap, .quote-page-surface .table-wrap, .order-page-surface .table-wrap, .reports-page-surface .table-wrap, .settings-page-surface .table-wrap { max-height: 240px; }
  .content > .table-wrap, .content > .panel > .table-wrap { max-height: 260px; }
  .shipment-editor-row { grid-template-columns: 1fr; align-items: stretch; }
  .reports-page-surface .scroll-box { max-height: 240px; }
  .items-wrap { max-height: 300px; }
  .mini-list, .multi-list, .kanban-body { max-height: 280px; }
  .dashboard-grid { grid-template-columns: 1fr; }
}
