:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --panel: #fff;
  --text: #16213a;
  --muted: #6a7894;
  --line: #e3e8f1;
  --line-strong: #cbd3e2;
  --primary: #c72b2b;
  --primary-dark: #a21f1f;
  --blue: #1e5fd2;
  --green: #138a52;
  --orange: #a7590b;
  --danger: #b42318;
  --bg-soft: #f8fafd;
  --shadow-sm: 0 1px 2px rgba(20, 32, 60, 0.06);
  --shadow: 0 6px 20px rgba(20, 32, 60, 0.08);
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 12px; min-height: 16px; }
code { background: #eef2f8; padding: 1px 6px; border-radius: 4px; font-size: 12px; }

.btn {
  border: 0; border-radius: 6px; padding: 6px 12px; font-size: 13px; cursor: pointer;
  background: #edf1f8; color: var(--text); line-height: 1.5;
  display: inline-flex; align-items: center; gap: 4px;
}
.btn:hover { filter: brightness(0.96); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; border: 1px solid var(--line-strong); color: var(--muted); }
.btn.ghost:hover { color: var(--text); border-color: var(--muted); }
.btn.danger { background: #fee4e2; color: var(--danger); }
.btn.link { background: transparent; color: var(--blue); padding: 4px 6px; }
.btn.icon { padding: 2px 8px; background: transparent; font-size: 20px; color: var(--muted); }
.btn.xs { padding: 2px 8px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Login */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px; display: grid; gap: 12px;
}
.login-card h1 { font-size: 20px; margin: 0; }
.login-card label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.login-card input {
  height: 36px; border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 0 10px; font-size: 13px;
}
.brand-mark {
  min-width: 36px; width: auto; height: 36px; padding: 0 8px; border-radius: 6px; background: var(--primary);
  color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 11px; line-height: 1.1; text-align: center;
}

/* App shell */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: #101725; color: #cfd7ea; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.sidebar .brand-title { color: #fff; font-weight: 700; font-size: 14px; }
.sidebar .brand-sub { color: #6f7a93; font-size: 11px; margin-top: 2px; }
.menu { padding: 10px 8px; flex: 1; display: grid; gap: 2px; align-content: start; }
.menu button {
  width: 100%; border: 0; background: transparent; color: #bac3d6; text-align: left;
  padding: 9px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.menu button:hover { background: rgba(255,255,255,0.04); color: #fff; }
.menu button.active { background: var(--primary); color: #fff; }
.sidebar-footer { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-top: 1px solid rgba(255,255,255,0.06); font-size: 12px; }
.sidebar-footer .muted { color: #98a3bd; }

/* Main */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; padding: 0 20px; height: 46px;
  position: sticky; top: 0; z-index: 5;
}
.tabs { flex: 1; display: flex; gap: 2px; overflow-x: auto; }
.tabs button {
  border: 0; background: transparent; padding: 0 14px; height: 46px;
  font-size: 13px; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.top-actions { display: flex; gap: 10px; align-items: center; }
.badge {
  padding: 2px 8px; border-radius: 999px; font-size: 11px;
  background: #eef2f8; color: var(--muted);
}
.badge.ok { background: #e5f6ec; color: var(--green); }
.badge.bad { background: #fee4e2; color: var(--danger); }

/* Toolbar */
.toolbar {
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 10px 20px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.toolbar .field { display: inline-flex; align-items: center; gap: 6px; }
.toolbar label { font-size: 12px; color: var(--muted); }
.toolbar input, .toolbar select {
  height: 30px; border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 0 8px; font-size: 13px; min-width: 120px; background: #fff;
}
.toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--primary); }

/* Workspace */
.workspace { flex: 1; padding: 16px 20px; overflow: auto; }
.workspace > * + * { margin-top: 16px; }
.table-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; max-height: calc(100vh - 160px);
}
.activity-types-list {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.activity-type-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  padding: 12px;
  display: grid;
  gap: 8px;
}
.activity-type-item-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.activity-type-item-title {
  font-size: 14px;
  font-weight: 700;
}
.activity-type-item-sub {
  color: var(--muted);
  font-size: 12px;
}
.activity-type-item-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.activity-type-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 8px 0;
}
.custom-page {
  display: grid;
  gap: 16px;
}
.content-page-head {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.content-page-title {
  font-size: 18px;
  font-weight: 700;
}
.content-page-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}
.content-page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.content-grid {
  display: grid;
  gap: 16px;
}
.content-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.content-card-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.content-card-title {
  font-size: 14px;
  font-weight: 700;
}
.content-card-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.content-card-body {
  padding: 16px;
  display: grid;
  gap: 12px;
}
.content-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px 14px;
}
.content-form-grid label,
.content-regulations label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.content-form-grid input,
.content-form-grid textarea,
.content-form-grid select,
.content-regulations textarea,
.content-regulations input,
.content-editor-row input,
.content-editor-row textarea,
.content-editor-row select {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 13px;
  width: 100%;
  background: #fff;
  color: var(--text);
}
.content-form-grid textarea,
.content-regulations textarea {
  min-height: 110px;
  resize: vertical;
  font-family: inherit;
}
.content-image-label {
  gap: 6px;
}
.content-image-field {
  display: grid;
  gap: 8px;
}
.content-image-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.content-image-hint {
  font-size: 11px;
  color: var(--muted);
}
.content-image-field img {
  width: 100%;
  max-height: 120px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
.content-form-grid .span-2 {
  grid-column: span 2;
}
.content-editor-list {
  display: grid;
  gap: 10px;
}
.item-card {
  gap: 14px;
}
.item-card.is-collapsed .item-card-body {
  display: none;
}
.item-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.item-card-head-main {
  min-width: 0;
}
.item-card-head-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.item-card-body {
  display: grid;
  gap: 12px;
}
.item-group-section {
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px dashed var(--line-strong);
}
.item-group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.item-group-list {
  display: grid;
  gap: 10px;
}
.item-group-row {
  background: #fff;
}
.item-group-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.content-editor-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-soft);
  padding: 12px;
  display: grid;
  gap: 10px;
}
.content-editor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
}
.content-editor-row-actions {
  display: flex;
  justify-content: flex-end;
}
.content-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 8px 0;
}
.content-regulations {
  display: grid;
  gap: 12px;
}
.content-loading,
.content-error {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 32px;
  text-align: center;
  color: var(--muted);
}
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.card-title { font-weight: 700; font-size: 14px; }
.card-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.card-actions { display: flex; gap: 6px; }

.table-wrap { overflow: auto; flex: 1; }
table.compact { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.compact thead { background: var(--bg-soft); position: sticky; top: 0; z-index: 1; }
table.compact th, table.compact td {
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  text-align: left; vertical-align: middle; white-space: nowrap;
  max-width: 240px; overflow: hidden; text-overflow: ellipsis;
}
table.compact th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.compact tbody tr:hover { background: #fafbfe; }
table.compact tbody tr.selected { background: #fff4f4; }
table.compact td img.thumb { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; display: block; }
table.compact td.actions { white-space: nowrap; }
table.compact td.actions .btn { margin-right: 4px; }

.status-pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px;
  background: #eef2f8; color: var(--muted);
}
.status-pill.enabled { background: #e5f6ec; color: var(--green); }
.status-pill.disabled { background: #fff4e5; color: var(--orange); }
.status-pill.deleted { background: #fee4e2; color: var(--danger); }
.status-pill.pending { background: #fff4e5; color: var(--orange); }
.status-pill.approved { background: #e5f6ec; color: var(--green); }
.status-pill.rejected { background: #fee4e2; color: var(--danger); }
.status-pill.paid { background: #e5f6ec; color: var(--green); }
.status-pill.unpaid { background: #eef2f8; color: var(--muted); }
.status-pill.canceled { background: #eef2f8; color: var(--muted); }
.status-pill.refunded { background: #fef3cd; color: var(--orange); }
.status-pill.requested { background: #fff4e5; color: var(--orange); }

.pager {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px; border-top: 1px solid var(--line); background: var(--bg-soft);
  font-size: 12px; color: var(--muted);
}
.pager .pages { display: flex; gap: 4px; align-items: center; }
.pager select { height: 26px; border: 1px solid var(--line-strong); border-radius: 4px; padding: 0 6px; }

/* Drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 92vw);
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -10px 0 30px rgba(20, 32, 60, 0.08);
  display: flex; flex-direction: column; z-index: 20;
  animation: slidein 0.16s ease-out;
}
@keyframes slidein { from { transform: translateX(24px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.drawer-title { font-weight: 700; }
.drawer-sub { font-size: 12px; }
.drawer-form { flex: 1; overflow: auto; padding: 16px 18px; display: grid; gap: 12px; }
.drawer-form label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.drawer-form label .required::before { content: '*'; color: var(--danger); margin-right: 4px; }
.drawer-form input, .drawer-form textarea, .drawer-form select {
  border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 7px 9px; font-size: 13px; width: 100%; background: #fff; color: var(--text);
}
.drawer-form textarea { min-height: 80px; resize: vertical; font-family: inherit; }
.drawer-form .hint { font-size: 11px; color: var(--muted); }
.drawer-form .image-field { display: grid; gap: 4px; }
.drawer-form .upload-row { display: flex; gap: 8px; align-items: center; }
.drawer-form .upload-row input[type="file"] { flex: 1; padding: 6px 0; border: 0; background: transparent; }
.drawer-form .upload-btn { white-space: nowrap; }
.drawer-form .image-field img { width: 100%; max-height: 120px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; }
.drawer-foot {
  display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line);
  background: var(--bg-soft);
}
.drawer-foot .btn.primary { margin-left: auto; }

/* Toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: #111827; color: #fff; padding: 8px 14px; border-radius: 6px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: 0.16s; z-index: 30;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Action menu */
.action-menu { display: inline-block; position: relative; }
.action-menu-items {
  position: absolute; right: 0; top: calc(100% + 2px); background: var(--panel);
  border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 6px;
  min-width: 140px; display: none; z-index: 10; padding: 4px 0;
}
.action-menu-items.show { display: block; }
.action-menu-items button {
  border: 0; background: transparent; width: 100%; text-align: left;
  padding: 6px 12px; font-size: 12px; color: var(--text); cursor: pointer;
}
.action-menu-items button:hover { background: var(--bg-soft); }

/* Overlay */
.overlay {
  position: fixed; inset: 0; background: rgba(20, 32, 60, 0.2); z-index: 18;
}

/* Dashboard */
.dashboard { padding: 16px 20px; }
.dash-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 20px;
}
.stat-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 16px 18px; display: flex; align-items: center; gap: 14px;
}
.stat-icon { font-size: 32px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dash-panels {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 16px;
}
.dash-panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.panel-title {
  padding: 12px 16px; font-weight: 600; font-size: 14px;
  border-bottom: 1px solid var(--line);
}
.panel-body { max-height: 300px; overflow: auto; }
.panel-item {
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px;
}
.panel-item:last-child { border-bottom: none; }
.panel-item-title { color: var(--text); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-item-meta { color: var(--muted); font-size: 12px; }
.panel-empty {
  padding: 32px; text-align: center; color: var(--muted); font-size: 13px;
}

/* Batch Action Bar */
.batch-bar {
  background: #fef4f4; border-bottom: 1px solid var(--line);
  padding: 8px 16px; display: flex; gap: 8px; align-items: center;
}
.batch-info { font-size: 13px; color: var(--text); margin-right: 8px; }
.batch-info strong { color: var(--primary); font-weight: 700; }

/* Checkbox Column */
table.compact .checkbox-col { width: 36px; text-align: center; }
table.compact input[type="checkbox"] {
  width: 15px; height: 15px; cursor: pointer; accent-color: var(--primary);
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .sidebar, .sidebar-footer { display: none; }
  .dash-summary { grid-template-columns: repeat(2, 1fr); }
  .dash-panels { grid-template-columns: 1fr; }
  .activity-type-item-head { flex-direction: column; }
  .content-page-head { align-items: flex-start; flex-direction: column; }
  .content-form-grid .span-2 { grid-column: span 1; }
}
