:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --accent: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, #2481cc));
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --separator: var(--tg-theme-section-separator-color, rgba(0, 0, 0, 0.08));
  --destructive: var(--tg-theme-destructive-text-color, #e53935);
  --best: #2e9e4f;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.screen { padding: 12px 16px 24px; }
[hidden] { display: none !important; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
}

.settings { margin-bottom: 20px; }

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 13px 16px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.row + .row { border-top: 0.5px solid var(--separator); }
.row:active { opacity: 0.6; }
.row-label { flex: 1; }
.row-value { color: var(--hint); max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chevron { color: var(--hint); font-size: 20px; line-height: 1; }

.rates-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin: 0 4px 10px;
}
h1 { margin: 0; font-size: 20px; font-weight: 600; }
.hint { margin: 2px 0 0; color: var(--hint); font-size: 13px; }

.icon-btn {
  border: 0;
  background: var(--card);
  color: var(--accent);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
}
.icon-btn.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.segmented {
  display: flex;
  padding: 2px;
  margin-bottom: 12px;
  border-radius: 9px;
  background: var(--separator);
}
.segmented button {
  flex: 1;
  padding: 7px 0;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.segmented button.active { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.rates-header, .rate {
  display: grid;
  grid-template-columns: 1fr 76px 76px;
  gap: 8px;
  align-items: center;
  padding: 10px 16px;
}
.rates-header { color: var(--hint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
.rates-header > span:not(:first-child), .rate > span:not(:first-child) { text-align: right; }

.rates, .list { list-style: none; margin: 0; padding: 0; }
.rate { border-top: 0.5px solid var(--separator); }
.rate .bank { min-width: 0; }
.rate .bank-name, .rate .bank-sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rate .bank-sub { color: var(--hint); font-size: 12px; }
.rate.clickable { cursor: pointer; }
.rate.clickable:active { opacity: 0.6; }
.rate .num { font-variant-numeric: tabular-nums; }
.rate .num.sorted { font-weight: 600; }
.rate .num.best { color: var(--best); }
.rate .num.empty { color: var(--hint); }

.offices { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.office { padding: 12px 16px; }
.office-name { font-weight: 600; }
.office-metro { color: var(--hint); font-size: 13px; margin-top: 2px; }
.office-rates { display: flex; gap: 24px; margin-top: 10px; }
.office-rates div { display: flex; flex-direction: column; }
.office-rates .lbl { color: var(--hint); font-size: 12px; }
.office-rates .num { font-size: 17px; font-variant-numeric: tabular-nums; }
.office-rates .num.sorted { font-weight: 600; }
.office-rates .num.best { color: var(--best); }
.office-rates .num.empty { color: var(--hint); }
.office-hours { margin-top: 10px; font-size: 13px; }
.office-commission { margin-top: 8px; font-size: 13px; }
.office-commission summary { color: var(--accent); cursor: pointer; }
.office-commission p { margin: 6px 0 0; color: var(--hint); white-space: pre-line; }
.office-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 10px; }
.office-actions button {
  padding: 7px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--button);
  color: var(--button-text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.office-actions a { color: var(--accent); text-decoration: none; font-size: 14px; }
.office-updated { margin-top: 8px; color: var(--hint); font-size: 12px; }

.search {
  width: 100%;
  margin-bottom: 12px;
  padding: 10px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  outline: none;
  -webkit-appearance: none;
}
.search::placeholder { color: var(--hint); }

.list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
}
.list li + li { border-top: 0.5px solid var(--separator); }
.list li:active { opacity: 0.6; }
.list .main { flex: 1; min-width: 0; }
.list .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { color: var(--hint); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .code { font-weight: 600; width: 44px; flex-shrink: 0; }
.list .check { color: var(--accent); font-size: 18px; }

.state { margin: 24px 16px; text-align: center; color: var(--hint); }
.state.error { color: var(--destructive); }
.state.retry { cursor: pointer; }
.state:empty { display: none; }

.section-title {
  margin: 4px 4px 10px;
  color: var(--hint);
  font-size: 13px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.alert-current { padding: 14px 16px; margin-bottom: 20px; }
.alert-status { font-size: 13px; color: var(--accent); }
.alert-status.reached { color: var(--best); }
.alert-title { margin: 4px 0 2px; font-size: 17px; font-weight: 600; }

.link-btn {
  margin-top: 10px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}
.link-btn.danger { color: var(--destructive); }

.form .field {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 16px;
  min-height: 46px;
}
.form .field + .field { border-top: 0.5px solid var(--separator); }
.form .field span { flex-shrink: 0; }
.form select, .form input {
  flex: 1;
  min-width: 0;
  padding: 8px 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: right;
  text-align-last: right;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.form input { font-variant-numeric: tabular-nums; }
.form input::placeholder { color: var(--hint); }

.form-hint { margin: 8px 4px 0; }

.primary-btn {
  width: 100%;
  margin-top: 16px;
  padding: 13px;
  border: 0;
  border-radius: 10px;
  background: var(--button);
  color: var(--button-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:disabled { opacity: 0.5; cursor: default; }
