/* public/css/styles.css —— 设计稿配色与布局变量 */
:root {
  --teal: #0D9488;
  --teal-dark: #0F766E;
  --bg: #F9FAFB;
  --card: #FFFFFF;
  --border: #E5E7EB;
  --text: #111827;
  --text-muted: #6B7280;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }
/* 必须放在通用 display 规则之前：确保 [hidden] 始终隐藏元素，
   否则 .layout/.login-screen 的 display 会覆盖浏览器原生的 [hidden]{display:none}，
   导致登录后无法隐藏登录屏、跳不到工作台。 */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Sarasa Gothic SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
}
.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--teal);
  padding: 8px 12px 18px;
}
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--teal); color: #fff; }

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
}
.avatar-sm { width: 28px; height: 28px; font-size: 12px; }
.user-name { font-weight: 600; }
.user-role { font-size: 12px; color: var(--text-muted); }

/* 主区域 */
.main { padding: 24px 32px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.topbar-title { font-size: 22px; margin: 0; }
.topbar-sub { margin: 4px 0 0; color: var(--text-muted); }
.topbar-actions { display: flex; align-items: center; gap: 12px; font-size: 18px; }

/* 统计卡片 */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}
.stat-label { color: var(--text-muted); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat-value-sm { font-size: 16px; font-weight: 600; }

/* 新注册提示条（站内感知，替代外部通知通道） */
.notice {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; margin-bottom: 16px;
  background: #F0FDFA; border: 1px solid #99F6E4;
  border-radius: 12px; color: #115E59;
}
.notice-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--teal); flex: 0 0 auto;
}
.notice-text { flex: 1; font-size: 14px; line-height: 1.5; }
.badge-new {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  border-radius: 999px; background: var(--teal); color: #fff;
  font-size: 11px; font-weight: 600; vertical-align: middle;
}

/* 工具栏 */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.toolbar-left { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: 10px; }
.input, .select {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  font-size: 14px;
  color: var(--text);
}
.input { min-width: 220px; }
.input:focus, .select:focus { outline: 2px solid var(--teal); border-color: var(--teal); }

.btn {
  height: 36px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: #fff; border-color: #FCA5A5; color: #DC2626; }
.btn-danger:hover { background: #FEF2F2; }

/* 表格 */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.table th { background: var(--bg); color: var(--text-muted); font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
.empty { padding: 32px; text-align: center; color: var(--text-muted); }

/* 状态胶囊（已移除：状态字段在 v1.x 已删除） */

.row-actions { display: flex; gap: 8px; }
.link-btn {
  background: none; border: none; cursor: pointer;
  color: var(--teal); font-size: 13px; padding: 0;
}
.link-btn.danger { color: #DC2626; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: #fff; border-radius: 12px;
  width: 520px; max-width: 92vw;
  padding: 24px; max-height: 88vh; overflow: auto;
}
.modal h2 { margin: 0 0 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.form-grid input, .form-grid select {
  width: 100%; height: 36px;
  border: 1px solid var(--border); border-radius: 8px; padding: 0 10px;
}
.field-inline { display: flex; gap: 8px; align-items: center; }
.field-inline input, .field-inline select { flex: 1; min-width: 0; }
.btn-sm { height: 36px; padding: 0 10px; font-size: 13px; white-space: nowrap; }
.form-grid .full { grid-column: 1 / -1; }
.field-error { color: #DC2626; font-size: 12px; margin-top: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* 角色化：非管理员隐藏「渠道价」列 */
body:not(.role-admin) .col-channel { display: none; }

/* 登录屏 */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh;   /* dvh：避开手机浏览器工具栏遮挡 */
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  overflow-y: auto;                         /* 键盘弹出时内容可滚动，不顶掉卡片 */
  background: linear-gradient(135deg, #0F766E 0%, #134E4A 100%);
}
.login-card {
  width: 100%; max-width: 400px;
  margin: auto;                            /* 配合 overflow-y:auto，内容超高时仍居中且不裁切 */
  background: #fff; border-radius: 18px; padding: 28px 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  animation: cardIn .35s cubic-bezier(.2, .7, .3, 1) both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .login-card { animation: none; } }
.login-logo { text-align: center; font-size: 20px; font-weight: 700; color: var(--teal-dark); margin-bottom: 18px; }
.login-form { display: flex; flex-direction: column; }
/* 登录/注册两个独立界面之间的切换入口 */
.login-switch { text-align: center; font-size: 13px; color: var(--text-muted); margin-top: 16px; }
.login-switch a { color: var(--teal-dark); font-weight: 600; text-decoration: none; cursor: pointer; }
.login-switch a:hover { text-decoration: underline; }
.login-form label { font-size: 14px; color: var(--text-muted); margin: 10px 0 4px; }
.login-input {
  width: 100%;
  min-height: 48px; height: 48px;          /* 48px：满足拇指触控舒适区 */
  border: 1px solid var(--border); border-radius: 10px; padding: 0 14px;
  font-size: 16px;                          /* 16px：iOS 聚焦不自动放大页面 */
  color: var(--text);
}
.login-input:focus { outline: 2px solid var(--teal); border-color: var(--teal); }
.login-error { color: #DC2626; font-size: 12px; min-height: 16px; margin: 8px 0 0; }
.login-submit { margin-top: 16px; min-height: 50px; height: 50px; font-size: 16px; border-radius: 10px; }

/* 密码框 + 显示密码眼睛按钮 */
.login-field { position: relative; display: flex; align-items: center; }
.login-field .login-input { padding-right: 48px; }
.login-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; cursor: pointer;
  font-size: 18px; line-height: 1; color: var(--text-muted); border-radius: 8px;
}
.login-eye:active { background: var(--bg); }

/* 账号管理页 */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; margin-bottom: 16px; }
.card-title { margin: 0 0 14px; font-size: 15px; color: var(--text); }
.create-grid { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 12px 16px; align-items: end; }
.create-grid label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.create-grid .login-input, .create-grid .select { width: 100%; }
.create-actions { display: flex; align-items: flex-end; }
.create-grid .full { grid-column: 1 / -1; }
.muted { color: var(--text-muted); }

/* ============ 移动端底部药丸主导航 ============ */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 62%, rgba(249,250,251,0));
  z-index: 60;
  pointer-events: none; /* 仅药丸可点，透明区不挡内容 */
}
.bottom-pill {
  display: flex;
  width: 100%; max-width: 420px;
  height: 56px; padding: 4px;
  border-radius: 28px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
  pointer-events: auto;
}
.bottom-tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  border-radius: 24px;
  text-decoration: none;
  color: var(--text-muted);
}
.bottom-tab-icon { font-size: 19px; line-height: 1; }
.bottom-tab-label { font-size: 11px; font-weight: 600; }
.bottom-tab.active { background: var(--teal); color: #fff; }
/* 桌面端隐藏底部导航（用侧边栏） */
@media (min-width: 769px) {
  .bottom-nav { display: none !important; }
}

/* ============ 移动端布局（≤768px） ============ */
@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
    min-height: 100vh;
    min-height: 100dvh;
  }
  .sidebar { display: none; }            /* 移动端用底部导航替代 */
  .main {
    padding: 16px 16px 92px;             /* 底部留白给固定 Tab Bar */
  }
  .topbar { flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
  .topbar-title { font-size: 19px; }
  .topbar-sub { font-size: 12px; }

  /* 工具栏：搜索框与按钮全宽堆叠 */
  .toolbar { gap: 10px; }
  .toolbar-left, .toolbar-right {
    display: flex; flex-direction: column; width: 100%; gap: 10px;
  }
  .input, .select, .btn { width: 100%; min-height: 44px; font-size: 15px; }
  .input { min-width: 0; }

  /* 表格横向滚动，避免挤压变形 */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { min-width: 660px; }
  .table th, .table td { padding: 12px 12px; }

  /* 统计卡片单列 */
  .stats { grid-template-columns: 1fr; }

  /* 新注册提示条：文案与按钮换行堆叠 */
  .notice { flex-wrap: wrap; }
  .notice-text { flex: 1 1 100%; }
  .notice .btn { width: 100%; min-height: 44px; }

  /* 创建账号表单单列 */
  .create-grid { grid-template-columns: 1fr; }
  .create-grid .login-input, .create-grid .select { width: 100%; min-height: 44px; }
  .create-actions { width: 100%; }
  .create-actions .btn { width: 100%; min-height: 44px; }

  /* 弹窗移动端贴底抽屉式 */
  .modal-mask { align-items: flex-end; }
  .modal {
    width: 100%; max-width: 100vw;
    border-radius: 14px 14px 0 0;
    margin: auto auto 0;
    max-height: 92vh;
  }
  .form-grid { grid-template-columns: 1fr; }

  /* 登录/注册输入框触控区（与全局 48/50 保持一致，手机上更稳） */
  .login-input { min-height: 48px; }
  .login-submit { min-height: 50px; }

  /* 行内操作链接点击区放大 */
  .row-actions { gap: 4px; }
  .link-btn { padding: 6px 4px; min-height: 40px; display: inline-flex; align-items: center; }
}

/* 超小屏（≤380px）微调 */
@media (max-width: 380px) {
  .bottom-tab-label { font-size: 10px; }
  .topbar-actions { gap: 8px; }
}

/* ===== v2.2 角色化显隐：仅「本机管理员」可见 =====
   前端 applyRoleUI 会同步设置 inline style 兜底；此处 CSS 作为二次保险，
   防止 JS 未执行/时序问题导致管理功能泄漏给访客。 */
body:not(.role-admin) .col-channel,
body:not(.role-admin) .row-actions,
body:not(.role-admin) [data-admin-only] {
  display: none !important;
}

/* ===== 页脚：ICP 备案号 =====
   国内法规要求：备案号须展示在页面底部，并链接到工信部备案系统。 */
.site-footer {
  text-align: center;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.7;
}
.site-footer a { color: var(--text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--teal); text-decoration: underline; }

/* 移动端：底部有固定 Tab Bar（约 76px 高），页脚留白避免被遮挡。
   :not() 排除浮层版——浮层所在的登录/注册屏没有 Tab Bar。 */
@media (max-width: 768px) {
  .site-footer:not(.site-footer--overlay) {
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
  }
}

/* 登录/注册屏是 position:fixed 的全屏覆盖层，普通文档流里的页脚会被它盖住，
   因此页面内另放一份浮层版，绝对定位到覆盖层底部（父级 .login-screen 为定位祖先）。 */
.site-footer--overlay {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  color: rgba(255, 255, 255, .8);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  z-index: 5;
}
.site-footer--overlay a { color: rgba(255, 255, 255, .8); }
.site-footer--overlay a:hover { color: #fff; }
