:root {
  --bg: #0b0f17;
  --surface: #111827;
  --surface-2: #161f30;
  --border: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #3b82f6;
  --bull: #10b981;
  --bear: #ef4444;
  --ema21: #22d3ee;
  --ema34: #f59e0b;
  --ema90: #f43f5e;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.mono {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

.app-shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 20px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #f59e0b, #b45309);
  color: #111827;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  font-size: 12px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Buttons & Badges */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #2563eb;
}

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

.btn-secondary:hover:not(:disabled) {
  border-color: #374151;
  background: #1e293b;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-bull {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-bear {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-warn {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-neutral {
  background: rgba(156, 163, 175, 0.14);
  color: #d1d5db;
  border: 1px solid rgba(156, 163, 175, 0.25);
}

/* Notice Banner */
.notice {
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 13px;
  border: 1px solid transparent;
}

.notice-warn {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.3);
  color: #fde68a;
}

.notice-error {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fecaca;
}

.notice-info {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.3);
  color: #bfdbfe;
}

.hidden {
  display: none !important;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

@media (max-width: 1080px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.card-sub {
  font-size: 12px;
  color: var(--muted);
}

.price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.price-value {
  font-size: 22px;
  font-weight: 700;
}

.ema-values {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.ema-pill {
  display: flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.dot-ema21 { background: var(--ema21); }
.dot-ema34 { background: var(--ema34); }
.dot-ema90 { background: var(--ema90); }

.countdown-grid {
  display: flex;
  gap: 18px;
  font-size: 16px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.quota-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.progress-bar {
  width: 100%;
  height: 7px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #3b82f6);
  transition: width 0.3s ease;
}

/* Telegram Monitor Bar */
.tg-monitor-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.tg-monitor-left {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.tg-monitor-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.tg-monitor-detail {
  font-size: 12px;
  color: var(--muted);
}

.tg-monitor-detail.is-error {
  color: #fca5a5;
}

.tg-monitor-stats {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
}

.stat-ok { color: #34d399; }
.stat-fail { color: #f87171; }

.delivery-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.err-inline {
  font-size: 12px;
  color: #fca5a5;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Panel & Chart */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.tf-switcher, .tabs {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}

.tf-btn, .tab-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.tf-btn.active, .tab-btn.active {
  background: var(--surface-2);
  color: var(--text);
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
}

.legend-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.legend-toggle input {
  accent-color: var(--accent);
}

.chart-container {
  width: 100%;
  height: 480px;
  position: relative;
}

/* Tables */
.hint {
  font-size: 12px;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.015);
}

tbody tr.clickable {
  cursor: pointer;
}

tbody tr.clickable:hover {
  background: rgba(59, 130, 246, 0.08);
}

.empty-cell {
  text-align: center;
  color: var(--muted);
  padding: 28px 16px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #1f2937;
  color: #f9fafb;
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
  z-index: 1000;
  max-width: 380px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 900;
}

.modal-card {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}

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

.modal-header h2 {
  font-size: 16px;
  font-weight: 700;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 14px;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.form-group input[type='text'],
.form-group input[type='password'],
.form-group textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

.form-group textarea.mono {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
  resize: vertical;
  line-height: 1.6;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent);
}

.input-with-action {
  display: flex;
  gap: 8px;
}

.form-hint {
  font-size: 12px;
  color: var(--muted);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.checkbox-row input {
  accent-color: var(--accent);
}

.key-usage-list {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.key-usage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.modal-sm {
  max-width: 410px;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.password-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 520px) {
  .password-grid {
    grid-template-columns: 1fr;
  }
}
