/* ============================================================
   sleep-appt 设计系统 —— 参考 FMIS 财务系统 UI
   ============================================================ */
:root {
  --bg: #f4f6f9;
  --card: #fff;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-soft: #344054;
  --muted: #667085;
  --muted-light: #98a2b3;

  --primary: #1570ef;
  --primary-hover: #175cd3;
  --primary-soft: #eff4ff;
  --primary-ring: rgba(21, 112, 239, 0.12);

  --success: #039855;
  --success-soft: #ecfdf3;
  --success-text: #027a48;

  --warning: #b54708;
  --warning-soft: #fffaeb;

  --danger: #d92d20;
  --danger-soft: #fef3f2;
  --danger-text: #b42318;

  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #94a3b8;
  --sidebar-active: #1e293b;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, 0.18);

  --sidebar-w: 232px;
  --topbar-h: 60px;
}

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- 布局 ---------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 0 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 60;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px 20px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.brand-text { min-width: 0; }

.brand-name { color: #fff; font-size: 15px; font-weight: 600; line-height: 1.25; white-space: nowrap; }
.brand-sub { color: var(--sidebar-muted); font-size: 11px; line-height: 1.3; margin-top: 2px; white-space: nowrap; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 500; box-shadow: inset 3px 0 0 var(--primary); }
.nav-item svg { width: 17px; height: 17px; flex: 0 0 17px; opacity: 0.9; }
.nav-item .nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .nav-count {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}
.nav-item.active .nav-count { background: var(--primary); }

.nav-group-label {
  padding: 16px 12px 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #64748b;
}

.sidebar-foot {
  margin-top: auto;
  padding: 14px 14px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-chip { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.user-meta { min-width: 0; flex: 1; }
.user-name { color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-account { color: var(--sidebar-muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-logout {
  margin-top: 10px;
  width: 100%;
  height: 32px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: transparent;
  color: var(--sidebar-text);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
}
.user-logout:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}

.hamburger {
  display: none;
  width: 38px; height: 38px;
  align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text-soft);
  cursor: pointer;
  flex: 0 0 38px;
  padding: 0;
}
.hamburger:hover { background: #f9fafb; }
.hamburger svg { width: 18px; height: 18px; }

.topbar-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.content { flex: 1; padding: 24px 28px 72px; width: 100%; max-width: 1440px; }

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 55;
  opacity: 0;
  transition: opacity 0.22s ease;
}

/* ---------------- 卡片 ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 14px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
}
.card-title { margin: 0; font-size: 14.5px; font-weight: 600; }
.card-title small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.card-body { padding: 16px 18px; }
.card-body.flush { padding: 0; }

/* ---------------- 统计 ---------------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 25px; font-weight: 600; letter-spacing: -0.6px; line-height: 1.15; }
.stat-value.accent { color: var(--primary); }
.stat-value.success { color: var(--success); }
.stat-value.warn { color: var(--warning); }
.stat-foot { font-size: 11.5px; color: var(--muted-light); margin-top: 5px; }

/* ---------------- 工具栏 ---------------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.toolbar .spacer { flex: 1; }

/* 日期区间 */
.date-range {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.date-range:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.date-range input[type="date"] {
  border: 0;
  box-shadow: none;
  height: 32px;
  padding: 0 2px;
  width: 128px;
  font-size: 13px;
  background: transparent;
}
.date-range input[type="date"]:focus { outline: none; box-shadow: none; }
.date-sep { color: var(--muted-light); font-size: 12px; flex: 0 0 auto; }

/* ---------------- 表格 ---------------- */
.table-wrap { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left;
  padding: 10px 14px;
  color: var(--muted);
  font-weight: 500;
  font-size: 12.5px;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #fafbfc; }
table.data td.num { font-variant-numeric: tabular-nums; }
table.data td.nowrap { white-space: nowrap; }
table.data .primary-cell { font-weight: 500; }
table.data .sub { display: block; color: var(--muted-light); font-size: 11.5px; margin-top: 2px; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

.btn.ghost { background: #fff; color: var(--text-soft); border-color: var(--border); }
.btn.ghost:hover { background: #f9fafb; border-color: var(--border-strong); }
.btn.danger { background: #fff; color: var(--danger); border-color: #fecdca; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn.block { width: 100%; }
.btn.lg { height: 46px; font-size: 15px; border-radius: 10px; }

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--primary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }

/* ---------------- 表单 ---------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 16px;
}
.form-item { min-width: 0; }
.form-item > label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
  line-height: 1.35;
}
.form-item.span-2 { grid-column: span 2; }
.form-item.full { grid-column: 1 / -1; }

input, select, textarea {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { height: auto; min-height: 78px; padding: 9px 11px; line-height: 1.55; resize: vertical; }
select { padding-right: 28px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
input[readonly], textarea[readonly] { background: #f9fafb; color: var(--muted); }
input::placeholder, textarea::placeholder { color: var(--muted-light); }

.field-row { display: flex; gap: 8px; }
.field-row > * { flex: 1; }

.form-hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.form-err {
  margin: 12px 0 0;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  border: 1px solid #fecdca;
  color: var(--danger-text);
  font-size: 13px;
}

.form-actions {
  position: sticky;
  bottom: 0;
  margin-top: 16px;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: linear-gradient(180deg, rgba(244, 246, 249, 0) 0%, var(--bg) 45%);
  z-index: 20;
}

/* ---------------- 标签 ---------------- */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}
.tag.blue { background: var(--primary-soft); color: #175cd3; }
.tag.green { background: var(--success-soft); color: var(--success-text); }
.tag.amber { background: var(--warning-soft); color: var(--warning); }
.tag.gray { background: #f2f4f7; color: #475467; }
.tag.red { background: var(--danger-soft); color: var(--danger-text); }

/* ---------------- 选项卡 ---------------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: #eaecf0;
  border-radius: 10px;
  margin-bottom: 16px;
  overflow-x: auto;
}
.tab {
  flex: 1 0 auto;
  border: 0;
  background: transparent;
  border-radius: 7px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }

/* ---------------- 空状态 / 加载 ---------------- */
.empty { text-align: center; padding: 44px 16px; color: var(--muted); font-size: 13px; }
.empty-icon { width: 40px; height: 40px; margin: 0 auto 10px; color: var(--muted-light); }

/* ---------------- 弹层 ---------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}
.modal-box {
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 20px 22px;
}
.modal-box h3 { margin: 0 0 16px; font-size: 17px; font-weight: 600; }

/* ---------------- Toast ---------------- */
.toast-wrap {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #101828;
  color: #fff;
  padding: 11px 16px;
  border-radius: 9px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  max-width: 320px;
  animation: toastIn 0.18s ease;
}
.toast.success { background: #054f31; }
.toast.error { background: #912018; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- 登录页 ---------------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #0f172a 0%, #1e3a5f 100%);
}
.auth-card {
  width: min(396px, 100%);
  background: #fff;
  border-radius: 16px;
  padding: 30px 28px 26px;
  box-shadow: var(--shadow-lg);
}
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.auth-brand .brand-mark { width: 40px; height: 40px; flex-basis: 40px; }
.auth-title { margin: 0 0 22px; font-size: 20px; font-weight: 600; letter-spacing: -0.3px; }
.auth-brand-name { font-size: 16px; font-weight: 600; line-height: 1.2; }
.auth-brand-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.auth-card .form-item + .form-item { margin-top: 14px; }
.auth-foot { margin-top: 18px; text-align: center; font-size: 12.5px; color: var(--muted); }

/* ---------------- H5 移动端表单页 ---------------- */
.page-title { margin: 2px 0 6px; font-size: 21px; font-weight: 600; letter-spacing: -0.4px; }
.page-desc { margin: 0 0 18px; font-size: 13px; color: var(--muted); line-height: 1.6; }

/* 手机端给固定底栏留出空间 */
@media (max-width: 900px) {
  body.has-mobile-actions .content { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
}

.mobile-actions {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 560px;
  z-index: 40;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}

/* 宽屏时底栏回到文档流，避免悬空 */
@media (min-width: 901px) {
  .mobile-actions {
    position: static;
    transform: none;
    max-width: 100%;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-top: 0;
    padding: 16px 0 0;
  }
  .mobile-actions .btn { flex: 0 0 auto; min-width: 160px; height: 40px; font-size: 14px; }
  body.has-mobile-actions .content { padding-bottom: 40px; }
}

/* 表单页内容限宽，避免宽屏下卡片过宽 */
.narrow-page { max-width: 620px; }
.mobile-actions .btn { flex: 1; height: 46px; font-size: 15px; border-radius: 10px; }

/* ---------------- 概览时间线 ---------------- */
.kv-list { display: grid; gap: 12px; }
.kv-row { display: flex; gap: 12px; font-size: 13.5px; }
.kv-row .k { flex: 0 0 96px; color: var(--muted); }
.kv-row .v { flex: 1; min-width: 0; word-break: break-word; }

.summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 26px;
  padding: 14px 18px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}
.summary-strip strong { color: var(--text); font-weight: 600; }

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 1100px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-item.span-2 { grid-column: span 2; }
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
    flex-basis: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); }

  .backdrop { display: block; pointer-events: none; }
  body.nav-open .backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }

  .hamburger { display: inline-flex; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar-title { font-size: 16px; }
  .content { padding: 16px 14px 72px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 13px 14px; }
  .stat-value { font-size: 21px; }
  .toast-wrap { left: 12px; right: 12px; top: 12px; }
  .toast { max-width: none; }
}

@media (max-width: 760px) {
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tbody tr {
    padding: 6px 0;
    border-bottom: 8px solid var(--bg);
  }
  table.data tbody tr:hover td { background: transparent; }
  table.data td {
    border: 0;
    padding: 5px 14px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 13.5px;
  }
  table.data td::before {
    content: attr(data-label);
    flex: 0 0 78px;
    color: var(--muted);
    font-size: 12.5px;
    padding-top: 1px;
  }
  table.data td.primary-cell { font-weight: 600; font-size: 15px; }
  table.data td.primary-cell::before { content: ""; flex: 0 0 0; }
  table.data td .sub { display: inline; margin-left: 4px; }
  .row-actions { padding-top: 4px; }

  .card-head { padding: 12px 14px; }
  .card-body { padding: 14px; }
  .summary-strip { gap: 8px 18px; padding: 12px 14px; }
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; gap: 13px; }
  .form-item.span-2, .form-item.full { grid-column: 1 / -1; }
  input, select { height: 44px; font-size: 15px; }
  input, select, textarea { border-radius: 9px; }
  .btn { height: 40px; }
  .btn.lg { height: 48px; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-box { border-radius: 16px 16px 0 0; max-height: 92vh; padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px)); }
  .form-actions { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .form-actions .btn { flex: 1; height: 46px; font-size: 15px; }
}
