/* ============================================================
   VDX Frontend — Unified Stylesheet
   Dark theme: #1a1a2e bg, #16213e card, #0f3460 accent, #e94560 highlight
   ============================================================ */

/* --- Reset & Base ------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #1a1a2e;
  --bg-alt:     #0f0f23;
  --card:       #16213e;
  --card-hover: #1a2a4e;
  --accent:     #0f3460;
  --highlight:  #e94560;
  --text:       #e0e0e0;
  --text-muted: #8892a4;
  --text-dim:   #5a6478;
  --border:     #2a3a5c;
  --success:    #00d68f;
  --warning:    #ffaa00;
  --danger:     #e94560;
  --info:       #3dc2ec;
  --radius:     8px;
  --radius-lg:  12px;
  --shadow:     0 2px 12px rgba(0,0,0,.35);
  --font:       'Segoe UI', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --mono:       'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --transition: .2s ease;
}

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--info); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--highlight); }

/* --- Navigation -------------------------------------------- */
.navbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.navbar-brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--highlight);
  letter-spacing: .5px;
  white-space: nowrap;
}

.navbar-links {
  display: flex;
  gap: .25rem;
  list-style: none;
  overflow-x: auto;
}

.navbar-links a {
  display: block;
  padding: .5rem .85rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: .88rem;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}

.navbar-links a:hover,
.navbar-links a.active {
  background: var(--accent);
  color: #fff;
}

.navbar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
}

/* --- Layout ------------------------------------------------ */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
}

.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: #fff;
}

.page-subtitle {
  font-size: .95rem;
  color: var(--text-muted);
  margin-top: -.75rem;
  margin-bottom: 1.5rem;
}

/* --- Cards ------------------------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  transition: border-color var(--transition);
}

.card:hover { border-color: var(--accent); }

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .75rem;
}

.card-value {
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
}

.card-value .unit {
  font-size: .85rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: .25rem;
}

/* Summary card grid */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* --- Tables ------------------------------------------------ */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--card);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}

thead th {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: .7rem 1rem;
  text-align: left;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

tbody td {
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr { transition: background var(--transition); }
tbody tr:hover { background: rgba(15,52,96,.35); }
tbody tr.clickable { cursor: pointer; }

/* Numeric alignment */
.text-right { text-align: right; }
.text-center { text-align: center; }

/* Color helpers */
.text-up   { color: var(--highlight); }
.text-down { color: var(--success); }
.text-flat { color: var(--text-muted); }

/* --- Forms ------------------------------------------------- */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: .35rem;
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  padding: .55rem .85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .9rem;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition);
}

input:focus, select:focus {
  border-color: var(--info);
}

/* --- Buttons ----------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: .88rem;
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform .1s;
  color: #fff;
}

.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--accent);
}
.btn-primary:hover { background: #0d4a8f; }

.btn-danger {
  background: var(--highlight);
}
.btn-danger:hover { background: #c63050; }

.btn-sm {
  padding: .35rem .75rem;
  font-size: .8rem;
}

/* --- Search Bar -------------------------------------------- */
.search-bar {
  display: flex;
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.search-bar input {
  flex: 1;
  max-width: 400px;
}

/* --- Grid layouts ------------------------------------------ */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}

.grid-sidebar {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.25rem;
}

/* --- Chart container --------------------------------------- */
.chart-container {
  position: relative;
  width: 100%;
  padding: 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.chart-container canvas {
  width: 100% !important;
}

/* --- Loading skeleton -------------------------------------- */
.skeleton {
  background: linear-gradient(90deg, var(--card) 25%, var(--accent) 50%, var(--card) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius);
  min-height: 1em;
}

@keyframes skeleton-pulse {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 1rem;
  width: 60%;
  margin-bottom: .5rem;
}

.skeleton-card {
  height: 100px;
}

.skeleton-chart {
  height: 300px;
}

/* --- Spinner ----------------------------------------------- */
.spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--info);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: 3rem;
  color: var(--text-muted);
  font-size: .9rem;
}

/* --- Tags / Badges ----------------------------------------- */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.5;
}

.badge-accent  { background: var(--accent); color: #fff; }
.badge-danger  { background: rgba(233,69,96,.2); color: var(--highlight); }
.badge-success { background: rgba(0,214,143,.15); color: var(--success); }

/* --- Detail panel ------------------------------------------ */
.detail-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.detail-panel .detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.detail-panel .detail-header h3 {
  font-size: 1.2rem;
  color: #fff;
}

.detail-panel .close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  transition: color var(--transition);
}
.detail-panel .close-btn:hover { color: var(--highlight); }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}

.detail-item label {
  display: block;
  font-size: .75rem;
  color: var(--text-muted);
  margin-bottom: .15rem;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.detail-item .value {
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
}

/* --- BOM list ---------------------------------------------- */
.bom-list {
  list-style: none;
}

.bom-list li {
  display: flex;
  justify-content: space-between;
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
}

.bom-list li:last-child { border-bottom: none; }

/* --- Indicator list ---------------------------------------- */
.indicator-list {
  list-style: none;
  max-height: 70vh;
  overflow-y: auto;
}

.indicator-list li {
  padding: .6rem .85rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: .88rem;
  transition: background var(--transition);
}

.indicator-list li:hover,
.indicator-list li.active {
  background: var(--accent);
  color: #fff;
}

/* --- Commodity grid ---------------------------------------- */
.commodity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.commodity-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
}

.commodity-card:hover {
  border-color: var(--info);
  transform: translateY(-2px);
}

.commodity-card .name {
  font-weight: 600;
  color: #fff;
  font-size: 1rem;
  margin-bottom: .35rem;
}

.commodity-card .meta {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: .82rem;
}

.commodity-card .price {
  font-weight: 700;
  color: var(--info);
  font-size: 1.1rem;
  margin-top: .4rem;
}

/* --- Notice / Placeholder ---------------------------------- */
.notice {
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 3rem 2rem;
  text-align: center;
  color: var(--text-muted);
}

.notice h2 {
  font-size: 1.3rem;
  color: var(--text);
  margin-bottom: .5rem;
}

.notice p {
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.7;
}

/* --- Error ------------------------------------------------- */
.error-message {
  background: rgba(233,69,96,.1);
  border: 1px solid var(--highlight);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  color: var(--highlight);
  font-size: .88rem;
  margin-bottom: 1rem;
}

/* --- Empty state ------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 2.5rem;
  margin-bottom: .5rem;
  opacity: .5;
}

/* --- Simulation form --------------------------------------- */
.sim-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  align-items: end;
}

/* --- Quarter selector -------------------------------------- */
.quarter-selector {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.quarter-selector label {
  font-size: .9rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.quarter-selector select {
  width: auto;
  min-width: 180px;
}

/* --- Scrollbar --------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* --- Responsive -------------------------------------------- */
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-sidebar { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  html { font-size: 14px; }

  .navbar {
    flex-wrap: wrap;
    height: auto;
    padding: .5rem 1rem;
  }

  .navbar-toggle { display: block; }

  .navbar-links {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 0;
    padding: .5rem 0;
  }

  .navbar-links.open { display: flex; }

  .navbar-links a { padding: .6rem 0; }

  .container { padding: 1rem; }

  .summary-grid { grid-template-columns: 1fr 1fr; }

  .commodity-grid { grid-template-columns: 1fr; }

  .sim-form { grid-template-columns: 1fr; }
}

/* --- Fetch panel ------------------------------------------- */
.fetch-panel {
  margin-bottom: 1.25rem;
}

.fetch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .25rem;
}

.fetch-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
}

.fetch-btn {
  position: relative;
  min-width: 110px;
  padding: .6rem 1.3rem;
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: .3px;
  border: 1px solid transparent;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  transition: transform .15s, box-shadow .15s, filter .15s;
}
.fetch-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
  filter: brightness(1.15);
}
.fetch-btn:active {
  transform: translateY(0) scale(.97);
}

/* Per-source colors */
.fetch-btn[data-source="futures"] { background: linear-gradient(135deg, #e65c00, #f09819); }
.fetch-btn[data-source="sina"]    { background: linear-gradient(135deg, #1d976c, #2ecc71); }
.fetch-btn[data-source="price"]   { background: linear-gradient(135deg, #2980b9, #6dd5fa); }
.fetch-btn[data-source="customs"] { background: linear-gradient(135deg, #8e44ad, #c39bd3); }
.fetch-btn[data-source="stock"]   { background: linear-gradient(135deg, #c0392b, #e74c3c); }

/* Running state */
.fetch-btn.running {
  background: linear-gradient(135deg, #b8860b, #daa520) !important;
  color: #fff;
  pointer-events: none;
  animation: pulse-glow 1.5s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 2px 8px rgba(218,165,32,.3); }
  50%      { box-shadow: 0 2px 16px rgba(218,165,32,.6); }
}

/* Success state */
.fetch-btn.success {
  background: linear-gradient(135deg, #1d976c, #2ecc71) !important;
  color: #fff;
}

/* Failed state */
.fetch-btn.failed {
  background: linear-gradient(135deg, #c0392b, #e74c3c) !important;
  color: #fff;
}

.fetch-btn .spinner-inline {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin-right: .35rem;
  vertical-align: middle;
}

.fetch-status-area {
  margin-top: .75rem;
  font-size: .82rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  max-height: 200px;
  overflow-y: auto;
}

.fetch-status-area .status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .3rem 0;
  border-bottom: 1px solid var(--border);
}

.fetch-status-area .status-row:last-child {
  border-bottom: none;
}

.status-badge {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
}

.status-badge.running { background: rgba(255,170,0,.2); color: var(--warning); }
.status-badge.success { background: rgba(0,214,143,.15); color: var(--success); }
.status-badge.failed  { background: rgba(233,69,96,.2); color: var(--danger); }

/* --- Utility ----------------------------------------------- */
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.hidden { display: none !important; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
