:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #6b7684;
  --line: #e3e7ec;
  --accent: #2f6df6;
  --danger: #d1435b;
  --ok: #1f9d63;
  --radius: 12px;
  --pad: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --card: #1a2029;
    --ink: #e8ecf1;
    --muted: #97a1ad;
    --line: #2a323d;
    --accent: #5b8bff;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px var(--pad);
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink); }
.topbar nav { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.topbar .who { color: var(--muted); max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.topbar button.who { background: none; border: none; padding: 0; font: inherit; cursor: pointer; }
.topbar .who:hover { color: var(--ink); text-decoration: underline; }

main { max-width: 860px; margin: 0 auto; padding: var(--pad); }

h1 { font-size: 22px; margin: 8px 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }

.muted { color: var(--muted); font-weight: 400; }
.error { background: rgba(209,67,91,.12); color: var(--danger); padding: 10px 12px; border-radius: 10px; }
.notice { background: rgba(31,157,99,.14); color: var(--ok); padding: 10px 12px; border-radius: 10px; }

/* Cards */
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .cards { grid-template-columns: 1fr 1fr; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.card a { display: flex; flex-direction: column; gap: 4px; padding: 16px; text-decoration: none; color: var(--ink); }
.card-title { font-weight: 600; }
.card-sub { color: var(--muted); font-size: 14px; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--pad); margin-top: 16px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.back { text-decoration: none; color: var(--muted); font-size: 14px; }
.head-actions { display: flex; align-items: center; gap: 12px; }
.btn-add { width: auto; padding: 9px 14px; font-size: 14px; }
.icon-btn { width: auto; background: var(--card); border: 1px solid var(--line); color: var(--ink); padding: 9px 12px; font-size: 15px; line-height: 1; border-radius: 10px; }
.icon-btn:hover { border-color: var(--accent); }
.sym-link { color: var(--accent); text-decoration: none; font-weight: 600; }
.sym-link:hover { text-decoration: underline; }

/* Summary stats */
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
@media (min-width: 560px) { .summary { grid-template-columns: repeat(3, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.stat-value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Forms */
form label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
input, select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  font-size: 16px; /* keeps iOS from zooming on focus */
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }
input[readonly] { opacity: .65; cursor: not-allowed; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: 1fr 1fr 1fr; } }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
}
button.primary { background: var(--accent); color: #fff; font-weight: 600; width: 100%; }
button.link { background: none; padding: 4px 6px; color: var(--muted); }
button.danger { color: var(--danger); }
form.inline { display: inline; margin: 0; }

/* Bulk selection */
.bulk-toolbar { display: flex; justify-content: flex-end; align-items: center; min-height: 34px; margin-bottom: 8px; }
th.chk, td.chk { width: 1%; text-align: center; padding-left: 6px; padding-right: 6px; }
th.chk input[type="checkbox"], td.chk input[type="checkbox"] { width: auto; margin: 0; display: inline-block; }
button.btn-danger-sm { width: auto; background: transparent; border: 1px solid var(--danger); color: var(--danger); font-weight: 600; padding: 7px 12px; font-size: 13px; }
button.btn-danger-sm:disabled { opacity: .5; cursor: not-allowed; border-color: var(--line); color: var(--muted); }
button.btn-danger-sm:not(:disabled):hover { background: rgba(209, 67, 91, .08); }

.icon { display: block; }
.row-actions .link { display: inline-flex; align-items: center; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; }
.row-actions { display: flex; gap: 10px; align-items: center; justify-content: flex-end; }
.row-actions form { display: inline; margin: 0; }
.row-actions a.link { color: var(--accent); text-decoration: none; padding: 4px 6px; }

.actions { display: flex; gap: 12px; align-items: center; margin-top: 8px; }
.btn-secondary { text-decoration: none; color: var(--muted); padding: 11px 16px; }

.field-hint { margin: -6px 0 16px; font-size: 13px; }
.modal-subhead { font-size: 15px; margin: 0 0 6px; }
.import-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 12px; }
.import-form input[type="file"] { flex: 1; min-width: 180px; }
.import-form button { width: auto; }
.modal-sep { border: none; border-top: 1px solid var(--line); margin: 20px 0 16px; }
button.btn-danger { width: 100%; background: transparent; border: 1px solid var(--danger); color: var(--danger); font-weight: 600; }
button.btn-danger:hover { background: rgba(209, 67, 91, .08); }

.row-form { display: grid; grid-template-columns: 1fr; gap: 0; }
@media (min-width: 560px) { .row-form { grid-template-columns: 2fr 1fr auto; gap: 12px; align-items: end; } .row-form button { width: auto; } }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.sym { font-weight: 600; }

.auth-card { max-width: 380px; margin: 8vh auto 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.auth-card button { margin-top: 8px; }

.price-note { font-size: 13px; margin: 10px 2px 0; }
.price-note a { color: var(--accent); text-decoration: none; }
.price-note .warn { color: var(--danger); }
.ccy { color: var(--muted); font-size: 11px; }

/* Modal */
[hidden] { display: none !important; }
body.modal-open { overflow: hidden; }
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
@media (min-width: 560px) {
  .modal-overlay { align-items: center; padding: 16px; }
}
.modal {
  background: var(--card);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .3);
}
@media (min-width: 560px) {
  .modal { border-radius: 16px; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h2 { margin: 0; }
.modal-close { background: none; border: none; font-size: 18px; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.check { display: flex; flex-direction: row; align-items: center; gap: 8px; color: var(--ink); margin-bottom: 12px; }
.check input[type="checkbox"] { width: auto; margin: 0; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 16px max(24px, env(safe-area-inset-bottom)); }
