/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
  --primary:       #1e3a5f;
  --primary-hover: #2c5282;
  --accent:        #2b6cb0;
  --bg:            #f0f2f5;
  --card:          #ffffff;
  --border:        #e2e8f0;
  --text:          #1a202c;
  --muted:         #718096;
  --green:         #276749;
  --green-bg:      #f0fff4;
  --green-border:  #9ae6b4;
  --red:           #c53030;
  --red-bg:        #fff5f5;
  --red-border:    #feb2b2;
  --yellow:        #92400e;
  --yellow-bg:     #fffbeb;
  --yellow-border: #fcd34d;
  --shadow:        0 2px 10px rgba(0,0,0,0.07);
  --radius:        10px;
  --radius-sm:     6px;
  --font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:     'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
}

/* ── Reset & base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, button { font-family: inherit; font-size: inherit; }

/* ── Navigation ────────────────────────────────────────────────────────── */
nav {
  background: var(--primary);
  color: #fff;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.nav-brand {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #fff;
}
.nav-links { display: flex; gap: 4px; }
.nav-links a {
  color: rgba(255,255,255,0.8);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-links a:hover { background: rgba(255,255,255,0.12); color: #fff; text-decoration: none; }
.nav-links a.active { background: rgba(255,255,255,0.2); color: #fff; }

/* ── Refresh bar ───────────────────────────────────────────────────────── */
.refresh-wrapper {
  background: var(--primary-hover);
  height: 28px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  position: relative;
  overflow: hidden;
}
.refresh-wrapper::after {
  content: '';
  position: absolute;
  left: 0; bottom: 0;
  height: 2px;
  width: var(--progress, 100%);
  background: rgba(255,255,255,0.5);
  transition: width 1s linear;
}
.refresh-text {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
}
#countdown {
  font-weight: 700;
  color: #fff;
}

/* ── Container ─────────────────────────────────────────────────────────── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

/* ── Alerts ────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: 0.9rem;
  border-left: 4px solid;
}
.alert-warning  { background: var(--yellow-bg); border-color: #f59e0b; color: var(--yellow); }
.alert-success  { background: var(--green-bg);  border-color: #38a169; color: var(--green); }
.alert-error    { background: var(--red-bg);    border-color: #e53e3e; color: var(--red); }

/* ── Cards grid ────────────────────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  align-items: stretch;
  gap: 20px;
  margin-bottom: 24px;
}
@media (max-width: 800px) {
  .cards-grid { grid-template-columns: 1fr; }
}

/* ── Card ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafbfc;
}
.card-header h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}
.card-body { padding: 16px 20px; }

/* ── Stat rows ─────────────────────────────────────────────────────────── */
.stat-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.stat-row:last-child { border-bottom: none; }

/* ── Card section separator ────────────────────────────────────────────── */
.card-section-sep {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--primary);
  border-top: 1px solid var(--border);
  padding: 7px 0 3px;
  margin-top: 2px;
}
.stat-label {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.stat-value {
  font-size: 0.95rem;
  font-weight: 600;
  text-align: right;
  word-break: break-all;
}
.stat-value.small { font-size: 0.78rem; font-weight: 400; color: var(--muted); }

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.badge-active { background: var(--green-bg); color: var(--green); border-color: var(--green-border); }

.decision-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.4px;
}
.decision-buy  { background: var(--green-bg);  color: var(--green);  border: 1px solid var(--green-border); }
.decision-sell { background: var(--red-bg);    color: var(--red);    border: 1px solid var(--red-border); }
.decision-hold { background: #f7fafc;          color: var(--muted);  border: 1px solid var(--border); }

/* ── RSI badge ─────────────────────────────────────────────────────────── */
.rsi-badge {
  display: inline-block;
  font-size: 1.3rem;
  font-weight: 800;
  padding: 2px 14px;
  border-radius: var(--radius-sm);
  line-height: 1.8;
}
.rsi-low  { background: var(--red-bg);    color: var(--red);    border: 1px solid var(--red-border); }
.rsi-mid  { background: var(--yellow-bg); color: var(--yellow); border: 1px solid var(--yellow-border); }
.rsi-high { background: var(--green-bg);  color: var(--green);  border: 1px solid var(--green-border); }

/* ── Text utilities ────────────────────────────────────────────────────── */
.text-green  { color: var(--green) !important; }
.text-red    { color: var(--red)   !important; }
.text-blue   { color: var(--accent)!important; }
.text-muted  { color: var(--muted) !important; }
.text-center { text-align: center; }
.mono        { font-family: var(--font-mono); }
.small       { font-size: 0.82rem; }

/* ── Table section ─────────────────────────────────────────────────────── */
.table-section {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-section-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafbfc;
}
.table-section-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
thead th {
  background: #f7f8fa;
  padding: 10px 14px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fafb !important; }

.row-buy  { background: #f6fff9; }
.row-sell { background: #fff8f8; }
.row-hold { background: #fff; }

/* ── Pagination ────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px;
  flex-wrap: wrap;
}
.page-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.page-btn:hover:not(.disabled):not(.active) {
  background: var(--bg);
  border-color: var(--accent);
  color: var(--accent);
}
.page-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.page-btn.disabled { opacity: 0.35; cursor: default; }
.page-dots { color: var(--muted); padding: 0 4px; line-height: 34px; }

/* ── Config container ──────────────────────────────────────────────────── */
.config-container,
.container:has(.config-form) {
  max-width: 1280px;
  margin: 8px auto;
  padding: 0 12px 8px;
}

/* ── Config form ───────────────────────────────────────────────────────── */
.config-form { display: flex; flex-direction: column; gap: 4px; }

.fieldset {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.fieldset-legend {
  padding: 4px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--primary);
  background: #fafbfc;
}
.fields-grid {
  padding: 8px 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px 12px;
}
.fields-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) {
  .fields-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .fields-grid,
  .fields-grid.cols-2 { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 2px; }
.field label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text);
  font-family: var(--font-mono);
}
.field input[type=text],
.field input[type=number],
.field select {
  padding: 2px 6px;
  height: 24px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
  box-sizing: border-box;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(43,108,176,0.12);
}
.field .hint {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.2;
  margin-bottom: 0;
}

/* Checkbox field ── */
.field-check { display: flex; flex-direction: column; gap: 2px; }
.field-check label {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 0;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: var(--font-mono);
  cursor: pointer;
}
.field-check input[type=checkbox] {
  width: 13px; height: 13px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.field-check .hint {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.2;
  margin-bottom: 0;
  padding-left: 17px;
}

/* Form actions ── */
.form-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 4px;
}
.btn-save {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 9px 28px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.2px;
}
.btn-save:hover  { background: var(--primary-hover); }
.btn-save:active { transform: scale(0.98); }
