@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@500;600&family=Noto+Sans+SC:wght@400;500;600;700&display=swap");

:root {
  --bg: #f3f1ec;
  --ink: #171717;
  --muted: #6b6b6b;
  --line: #e4e0d8;
  --panel: #ffffff;
  --soft: #f7f5f1;
  --accent: #0e6b45;
  --accent-2: #0a5235;
  --price: #b42318;
  --shadow: 0 1px 0 rgba(23, 23, 23, 0.04), 0 12px 32px rgba(23, 23, 23, 0.06);
  --radius: 12px;
  --h: 38px;
  --font: "Noto Sans SC", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% -10%, #e7efe8 0%, transparent 55%),
    radial-gradient(700px 360px at 100% 0%, #efe6d8 0%, transparent 50%),
    var(--bg);
}

.hidden { display: none !important; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.btn {
  height: var(--h);
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  transition: 0.15s ease;
}
.btn-solid {
  background: var(--accent);
  color: #fff;
}
.btn-solid:hover { background: var(--accent-2); }
.btn-soft {
  background: var(--panel);
  border-color: var(--line);
  color: var(--ink);
}
.btn-soft:hover { background: var(--soft); }
.btn-soft:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Login */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  margin: 0;
  font-size: 1.35rem;
}
.login-card > p {
  margin: 6px 0 20px;
  color: var(--muted);
}
.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}
.field span {
  font-size: 0.8rem;
  color: var(--muted);
}
.field input {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  background: #fff;
  outline: none;
}
.field input:focus {
  border-color: #9bb9a8;
  box-shadow: 0 0 0 3px rgba(14, 107, 69, 0.12);
}
.err {
  min-height: 1.2em;
  margin: 0 0 10px;
  color: var(--price);
  font-size: 0.88rem;
}
#btn-login { width: 100%; }

/* App shell */
.app-view {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  padding: 16px 18px 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  background: rgba(255,255,255,0.78);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(228, 224, 216, 0.95);
  border-radius: 14px;
  padding: 10px;
  box-shadow: var(--shadow);
}

.topbar-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
}

.topbar-side {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.seg {
  display: inline-flex;
  align-items: center;
  height: var(--h);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.seg.pair { min-width: 280px; }
.seg-split {
  width: 1px;
  align-self: stretch;
  background: var(--line);
}
.seg-select {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  outline: none;
  background: transparent;
  height: 100%;
  padding: 0 32px 0 12px;
  min-width: 128px;
  font-size: 0.88rem;
  font-weight: 600;
  background-image:
    linear-gradient(45deg, transparent 50%, #7a7a7a 50%),
    linear-gradient(135deg, #7a7a7a 50%, transparent 50%);
  background-position:
    calc(100% - 14px) calc(50% - 1px),
    calc(100% - 9px) calc(50% - 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.seg.pair .seg-select {
  flex: 1;
  min-width: 0;
}
.seg-select.mono {
  font-family: var(--mono);
  letter-spacing: 0.02em;
  min-width: 148px;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--h);
  min-width: 220px;
  max-width: 360px;
  flex: 1 1 260px;
  padding: 0 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.search:focus-within {
  border-color: #9bb9a8;
  box-shadow: 0 0 0 3px rgba(14, 107, 69, 0.1);
}
.search-ico {
  width: 16px;
  height: 16px;
  color: #8a8a8a;
  flex: 0 0 auto;
}
.search input {
  border: 0;
  outline: none;
  width: 100%;
  background: transparent;
  font-size: 0.9rem;
}

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}
.meta span { color: var(--ink); font-weight: 700; }
.meta i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #c2c2c2;
  display: inline-block;
}
.account {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 8px;
  border-left: 1px solid var(--line);
  margin-left: 2px;
}
.account #who {
  font-size: 0.86rem;
  color: var(--muted);
}
.linkish {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.86rem;
  padding: 0;
}
.linkish:hover { color: var(--accent-2); }

.board {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: grid;
  grid-template-rows: 1fr auto;
}

.table-scroll {
  height: calc(100vh - 128px);
  min-height: 380px;
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
}
.data-table th,
.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid #eeebe5;
  text-align: left;
  white-space: nowrap;
}
.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #faf8f4;
  color: #737373;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: none;
  cursor: pointer;
  user-select: none;
}
.data-table th.num,
.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.data-table tbody tr {
  cursor: pointer;
  transition: background 0.12s ease;
}
.data-table tbody tr:hover { background: #f7faf7; }
.data-table tbody tr.active { background: #eaf4ee; }
.name-cell {
  max-width: 380px;
  white-space: normal;
  font-weight: 600;
  line-height: 1.35;
}
.tag {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef5f0;
  color: var(--accent-2);
  font-size: 0.76rem;
  font-weight: 600;
}
.price { color: var(--price); font-weight: 700; }
.muted { color: var(--muted); }
.empty {
  padding: 80px 24px;
  text-align: center;
  color: var(--muted);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: #faf8f4;
}
.pager-info {
  min-width: 110px;
  text-align: center;
  color: var(--muted);
  font-size: 0.84rem;
}

/* Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 20, 0.28);
  backdrop-filter: blur(2px);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.drawer-backdrop.open { opacity: 1; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(460px, 100vw);
  height: 100vh;
  background: #fff;
  z-index: 50;
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 40px rgba(0,0,0,0.12);
  transform: translateX(104%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: grid;
  grid-template-rows: auto 1fr;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}
.drawer-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}
.drawer-head h2 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.3;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 1.3rem;
  color: var(--muted);
}
.icon-btn:hover { background: var(--soft); color: var(--ink); }
.drawer-body {
  overflow: auto;
  padding: 16px 18px 28px;
}
.detail-sub {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
  word-break: break-all;
}
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.kpi {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.kpi .l { color: var(--muted); font-size: 0.74rem; font-weight: 600; }
.kpi .v { margin-top: 4px; font-size: 1.1rem; font-weight: 700; }
.chart-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
}
.chart-box h3 {
  margin: 0 0 8px;
  font-size: 0.88rem;
}
#priceChart {
  width: 100%;
  height: 280px;
  display: block;
}
.hist {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}
.hist th,
.hist td {
  text-align: left;
  padding: 9px 6px;
  border-bottom: 1px solid #eeebe5;
}
.hist th { color: var(--muted); font-weight: 700; }

@media (max-width: 980px) {
  .topbar-main, .topbar-side { width: 100%; }
  .search { max-width: none; }
  .seg.pair { min-width: 0; width: 100%; }
  .table-scroll { height: calc(100vh - 210px); }
  .kpi-grid { grid-template-columns: 1fr; }
  .account { border-left: 0; padding-left: 0; }
}
