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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3347;
  --accent: #6c63ff;
  --accent-hover: #5a52e0;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 10px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

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

/* Layout */
.container { max-width: 900px; margin: 0 auto; padding: 0 20px; }
.page-center { display: flex; align-items: center; justify-content: center; min-height: 100vh; }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

/* Form */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; color: var(--text-muted); font-size: 13px; }
.form-control {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}
.form-control:focus { border-color: var(--accent); }
.form-control::placeholder { color: var(--text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.inline-form { display: flex; gap: 8px; align-items: stretch; }
.inline-form .btn { flex: 0 0 auto; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background .2s, opacity .2s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-active { background: rgba(34,197,94,.15); color: var(--success); }
.badge-disabled { background: rgba(239,68,68,.15); color: var(--danger); }
.badge-expired { background: rgba(245,158,11,.15); color: var(--warning); }

/* Progress bar */
.progress-wrap { margin-bottom: 12px; }
.progress-label { display: flex; justify-content: space-between; margin-bottom: 4px; font-size: 12px; color: var(--text-muted); }
.progress-bar { height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .4s; }
.progress-fill.warn { background: var(--warning); }
.progress-fill.danger { background: var(--danger); }
.reset-hint { font-size: 11px; color: var(--text-muted); margin-top: 2px; opacity: 0.8; }

/* Alert */
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; }
.alert-error { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }
.alert-success { background: rgba(34,197,94,.1); border: 1px solid rgba(34,197,94,.3); color: #86efac; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; background: var(--surface2); }
tr:hover td { background: rgba(255,255,255,.02); }
td.mono { font-family: monospace; font-size: 13px; }

/* Navbar */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar-brand { font-weight: 700; font-size: 16px; color: var(--text); }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 20px; line-height: 1; }
.modal-message { color: var(--text); font-size: 14px; line-height: 1.7; }
.modal-message.success { color: var(--success); font-weight: 600; }
.modal-intent {
  border: 1px solid rgba(245,158,11,.45);
  border-left: 4px solid var(--warning);
  border-radius: 8px;
  background: rgba(245,158,11,.1);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.modal-intent-new {
  border-color: rgba(59,130,246,.45);
  border-left-color: var(--info);
  background: rgba(59,130,246,.1);
}
.modal-intent-renew {
  border-color: rgba(245,158,11,.45);
  border-left-color: var(--warning);
  background: rgba(245,158,11,.1);
}
.modal-intent-label {
  display: inline-block;
  color: var(--warning);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}
.modal-intent-new .modal-intent-label { color: #93c5fd; }
.modal-intent-title {
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.5;
}
.modal-intent-desc {
  color: var(--text);
  font-size: 13px;
  line-height: 1.7;
  margin-top: 6px;
  opacity: .92;
}
.preview-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-top: 12px;
}
.preview-label {
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 6px;
}
.preview-value {
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}
.preview-muted {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 8px;
}
.key-output {
  display: block;
  width: 100%;
  color: var(--text);
  background: rgba(15,17,23,.72);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: normal;
  overflow-wrap: anywhere;
  user-select: all;
}
.key-copy-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.key-copy-row .key-output {
  flex: 1 1 auto;
}
.key-copy-row .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}
.key-copy-row .btn.copied {
  background: var(--success);
}

/* Toolbar */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar-right { margin-left: auto; }
.search-input { width: 220px; }

/* Pagination */
.pagination { display: flex; gap: 6px; align-items: center; justify-content: center; margin-top: 16px; }
.page-btn {
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-btn.active { background: var(--accent); border-color: var(--accent); }

/* Batch bar */
.batch-bar {
  display: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 16px;
  margin-bottom: 12px;
  align-items: center;
  gap: 10px;
}
.batch-bar.visible { display: flex; }

/* Quota page specific */
.quota-header { text-align: center; padding: 40px 0 20px; }
.quota-header h1 { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
.quota-header p { color: var(--text-muted); }
.redeem-card { padding: 20px; }
.redeem-card-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.redeem-card-title span:first-child {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.redeem-mode-hint {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: var(--text);
  background: rgba(245,158,11,.1);
  border: 1px solid rgba(245,158,11,.35);
  border-left: 4px solid var(--warning);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.6;
}
.redeem-mode-label {
  flex: 0 0 auto;
  color: var(--warning);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.quota-result { margin-top: 24px; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.info-item { background: var(--surface2); border-radius: 6px; padding: 12px 16px; }
.info-item .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.info-item .value { font-size: 15px; font-weight: 600; }
.quota-expire-note { color: var(--text-muted); font-size: 11px; font-weight: 500; margin-left: 4px; white-space: nowrap; }

/* Spinner */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Select */
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238892a4' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

/* Checkbox */
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

/* Responsive */
@media (max-width: 600px) {
  .info-grid { grid-template-columns: 1fr; }
  .search-input { width: 100%; }
  .toolbar { flex-direction: column; align-items: stretch; }
}

/* Toast animations */
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

/* Notification badge & items */
.notif-badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700;
  border-radius: 50%; min-width: 18px; height: 18px;
  line-height: 18px; text-align: center; padding: 0 4px;
}
.notif-item { transition: background .15s; }
.notif-item:hover { background: var(--surface2); }
.notif-unread { border-left: 3px solid var(--accent); }
.notif-filter { background: transparent; border: 1px solid var(--border); color: var(--text-muted); cursor: pointer; }
.notif-filter.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Editable note styling */
.editable-note {
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  transition: background 0.2s;
}
.editable-note:hover {
  background: var(--surface2);
}

/* Quota banner */
.quota-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px 20px;
}
.quota-banner-key {
  font-family: monospace;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.quota-banner-plan {
  font-size: 14px;
  font-weight: 600;
}
.quota-banner-sep {
  color: var(--text-muted);
  margin: 0 6px;
}

/* Tabs */
.q-tabs {
  display: flex;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.q-tab {
  flex: 1;
  padding: 10px 0;
  text-align: center;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color .2s, border-color .2s;
}
.q-tab:hover { color: var(--text); }
.q-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Tab panels */
.q-tab-panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 20px;
}
.q-tab-panel.active { display: block; }

/* Quota stat cards */
.quota-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.quota-stat-card {
  background: var(--surface2);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}
.quota-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}
.quota-stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

/* Quota progress section */
.quota-progress-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Logs filters */
.logs-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.form-control-sm {
  padding: 6px 10px;
  font-size: 12px;
}
select.form-control.form-control-sm {
  padding-right: 28px;
}

/* Logs table tweaks */
#logs-table-wrap th { font-size: 11px; }
#logs-table-wrap td { font-size: 12px; padding: 8px 10px; }
.log-model { font-weight: 600; }
.log-type-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 500;
}
.log-type-stream { background: rgba(59,130,246,.15); color: var(--info); }
.log-type-nonstream { background: rgba(139,92,246,.15); color: #a78bfa; }
.log-type-ws { background: rgba(245,158,11,.15); color: var(--warning); }
.log-cost { color: var(--warning); font-weight: 600; font-family: monospace; }
.log-duration { color: var(--text-muted); font-family: monospace; }
.log-tokens { font-family: monospace; font-size: 11px; }
.log-tokens-in { color: var(--info); }
.log-tokens-out { color: var(--success); }

/* Admin tabs */
.admin-tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 56px;
  z-index: 99;
}
.admin-tab {
  padding: 12px 24px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color .2s, border-color .2s;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

@media (max-width: 600px) {
  .quota-stats { grid-template-columns: 1fr; }
  .logs-filters { grid-template-columns: 1fr; }
  .quota-banner { flex-direction: column; gap: 8px; align-items: flex-start; }
  .inline-form { flex-direction: column; }
  .inline-form .btn { width: 100%; justify-content: center; }
  .redeem-card-title { flex-direction: column; align-items: flex-start; gap: 2px; }
  .redeem-card-title span:last-child { text-align: left; }
  .modal { margin: 0 14px; padding: 22px; }
  .redeem-mode-hint { flex-direction: column; gap: 4px; }
  .key-copy-row { flex-direction: column; }
}
