@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --blue: #2563eb;
  --blue-hover: #1d4ed8;
  --blue-light: #eff6ff;
  --blue-subtle: #dbeafe;
  --red: #dc2626;
  --red-light: #fef2f2;
  --green: #16a34a;
  --green-light: #f0fdf4;
  --yellow: #ca8a04;
  --yellow-light: #fefce8;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-hover: #fafbfc;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --ring: rgba(37, 99, 235, 0.15);
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #1e293b;
  --sidebar-active: #1e3a5f;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-xs: 4px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 40;
  border-right: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand svg { flex-shrink: 0; }

.sidebar-brand-text {
  font-size: 13px;
  font-weight: 600;
  color: #f1f5f9;
  letter-spacing: -0.01em;
}

.sidebar-nav { padding: 12px 8px; flex: 1; }

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  color: #475569;
  padding: 4px 10px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
  position: relative;
}

.sidebar-link:hover { background: var(--sidebar-hover); color: #cbd5e1; }
.sidebar-link.active { background: var(--sidebar-active); color: #e2e8f0; }
.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  background: var(--blue);
  border-radius: 0 2px 2px 0;
}
.sidebar-link svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.5; }
.sidebar-link.active svg, .sidebar-link:hover svg { opacity: 0.9; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-avatar {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  background: #1e293b;
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.sidebar-user-name { font-size: 13px; font-weight: 500; color: #cbd5e1; }
.sidebar-user-role { font-size: 11px; color: #64748b; }
.sidebar-footer-right { margin-left: auto; }

.sidebar-footer-right a {
  color: #64748b;
  padding: 6px;
  border-radius: var(--radius-xs);
  transition: all 0.15s ease;
  display: flex;
}

.sidebar-footer-right a:hover { color: #ef4444; background: rgba(255,255,255,0.05); }

.main-content {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: 52px;
  background: rgba(255,255,255,0.9);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(8px);
}

.topbar-title { font-size: 14px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }

.topbar-status {
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-status .dot { width: 6px; height: 6px; border-radius: 50%; }
.topbar-status .dot-green { background: var(--green); box-shadow: 0 0 0 2px rgba(22,163,74,0.15); }
.topbar-status .dot-gray { background: var(--text-3); }

.page-content { padding: 24px; flex: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 { font-size: 13px; font-weight: 600; }
.card-body { padding: 18px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  position: relative;
  overflow: hidden;
}

.stat-card:hover { box-shadow: var(--shadow-sm); border-color: #cbd5e1; }

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--blue);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.stat-card:hover::before { opacity: 1; }

.stat-label {
  font-size: 12px;
  color: var(--text-3);
  font-weight: 500;
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}

.btn svg { width: 14px; height: 14px; }

.btn-primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 1px 2px rgba(37,99,235,0.2);
}

.btn-primary:hover { background: var(--blue-hover); box-shadow: 0 2px 4px rgba(37,99,235,0.25); }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  background: var(--surface);
  color: var(--text-2);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover { background: var(--bg); border-color: #cbd5e1; }

.btn-danger {
  background: var(--surface);
  color: var(--red);
  border-color: var(--border);
}

.btn-danger:hover { background: var(--red-light); border-color: #fecaca; }

.btn-ghost { background: transparent; color: var(--text-2); border-color: transparent; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 12px; border-radius: var(--radius-xs); }

.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

.form-hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }

.form-input {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  outline: none;
}

.form-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--ring); }
.form-input::placeholder { color: var(--text-3); }

textarea.form-input { resize: vertical; min-height: 80px; }

select.form-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 8px center;
  background-repeat: no-repeat;
  background-size: 16px;
  padding-right: 32px;
}

.form-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-2);
}

.form-checkbox input[type="checkbox"] {
  width: 15px; height: 15px;
  border-radius: var(--radius-xs);
  border: 1.5px solid #cbd5e1;
  appearance: none;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
}

.form-checkbox input[type="checkbox"]:checked { background: var(--blue); border-color: var(--blue); }

.form-checkbox input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px; top: 1px;
  width: 4px; height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-error { background: var(--red-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--yellow-light); color: #92400e; border: 1px solid #fde68a; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}

.data-table thead th {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
  white-space: nowrap;
  transition: background 0.1s ease;
}

.data-table tbody tr { transition: background 0.1s ease; }
.data-table tbody tr:hover { background: var(--blue-light); }
.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tfoot td {
  padding: 12px 14px;
  font-weight: 600;
  border-top: 2px solid var(--border);
  background: var(--bg);
  white-space: nowrap;
}

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-mono { font-family: 'SF Mono', ui-monospace, 'Cascadia Code', monospace; font-size: 12px; }
.text-muted { color: var(--text-2); }

.sortable { cursor: pointer; user-select: none; transition: color 0.15s ease; }
.sortable:hover { color: var(--text); }

.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s ease;
}

.table-link:hover { color: var(--blue-hover); text-decoration: underline; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge-active { background: var(--green-light); color: #15803d; }
.badge-paused { background: var(--yellow-light); color: #a16207; }
.badge-archived { background: var(--bg); color: var(--text-3); }
.badge-blue { background: var(--blue-subtle); color: #1e40af; }

.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-3);
}

.empty-state svg { margin-bottom: 12px; opacity: 0.3; }
.empty-title { font-size: 14px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.empty-desc { font-size: 13px; color: var(--text-3); max-width: 320px; margin: 0 auto; }

.token-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-xs);
}

.token-item:hover { border-color: #cbd5e1; box-shadow: var(--shadow-sm); }

.token-icon {
  width: 36px; height: 36px;
  background: var(--yellow-light);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.token-info { flex: 1; min-width: 0; }
.token-label { font-size: 13px; font-weight: 600; color: var(--text); }

.token-value {
  font-size: 12px;
  font-family: 'SF Mono', ui-monospace, monospace;
  color: var(--text-3);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  display: inline-block;
  margin-top: 3px;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.token-date { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.token-actions { display: flex; gap: 4px; flex-shrink: 0; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 11px; font-weight: 500; color: var(--text-3); }
.filter-group .form-input { padding: 7px 10px; font-size: 12px; border-color: var(--border); }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-3);
  text-decoration: none;
  margin-bottom: 16px;
  transition: color 0.15s ease;
}

.back-link:hover { color: var(--text-2); }
.back-link svg { width: 14px; height: 14px; }

.detail-header { margin-bottom: 20px; }
.detail-header h2 { font-size: 16px; font-weight: 600; margin-bottom: 8px; letter-spacing: -0.01em; }

.detail-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-2);
}

.ad-card {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.1s ease;
}

.ad-card:hover { background: var(--surface-hover); }
.ad-card:last-child { border-bottom: none; }

.ad-thumb {
  width: 72px; height: 72px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.ad-thumb-placeholder {
  width: 72px; height: 72px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  flex-shrink: 0;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card { width: 100%; max-width: 360px; padding: 0 24px; }
.login-card h1 { font-size: 18px; font-weight: 600; margin-bottom: 4px; letter-spacing: -0.01em; }
.login-card .subtitle { font-size: 13px; color: var(--text-3); margin-bottom: 28px; }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 10px; }

.login-footer { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-3); }
.login-footer a { color: var(--blue); text-decoration: none; font-weight: 500; }
.login-footer a:hover { text-decoration: underline; }

.login-icon-row { display: flex; align-items: center; gap: 8px; }
.login-icon-row svg { color: var(--text-3); }

.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.info-cell {
  padding: 12px 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

.info-cell-label {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.info-cell-value { font-size: 14px; font-weight: 600; color: var(--text); margin-top: 3px; }

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
}

.action-cell {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease;
}

.action-cell:hover { border-color: #cbd5e1; }

.action-cell-label {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 500;
  text-transform: capitalize;
}

.action-cell-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-top: 3px;
  letter-spacing: -0.01em;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-track {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #e2e8f0;
  border-radius: 20px;
  transition: background 0.2s ease;
}

.toggle-switch input:checked + .toggle-track { background: var(--blue); }

.toggle-track::before {
  content: '';
  position: absolute;
  height: 16px; width: 16px;
  left: 2px; bottom: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.06);
}

.toggle-switch input:checked + .toggle-track::before { transform: translateX(16px); }

.toggle-switch.disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

.status-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  letter-spacing: 0.01em;
}

.status-tag.active { background: var(--green-light); color: #15803d; }
.status-tag.paused { background: var(--yellow-light); color: #a16207; }
.status-tag.archived { background: var(--bg); color: var(--text-3); }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .mobile-menu-btn { display: flex !important; }
  .mobile-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 35; backdrop-filter: blur(2px); }
  .mobile-overlay.show { display: block; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .page-content { padding: 16px; }
  .data-table { font-size: 12px; }
  .data-table thead th, .data-table tbody td, .data-table tfoot td { padding: 8px 10px; }
  .table-responsive { margin: 0 -16px; padding: 0 16px; }
}

.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-2);
  transition: all 0.15s ease;
}

.mobile-menu-btn:hover { background: var(--bg); }

.loading-bar {
  height: 2px;
  background: var(--border);
  position: relative;
  overflow: hidden;
  margin-bottom: 16px;
  border-radius: 1px;
}

.loading-bar::after {
  content: '';
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 30%;
  background: var(--blue);
  border-radius: 1px;
  animation: loading-slide 1s ease-in-out infinite;
}

@keyframes loading-slide {
  0% { left: -30%; }
  100% { left: 100%; }
}

.skeleton-row {
  display: flex;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
}

.skeleton-cell {
  height: 14px;
  background: var(--border-light);
  border-radius: 3px;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.loading-text {
  font-size: 13px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px;
  justify-content: center;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  padding: 12px 16px;
  background: var(--red-light);
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: #991b1b;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-xs);
}

.error-banner svg { flex-shrink: 0; }

.error-banner .retry-btn {
  margin-left: auto;
  background: white;
  border: 1px solid #fecaca;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: #991b1b;
  transition: all 0.15s ease;
}

.error-banner .retry-btn:hover { background: #fff5f5; border-color: #fca5a5; }

/* Preset button group */
.preset-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}

.preset-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.preset-btn {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-2);
  background: var(--surface);
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.preset-btn:last-child { border-right: none; }
.preset-btn:hover { background: var(--bg); color: var(--text); }
.preset-btn.active { background: var(--blue-light); color: var(--blue); font-weight: 600; }

@media (max-width: 768px) {
  .preset-group { flex-wrap: wrap; }
  .preset-btn { border-right: none; border-bottom: 1px solid var(--border); }
  .preset-btn:last-child { border-bottom: none; }
}
