/* FAOS 统一白底格式 - 全站共用 */
:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0d9488;
  --accent-2: #14b8a6;
  --accent-strong: #0f766e;
  --border: #e2e8f0;
  --active: #0f766e;
  --success: #059669;
  --error: #ef4444;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-card: 0 4px 12px rgba(0,0,0,0.06);
  --header-bg: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%);
  --header-text: #f8fafc;
  --header-muted: #cbd5e1;
  --header-border: rgba(255,255,255,0.08);
  /* 流畅动画：只动 transform/opacity，60fps 友好 */
  --ease-out: cubic-bezier(0.25, 0.1, 0.25, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --duration-fast: 0.15s;
  --duration-normal: 0.2s;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* T0 体感：站内跳转时轻微变暗，仅视觉 */
body.nav-loading {
  opacity: 0.92;
  transition: opacity var(--duration-fast, 0.15s) var(--ease-out, ease-out);
}

#faos-transition-layer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 99999;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}
#faos-transition-layer.show {
  opacity: 1;
  transform: translateY(0);
}
.faos-transition-bar {
  height: 3px;
  background: rgba(15, 23, 42, 0.18);
  overflow: hidden;
}
.faos-transition-bar > span {
  display: block;
  height: 100%;
  width: 34%;
  background: linear-gradient(90deg, #22d3ee 0%, #14b8a6 55%, #22d3ee 100%);
  animation: faos-transition-scan 1s linear infinite;
}
@keyframes faos-transition-scan {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(360%); }
}
.faos-transition-text {
  margin: 6px 12px 0 auto;
  width: max-content;
  max-width: calc(100vw - 24px);
  font-size: 11px;
  font-weight: 600;
  color: #0f766e;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(20, 184, 166, 0.25);
  border-radius: 999px;
  padding: 4px 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

a.faos-nav-pending,
button.faos-nav-pending {
  opacity: 0.72 !important;
  transform: translateY(1px);
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 24px 32px 28px;
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: none;
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.25);
  position: relative;
}
header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, transparent 100%);
  opacity: 0.9;
}

.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.header-copy {
  display: grid;
  gap: 6px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: nowrap;
}

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

.brand-logo,
.header-logo {
  height: 80px;
  width: auto;
  max-width: 280px;
  object-fit: contain;
  display: block;
}

.brand-text,
.header-text {
  display: grid;
  gap: 6px;
}

header h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 600;
}

header p {
  margin: 0;
  color: var(--header-muted);
}

.lang-switch {
  display: grid;
  gap: 6px;
  justify-items: end;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.lang-switch select,
.lang-select {
  background: #0b1220;
  color: var(--header-text);
  border: 1px solid var(--header-border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

main {
  padding: 24px 32px 40px;
  display: grid;
  gap: 24px;
  background: var(--bg);
}

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateZ(0);
  backface-visibility: hidden;
}

.grid {
  display: grid;
  gap: 16px;
}

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

input,
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 14px;
  background: var(--panel);
  color: var(--text);
}

button,
a.btn,
.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: white;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.25);
}

button.secondary,
a.secondary,
.btn.secondary {
  background: var(--panel);
  color: var(--text);
  border-color: var(--border);
  box-shadow: none;
}

/* 可读性：表单标签与次要文字统一用主色，确保白底上清晰 */
label {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

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

/* 切换/选项卡未选中项也使用主色，保证可读 */
.tab:not(.active),
.login-toggle label,
[role="tab"]:not([aria-selected="true"]) {
  color: var(--text);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(13, 148, 136, 0.12);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 600;
}

.hidden {
  display: none;
}

/* 统一：各页 status 栏（Database/Email OK、Back、Logout）- 极小紧凑版 */
.status-header {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateZ(0);
}
.status-badge {
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(13, 148, 136, 0.16);
  color: var(--accent-strong);
  font-size: 10px;
  font-weight: 600;
}
.status-badge.warn {
  background: rgba(239, 68, 68, 0.12);
  color: var(--error);
}
.status-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}
.status-actions a,
.status-actions button {
  border-radius: 999px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  font-size: 11px;
}
.status-actions button:not(.secondary) {
  background: var(--accent);
  color: white;
  border-color: transparent;
}

/* 流畅帧率：按钮/链接 hover 只动 transform/opacity/颜色，避免 layout */
button,
a.btn,
.btn,
.status-actions a,
.status-actions button {
  transition: transform var(--duration-fast) var(--ease-out),
    opacity var(--duration-fast) var(--ease-out),
    background-color var(--duration-normal) var(--ease-out),
    border-color var(--duration-normal) var(--ease-out),
    color var(--duration-normal) var(--ease-out),
    box-shadow var(--duration-normal) var(--ease-out);
  backface-visibility: hidden;
}
button:active,
a.btn:active,
.btn:active {
  transition-duration: 0.05s;
}

/* 可滚动区域：启用 GPU 加速滚动 */
[class*="-scroll"],
[class*="scroll-content"],
[class*="list-scroll"],
[class*="table-wrap"] {
  -webkit-overflow-scrolling: touch;
  overflow-anchor: auto;
}

/* ========== Unified Layout System ========== */
:root {
  --page-padding: 16px;
  --card-padding: 16px;
  --section-gap: 12px;
  --header-height: 72px;
  --font-base: 14px;
  --font-small: 12px;
  --font-title: 22px;
  --table-header-weight: 600;
  --table-header-size: 12px;
  --table-body-size: 13px;
  --table-body-weight: 500;
}

.app-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.app-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px var(--page-padding);
  min-height: var(--header-height);
  background: var(--header-bg);
  color: var(--header-text);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.2);
}

.app-header h1 {
  margin: 0;
  font-size: var(--font-title);
  font-weight: 600;
}

.app-header .subtitle,
.app-header p {
  margin: 4px 0 0;
  font-size: var(--font-small);
  color: var(--header-muted);
}

.app-header__right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: nowrap;
}

.app-header__right .lang-select {
  max-width: 100px;
  font-size: 11px;
  padding: 5px 8px;
}

.app-header__right #global-logout-btn {
  margin-left: auto;
}

.app-header__right .lang-switch { margin: 0; }
.app-header__right a:not(.btn-finance),
.app-header__right button {
  padding: 6px 12px;
  font-size: var(--font-small);
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--header-border);
  background: rgba(255,255,255,0.1);
  color: var(--header-text);
  text-decoration: none;
  cursor: pointer;
}

.app-header__right a:not(.btn-finance):hover,
.app-header__right button:hover {
  background: rgba(255,255,255,0.15);
}

.status-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px var(--page-padding);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  min-height: 36px;
}

.status-bar .status-pill,
.status-bar .status-badge {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: var(--font-small);
  font-weight: 600;
  background: rgba(13, 148, 136, 0.14);
  color: var(--accent-strong);
}

.status-bar .status-pill.warn,
.status-bar .status-badge.warn {
  background: rgba(239, 68, 68, 0.12);
  color: var(--error);
}

.status-bar .status-actions,
.status-bar .actions {
  margin-left: auto;
}

.status-bar .status-meta {
  font-size: var(--font-small);
  color: var(--muted);
}

.app-main {
  flex: 1;
  padding: var(--section-gap) var(--page-padding);
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

.card {
  padding: var(--card-padding);
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  background: var(--card);
}

.table,
table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--table-body-size);
  font-weight: var(--table-body-weight);
  color: var(--text);
}

.table thead th,
table.table thead th {
  font-weight: var(--table-header-weight);
  font-size: var(--table-header-size);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.table tbody td,
table.table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.table tbody tr:hover,
table.table tbody tr:hover {
  background: rgba(13, 148, 136, 0.04);
}

.btn,
.btn-primary {
  padding: 8px 14px;
  font-size: var(--font-base);
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--accent);
  color: white;
  cursor: pointer;
  text-decoration: none;
}

.btn-secondary {
  background: var(--panel);
  color: var(--text);
  border-color: var(--border);
}

.input,
select.input,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"] {
  padding: 8px 12px;
  font-size: var(--font-base);
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

/* status-header 作为 status-bar 别名，保持兼容 */
.status-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px var(--page-padding);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  min-height: 36px;
}

.status-header .status-badge {
  padding: 3px 8px;
  font-size: var(--font-small);
}

/* Soft-match customer_match badge (Linked / Email not linked / Name only) */
.customer-match-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 8px;
  vertical-align: middle;
}
.customer-match-badge.matched {
  background: rgba(5, 150, 105, 0.15);
  color: var(--success);
  border: 1px solid rgba(5, 150, 105, 0.35);
}
.customer-match-badge.unmatched_email {
  background: rgba(234, 179, 8, 0.15);
  color: #a16207;
  border: 1px solid rgba(234, 179, 8, 0.35);
}
.customer-match-badge.name_only {
  background: rgba(100, 116, 139, 0.2);
  color: var(--muted);
  border: 1px solid rgba(100, 116, 139, 0.35);
}
.customer-match-link {
  font-size: 12px;
  margin-left: 8px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}
.customer-match-link:hover {
  color: var(--accent-strong);
}

/* ========== Unified status badges (orders, inventory, PO, factory, delivery, invoice, finance, AI) ========== */
.faos-badge,
.faos-status {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}
.faos-badge--success,
.faos-status--success {
  background: var(--faos-success-subtle, rgba(5, 150, 105, 0.12));
  color: var(--faos-success, #059669);
}
.faos-badge--warning,
.faos-status--warning {
  background: var(--faos-warning-subtle, rgba(217, 119, 6, 0.12));
  color: var(--faos-warning, #d97706);
}
.faos-badge--error,
.faos-status--error {
  background: var(--faos-error-subtle, rgba(220, 38, 38, 0.12));
  color: var(--faos-error, #dc2626);
}
.faos-badge--info,
.faos-status--info {
  background: var(--faos-info-subtle, rgba(37, 99, 235, 0.12));
  color: var(--faos-info, #2563eb);
}
.faos-badge--processing,
.faos-status--processing {
  background: var(--faos-info-subtle, rgba(37, 99, 235, 0.12));
  color: var(--faos-info, #2563eb);
}
.faos-badge--ai,
.faos-status--ai {
  background: var(--faos-ai-accent-subtle, rgba(99, 102, 241, 0.12));
  color: var(--faos-ai-accent, #6366f1);
}
.faos-badge--neutral,
.faos-status--neutral {
  background: var(--faos-neutral-100, #f1f5f9);
  color: var(--faos-neutral-600, #475569);
}

/* ========== Empty state (unified pattern) ========== */
.faos-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.faos-empty__icon {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 16px;
  opacity: 0.6;
}
.faos-empty__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 8px;
}
.faos-empty__description {
  font-size: 14px;
  margin: 0 0 20px;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}
.faos-empty__action {
  margin-top: 16px;
}

/* ========== Skeleton loading ========== */
.faos-skeleton {
  background: linear-gradient(90deg, var(--border) 25%, #f1f5f9 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: faos-skeleton 1.2s ease-in-out infinite;
  border-radius: 6px;
}
@keyframes faos-skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ========== Toast (global feedback) ========== */
.faos-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 20px;
  border-radius: 8px;
  background: #1e293b;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 9999;
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.faos-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.faos-toast--success { background: var(--success); }
.faos-toast--error { background: var(--error); }
.faos-toast--warning { background: #d97706; }

/* ========== Drawer (right-side detail panel) ========== */
.faos-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 500;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.faos-drawer-overlay.is-open {
  opacity: 1;
  visibility: visible;
}
.faos-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 480px;
  background: var(--card);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
  z-index: 501;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.faos-drawer-overlay.is-open .faos-drawer {
  transform: translateX(0);
}
.faos-drawer__header {
  flex-shrink: 0;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.faos-drawer__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.faos-drawer__close {
  padding: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  color: var(--muted);
}
.faos-drawer__close:hover {
  background: var(--bg);
  color: var(--text);
}
.faos-drawer__body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
