:root {
  --green-dark: #0a7a4a;
  --green: #12a35d;
  --green-mid: #16b56a;
  --bg: #e8ebe9;
  --panel: #ffffff;
  --text: #333;
  --muted: #777;
  --red: #e74c3c;
  --blue: #3498db;
  --orange: #e67e22;
  --purple: #8e44ad;
  --yellow: #f1c40f;
  --beige: #d4a574;
  --border: #dde3df;
  --sidebar-w: 248px;
  --topbar-h: 52px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); font-size: 13px; color: var(--text); background: var(--bg); overflow: hidden; }
a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 13px; }
[hidden] { display: none !important; }

/* TOPBAR */
.topbar {
  height: var(--topbar-h); background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px 0 16px; z-index: 100; box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; }
.brand { font-weight: 800; font-size: 22px; letter-spacing: 1px; display: flex; margin-right: 6px; }
.brand-n,.brand-t,.brand-o { color: #1a1a1a; }
.brand-1,.brand-r { color: #22c55e; }

.btn-icon {
  width: 34px; height: 34px; border-radius: 4px; color: #555;
  display: inline-flex; align-items: center; justify-content: center; position: relative;
}
.btn-icon:hover { background: #f0f0f0; color: var(--green); }
.badge-wrap .badge {
  position: absolute; top: 0; right: -2px; font-size: 9px; font-weight: 700;
  padding: 1px 4px; border-radius: 8px; color: #fff; min-width: 16px; text-align: center;
}
.badge.red { background: #e74c3c; }
.badge.orange { background: #e67e22; }

.user-info {
  display: flex; align-items: center; gap: 6px; font-size: 12px; color: #444;
  padding: 0 8px; border-left: 1px solid #eee; border-right: 1px solid #eee; margin: 0 4px;
}
.user-info i { font-size: 18px; color: #666; }
.user-sep { color: #ccc; }
.user-level strong { color: var(--green-dark); }
.clock { font-size: 11px; color: #666; white-space: nowrap; }

/* LAYOUT */
.layout { display: flex; height: calc(100vh - var(--topbar-h)); }

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: linear-gradient(180deg, #14b866 0%, #0fa35a 40%, #0d9452 100%);
  color: #fff; display: flex; flex-direction: column; overflow: hidden;
  transition: margin-left .25s ease, width .25s ease;
}
.sidebar.collapsed { margin-left: calc(var(--sidebar-w) * -1); width: 0; min-width: 0; }

.balance-box {
  background: linear-gradient(135deg, #17c972, #0faa5c);
  padding: 14px 16px 12px; border-bottom: 1px solid rgba(255,255,255,.15);
}
.balance-label { font-size: 12px; opacity: .95; }
.balance-value { font-size: 17px; font-weight: 700; margin: 4px 0 6px; }
.balance-value.negative { color: #ffeb3b; text-shadow: 0 1px 0 rgba(0,0,0,.15); }
.credit-label { font-size: 11px; opacity: .9; }

.menu-section {
  padding: 10px 16px 6px; font-size: 10px; font-weight: 700;
  letter-spacing: .8px; opacity: .85; text-transform: uppercase;
}
.menu { flex: 1; overflow-y: auto; padding-bottom: 12px; }
.menu::-webkit-scrollbar { width: 5px; }
.menu::-webkit-scrollbar-thumb { background: rgba(0,0,0,.2); border-radius: 3px; }

.menu-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  color: rgba(255,255,255,.95); font-size: 13px; transition: background .15s; cursor: pointer;
}
.menu-item i:first-child { width: 18px; text-align: center; font-size: 13px; }
.menu-item span { flex: 1; }
.menu-item .chev { font-size: 10px; opacity: .7; transition: transform .2s; }
.menu-item:hover { background: rgba(0,0,0,.12); }
.menu-group.open > .menu-item.has-children { background: rgba(0,0,0,.18); font-weight: 600; }
.menu-group.open > .menu-item .chev { transform: rotate(180deg); }
.submenu { display: none; background: rgba(0,0,0,.12); }
.menu-group.open .submenu { display: block; }
.menu-item.sub { padding: 8px 16px 8px 44px; font-size: 12.5px; font-weight: 400; }
.menu-item.sub.active {
  background: rgba(0,0,0,.22); border-left: 3px solid #fff; padding-left: 41px; font-weight: 600;
}
.sidebar-footer {
  padding: 10px 12px; font-size: 9px; text-align: center; opacity: .7;
  border-top: 1px solid rgba(255,255,255,.1); letter-spacing: .3px;
}

/* MAIN */
.main { flex: 1; overflow-y: auto; padding: 14px 18px 40px; background: #e9eceb; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 12px; }
.breadcrumb { font-size: 15px; font-weight: 600; color: #444; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* CARDS / PANEL */
.status-row { display: flex; gap: 28px; margin-bottom: 14px; font-size: 12.5px; flex-wrap: wrap; }
.status-row .muted { color: var(--muted); margin-right: 4px; }
.status-online { color: #1bb85a; font-weight: 700; }
.status-offline { color: var(--red); font-weight: 700; }

.stat-cards {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px;
}
.stat-cards.c2 { grid-template-columns: repeat(2, 1fr); }
.stat-cards.c3 { grid-template-columns: repeat(3, 1fr); }
.stat-cards.c5 { grid-template-columns: repeat(5, 1fr); }

.stat-card {
  background: #fff; border-radius: 4px; padding: 18px 16px 16px; text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); border: 1px solid #eef1ef; min-height: 96px;
  display: flex; flex-direction: column; justify-content: center;
}
.stat-title {
  font-size: 12.5px; color: #444; font-weight: 600; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: .3px; }
.stat-value.lg { font-size: 26px; }
.stat-value.negative { color: #e74c3c; }
.stat-value.positive, .stat-value.blue { color: #3498db; }
.stat-value.green { color: #27ae60; }
.stat-sub { font-size: 11px; color: #999; margin-top: 4px; }

.online-pill {
  display: inline-flex; align-items: center; gap: 6px; background: #1bb85a;
  color: #fff; font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 3px;
}
.online-pill .dot {
  width: 7px; height: 7px; background: #fff; border-radius: 50%;
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

.panel {
  background: #fff; border-radius: 4px; border: 1px solid #eef1ef;
  box-shadow: 0 1px 3px rgba(0,0,0,.05); padding: 16px 18px; margin-bottom: 14px;
}
.panel-header { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.panel-header h3 { font-size: 15px; font-weight: 600; color: #333; }

.filter-row {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: #555; font-weight: 500; }
.field input, .field select, .field textarea,
.search-input, .select-input, .form-input {
  border: 1px solid #d0d5d2; border-radius: 3px; padding: 7px 12px; outline: none; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus,
.search-input:focus, .select-input:focus, .form-input:focus { border-color: var(--green); }
.date-input {
  display: flex; align-items: center; gap: 8px; border: 1px solid #d0d5d2;
  border-radius: 3px; padding: 7px 12px; background: #fff; min-width: 220px;
}
.date-input i { color: #888; }
.date-input input { border: none; outline: none; width: 170px; background: transparent; }

.form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
  border-radius: 3px; font-size: 12.5px; font-weight: 600; color: #fff; transition: filter .15s;
}
.btn:active { transform: scale(.98); }
.btn-sm { padding: 4px 9px; font-size: 11.5px; }
.btn-xs { padding: 3px 7px; font-size: 11px; }
.btn-primary { background: #3498db; }
.btn-danger { background: #e74c3c; }
.btn-success { background: #27ae60; }
.btn-warning { background: #f39c12; }
.btn-dark { background: #2c3e50; }
.btn-outline { background: #fff; color: #555; border: 1px solid #ccc; }
.btn:hover { filter: brightness(1.08); }

.filter-actions, .tool-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tool-row { margin-bottom: 12px; justify-content: space-between; }
.tool-left, .tool-right { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search-input { min-width: 220px; }
.download-row { display: flex; justify-content: flex-end; margin-bottom: 10px; }

/* CHART */
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 14px 18px; margin-top: 10px;
  font-size: 11.5px; color: #555; justify-content: center;
}
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.beige { background: #d4a574; } .dot.red { background: #e74c3c; }
.dot.purple { background: #8e44ad; } .dot.green { background: #27ae60; }
.dot.yellow { background: #f1c40f; }
.chart-wrap { position: relative; width: 100%; max-height: 360px; }

/* TABLE */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th {
  background: #f7f9f8; text-align: left; padding: 10px 12px; font-weight: 600;
  color: #444; border-bottom: 2px solid #e5eae7; white-space: nowrap;
}
.data-table td { padding: 9px 12px; border-bottom: 1px solid #eef1ef; vertical-align: middle; }
.data-table tbody tr:hover { background: #f9fbfa; }
.data-table .mono { font-family: ui-monospace, monospace; font-size: 12px; }
.right { text-align: right; }
.center { text-align: center; }

.status-badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; text-transform: capitalize;
}
.status-badge.active, .status-badge.approved, .status-badge.published, .status-badge.win { background: #d4edda; color: #155724; }
.status-badge.pending { background: #fff3cd; color: #856404; }
.status-badge.suspended, .status-badge.rejected, .status-badge.lose { background: #f8d7da; color: #721c24; }
.status-badge.banned, .status-badge.inactive { background: #343a40; color: #fff; }
.status-badge.vip { background: #fff3cd; color: #856404; }
.status-badge.vvip { background: #e8d5f5; color: #6c3483; }

.action-btns { display: flex; gap: 4px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  padding: 5px 12px; border-radius: 3px; font-size: 12px; font-weight: 600;
  color: #666; background: #f0f0f0;
}
.tab.active { background: var(--green); color: #fff; }
.tab:hover:not(.active) { background: #e0e0e0; }
.tab .count {
  display: inline-block; background: rgba(0,0,0,.15); border-radius: 8px;
  padding: 0 5px; margin-left: 4px; font-size: 10px;
}
.tab.active .count { background: rgba(255,255,255,.25); }

.pagination { display: flex; justify-content: flex-end; gap: 4px; margin-top: 14px; flex-wrap: wrap; }
.pagination button {
  min-width: 30px; height: 30px; border: 1px solid #ddd; border-radius: 3px;
  background: #fff; font-size: 12px; color: #555;
}
.pagination button.active, .pagination button:hover {
  background: var(--green); color: #fff; border-color: var(--green);
}
.pagination .info { align-self: center; margin-right: auto; color: #888; font-size: 12px; }

/* MEMO / LOG card */
.memo-card {
  border: 1px solid #eef1ef; border-radius: 4px; padding: 14px; margin-bottom: 10px;
  background: #fafcfb;
}
.memo-card.pinned { border-left: 3px solid var(--orange); }
.memo-card h4 { font-size: 14px; margin-bottom: 6px; }
.memo-card p { color: #555; line-height: 1.5; margin-bottom: 8px; }
.memo-meta { font-size: 11px; color: #999; display: flex; gap: 12px; flex-wrap: wrap; }

/* SETTINGS */
.settings-list { display: grid; gap: 12px; }
.setting-row {
  display: grid; grid-template-columns: 220px 1fr; gap: 12px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid #f0f0f0;
}
.setting-row label { font-weight: 600; color: #444; }
.switch {
  position: relative; width: 42px; height: 22px; display: inline-block;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: #ccc; border-radius: 22px; transition: .2s; cursor: pointer;
}
.switch .slider:before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider:before { transform: translateX(20px); }

/* MODAL */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: #fff; border-radius: 6px; width: 100%; max-width: 560px;
  max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.modal.wide { max-width: 780px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid #eee;
}
.modal-head h3 { font-size: 15px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  padding: 12px 18px; border-top: 1px solid #eee; display: flex; justify-content: flex-end; gap: 8px;
}

/* TOAST */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: #2c3e50; color: #fff;
  padding: 12px 18px; border-radius: 4px; font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,.2);
  opacity: 0; transform: translateY(10px); transition: all .25s; z-index: 9999;
  pointer-events: none; max-width: 340px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: #27ae60; }
.toast.error { background: #e74c3c; }
.toast.info { background: #3498db; }

.empty {
  text-align: center; padding: 40px 20px; color: #999;
}
.empty i { font-size: 36px; color: #ddd; margin-bottom: 10px; display: block; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; font-size: 13px; }
.kv dt { color: #888; }
.kv dd { font-weight: 600; }

/* RESPONSIVE */
@media (max-width: 1280px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .stat-cards.c5 { grid-template-columns: repeat(3, 1fr); }
  .user-info .user-code, .user-info .user-level { display: none; }
}
@media (max-width: 900px) {
  .form-grid { grid-template-columns: 1fr; }
  .setting-row { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .stat-cards, .stat-cards.c2, .stat-cards.c3, .stat-cards.c5 { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-h); height: calc(100vh - var(--topbar-h));
    z-index: 90; box-shadow: 4px 0 12px rgba(0,0,0,.15);
  }
  .clock { display: none; }
  .user-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* LIVE BADGE */
.live-badge {
  display:inline-flex; align-items:center; gap:6px;
  padding:4px 10px; border-radius:12px; font-size:11px; font-weight:700;
  background:#eee; color:#666; border:1px solid #ddd;
}
.live-badge.on { background:#e8f8ef; color:#0a7a4a; border-color:#a8e0c0; }
.live-badge.err { background:#fdecea; color:#c0392b; border-color:#f5c6cb; }
.live-badge .live-dot {
  width:8px; height:8px; border-radius:50%; background:#aaa;
}
.live-badge.on .live-dot { background:#1bb85a; box-shadow:0 0 0 0 rgba(27,184,90,.7); animation: livepulse 1.4s infinite; }
.live-badge.err .live-dot { background:#e74c3c; }
@keyframes livepulse {
  0% { box-shadow:0 0 0 0 rgba(27,184,90,.55); }
  70% { box-shadow:0 0 0 8px rgba(27,184,90,0); }
  100% { box-shadow:0 0 0 0 rgba(27,184,90,0); }
}
.live-panel-note {
  background: linear-gradient(90deg,#e8f8ef,#fff);
  border:1px solid #b7e0c8; border-radius:4px; padding:10px 14px;
  margin-bottom:12px; font-size:12.5px; color:#0a7a4a;
  display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap;
}
.live-panel-note.warn { background:#fff8e8; border-color:#f0d78c; color:#856404; }
.live-panel-note.err { background:#fdecea; border-color:#f5c6cb; color:#721c24; }
