/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --bg2:       #161b22;
  --bg3:       #21262d;
  --border:    #30363d;
  --text:      #c9d1d9;
  --text-dim:  #8b949e;
  --green:     #3fb950;
  --red:       #f85149;
  --yellow:    #d29922;
  --blue:      #58a6ff;
  --purple:    #bc8cff;
  --cyan:      #39d0da;
  --radius:    6px;
  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI",
               "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
               "Helvetica Neue", Arial, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Nav ──────────────────────────────────────────────────────────────────── */
nav {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 48px;
  gap: 4px;
}

nav .brand {
  font-weight: 700;
  color: var(--cyan);
  margin-right: 24px;
  font-size: 15px;
  letter-spacing: 1px;
}

nav a {
  color: var(--text-dim);
  padding: 4px 12px;
  border-radius: var(--radius);
  font-size: 13px;
}

nav a:hover, nav a.active {
  color: var(--text);
  background: var(--bg3);
  text-decoration: none;
}

/* ── Main content ─────────────────────────────────────────────────────────── */
main {
  flex: 1;
  padding: 24px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

h1 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text);
}

h2 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-dim);
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  font-size: 12px;
  transition: background .15s, border-color .15s;
}

.btn:hover { background: var(--bg); border-color: var(--text-dim); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-blue   { border-color: var(--blue); color: var(--blue); }
.btn-blue:hover   { background: rgba(88,166,255,.1); }
.btn-green  { border-color: var(--green); color: var(--green); }
.btn-green:hover  { background: rgba(63,185,80,.1); }
.btn-red    { border-color: var(--red); color: var(--red); }
.btn-red:hover    { background: rgba(248,81,73,.1); }

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
  justify-content: center;
  padding: 10px 14px;
  font-size: 14px;
}

.btn-solid-green {
  background: rgba(63,185,80,.18);
  border-color: rgba(63,185,80,.7);
  color: var(--text);
}
.btn-solid-green:hover { background: rgba(63,185,80,.28); border-color: var(--green); }

.btn-solid-red {
  background: rgba(248,81,73,.16);
  border-color: rgba(248,81,73,.7);
  color: var(--text);
}
.btn-solid-red:hover { background: rgba(248,81,73,.26); border-color: var(--red); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg3);
  font-size: 12px;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }

label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

input, select {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
}

input:focus, select:focus { border-color: var(--blue); }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.muted-line {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 8px;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.table-wrap th,
.table-wrap td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table-wrap th {
  color: var(--text-dim);
  font-weight: 600;
}

.table-wrap tbody tr:hover {
  background: var(--bg3);
}

.empty-state {
  color: var(--text-dim);
  padding: 16px 0;
}

/* ── Stat tiles ───────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-tile {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-tile .label {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.stat-tile .value {
  font-size: 22px;
  font-weight: 700;
}

/* ── Colour helpers ───────────────────────────────────────────────────────── */
.green  { color: var(--green); }
.red    { color: var(--red); }
.yellow { color: var(--yellow); }
.blue   { color: var(--blue); }
.dim    { color: var(--text-dim); }

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.flex-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spacer   { flex: 1; }
.mt-16    { margin-top: 16px; }
.mb-16    { margin-bottom: 16px; }

/* ── Alert banner ─────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 12px;
}

.alert-success { background: rgba(63,185,80,.1); border: 1px solid var(--green); color: var(--green); }
.alert-error   { background: rgba(248,81,73,.1); border: 1px solid var(--red); color: var(--red); }

/* ── Mobile tweaks ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body {
    font-size: 14px;
  }

  nav {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 12px;
    gap: 4px;
  }

  nav .brand {
    margin-right: 8px;
    font-size: 14px;
  }

  /* Larger touch targets for nav links (min ~36px height) */
  nav a {
    font-size: 13px;
    padding: 8px 10px;
  }

  /* Push logout to its own row so it doesn't fight for space */
  nav .spacer {
    display: none;
  }

  nav form[action="/auth/logout"] {
    margin-left: auto !important;
  }

  main {
    padding: 12px;
  }

  .card {
    padding: 14px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .row-2, .row-3 {
    grid-template-columns: 1fr;
  }

  /* 2-column stat grid on phones; 3+ columns when room allows */
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Slightly smaller to avoid overflow on narrow tiles */
  .stat-tile .value {
    font-size: 18px;
  }

  /* Larger touch targets for small action buttons (min ~36px height) */
  .btn-sm {
    padding: 8px 12px;
    font-size: 13px;
  }

  /* Full-width manual buy/sell forms on mobile */
  .row-2 form,
  .row-2 form .form-group {
    width: 100%;
  }
}


.pagination { display:flex; align-items:center; gap:10px; margin-top:16px; justify-content:center; }
.pagination .page-info { font-size:0.9em; color:var(--muted,#888); }
.pagination .btn.disabled { opacity:.4; pointer-events:none; }
