/* ====================== Base UI ====================== */
* {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

body {
  margin: 0;
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  color: #222;
  background: #f7f7f9;
}

/* Links */
a {
  color: #3057d5;
  text-decoration: none
}

a:hover {
  text-decoration: underline
}

/* Layout */
.app {
  display: flex;
  min-height: 100vh
}

.sidebar {
  width: 240px;
  flex: 0 0 240px;
  height: 100vh;
  align-self: flex-start;
  position: sticky;
  top: 0;
  overflow: auto;
  transition: width .2s ease, transform .2s ease;
  will-change: width, transform;
}

.brand {
  font-weight: 700;
  font-size: 18px;
  padding: 12px 16px 8px
}

.menu {
  list-style: none;
  margin: 0;
  padding: 0
}

.menu li a {
  display: block;
  padding: 10px 16px;
  border-left: 3px solid transparent;
}

.menu li a.active {
  font-weight: 600
}

.menu .menu-group {
  padding: 8px 16px;
  font-size: 11px;
  letter-spacing: .08em;
  opacity: .7;
  text-transform: uppercase;
}

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0
}

.admin-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid #eaeaea
}

.header-title {
  font-weight: 600
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.main {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px
}

/* Cards */
.card {
  background: #fff;
  border: 1px solid #e8e8ef;
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, .04)
}

.card-title {
  font-weight: 600;
  margin-bottom: 10px
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid #dadbe7;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  user-select: none
}

.btn:hover {
  filter: brightness(1.02)
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed
}

.btn-ghost {
  background: transparent;
  border: 1px solid #d0d3e2
}

/* Inputs */
.input,
select,
textarea {
  height: 34px;
  padding: 0 10px;
  border: 1px solid #d8dbe6;
  border-radius: 10px;
  background: #fff;
  outline: 0;
  max-width: 100%
}

.input:focus,
select:focus,
textarea:focus {
  border-color: #9bb4ff;
  box-shadow: 0 0 0 3px rgba(155, 180, 255, .25)
}

label {
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
  color: #666
}

small.muted {
  color: #888
}

/* Tables */
.table-wrap {
  overflow: auto
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 10px;
  overflow: hidden
}

.table thead th {
  font-weight: 600;
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid #eceff5;
  background: #f6f7fb
}

.table tbody td {
  padding: 8px;
  border-bottom: 1px solid #f0f2f7
}

.table tr:hover td {
  background: #fafbff
}

.table tr.danger td {
  background: #fdecec;
  color: #8b1c1c
}

/* KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px
}

.kpi {
  padding: 12px
}

.kpi .kpi-label {
  font-size: 12px;
  color: #666
}

.kpi .kpi-value {
  font-size: 22px;
  font-weight: 700
}

/* Footer */
.footer {
  padding: 14px 16px;
  opacity: .7
}


/* ====================== Birdnest Theme ====================== */
:root {
  --bg: #F8F5F0;
  --surface: #FFFFFF;
  --ink: #433B2F;
  --muted: #8A8173;
  --brand1: #6B4F2C;
  --brand2: #B08968;
  --accent: #C49A6C;
  --accent2: #DABA84;
  --ring: #F2E4C4;
  --table-head: #F4EADB;
  --link-on-dark: #FFF3E0;
  --highlight: #E6C08B;
  --danger: #FDECEC;
  --danger-ink: #8B1C1C;
}

/* 背景与文字色 */
body {
  background: var(--bg);
  color: var(--ink);
}

/* Header & Sidebar 渐变 */
.admin-header {
  background: linear-gradient(to right, var(--brand1), var(--brand2));
  color: var(--link-on-dark);
  border-bottom: 1px solid rgba(0, 0, 0, .05);
}

.sidebar {
  background: linear-gradient(to bottom, var(--brand1), var(--brand2));
  color: var(--link-on-dark);
}

.menu li a {
  color: var(--link-on-dark);
}

.menu li a:hover {
  background: rgba(255, 255, 255, .08);
}

.menu li a.active {
  background: rgba(255, 255, 255, .14);
  border-left-color: var(--highlight);
}

/* 顶部按钮/用户区在深底上的颜色 */
.btn-ghost {
  color: var(--link-on-dark);
  border: 1px solid rgba(255, 255, 255, .35);
}

/* 卡片/表格暖色 */
.card {
  background: var(--surface);
  border: 1px solid #E9E2D6;
  box-shadow: 0 8px 24px rgba(107, 79, 44, .06);
}

.card-title {
  color: var(--ink);
}

.table thead th {
  background: var(--table-head);
  color: #3A342A;
  border-bottom: 1px solid #E6D8C4;
}

.table tbody td {
  border-bottom: 1px solid #EFE8DC;
}

.table tr:hover td {
  background: #FBF8F2;
}

/* 输入高亮为暖金色 */
.input:focus,
select:focus,
textarea:focus {
  border-color: #D6C2A3;
  box-shadow: 0 0 0 3px var(--ring);
}

/* 金色按钮 */
.btn {
  background: linear-gradient(to right, var(--accent), var(--accent2));
  color: #3B2E1F;
  border: 1px solid #E7D1A8;
}

.btn:hover {
  filter: brightness(1.04);
}

.btn:disabled {
  opacity: .6;
}

/* 链接（浅底） */
a {
  color: #B07A2A;
}

a:hover {
  text-decoration: underline;
}

/* 报警行暖红 */
.table tr.danger td {
  background: var(--danger);
  color: var(--danger-ink);
}

/* 页脚暖灰 */
.footer {
  color: #9A8F80;
}

/* ===== Dashboard 小增强 ===== */
.kpi .kpi-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 1024px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

.search .search-form {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}

.search .table-wrap {
  margin-top: 8px;
}

.pre {
  white-space: pre-wrap;
  background: #faf7ef;
  border: 1px solid #eee2cf;
  padding: 6px 8px;
  border-radius: 8px;
  max-height: 160px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.muted {
  color: var(--muted);
}

/* 收起侧栏：同时把 flex-basis 设为 0，彻底不占位 */
body.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
  width: 0 !important;
  flex-basis: 0 !important;
  /* 关键：取消 240px 的占位 */
  padding: 0;
  border: 0;
  overflow: hidden;
}

/* 小屏抽屉：固定定位并且不占 flex 空间 */
@media (max-width: 960px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 30;
    width: 240px;
    /* 抽屉展开的实际宽度 */
    flex-basis: 0;
    /* 不让 flex 布局为它预留空间 */
    transform: translateX(-100%);
  }

  body:not(.sidebar-collapsed) .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .25);
    display: none;
    z-index: 25;
  }

  body:not(.sidebar-collapsed) .sidebar-backdrop {
    display: block;
  }
}

/* 顶部布局与右侧固定到边缘 */
.admin-header{
  display:flex;
  align-items:center;
  gap:12px;
  padding:10px 16px;
}
.admin-header .header-title{
  font-weight:600;
  color:#fff;                 /* 顶栏浅字色 */
  letter-spacing:.2px;
}
.flex-spacer{ flex:1 1 auto; }

.header-right{
  margin-left:auto;
  display:flex;
  align-items:center;
  gap:14px;
}

/* 语言分段胶囊：EN / MS / 中 */
.lang-switch{
  display:inline-flex;
  background: transparent;
  border-radius: 999px;
  padding: 2px;
  border: 1px solid rgba(255,255,255,.55);
  box-shadow: 0 1px 2px rgba(0,0,0,.05) inset;
  overflow:hidden;
}
.lang-pill{
  min-width: 44px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  text-decoration: none;
  color: #4a3a2a;             /* 棕系主题文字 */
  border-radius: 999px;
  transition: background .15s, color .15s, transform .03s, box-shadow .15s;
}
.lang-pill:hover{ background:#efe6db; }
.lang-pill:active{ transform: translateY(1px); }
.lang-pill.is-active{
  background:#fff;
  color:#1f1f1f;
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
}

/* 用户 chip 与登出胶囊 */
.user-chip{
  display:inline-flex;
  align-items:center;
  gap:10px;
  color:#fff;
}
.user-chip .user-name{
  opacity:.95;
  font-weight:600;
}
.logout-btn{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:7px 12px;
  border-radius: 999px;
  text-decoration:none;
  color:#fff;
  background: #ffffff1f;
  border: 1px solid #ffffff40;
  transition: background .15s, border-color .15s, transform .03s;
  backdrop-filter: saturate(120%) blur(2px);
}
.logout-btn:hover{
  background:#ffffff33;
  border-color:#ffffff66;
}
.logout-btn:active{ transform: translateY(1px); }
.icon-power{ display:block; }
.logout-text{ font-weight:700; letter-spacing:.2px; }

/* 侧栏按钮（可选加强点击区） */
.btn-ghost{
  background: transparent;
  border: 1px solid transparent;
  color: #fff;
  border-radius: 8px;
  padding: 6px 10px;
}
.btn-ghost:hover{ background: #ffffff22; border-color: #ffffff33; }

/* ========== Responsive Drawer + Collapse (patch) ========== */

/* 桌面：支持收起（与现有 .sidebar-collapsed 兼容） */
body.sidebar-collapsed .sidebar{
  transform: translateX(-100%);
  width: 0 !important;
  flex-basis: 0 !important;
  padding: 0;
  border: 0;
  overflow: hidden;
}

/* 移动端：抽屉（默认隐藏，body.sidebar-open 时显示） */
@media (max-width: 1024px){
  .sidebar{
    position: fixed;
    left: 0; top: 0; bottom: 0; right: auto;
    width: 280px; max-width: 85vw;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform .2s ease-out;
    box-shadow: 8px 0 24px rgba(0,0,0,.10);
  }
  /* 兼容两种开关：sidebar-open（推荐） 或 旧的 “非 collapsed” */
  body.sidebar-open .sidebar,
  body:not(.sidebar-collapsed) .sidebar{
    transform: translateX(0);
  }

  /* 抽屉遮罩 */
  .sidebar-overlay{
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease-out;
    z-index: 999;
  }
  body.sidebar-open .sidebar-overlay{ opacity: 1; pointer-events: auto; }

  /* 移动端主内容不保留左侧空位 */
  .content .main{ margin-left: 0 !important; }
}

/* 顶部汉堡按钮（如果你想单独样式，可用这个类；否则保留 .btn-ghost 也行） */
.hamburger{
  display: none;
  align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid #e5dccf; background: transparent; color: #fff;
  font-size: 20px; line-height: 1; cursor: pointer;
}
@media (max-width:1024px){ .hamburger{ display:inline-flex; } }

/* ---------- Mobile responsiveness & header fixes (append) ---------- */

/* 手机：内容边距更紧、卡片/图表一列排列、表格可横向滚动 */
@media (max-width: 768px) {
  .main { padding: 10px; gap: 10px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .card { padding: 12px; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* 让语言胶囊不被裁掉/压扁，并在小屏缩小占位 */
.lang-switch { 
  overflow: visible;          /* 原先有 overflow:hidden 会把“中”裁掉 */
  flex-shrink: 0;             /* 不随 header-right 被压缩 */
  min-width: max-content;     /* 宽度随内容 */
}
@media (max-width: 560px) {
  .lang-pill { 
    min-width: auto; 
    padding: 6px 8px; 
    font-size: 12px; 
    font-weight: 700; 
  }
  .user-chip .user-name { display: none; } /* 省位置，保留(管理员)括号可去掉的话更省 */
  .logout-text { display: none; }          /* 只留图标，手机更清爽 */
}

/* 侧栏抽屉时的遮罩（配合 footer 里的脚本） */
.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 25;
  background: rgba(0,0,0,.25); display: none;
}
@media (max-width: 960px) {
  body:not(.sidebar-collapsed) .sidebar-backdrop { display: block; }
}

/* ===== Mobile: 单列到底，不超出屏幕 ===== */
@media (max-width: 640px) {
  /* 禁止页面横向滚动 */
  html, body { overflow-x: hidden; }

  /* 主区不超屏，左右留一点边距 */
  .main {
    padding: 12px;
    max-width: 100vw;
  }

  /* KPI 一列排 */
  .kpi-grid {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  /* 两列图表区域改成一列 */
  .grid-2 {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  /* 卡片收紧一点间距 */
  .card {
    padding: 12px;
    border-radius: 10px;
  }

  /* 表格如超宽则横向滚动，不让页面横向抖动 */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* 代码块/明细也允许自己滚 */
  .pre {
    max-width: 100%;
    overflow-x: auto;
  }

  /* 图表画布自适应容器宽度 */
  canvas {
    display: block;
    max-width: 100% !important;
    width: 100% !important;
    height: auto !important;  /* Chart.js 会按比例缩放 */
  }

  /* 顶栏更紧凑一些 */
  .admin-header { padding: 8px 10px; gap: 8px; }
  .header-right { gap: 10px; }
}

/* 防止任何元素把页面撑出屏幕 */
img, svg, video, iframe {
  max-width: 100%;
  height: auto;
}
