:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --danger: #dc2626;
  --ok: #059669;
  --sidebar: #0f172a;
  --sidebar-ink: #cbd5e1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }

code { font-family: Consolas, "SFMono-Regular", monospace; font-size: 12px; }

.layout { display: flex; min-height: 100vh; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 224px;
  flex: 0 0 224px;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }

.logo {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  color: #fff; font-size: 18px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { color: #fff; font-size: 15px; letter-spacing: .5px; }
.brand-text small { color: #7c8ba1; font-size: 11px; }

#nav { display: flex; flex-direction: column; gap: 4px; }

#nav button {
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--sidebar-ink);
  cursor: pointer;
  transition: background .15s, color .15s;
}

#nav button:hover { background: rgba(148, 163, 184, .14); color: #fff; }
#nav button.active { background: rgba(59, 130, 246, .22); color: #fff; font-weight: 600; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; font-size: 12px; }
.sidebar-foot label { display: flex; flex-direction: column; gap: 4px; color: #94a3b8; }
.sidebar-foot input {
  background: rgba(148, 163, 184, .12);
  border: 1px solid rgba(148, 163, 184, .2);
  border-radius: 8px;
  padding: 7px 9px;
  color: #e2e8f0;
  outline: none;
}
.sidebar-foot input:focus { border-color: #3b82f6; }
.server-line { color: #64748b; font-size: 11px; padding-left: 2px; }

#companyBox select {
  width: 100%;
  background: rgba(148, 163, 184, .12);
  border: 1px solid rgba(148, 163, 184, .2);
  border-radius: 8px;
  padding: 7px 9px;
  color: #e2e8f0;
  outline: none;
}
#companyBox select option { color: #0f172a; }

.company-static { font-size: 12px; color: #94a3b8; }
.company-static strong { display: block; color: #e2e8f0; font-size: 13px; font-weight: 600; }

.user-box {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px; border-radius: 10px; background: rgba(148, 163, 184, .1);
}
#userInfo { color: #e2e8f0; font-size: 12px; line-height: 1.5; }
#userInfo .role {
  display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px;
  background: rgba(59, 130, 246, .25); color: #bfdbfe; font-size: 11px;
}
.user-actions { display: flex; gap: 8px; }
.user-actions button {
  font-size: 12px; color: #cbd5e1; background: transparent; border-color: rgba(148, 163, 184, .28);
}
.user-actions button:hover { background: rgba(148, 163, 184, .16); }

/* ---------- 登录页 ---------- */
.login {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 20% 10%, #1e3a8a 0%, transparent 55%),
             radial-gradient(900px 500px at 85% 90%, #0e7490 0%, transparent 50%),
             #0b1220;
  padding: 20px;
}

.login-card {
  width: min(360px, 92vw);
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 30px 70px rgba(2, 6, 23, .5);
}

.login-brand { display: flex; align-items: center; gap: 10px; }
.login-brand .brand-text strong { color: #0f172a; font-size: 16px; }
.login-brand .brand-text small { color: #94a3b8; font-size: 11px; }

.login-card h2 { margin: 2px 0 4px; font-size: 18px; }

.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }

.login-card input {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  outline: none; font-size: 14px;
}
.login-card input:focus { border-color: var(--primary); }
.login-card .primary { padding: 10px; }

.login-error { min-height: 16px; margin: 0; color: var(--danger); font-size: 12px; }
.login-card .field-note { margin: 0; }

/* ---------- 主区域 ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 22px 28px 12px;
}

.topbar h1 { margin: 0; font-size: 20px; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

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

.cache-hint {
  padding: 3px 10px; border-radius: 999px;
  background: #eff6ff; color: #1d4ed8; font-size: 11px; white-space: nowrap;
}

.view { padding: 8px 28px 36px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- 按钮 ---------- */
button { cursor: pointer; }

.primary, .ghost, .danger-btn {
  border-radius: 8px;
  padding: 8px 14px;
  border: 1px solid transparent;
  transition: filter .15s, background .15s, border-color .15s;
}

.primary { background: var(--primary); color: var(--primary-ink); }
.primary:hover { filter: brightness(1.08); }

.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.ghost:hover { border-color: #cbd5e1; background: #f8fafc; }
.ghost.danger { color: var(--danger); }
.ghost.danger:hover { border-color: #fecaca; background: #fef2f2; }

.small { padding: 4px 10px; font-size: 12px; border-radius: 6px; }

button:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- 卡片 ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }

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

.card .label { color: var(--muted); font-size: 12px; }
.card .value { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: .5px; }
.card .value small { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 4px; }

/* ---------- 面板 ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line);
}

.panel-head h2 { margin: 0; font-size: 15px; }
.hint { color: var(--muted); font-size: 12px; }

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

table { width: 100%; border-collapse: collapse; }

th, td { padding: 11px 16px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }

th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfe; white-space: nowrap; }

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafc; }

td.right, th.right { text-align: right; white-space: nowrap; }
td .sub { color: var(--muted); font-size: 11px; margin-top: 2px; }

.empty { padding: 40px 18px; text-align: center; color: var(--muted); }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- 徽标 ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; background: #f1f5f9; color: #475569; white-space: nowrap;
}
.badge.ok { background: #ecfdf5; color: var(--ok); }
.badge.warn { background: #fff7ed; color: #c2410c; }
.badge.info { background: #eff6ff; color: #1d4ed8; }

/* ---------- 工具栏 ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.toolbar .search {
  flex: 1; min-width: 200px; max-width: 360px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; outline: none;
}
.toolbar .search:focus { border-color: var(--primary); }
.toolbar .spacer { flex: 1; }

/* ---------- 版本号 ---------- */
.versions { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line); }
.version-item { background: #fff; padding: 14px 18px; }
.version-item .k { color: var(--muted); font-size: 12px; }
.version-item .v { font-size: 20px; font-weight: 600; margin-top: 2px; }

/* ---------- 头像 ---------- */
.avatar {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
  background: #e2e8f0; color: #475569; display: inline-grid; place-items: center;
  font-size: 12px; font-weight: 600;
}

.person-cell { display: flex; align-items: center; gap: 10px; }

/* ---------- 弹窗 ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(760px, 92vw); max-height: 88vh;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .25); overflow: hidden;
}
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog[open] { animation: pop .16s ease-out; }

@keyframes pop { from { transform: translateY(6px); opacity: .6; } to { transform: none; opacity: 1; } }

.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.dialog-head h2 { margin: 0; font-size: 16px; }
.dialog-close { border: 0; background: transparent; font-size: 20px; line-height: 1; color: var(--muted); }
.dialog-body { padding: 18px 20px; overflow-y: auto; max-height: calc(88vh - 130px); }
.dialog-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--line); background: #fafbfe;
}

/* ---------- 表单 ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }

.form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }

.form input[type="text"], .form input[type="number"], .form input[type="password"],
.form input:not([type]), .form select, .form textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  outline: none; color: var(--ink); font-size: 13px;
}
.form input:focus, .form select:focus, .form textarea:focus { border-color: var(--primary); }
.form input[readonly] { background: #f8fafc; color: var(--muted); }

.form fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 0; }
.form legend { padding: 0 6px; font-size: 12px; color: var(--muted); }

.radio-row { display: flex; gap: 18px; align-items: center; }
.radio-row label { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; }

.check-row { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); }

.device-picker {
  margin-top: 10px; max-height: 150px; overflow-y: auto;
  border: 1px dashed var(--line); border-radius: 8px; padding: 10px;
  display: grid; gap: 6px;
}
.device-picker label { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 12px; }
.device-picker code { color: var(--muted); }
.hidden { display: none !important; }

.photo-box { display: flex; align-items: center; gap: 16px; }
.photo-preview {
  width: 88px; height: 88px; border-radius: 12px; background: #f1f5f9;
  display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 12px;
  border: 1px solid var(--line);
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.photo-actions small { color: var(--muted); font-size: 11px; }

.mini td, .mini th { padding: 7px 8px; }
.mini input, .mini select { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; background: #fff; }

.field-note { color: var(--muted); font-size: 11px; }

.week-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }

/* ---------- 提示 ---------- */
.toasts { position: fixed; right: 22px; bottom: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 999; }

.toast {
  min-width: 200px; max-width: 360px; padding: 10px 14px; border-radius: 10px;
  background: #111827; color: #f9fafb; font-size: 13px; box-shadow: var(--shadow);
  animation: toast-in .18s ease-out;
}
.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }

@keyframes toast-in { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 响应式 ---------- */
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex: none; flex-direction: row; align-items: center; gap: 14px; flex-wrap: wrap; }
  .brand { padding: 0; }
  #nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin: 0; flex-direction: row; align-items: center; }
  .sidebar-foot label { flex-direction: row; align-items: center; gap: 6px; }
  .sidebar-foot input { width: 120px; }
  .server-line { display: none; }
  .view { padding: 8px 16px 28px; }
  .topbar { padding: 18px 16px 8px; }
  .grid2, .grid3, .week-grid { grid-template-columns: 1fr; }
}
