:root {
  color-scheme: light;
  --bg: #f4f7f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #62717c;
  --line: #dce4e8;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #b42318;
  --danger-bg: #fee4e2;
  --success-bg: #dcfae6;
  --success: #067647;
  --shadow: 0 16px 40px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
}

.topbar {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 82px;
  padding: 0 28px;
}

.brand {
  align-items: center;
  color: var(--text);
  display: inline-flex;
  font-size: 1.05rem;
  font-weight: 800;
  gap: 8px;
  text-decoration: none;
}

.brand-logo {
  display: block;
  height: 64px;
  object-fit: contain;
  width: 64px;
}

.nav {
  align-items: center;
  display: flex;
  gap: 18px;
}

.nav a,
.link-button {
  color: var(--muted);
  font: inherit;
  font-weight: 650;
  text-decoration: none;
}

.nav form {
  margin: 0;
}

.link-button {
  background: none;
  border: 0;
  cursor: pointer;
  padding: 0;
}

.page {
  margin: 0 auto;
  max-width: 1180px;
  padding: 32px 24px;
}

.auth-shell {
  display: grid;
  min-height: calc(100vh - 64px);
  place-items: center;
}

.panel,
.chart-shell {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel,
.form-panel {
  display: grid;
  gap: 18px;
  max-width: 420px;
  padding: 28px;
  width: 100%;
}

h1 {
  font-size: clamp(1.75rem, 3vw, 2.5rem);
  letter-spacing: 0;
  line-height: 1.1;
  margin: 0;
}

.muted {
  color: var(--muted);
  margin: 8px 0 0;
}

label {
  color: var(--text);
  display: grid;
  font-size: 0.92rem;
  font-weight: 700;
  gap: 8px;
}

input {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  min-height: 42px;
  padding: 9px 11px;
}

input:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(15, 118, 110, 0.16);
}

button,
.button {
  align-items: center;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 750;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  text-decoration: none;
}

.primary {
  background: var(--primary);
  color: #ffffff;
}

.primary:hover {
  background: var(--primary-dark);
}

.secondary {
  background: #e7eef0;
  color: var(--text);
}

.danger {
  background: var(--danger-bg);
  color: var(--danger);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.flash-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}

.flash {
  border-radius: 6px;
  font-weight: 650;
  padding: 12px 14px;
}

.flash.error {
  background: var(--danger-bg);
  color: var(--danger);
}

.flash.success {
  background: var(--success-bg);
  color: var(--success);
}

.section-heading {
  align-items: end;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 20px;
}

.chart-area {
  display: grid;
  gap: 8px;
}

.chart-toolbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  min-height: 34px;
}

.pair-label,
.price-label,
.buy-inline-label,
.currency-label {
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
}

.market-stat {
  color: var(--success);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.buy-price-stat,
.stop-loss-stat {
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
}

.buy-stat {
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 750;
}

.buy-amount-input {
  border: 2px solid #2f3437;
  border-radius: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  height: 22px;
  min-height: 22px;
  padding: 0 4px;
  text-align: right;
  width: 78px;
}

.buy-amount-input::-webkit-outer-spin-button,
.buy-amount-input::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

.buy-amount-input[type="number"] {
  appearance: textfield;
}

.currency-label {
  margin-left: -5px;
}

.buy-inline-label {
  display: inline;
}

.market-stat.price-up {
  color: var(--success);
}

.market-stat.price-down {
  color: var(--danger);
}

.binance-status {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 750;
}

.binance-status.connected {
  color: var(--success);
}

.binance-status.disconnected {
  color: var(--muted);
}

.purchase-status {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 750;
}

.purchase-status.has-purchase {
  color: var(--success);
}

.purchase-status.no-purchase {
  color: var(--muted);
}

.purchase-status.error {
  color: var(--danger);
}

.balance-status {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 750;
}

.balance-status.ready {
  color: var(--text);
}

.balance-status.error {
  color: var(--danger);
}

.buy-form {
  align-items: center;
  display: flex;
  gap: 7px;
  justify-content: flex-start;
  margin: 0;
}

.buy-form input {
  min-height: 22px;
}

.buy-button {
  border-radius: 5px;
  font-size: 12px;
  font-weight: 800;
  min-height: 22px;
  min-width: 58px;
  padding: 1px 10px;
  white-space: nowrap;
}

.adjust-stop-button {
  background: var(--primary);
  color: #ffffff;
  font-size: 12px;
  min-height: 24px;
  padding: 3px 8px;
  white-space: nowrap;
}

.adjust-stop-button:hover {
  background: var(--primary-dark);
}

.order-status {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 750;
  min-height: 1.1rem;
}

.order-status.success {
  color: var(--success);
}

.order-status.error {
  color: var(--danger);
}

.status-banner {
  background: #eef6ff;
  border: 1px solid #b9dcff;
  border-radius: 6px;
  color: #184e77;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.15;
  margin-left: auto;
  max-width: 460px;
  padding: 5px 8px;
}

.status-banner.success {
  background: var(--success-bg);
  border-color: #abefc6;
  color: var(--success);
}

.status-banner.error {
  background: var(--danger-bg);
  border-color: #fecdca;
  color: var(--danger);
}

.price-row {
  align-items: center;
  display: flex;
  gap: 4px;
}

.copy-price {
  align-items: center;
  background: transparent;
  color: var(--text);
  height: 18px;
  min-height: 18px;
  padding: 0;
  width: 18px;
}

.copy-price svg {
  height: 14px;
  width: 14px;
}

.copy-price .copy-icon {
  fill: currentColor;
}

.copy-price .check-icon {
  display: none;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.5;
}

.copy-price.copied {
  background: var(--success-bg);
  color: var(--success);
}

.copy-price.copied .copy-icon {
  display: none;
}

.copy-price.copied .check-icon {
  display: block;
}

.copy-price.failed {
  background: var(--danger-bg);
  color: var(--danger);
}

.refresh-toggle {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 0.82rem;
  font-weight: 750;
  gap: 5px;
}

.refresh-toggle input {
  min-height: auto;
}

.chart-shell {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 0;
  box-shadow: 0 0 0 4px #eef2f3;
  min-height: 560px;
  padding: 10px;
  position: relative;
}

.chart {
  height: 520px;
  width: 100%;
}

.chart-error {
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  color: var(--danger);
  display: flex;
  font-weight: 750;
  inset: 18px;
  justify-content: center;
  padding: 24px;
  position: absolute;
  text-align: center;
}

.chart-meta {
  align-items: center;
  background: #f5f8f9;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  min-height: 20px;
  padding: 8px 10px;
}

.chart-footer {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.chart-footer p {
  color: var(--text);
  font-size: 1rem;
  margin: 0;
}

.table-panel {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.actions {
  text-align: right;
}

td.actions {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

td.actions form {
  margin: 0;
}

.form-panel {
  max-width: 560px;
}

.field-note {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.check-row {
  align-items: center;
  display: flex;
}

.check-row input {
  min-height: auto;
}

@media (max-width: 720px) {
  .topbar,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    gap: 12px;
    padding: 16px 20px;
  }

  .nav {
    flex-wrap: wrap;
  }

  .page {
    padding: 24px 16px;
  }

  .price-row {
    align-items: center;
    gap: 8px;
  }

  .chart-toolbar,
  .chart-meta {
    align-items: flex-start;
    gap: 10px;
  }

  .purchase-status,
  .balance-status {
    text-align: left;
  }

  .buy-form {
    align-items: stretch;
    justify-content: flex-start;
  }

  .chart-shell {
    min-height: 420px;
    padding: 12px;
  }

  .chart {
    height: 380px;
  }
}
