:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --border: #e1e6ec;
  --text: #1a2332;
  --text-muted: #5a6878;
  --accent: #2d6cdf;
  --accent-light: #e7f0ff;
  --success: #2e7d32;
  --success-bg: #e8f5e9;
  --warning: #b06000;
  --warning-bg: #fff4e0;
  --danger: #c62828;
  --danger-bg: #ffebee;
  --info: #2d6cdf;
  --info-bg: #e7f0ff;
  --neutral: #6b7280;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.08);
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
}

/* Top Navigation */
.top-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}
.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  padding: 0 20px;
}
.nav-link {
  padding: 16px 20px;
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}
.nav-link:hover { color: var(--text); }
.nav-link.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 80px; }

header.page-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 24px;
  margin-top: 12px;
}
header.page-head h1 {
  font-size: 24px;
  margin: 0 0 4px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
header.page-head .subtitle {
  color: var(--text-muted);
  font-size: 14px;
}

/* Currency Switcher */
.currency-switcher {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cur-btn-group {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
}
.cur-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 9px;
  font-family: inherit;
  transition: background 0.15s, box-shadow 0.15s;
  min-width: 56px;
}
.cur-btn:hover:not(.active) { background: rgba(0,0,0,0.04); }
.cur-btn.active { background: var(--surface); box-shadow: var(--shadow); }
.cur-symbol {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1;
  transition: color 0.15s;
}
.cur-code {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  transition: color 0.15s;
}
.cur-btn.active .cur-symbol,
.cur-btn.active .cur-code { color: var(--accent); }
.fx-info {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 18px;
  font-size: 12px;
  padding: 0 2px;
}
.fx-rate { color: var(--text-muted); font-size: 12px; }
.fx-edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  padding: 2px 5px;
  border-radius: 4px;
}
.fx-reset-btn {
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: inherit;
}
.fx-reset-btn:hover { color: var(--accent); border-color: var(--accent); }
.fx-edit-panel { display: flex; align-items: center; gap: 4px; }
.fx-edit-panel input {
  width: 60px;
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
}
.fx-panel-btn { background: none; border: none; cursor: pointer; padding: 2px 4px; }
.fx-panel-btn.save { color: var(--success); }
.fx-panel-btn.cancel { color: var(--danger); }
.fx-manual-tag {
  font-size: 10px;
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid #f0c97a;
  border-radius: 3px;
  padding: 0 4px;
}

/* Cards & Grid */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.field input, .field select {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
  color: var(--text);
  outline: none;
  font-family: inherit;
}
.field input:focus { border-color: var(--accent); }
.field .hint { font-size: 11px; color: var(--text-muted); }

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius);
  margin: 24px 0 16px;
  border: 1px solid var(--border);
}
.tab {
  flex: 1;
  padding: 10px 14px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 7px;
  font-family: inherit;
}
.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* Summary Grid (4 items) */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.summary .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.summary .value { font-size: 22px; font-weight: 600; }
.summary .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.summary.accent { background: var(--accent-light); border-color: #c5dafd; }
.summary.accent .value { color: var(--accent); }

/* Disclaimer */
.disclaimer {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--warning-bg);
  border: 1px solid #f0c97a;
  border-left: 4px solid var(--warning);
  color: var(--warning);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 14px;
}
.disclaimer.settings-warn {
  background: var(--accent-light);
  border-color: #c5dafd;
  border-left-color: var(--accent);
  color: var(--accent);
}
.disclaimer-icon {
  flex-shrink: 0;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--warning);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold;
}
.disclaimer.settings-warn .disclaimer-icon { background: var(--accent); }

/* Tables */
table.breakdown, table.compare {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table th, table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
table.breakdown tr.section td { font-weight: 600; background: var(--surface-2); }
table.breakdown tr.total td { font-weight: 600; background: var(--surface-2); border-top: 2px solid var(--text); }
table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

table.compare th, table.compare td { text-align: right; }
table.compare th:first-child, table.compare td:first-child { text-align: left; background: var(--surface-2); font-weight: 500; }
table.compare th:not(:first-child) { text-transform: uppercase; font-size: 12px; letter-spacing: 0.05em; font-weight: 600; }
.col-best { background: var(--success-bg) !important; }
.col-disabled { color: var(--text-muted) !important; background: var(--surface-2) !important; }
.delta.bad { color: var(--danger); font-size: 11px; }

.compare-legend { display: flex; gap: 20px; margin-top: 14px; font-size: 12px; color: var(--text-muted); }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--border); flex-shrink: 0; }
.legend-swatch.best { background: var(--success-bg); border-color: #a5d6a7; }
.legend-swatch.disabled { background: var(--surface-2); }

/* Radio buttons */
.radio-group { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 8px; border: 1px solid var(--border); }
.radio-btn {
  flex: 1; padding: 7px 6px; border: none; background: transparent; cursor: pointer; border-radius: 6px;
  display: flex; flex-direction: column; align-items: center;
}
.radio-btn.active { background: var(--surface); box-shadow: var(--shadow); }
.radio-btn .r-pct { font-weight: 600; font-size: 14px; }
.radio-btn .r-desc { font-size: 10px; color: var(--text-muted); text-transform: uppercase; }

/* Info & Tooltip */
.info-icon {
  display: inline-flex; width: 15px; height: 15px; border-radius: 50%;
  background: var(--surface-2); color: var(--text-muted); font-size: 10px;
  align-items: center; justify-content: center; margin-left: 6px;
  cursor: help; border: 1px solid var(--border);
}
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(-10px);
  background: #222; color: #fff; padding: 8px 12px; border-radius: 6px;
  font-size: 12px; width: 200px; text-align: center; visibility: hidden; opacity: 0; transition: 0.2s;
  z-index: 100;
}
[data-tip]:hover::after { visibility: visible; opacity: 1; transform: translateX(-50%) translateY(-5px); }

/* Settings Layout */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 32px; }
.settings-group h3 { font-size: 14px; border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 20px; }

.settings-field {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.settings-field:last-child { border-bottom: none; }
.sf-meta { flex: 1; min-width: 0; }
.sf-name { font-size: 14px; font-weight: 500; color: var(--text); margin-bottom: 3px; }
.sf-desc { font-size: 12px; color: var(--text-muted); line-height: 1.4; }
.sf-default { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.sf-default code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 3px; padding: 0 4px; font-family: ui-monospace, monospace; font-size: 10px; }
.sf-input-wrap { flex-shrink: 0; }
.input-group {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.input-group input {
  width: 90px;
  padding: 9px 10px;
  border: none;
  background: transparent;
  font-size: 14px;
  color: var(--text);
  outline: none;
  font-family: inherit;
  text-align: right;
}
.input-group input:focus { outline: none; }
.input-group:focus-within { border-color: var(--accent); }
.input-addon {
  padding: 9px 10px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 13px;
  border-left: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

.text-link { background: none; border: none; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 0; font: inherit; }
.btn-secondary { padding: 6px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-family: inherit; }

@media (max-width: 720px) {
  header.page-head { flex-direction: column; align-items: flex-start; }
  .currency-switcher { width: 100%; }
  .container { padding: 16px 12px 60px; }
  .card { padding: 16px; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .compare-legend { flex-wrap: wrap; gap: 10px; }
  .field input, .field select { min-height: 44px; }
  .tab { min-height: 44px; }
}

@media (max-width: 480px) {
  header.page-head h1 { font-size: 20px; }
  header.page-head .subtitle { font-size: 13px; }

  .summary { padding: 12px; }
  .summary .value { font-size: 18px; }

  /* Tabs scroll horizontally on narrow screens */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex: 0 0 auto; }

  table th, table td { padding: 8px 6px; font-size: 13px; }

  /* Compare table scrolls; first column stays pinned */
  table.compare { min-width: 500px; }
  table.compare th:first-child,
  table.compare td:first-child { position: sticky; left: 0; z-index: 1; }

  .radio-btn { padding: 6px 3px; }
  .radio-btn .r-pct { font-size: 13px; }
  .radio-btn .r-desc { font-size: 9px; }

  .disclaimer { font-size: 13px; padding: 10px 12px; }

  /* Keep tooltip on-screen at narrow widths */
  [data-tip]::after { max-width: 160px; left: 0; transform: translateY(-10px); }
  [data-tip]:hover::after { transform: translateY(-5px); }
}
