/**
 * YaoSenjutsu Dashboard Common CSS
 * Shared across all dashboard pages (Home, Usage, Keys, Quickstart, Plan).
 */

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

:root {
  --bg: #000; --bg-subtle: #0a0a0a; --bg-sidebar: #060606;
  --border: #1a1a1a; --border-hover: #333;
  --text: #f1f5f9; --text-secondary: #94a3b8; --text-tertiary: #64748b;
  --primary: #0d7ff2; --primary-dim: rgba(13,127,242,0.12);
  --cyan: #06b6d4; --gold: #f0c078;
  --green: #22c55e; --red: #ef4444; --purple: #a855f7;
  --card-bg: rgba(255,255,255,0.02); --card-bg-hover: rgba(255,255,255,0.04);
  --code-font: 'JetBrains Mono', 'SF Mono', monospace;
  --sidebar-w: 240px;
}

html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}

/* ═══ Top bar ═══ */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 52px; z-index: 100;
  background: var(--bg); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px 0 0;
}
.topbar-left { display: flex; align-items: center; gap: 0; height: 100%; }
.topbar-brand {
  display: flex; align-items: center; gap: 10px;
  width: var(--sidebar-w); padding: 0 20px; height: 100%;
  text-decoration: none; color: var(--text); border-right: 1px solid var(--border);
}
.topbar-brand img { width: 24px; height: 24px; }
.topbar-brand-name { font-size: 14px; font-weight: 700; letter-spacing: -0.02em; }
.topbar-sep { color: var(--text-tertiary); margin: 0 12px; font-size: 18px; font-weight: 300; }
.topbar-ctx { font-size: 13px; color: var(--text-secondary); padding: 0 12px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-link {
  font-size: 13px; color: var(--text-secondary); text-decoration: none;
  transition: color 0.15s;
}
.topbar-link:hover { color: var(--text); }
.topbar-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--border); border: 1px solid var(--border);
  cursor: pointer; transition: border-color 0.15s; display: none;
}
.topbar-avatar:hover { border-color: var(--border-hover); }
.topbar-settings {
  background: none; border: none; color: var(--text-tertiary);
  cursor: pointer; padding: 4px; transition: color 0.15s;
}
.topbar-settings:hover { color: var(--text); }
.topbar-mobile-btn {
  display: none; background: none; border: none;
  color: var(--text); cursor: pointer; padding: 4px;
}

/* ═══ Sidebar ═══ */
.sidebar {
  position: fixed; top: 52px; left: 0; bottom: 0;
  width: var(--sidebar-w); background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 12px 8px; overflow-y: auto; z-index: 90;
  display: flex; flex-direction: column;
}
.side-section { margin-bottom: 8px; }
.side-label {
  font-size: 11px; font-weight: 500; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 8px 12px 4px; user-select: none;
}
.side-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px;
  font-size: 13px; color: var(--text-secondary);
  text-decoration: none; cursor: pointer; transition: all 0.12s;
  border: 1px solid transparent;
}
.side-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.side-item.active {
  background: rgba(255,255,255,0.06); color: var(--text);
  border-color: rgba(255,255,255,0.06);
}
.side-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.6; }
.side-item.active svg { opacity: 1; }
.side-spacer { flex: 1; }

/* ═══ Main content ═══ */
.main {
  margin-left: var(--sidebar-w); padding: 72px 32px 48px;
  max-width: calc(1100px + var(--sidebar-w)); min-height: 100vh;
  opacity: 0; transition: opacity 0.15s ease;
}
.main.loaded { opacity: 1; }

/* ═══ Dashboard loading ═══ */
.dash-loading {
  position: fixed; inset: 0; z-index: 300;
  background: var(--bg, #000);
  display: flex; align-items: center; justify-content: center;
}
.dash-loading.hidden { display: none; }

/* ═══ Announcement banner ═══ */
.banner {
  position: relative; overflow: hidden;
  border: 1px solid var(--border); border-radius: 12px;
  padding: 24px 48px 24px 28px; margin-bottom: 28px;
  background: linear-gradient(135deg, rgba(13,127,242,0.08) 0%, rgba(6,182,212,0.06) 50%, rgba(168,85,247,0.04) 100%);
  animation: fade-up 0.5s ease-out both;
}
.banner-glow {
  position: absolute; top: -40px; right: -40px;
  width: 200px; height: 200px;
  background: radial-gradient(circle, rgba(13,127,242,0.15), transparent 70%);
  pointer-events: none;
}
.banner-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; position: relative; }
.banner-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 14px; position: relative; }
.banner-actions { display: flex; gap: 10px; position: relative; }
.banner-btn-fill {
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: #000; background: #fff; border: none;
  padding: 7px 18px; border-radius: 8px; cursor: pointer;
  transition: background 0.15s;
}
.banner-btn-fill:hover { background: #e2e8f0; }
.banner-btn-outline {
  font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--text-secondary); background: none;
  border: 1px solid var(--border); padding: 7px 18px; border-radius: 8px;
  cursor: pointer; text-decoration: none; transition: all 0.15s;
}
.banner-btn-outline:hover { border-color: var(--border-hover); color: var(--text); }
.banner-close {
  position: absolute; top: 12px; right: 12px;
  background: none; border: none; color: var(--text-tertiary);
  cursor: pointer; padding: 4px; transition: color 0.15s;
}
.banner-close:hover { color: var(--text); }

/* ═══ Page header ═══ */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; animation: fade-up 0.5s ease-out 0.05s both;
}
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.page-actions { display: flex; align-items: center; gap: 8px; }
.btn-create-key {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--text); background: none;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 16px; cursor: pointer; transition: all 0.15s;
}
.btn-create-key:hover { border-color: var(--border-hover); background: rgba(255,255,255,0.03); }
.btn-create-key svg { width: 14px; height: 14px; }
.range-group { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.range-btn {
  font-family: inherit; font-size: 12px; font-weight: 500;
  color: var(--text-tertiary); background: none; border: none;
  padding: 7px 14px; cursor: pointer; transition: all 0.12s;
  border-right: 1px solid var(--border);
}
.range-btn:last-child { border-right: none; }
.range-btn:hover { color: var(--text-secondary); }
.range-btn.active { color: var(--text); background: rgba(255,255,255,0.06); }

/* ═══ Stat cards (4-grid) ═══ */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  background: var(--border); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; margin-bottom: 24px;
  animation: fade-up 0.5s ease-out 0.1s both;
}
.stat-card {
  background: var(--bg); padding: 20px 24px;
  cursor: pointer; transition: background 0.15s;
}
.stat-card:hover { background: var(--card-bg-hover); }
.stat-label {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--text-tertiary); margin-bottom: 8px;
}
.stat-label svg { width: 12px; height: 12px; opacity: 0.5; }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.stat-sub { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }
.stat-bar { height: 3px; background: rgba(255,255,255,0.04); border-radius: 2px; margin-top: 10px; overflow: hidden; }
.stat-bar-fill { height: 100%; border-radius: 2px; transition: width 0.8s cubic-bezier(0.4,0,0.2,1); }
.bar-blue { background: var(--primary); }
.bar-gold { background: var(--gold); }
.bar-red { background: var(--red); }
.bar-green { background: var(--green); }
.stat-sparkline { margin-top: 10px; height: 32px; }
.stat-sparkline svg { width: 100%; height: 100%; }

/* ═══ Chart section ═══ */
.chart-section {
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); margin-bottom: 24px; overflow: hidden;
  animation: fade-up 0.5s ease-out 0.15s both;
}
.chart-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 0;
}
.chart-header-left { }
.chart-header-label { font-size: 13px; color: var(--text-secondary); }
.chart-header-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.chart-toggle { display: flex; gap: 4px; }
.chart-toggle-btn {
  font-family: inherit; font-size: 12px; color: var(--text-tertiary);
  background: none; border: 1px solid transparent; border-radius: 6px;
  padding: 4px 12px; cursor: pointer; transition: all 0.15s;
}
.chart-toggle-btn.active { color: var(--text-secondary); background: rgba(255,255,255,0.05); border-color: var(--border); }
.chart-toggle-btn:hover { color: var(--text-secondary); }
.chart-container { position: relative; padding: 16px 24px 20px; height: 220px; }
.chart-container svg { width: 100%; height: 100%; overflow: visible; }
.chart-tooltip {
  display: none; position: absolute;
  background: #111; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 12px; pointer-events: none; z-index: 10;
}
.chart-tooltip-date { color: var(--text-secondary); margin-bottom: 2px; }
.chart-tooltip-value { font-weight: 600; }

/* ═══ Two-column ═══ */
.columns {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px;
  animation: fade-up 0.5s ease-out 0.2s both;
}

/* ═══ Card ═══ */
.card {
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-head-title { font-size: 14px; font-weight: 600; }
.card-body { padding: 0; }

/* ═══ API Keys ═══ */
.key-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.key-row:last-child { border-bottom: none; }
.key-row:hover { background: var(--card-bg-hover); }
.key-info { flex: 1; min-width: 0; }
.key-name { font-size: 13px; font-weight: 500; }
.key-meta { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; display: flex; gap: 12px; }
.key-prefix { font-family: var(--code-font); font-size: 11px; }
.key-status {
  font-size: 10px; font-weight: 600; padding: 2px 6px;
  border-radius: 4px; text-transform: uppercase; letter-spacing: 0.04em;
}
.key-status-active { color: var(--green); background: rgba(34,197,94,0.1); }
.key-status-revoked { color: var(--text-tertiary); background: rgba(255,255,255,0.04); }
.btn-sm {
  font-family: inherit; font-size: 12px; padding: 4px 10px;
  border-radius: 6px; cursor: pointer; transition: all 0.15s;
}
.btn-sm-danger { color: var(--red); background: none; border: 1px solid rgba(239,68,68,0.2); }
.btn-sm-danger:hover { background: rgba(239,68,68,0.06); border-color: rgba(239,68,68,0.4); }
.keys-empty { text-align: center; padding: 32px 20px; color: var(--text-tertiary); font-size: 13px; }

/* ═══ Activity ═══ */
.activity-table { width: 100%; border-collapse: collapse; }
.activity-table th {
  font-size: 11px; color: var(--text-tertiary); font-weight: 500;
  text-align: left; padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.activity-table td { font-size: 13px; padding: 10px 20px; border-bottom: 1px solid var(--border); }
.activity-table tr:last-child td { border-bottom: none; }
.activity-table tr:hover td { background: var(--card-bg-hover); }
.endpoint-name { font-family: var(--code-font); font-size: 12px; color: var(--cyan); }

/* ═══ Credits breakdown ═══ */
.credits-section { padding: 20px; }
.credits-bar { height: 8px; border-radius: 4px; overflow: hidden; display: flex; background: rgba(255,255,255,0.03); }
.credits-bar-segment { height: 100%; transition: width 0.8s cubic-bezier(0.4,0,0.2,1); }
.credits-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
.credits-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.credits-legend-dot { width: 8px; height: 8px; border-radius: 2px; }
.color-feed { background: var(--cyan); }
.color-chart { background: var(--primary); }
.color-analysis { background: var(--gold); }
.color-decision { background: var(--purple); }
.color-oracle { background: var(--red); }

/* ═══ Plan grid ═══ */
.plan-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px; max-width: 720px;
}

/* ═══ Tier ═══ */
.tier-section { padding: 20px; }
.tier-badge {
  display: inline-flex; font-size: 12px; font-weight: 600;
  padding: 4px 12px; border-radius: 6px;
  border: 1px solid var(--gold); color: var(--gold);
  background: rgba(240,192,120,0.06); margin-bottom: 14px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.tier-quota { margin-bottom: 10px; }
.tier-quota-label { font-size: 11px; color: var(--text-tertiary); margin-bottom: 4px; display: flex; justify-content: space-between; }
.tier-quota-bar { height: 3px; background: rgba(255,255,255,0.04); border-radius: 2px; overflow: hidden; }
.tier-quota-fill { height: 100%; border-radius: 2px; transition: width 0.8s cubic-bezier(0.4,0,0.2,1); }
.btn-upgrade {
  display: flex; align-items: center; justify-content: center;
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: #000; background: #fff; border: none;
  padding: 8px; border-radius: 8px; cursor: pointer;
  transition: background 0.15s; width: 100%; margin-top: 14px;
  text-decoration: none;
}
.btn-upgrade:hover { background: #e2e8f0; }

/* ═══ Quickstart ═══ */
.qs-section { padding: 20px; }
.code-block {
  background: var(--bg-subtle); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.code-header {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.code-dot { width: 7px; height: 7px; border-radius: 50%; }
.code-dot-r { background: #ff5f57; }
.code-dot-y { background: #febc2e; }
.code-dot-g { background: #28c840; }
.code-tab {
  margin-left: 4px; font-size: 11px; color: var(--text-tertiary);
  padding: 3px 10px; border-radius: 5px; cursor: pointer;
  transition: all 0.15s; border: none; background: none; font-family: inherit;
}
.code-tab.active { background: rgba(255,255,255,0.05); color: var(--text-secondary); }
.code-copy-btn {
  margin-left: auto; font-size: 10px; color: var(--text-tertiary);
  background: none; border: 1px solid var(--border); border-radius: 5px;
  padding: 3px 8px; cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.code-copy-btn:hover { color: var(--text-secondary); border-color: var(--border-hover); }
.code-body {
  padding: 14px; font-family: var(--code-font);
  font-size: 11px; line-height: 1.8; overflow-x: auto;
}
.code-panel { display: none; }
.code-panel.active { display: block; }
.code-body .kw { color: var(--primary); }
.code-body .str { color: var(--cyan); }

/* ═══ Modal ═══ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(8px);
  display: none; align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #0a0a0a; border: 1px solid var(--border); border-radius: 14px;
  width: 100%; max-width: 420px; margin: 16px; padding: 32px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
  animation: modal-in 0.2s ease-out; position: relative;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-close {
  position: absolute; top: 14px; right: 14px;
  background: none; border: none; color: var(--text-tertiary);
  cursor: pointer; transition: color 0.15s;
}
.modal-close:hover { color: var(--text); }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.modal-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 20px; line-height: 1.5; }
.modal-error {
  display: none; font-size: 12px; color: #f87171;
  background: rgba(248,113,113,0.08); border: 1px solid rgba(248,113,113,0.15);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 12px;
}
.modal-warning {
  font-size: 12px; color: var(--gold);
  background: rgba(240,192,120,0.06); border: 1px solid rgba(240,192,120,0.15);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 14px;
}
.modal-input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px;
  font-family: inherit; font-size: 13px; color: var(--text);
  outline: none; transition: border-color 0.15s; margin-bottom: 16px;
}
.modal-input:focus { border-color: var(--primary); }
.modal-input::placeholder { color: var(--text-tertiary); }
.modal-input-mono { font-family: var(--code-font); font-size: 12px; }
.modal-btn-row { display: flex; gap: 10px; }
.modal-btn-fill {
  flex: 1; font-family: inherit; font-size: 13px; font-weight: 600;
  color: #000; background: #fff; border: none;
  padding: 10px; border-radius: 8px; cursor: pointer; transition: background 0.15s;
}
.modal-btn-fill:hover { background: #e2e8f0; }
.modal-btn-fill:disabled { opacity: 0.4; cursor: not-allowed; }
.modal-btn-outline {
  flex: 1; font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--text-secondary); background: none;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; cursor: pointer; transition: all 0.15s;
}
.modal-btn-outline:hover { color: var(--text); border-color: var(--border-hover); }
.modal-btn-danger {
  flex: 1; font-family: inherit; font-size: 13px; font-weight: 600;
  color: #fff; background: var(--red); border: none;
  padding: 10px; border-radius: 8px; cursor: pointer; transition: background 0.15s;
}
.modal-btn-danger:hover { background: #dc2626; }

/* ═══ Skeleton ═══ */
.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.02) 25%, rgba(255,255,255,0.05) 50%, rgba(255,255,255,0.02) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
/* SVG line chart draw-in */
@keyframes draw-line {
  from { stroke-dashoffset: 2000; }
  to { stroke-dashoffset: 0; }
}
@keyframes dot-pop {
  from { r: 0; opacity: 0; }
  to { r: 3.5; opacity: 1; }
}

/* ═══ Responsive ═══ */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .columns { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar {
    display: none;
    position: fixed; top: 52px; left: 0; right: 0; bottom: 0;
    width: 100%; z-index: 200;
    background: var(--bg); border-right: none;
    padding: 16px 12px;
  }
  .sidebar.open { display: flex; }
  .topbar-mobile-btn { display: block; }
  .topbar-right { gap: 10px; }
  .topbar-link { display: none; }
  .topbar-settings { display: none; }
  .topbar-brand { width: auto; border-right: none; padding: 0 12px; }
  .topbar-brand svg { display: none; }
  .main { margin-left: 0; padding: 64px 16px 32px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .page-actions { width: 100%; overflow-x: auto; }
  .chart-container { overflow-x: auto; }
  .columns { grid-template-columns: 1fr; }
  .plan-grid { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .topbar-brand svg { display: none; }
}
