/* ============================================================
   睿达进销存 · 苹果风设计系统 theme.css
   石墨黑 + 蓝点缀 · 浅色/深色双主题
   ============================================================ */

/* ---------- 设计变量(浅色 / 默认) ---------- */
:root {
  /* 品牌色 */
  --accent: #0a84ff;            /* iOS 系统蓝 */
  --accent-hover: #0066d6;
  --accent-soft: rgba(10,132,255,.12);

  /* 中性色阶(浅色) */
  --bg: #f5f5f7;                /* macOS 浅灰背景 */
  --bg-elev: #ffffff;           /* 卡片/面板 */
  --bg-elev2: #fafafa;          /* 次级面板 */
  --bg-hover: rgba(0,0,0,.04);
  --text: #1d1d1f;              /* 主文字(近黑) */
  --text-2: #6e6e73;            /* 次要文字 */
  --text-3: #86868b;            /* 弱化文字 */
  --border: rgba(0,0,0,.08);
  --border-strong: rgba(0,0,0,.14);

  /* 语义色 */
  --green: #30d158;
  --red: #ff453a;
  --orange: #ff9f0a;
  --yellow: #ffd60a;
  --blue: #0a84ff;
  --purple: #bf5af2;
  --teal: #64d2ff;

  /* 语义色文字(浅色下用深色文字) */
  --on-green: #1d5c2e;
  --on-red: #7a211a;
  --on-orange: #6d4a08;
  --on-blue: #0a4d99;

  /* 阴影(苹果式极淡柔和) */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.08);

  /* 圆角 */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-pill: 999px;

  /* 字体 */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;

  /* 顶栏高度 */
  --topbar-h: 56px;

  color-scheme: light;
}

/* ---------- 深色主题 ---------- */
[data-theme="dark"] {
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --accent-soft: rgba(10,132,255,.18);

  --bg: #000000;                /* 纯黑底(苹果深色) */
  --bg-elev: #1c1c1e;           /* 卡片(石墨) */
  --bg-elev2: #2c2c2e;
  --bg-hover: rgba(255,255,255,.06);
  --text: #f5f5f7;              /* 主文字(近白) */
  --text-2: #98989d;
  --text-3: #636366;
  --border: rgba(255,255,255,.10);
  --border-strong: rgba(255,255,255,.18);

  --green: #30d158;
  --red: #ff453a;
  --orange: #ff9f0a;
  --yellow: #ffd60a;
  --blue: #0a84ff;
  --purple: #bf5af2;
  --teal: #64d2ff;

  --on-green: #b7f5c8;
  --on-red: #ffc9c4;
  --on-orange: #ffe0b3;
  --on-blue: #b3d9ff;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.5);

  color-scheme: dark;
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background .35s ease, color .35s ease;
}
/* 标题层级:字重克制(600),行高紧凑(1.25) */
h1,h2,h3,h4 { font-weight: 600; letter-spacing: -.01em; margin: 0; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
h4 { font-size: 15px; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
::selection { background: var(--accent-soft); }

/* 滚动条(苹果风细滚动条) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 顶栏(毛玻璃) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 100;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg-elev) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}
.topbar h1, .topbar h2 {
  font-size: 17px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-2); }
.logout {
  padding: 5px 12px; border-radius: var(--r-pill); border: 1px solid var(--border);
  background: var(--bg-elev2); color: var(--text-2); font-size: 13px; cursor: pointer;
  transition: all .2s;
}
.logout:hover { background: var(--bg-hover); color: var(--text); }

/* 顶栏"返回工作台"链接(统一样式,跟随主题) */
.back-link { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 500; color: var(--text-2); white-space: nowrap; }
.back-link:hover { color: var(--text); }

/* 主题切换按钮 */
.theme-toggle {
  width: 34px; height: 34px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--bg-elev2);
  color: var(--text-2); font-size: 16px; cursor: pointer;
  transition: all .25s;
}
.theme-toggle:hover { background: var(--bg-hover); color: var(--text); transform: rotate(15deg); }

/* ---------- 导航 ---------- */
.nav {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 10px 0;
  background: var(--bg);
}
.nav a {
  padding: 7px 14px; border-radius: var(--r-pill);
  font-size: 14px; font-weight: 400; color: var(--text-2);
  border: 1px solid transparent;
  transition: all .2s;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  white-space: nowrap;
  box-sizing: border-box;
}
.nav a:hover { background: var(--bg-hover); color: var(--text); }
.nav a.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
  box-shadow: 0 2px 8px var(--accent-soft);
}

/* ---------- 容器 ---------- */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 20px;
}

/* ---------- 面板/卡片 ---------- */
.panel, .card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
  transition: box-shadow .25s, background .35s, border-color .35s;
}
.panel:hover, .card:hover { box-shadow: var(--shadow-md); }
.panel h3, .card h3 {
  font-size: 16px; font-weight: 600; color: var(--text);
  margin-bottom: 14px; display: flex; align-items: center; gap: 8px;
  line-height: 1.3;
}

/* 卡片网格 */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px,1fr)); gap: 12px; margin-bottom: 14px; }
.cards .card { margin-bottom: 0; }
.cards .card .label { font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 400; }
.cards .card .value { font-size: 24px; font-weight: 600; letter-spacing: -.02em; line-height: 1.2; }
.cards .card .sub { font-size: 12px; color: var(--text-3); margin-top: 4px; font-weight: 400; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--r-md);
  font-size: 14px; font-weight: 500; font-family: var(--font);
  border: none; cursor: pointer;
  background: var(--accent); color: #fff;
  transition: all .18s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* 按钮变体 */
.btn.blue { background: var(--accent); }
.btn.green { background: var(--green); }
.btn.red { background: var(--red); }
.btn.orange { background: var(--orange); }
.btn.gray, .btn.grey, .btn.secondary {
  background: var(--bg-elev2); color: var(--text);
  border: 1px solid var(--border);
}
.btn.gray:hover, .btn.grey:hover, .btn.secondary:hover { background: var(--bg-hover); }
.btn.green:hover { filter: brightness(1.05); }
.btn.red:hover { filter: brightness(1.05); }

/* 小按钮 */
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: var(--r-sm); }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 表单 ---------- */
/* 文字统一左对齐,label 用相对单位,宽度随内容 */
.row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.row label {
  font-size: 14px; color: var(--text-2); font-weight: 500;
  display: inline-flex; align-items: center;
  text-align: left; white-space: nowrap;
  min-width: 4.5em; flex: 0 0 auto;
}
/* 表单网格:label 固定列 + input 均分列,严格对齐(桌面) */
.form-grid {
  display: grid;
  grid-template-columns: 90px 1fr 90px 1fr;
  align-items: center;
  gap: 14px 24px;
}
.form-grid label {
  width: auto; min-width: 0; flex: none;
  justify-content: flex-end; text-align: right;
}
.form-grid input, .form-grid select { min-width: 0; width: 100%; box-sizing: border-box; }
.form-grid .full { grid-column: 2 / -1; }
input, select, textarea {
  font-family: var(--font); font-size: 14px; color: var(--text);
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  transition: border-color .2s, box-shadow .2s, background .35s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
.row input, .row select, .row textarea { flex: 1; min-width: 8em; }

/* 筛选栏 */
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filter-bar select, .filter-bar input { padding: 8px 12px; }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th {
  font-size: 12px; font-weight: 500; color: var(--text-2);
  letter-spacing: .02em;
  background: var(--bg-elev2);
  position: sticky; top: 0;
}
tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--bg-hover); }
tbody tr:last-child td { border-bottom: none; }
td input, td select { padding: 6px 8px; width: 100%; }

/* ---------- 状态标签 ---------- */
.status {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 3px 12px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 500;
  min-width: 3.5em; text-align: center;
  white-space: nowrap;
}
.status.pending { background: rgba(255,159,10,.16); color: var(--on-orange); }
.status.delivered { background: rgba(10,132,255,.16); color: var(--on-blue); }
.status.verified { background: rgba(48,209,88,.16); color: var(--on-green); }
.status.finished { background: rgba(48,209,88,.16); color: var(--on-green); }
.status.cancelled { background: rgba(255,69,58,.16); color: var(--on-red); }
.status.off { background: rgba(255,69,58,.16); color: var(--on-red); }
.status.on { background: rgba(48,209,88,.16); color: var(--on-green); }

/* 金额颜色(字重克制:500中等,不堆粗体;金额一律右对齐+等宽数字) */
.amount-red { color: var(--red); font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }
.amount-ok { color: var(--green); font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }
.stock-low { color: var(--red); font-weight: 500; }
.stock-ok { color: var(--green); }
.profit { color: var(--green); font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 统一图标系统(SVG,跟随文字颜色) ---------- */
.icon { flex-shrink: 0; display: inline-block; vertical-align: -0.125em; }
[data-icon] { display: inline-flex; align-items: center; gap: 6px; }
/* 图标尺寸统一(按容器上下文,覆盖 data-icon-size 的混乱,确保视觉对齐) */
.topbar h1 .icon, .topbar h2 .icon { width: 18px; height: 18px; }
.topbar .user .icon { width: 15px; height: 15px; }
.nav a .icon { width: 16px; height: 16px; }
.panel h3 .icon, .card h3 .icon { width: 16px; height: 16px; }
.cards .card .label .icon { width: 14px; height: 14px; }
.btn .icon { width: 15px; height: 15px; }
.back-link .icon { width: 14px; height: 14px; }
.login-wrap h2 .icon { width: 18px; height: 18px; }
.login-wrap h2[data-icon] { justify-content: center; }

/* ---------- 数字/金额统一右对齐 + 等宽数字(财务底线) ---------- */
.num, th.num, td.num, .amount { text-align: right; font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.center { text-align: center; }

/* ---------- 订单行 ---------- */
.order-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; margin-bottom: 8px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--r-md);
  flex-wrap: wrap; gap: 10px;
  transition: all .2s;
}
.order-row:hover { box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.order-row .info { font-size: 14px; }
.order-row .actions { display: flex; gap: 6px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.4);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  display: none; align-items: center; justify-content: center;
  animation: fadeIn .2s;
}
.modal-mask.show { display: flex; }
.modal {
  background: var(--bg-elev); border-radius: var(--r-xl);
  padding: 24px; max-width: 560px; width: 92%;
  max-height: 86vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  animation: slideUp .25s cubic-bezier(.32,.72,.35,1);
}
.modal h3 { margin-bottom: 16px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px) scale(.97); } }

/* ---------- 其他 ---------- */
.empty { text-align: center; color: var(--text-3); padding: 40px 20px; font-size: 14px; }
.tip { font-size: 13px; color: var(--text-2); line-height: 1.45; }
.err { color: var(--red); font-size: 13px; }
.hidden { display: none !important; }
/* 全局文字防溢出:长文本自动换行,不横向溢出 */
p, span, div, td, th, label, a, h1, h2, h3, h4 { overflow-wrap: break-word; word-wrap: break-word; }
.total-box { text-align: right; font-size: 16px; font-weight: 600; margin-top: 12px; line-height: 1.3; }
.total-box span { color: var(--accent); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .two-col { grid-template-columns: 1fr; } }

/* 信息条 */
.school-info, .summary-card {
  font-size: 13px; color: var(--text-2);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: var(--r-md); padding: 10px 14px;
  display: flex; gap: 18px; flex-wrap: wrap; margin: 10px 0;
}

/* 角色徽章 */
.role-badge { padding: 2px 8px; border-radius: var(--r-pill); font-size: 12px; font-weight: 600; min-width: 3em; text-align: center; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; }
.rb-boss { background: rgba(191,90,242,.16); color: var(--purple); }
.rb-staff { background: rgba(10,132,255,.16); color: var(--blue); }
.rb-finance { background: rgba(48,209,88,.16); color: var(--green); }

/* 通用分类/信息标签(长度不一的文字统一气泡宽度) */
.tag {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px 10px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 500;
  min-width: 4em; text-align: center; white-space: nowrap;
  background: var(--accent-soft); color: var(--accent);
}
.tag.neutral { background: color-mix(in srgb, var(--text-2) 12%, transparent); color: var(--text-2); }

/* 学校食堂/校区气泡(多校区标签) */
.campus-pill {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px 10px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 500; white-space: nowrap;
  min-width: 3.5em; text-align: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  margin: 1px 2px;
}

/* 登录页 */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 20px;
}
.login-wrap .panel { max-width: 380px; width: 100%; padding: 32px; }

/* 响应式:小屏(≤720px) */
@media (max-width: 720px) {
  .container { padding: 12px 14px; }
  .panel, .card { padding: 14px; border-radius: var(--r-md); margin-bottom: 12px; }
  .panel h3, .card h3 { margin-bottom: 12px; font-size: 15px; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(140px,1fr)); gap: 10px; }
  .cards .card .value { font-size: 22px; }
  .topbar { padding: 0 14px; }
  .nav { padding: 10px 0; }
  th, td { padding: 8px; font-size: 13px; }

  /* 移动端表格:容器内横向滚动,不撑破页面 */
  .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: max-content; white-space: nowrap; border-collapse: collapse; }
  th, td { white-space: nowrap; }

  /* 移动端表单:降级单列,label 占满一行,输入框另起一行 */
  .form-grid { grid-template-columns: 1fr !important; gap: 8px; }
  .form-grid label { justify-content: flex-start; text-align: left; width: 100%; min-width: 0; }
  .form-grid input, .form-grid select { width: 100%; flex: none; }

  /* 移动端行内表单:label 占满一行 */
  .row { gap: 8px; }
  .row label { min-width: 0; width: 100%; flex: 1 1 100%; }
  .row input, .row select, .row textarea { flex: 1 1 100%; min-width: 0; }
}

/* 超小屏(≤375px)进一步压缩 */
@media (max-width: 375px) {
  .container { padding: 10px 12px; }
  .panel, .card { padding: 12px; }
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .cards .card .value { font-size: 20px; }
}

/* 主题过渡(切换时平滑) */
body, .panel, .card, .topbar, .nav a, input, select, textarea, .order-row, .btn, table, th, td {
  transition-property: background, color, border-color, box-shadow;
  transition-duration: .3s;
  transition-timing-function: ease;
}
