:root {
  --bg: #f4f5f7; --sidebar: #1f2937; --sidebar-active: #2563eb;
  --text: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --brand: #2563eb; --warn: #f59e0b; --danger: #dc2626; --success: #16a34a;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui,-apple-system,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: #cbd5e1; display: flex; flex-direction: column; padding: 20px 0; }
.sidebar-brand { padding: 0 20px 20px; color: #fff; font-weight: 700; font-size: 16px; border-bottom: 1px solid #374151; margin-bottom: 12px; }
.sidebar-nav { flex: 1; padding: 0 10px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius); color: #cbd5e1; margin-bottom: 4px; }
.nav-item:hover { background: #374151; color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-icon { width: 20px; text-align: center; }
.sidebar-footer { padding: 14px 16px; border-top: 1px solid #374151; font-size: 12px; }
.who { color: #fff; font-weight: 600; margin-bottom: 2px; }
.role { color: #9ca3af; margin-bottom: 10px; }
.btn-logout { width: 100%; background: transparent; border: 1px solid #4b5563; color: #cbd5e1; padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; font-family: inherit; }
.btn-logout:hover { background: #374151; color: #fff; }
.main { padding: 24px 32px 60px; min-width: 0; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-title { margin: 0; font-size: 20px; font-weight: 700; }
.flash { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; padding: 6px 12px; border-radius: 6px; font-size: 13px; }

.panel { background: #fff; border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,.06); padding: 20px; margin-bottom: 20px; min-width: 0; overflow-x: auto; }
.panel-title { margin: 0 0 12px; font-size: 15px; font-weight: 600; }

.grid { display: grid; gap: 16px; margin-bottom: 20px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.detail-grid { display: grid; gap: 16px; grid-template-columns: 2fr 1fr; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; padding: 8px; overflow-x: auto; }
  .sidebar-brand { display: none; }
  .sidebar-nav { display: flex; flex: initial; padding: 0; }
  .sidebar-footer { display: none; }
  .nav-item { padding: 8px 12px; margin: 0 2px; white-space: nowrap; }
  .main { padding: 16px; }
}

.stat-card { background: #fff; border-radius: var(--radius); padding: 16px 18px; box-shadow: 0 1px 3px rgba(0,0,0,.06); border-left: 4px solid var(--brand); }
.stat-card.warn { border-left-color: var(--warn); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { background: #f9fafb; font-weight: 600; color: #374151; }
.table tbody tr:hover { background: #f9fafb; }
.table .right { text-align: right; }
.table .center { text-align: center; }
.table .mono { font-family: ui-monospace,Consolas,monospace; }
.table .small { font-size: 12px; }
.table .muted { color: var(--muted); }

.kv { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.kv td:first-child { color: var(--muted); width: 130px; white-space: nowrap; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; background: #fff; font-family: inherit; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.input-sm { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }

.btn { display: inline-block; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); font-size: 13px; cursor: pointer; line-height: 1.4; font-family: inherit; }
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-warn { background: var(--warn); color: #fff; border-color: var(--warn); }
.btn-warn:hover { background: #d97706; color: #fff; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; line-height: 1.6; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #e5e7eb; color: #374151; }

.status-pending { color: #6b7280; }
.status-paid { color: #2563eb; font-weight: 600; }
.status-writing { color: #d97706; font-weight: 600; }
.status-written { color: #16a34a; font-weight: 700; }
.status-failed { color: #dc2626; font-weight: 600; }
.status-expired { color: #6b7280; }
.status-refunded { color: #7c3aed; }

.online-dot, .offline-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.online-dot { background: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,.15); }
.offline-dot { background: #9ca3af; }

.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; }
.alert-success { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }
.alert-warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alert-info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }
.secret-value { word-break: break-all; font-size: 12px; background: #fff; padding: 8px 10px; border-radius: 4px; border: 1px solid #d1fae5; margin-top: 6px; }

.meta { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.mono { font-family: ui-monospace,Consolas,monospace; }
.small { font-size: 12px; }

.pager { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 16px; }
.pager-item { padding: 6px 10px; border-radius: 6px; background: #fff; border: 1px solid var(--line); color: var(--text); font-size: 12px; }
.pager-item:hover { background: #f3f4f6; text-decoration: none; }
.pager-item.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg,#1e3a8a 0%,#1e293b 100%); }
.login-box { background: #fff; padding: 36px 32px; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.2); width: 100%; max-width: 380px; }
.login-title { margin: 0 0 4px; font-size: 22px; text-align: center; }
.login-sub { margin: 0 0 24px; color: var(--muted); text-align: center; font-size: 13px; }
.login-error { background: #fee2e2; color: #991b1b; padding: 8px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 16px; }
.login-field { display: block; margin-bottom: 16px; }
.login-field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.login-field input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; outline: none; font-family: inherit; }
.login-field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.btn-login { width: 100%; padding: 12px; background: var(--brand); color: #fff; border: none; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; margin-top: 6px; font-family: inherit; }
.btn-login:hover { background: #1d4ed8; }
.login-note { margin: 20px 0 0; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.6; }
.client-stats-card { background:#fff; border-radius:12px; padding:16px 20px; margin-bottom:20px; box-shadow:0 1px 3px rgba(0,0,0,.06); }
.client-stats-header { font-size:14px; font-weight:600; color:#374151; margin-bottom:12px; }
.client-stats-counts { display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:14px; }
.client-stats-item { background:linear-gradient(135deg,#eff6ff 0%,#dbeafe 100%); border-radius:10px; padding:14px; text-align:center; }
.client-stats-label { font-size:12px; color:#6b7280; margin-bottom:6px; }
.client-stats-value { font-size:20px; font-weight:700; color:#1e40af; }
.client-stats-recent { border-top:1px solid #f3f4f6; padding-top:12px; }
.client-stats-recent-title { font-size:12px; color:#6b7280; margin-bottom:8px; }
.client-stats-recent-list { list-style:none; padding:0; margin:0; font-size:13px; }
.client-stats-recent-item { display:flex; align-items:center; padding:6px 0; gap:10px; border-bottom:1px dashed #f3f4f6; }
.client-stats-recent-item:last-child { border-bottom:none; }
.client-stats-role { flex:0 0 60px; color:#374151; font-weight:500; }
.client-stats-tier { flex:1 1 auto; color:#6b7280; font-size:12px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.client-stats-amount { flex:0 0 auto; color:#dc2626; font-weight:600; }
.client-stats-time { flex:0 0 auto; color:#9ca3af; font-size:12px; }
