*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #f4f5f7;
  --surface:  #ffffff;
  --border:   #dde1e7;
  --text:     #1a1d23;
  --muted:    #6b7280;
  --accent:   #1d4ed8;
  --acc-h:    #1e40af;
  --pos:      #15803d;
  --neg:      #b91c1c;
  --warn:     #92400e;
  --warn-bg:  #fef3c7;
  --r:        8px;
  --shadow:   0 1px 3px rgba(0,0,0,.07);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}

/* ── Auth ─────────────────────────────────────────────────── */

body.auth-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
}
.auth-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow);
  padding: 2rem; width: 100%; max-width: 360px;
}
.auth-card h1 { font-size: 1.35rem; font-weight: 700; margin-bottom: 1.5rem; }

/* ── Layout ───────────────────────────────────────────────── */

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .6rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10; gap: 1rem;
}
.header-right { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.account-info { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }

main {
  max-width: 760px; margin: 1.25rem auto;
  padding: 0 1rem; display: flex; flex-direction: column; gap: 1rem;
}

/* ── Cards ────────────────────────────────────────────────── */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 1.25rem 1.5rem; box-shadow: var(--shadow);
}
.card h2 {
  font-size: .75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); margin-bottom: 1rem;
}

.balance-card {
  background: var(--accent); color: #fff;
  border-radius: var(--r); padding: 1.4rem 1.5rem; box-shadow: var(--shadow);
}
.balance-label  { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; opacity: .8; margin-bottom: .2rem; }
.balance-amount { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* ── Forms ────────────────────────────────────────────────── */

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.form-row { display: flex; flex-direction: column; }
.span2    { grid-column: 1 / -1; }
.form-actions { align-self: end; }

label { font-size: .8rem; font-weight: 500; color: var(--muted); margin-bottom: .2rem; }
.opt  { font-weight: 400; font-size: .75rem; }

input, select {
  width: 100%; padding: .45rem .7rem;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: .95rem; background: var(--surface); color: var(--text);
  transition: border-color .12s;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

/* ── Buttons ──────────────────────────────────────────────── */

button {
  border: none; border-radius: 6px; font-size: .9rem; font-weight: 500;
  cursor: pointer; transition: background .12s; padding: .5rem 1.1rem;
}
button[type=submit], button.btn-primary {
  background: var(--accent); color: #fff; width: 100%;
}
button[type=submit]:hover { background: var(--acc-h); }
button.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
}
button.btn-ghost:hover { background: var(--bg); }
button.btn-sm { font-size: .8rem; padding: .3rem .75rem; }
button:disabled { opacity: .55; cursor: not-allowed; }

/* ── Past payments chips ──────────────────────────────────── */

.past-row   { display: flex; align-items: center; gap: .6rem; margin-bottom: .9rem; flex-wrap: wrap; }
.past-label { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.chips      { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip {
  font-size: .78rem; padding: .25rem .65rem; border-radius: 99px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  cursor: pointer; transition: border-color .12s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ── Transactions ─────────────────────────────────────────── */

.tx-list { display: flex; flex-direction: column; }
.tx-item {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: .65rem 0; border-bottom: 1px solid var(--border); gap: 1rem;
}
.tx-item:last-child { border-bottom: none; }
.tx-meta  { flex: 1; min-width: 0; }
.tx-name  { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-detail{ font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-right { display: flex; flex-direction: column; align-items: flex-end; gap: .1rem; white-space: nowrap; }
.tx-date  { font-size: .78rem; color: var(--muted); }
.tx-amount{ font-weight: 600; font-size: .95rem; font-variant-numeric: tabular-nums; }
.tx-amount.pos { color: var(--pos); }
.tx-amount.neg { color: var(--neg); }

/* ── Utility ──────────────────────────────────────────────── */

.error   { color: var(--neg);  font-size: .85rem; margin-top: .4rem; }
.success { color: var(--pos);  font-size: .85rem; margin-top: .4rem; }
.muted-sm{ color: var(--muted); font-size: .8rem; }

.key-warning {
  font-size: .78rem; font-weight: 500;
  background: var(--warn-bg); color: var(--warn);
  padding: .2rem .6rem; border-radius: 4px;
}

/* ── Settings ─────────────────────────────────────────────── */

.settings-card { padding: 0; }

.settings-toggle {
  width: 100%; text-align: left; background: none; border: none;
  padding: 1rem 1.5rem; font-size: .85rem; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
  cursor: pointer; border-radius: var(--r);
}
.settings-toggle:hover { background: var(--bg); }

#settingsBody { padding: 0 1.5rem 1.25rem; display: flex; flex-direction: column; gap: 1.5rem; }

.settings-block h3 { font-size: .9rem; font-weight: 600; margin-bottom: .35rem; }
.settings-block .muted-sm { margin-bottom: .6rem; }

.inline-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.inline-row input { flex: 1; min-width: 120px; }
.inline-row button { white-space: nowrap; }

/* ── Rotate-key UI ────────────────────────────────────────── */

.btn-link {
  background: none; border: none; color: var(--accent);
  font-size: .85rem; cursor: pointer; padding: .4rem 0;
  text-decoration: underline; text-align: left;
}
.btn-link:hover { color: var(--acc-h); }

.rotate-intro { font-size: .88rem; color: var(--muted); margin-bottom: .75rem; }

.new-key-box  { display: flex; flex-direction: column; gap: .6rem; }
.new-key-label{ font-size: .85rem; font-weight: 500; color: var(--muted); }
.new-key-value{
  display: block; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: .6rem .8rem;
  font-family: monospace; font-size: .9rem; word-break: break-all;
  user-select: all;
}
.new-key-hint { font-size: .8rem; color: var(--muted); }

@media (max-width: 500px) {
  .form-grid { grid-template-columns: 1fr; }
  .span2     { grid-column: auto; }
  .balance-amount { font-size: 1.7rem; }
  header { padding: .5rem .75rem; }
}
