:root {
  --bg:        #f8f5f0;
  --panel:     #ffffff;
  --line:      #e2d5c3;
  --gold:      #bf8127;
  --gold-dk:   #8b5a16;
  --text:      #1d160d;
  --muted:     #6f604e;
  --ok:        #1f7a3a;
  --danger:    #b3261e;
  --focus:     #1c64f2;
  --topbar-h:  60px;
  --tabbar-h:  42px;
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 2px solid var(--gold);
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}

.topbar-left { display: flex; align-items: baseline; gap: 10px; }

h1 { font-size: 18px; font-weight: 800; color: var(--gold-dk); white-space: nowrap; }

.store-select-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.store-select {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 600;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.store-select:focus { outline: 2px solid var(--focus); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.range-presets { display: flex; gap: 4px; }

.preset-btn {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 9px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.preset-btn[data-active] {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
}
.preset-btn:hover:not([data-active]) { background: #f1e8d8; }

.range-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
}

.range-inputs input[type="date"] {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}
.range-inputs input[type="date"]:focus { outline: 2px solid var(--focus); }

.range-inputs span { color: var(--muted); font-weight: 700; }

.btn-primary {
  border: none;
  border-radius: 7px;
  background: var(--gold);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  padding: 6px 14px;
  cursor: pointer;
}
.btn-primary:hover { background: var(--gold-dk); }

/* ── Tab bar ─────────────────────────────────────────────────────────────── */

.tabbar {
  display: flex;
  gap: 0;
  height: var(--tabbar-h);
  background: #f3eadb;
  border-bottom: 1px solid var(--line);
  padding: 0 16px;
  position: sticky;
  top: var(--topbar-h);
  z-index: 90;
}

.tab-btn {
  border: none;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  padding: 0 18px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.tab-btn.active {
  color: var(--gold-dk);
  border-bottom-color: var(--gold);
}
.tab-btn:hover:not(.active) { color: var(--text); }

/* ── Tab content ─────────────────────────────────────────────────────────── */

.tab-content { display: none; padding: 14px 16px; }
.tab-content.active { display: block; }

.tab-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.tab-title { font-size: 15px; font-weight: 800; color: var(--gold-dk); }
.tab-desc  { font-size: 12px; color: var(--muted); flex: 1; }

.btn-csv {
  border: 1px solid var(--gold);
  border-radius: 6px;
  background: #fff;
  color: var(--gold-dk);
  font-weight: 800;
  font-size: 12px;
  padding: 5px 11px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-csv:hover { background: var(--gold); color: #fff; }

.filter-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.filter-label input { width: 16px; height: 16px; accent-color: var(--gold); }

.group-btns { display: flex; gap: 3px; }
.group-btn {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 9px;
  cursor: pointer;
}
.group-btn.active { background: var(--gold); color: #fff; border-color: var(--gold); }

/* ── Table ───────────────────────────────────────────────────────────────── */

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - var(--topbar-h) - var(--tabbar-h) - 90px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(60,44,20,.06);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #f0e6d6;
  border-bottom: 2px solid var(--line);
  padding: 8px 10px;
  text-align: right;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold-dk);
}
thead th:first-child { text-align: left; }

tbody tr:nth-child(even) { background: #faf6f0; }
tbody tr:hover { background: #f5eddf; }

td {
  border-bottom: 1px solid #ede4d5;
  padding: 7px 10px;
  text-align: right;
  white-space: nowrap;
}
td:first-child { text-align: left; }

.col-date { min-width: 100px; text-align: left !important; }
.col-yen  { min-width: 90px; }
.col-n    { min-width: 60px; }

tfoot td {
  font-weight: 800;
  background: #f0e6d6;
  border-top: 2px solid var(--line);
  padding: 8px 10px;
  text-align: right;
  white-space: nowrap;
  position: sticky;
  bottom: 0;
}
tfoot td:first-child { text-align: left; }

.total-row td { background: #f0e6d6; font-weight: 800; }
.total-cell   { font-weight: 800; }

/* category separator row */
.cat-row td {
  background: #f7f0e6;
  padding: 6px 10px;
  color: var(--gold-dk);
  font-size: 12px;
  text-align: left !important;
  border-bottom: 1px solid var(--line);
}

.sponsor-cell { font-size: 11px; color: var(--muted); }

.badge.sponsor {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  background: #ffe0b2;
  color: #7a4500;
  font-size: 11px;
  font-weight: 700;
  margin-left: 6px;
}

.empty {
  text-align: center !important;
  color: var(--muted);
  padding: 32px 16px;
  font-size: 13px;
}

/* ── Status bar ──────────────────────────────────────────────────────────── */

.status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(255,255,255,.9);
  border-top: 1px solid var(--line);
  min-height: 28px;
}
.status-bar.ok    { color: var(--ok); }
.status-bar.error { color: var(--danger); }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 800px) {
  .topbar { flex-direction: column; height: auto; padding: 8px 12px; gap: 8px; }
  .topbar-right { justify-content: flex-start; }
  .tab-btn { padding: 0 10px; font-size: 13px; }
  .table-wrap { max-height: calc(100vh - 180px); }
}
