@import url('https://fonts.googleapis.com/css2?family=Zen+Kaku+Gothic+New:wght@400;500;700&family=Space+Grotesk:wght@500;700&display=swap');

:root {
  --bg: #0E1016; --bar: #12151C; --card: #161921; --card2: #1A1E29;
  --line: #252A35; --line2: #222631; --line3: #353B48;
  --text: #E8EAF0; --sub: #C2C7D3; --muted: #A3A9B8; --faint: #7F8698;
  --accent: #F5C451; --blue: #6E9BFF; --blue-t: #8FB0FF;
  --up: #7FD9A8; --down: #FF9C8F;
  --num: 'Space Grotesk', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-family: 'Zen Kaku Gothic New', 'Hiragino Sans', sans-serif; font-size: 15px; line-height: 1.6; }
a { color: var(--blue-t); }
a:hover { color: #C3D3FF; }
button, input, select, textarea { font: inherit; }
.num { font-family: var(--num); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ヘッダー */
.topbar { border-bottom: 1px solid var(--line); background: var(--bar); }
.topbar-in { max-width: 1240px; margin: 0 auto; padding: 14px 24px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-family: var(--num); font-weight: 700; font-size: 20px; letter-spacing: .08em; }
.logo span { color: var(--accent); }
.pill { font-size: 12px; color: var(--muted); border: 1px solid var(--line3); border-radius: 999px; padding: 2px 10px; }
.me { display: flex; align-items: center; gap: 12px; }
.me-text { text-align: right; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: #2A3040; object-fit: cover; }
.btn-ghost { font-size: 13px; color: var(--muted); background: transparent; border: 1px solid var(--line3); border-radius: 8px; padding: 10px 14px; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn { min-height: 44px; border: 0; border-radius: 10px; padding: 10px 18px; font-weight: 700; cursor: pointer; background: var(--accent); color: #15171C; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-danger { background: transparent; color: var(--down); border: 1px solid #5A3A3A; border-radius: 8px; padding: 8px 12px; cursor: pointer; min-height: 40px; }

/* レイアウト */
main.wrap { max-width: 1240px; margin: 0 auto; padding: 32px 24px 64px; display: flex; flex-direction: column; gap: 28px; }
.head-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
h1 { margin: 0; font-size: 28px; }
h2 { margin: 0; font-size: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.card-hi { background: var(--card2); border: 1px solid #2F3646; border-radius: 16px; padding: 20px 24px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }
.sec-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 16px; }

/* 期間切替 */
.seg { display: flex; gap: 4px; background: #181B23; border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg button { min-height: 44px; min-width: 64px; border: 0; border-radius: 9px; font-weight: 700; cursor: pointer; background: transparent; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #15171C; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.kpi-label { font-size: 13px; color: var(--muted); }
.kpi-value { font-family: var(--num); font-size: 30px; font-weight: 700; margin-top: 4px; }
.kpi-unit { font-size: 14px; color: var(--muted); margin-left: 4px; font-family: inherit; }
.kpi-diff { font-size: 12px; margin-top: 6px; min-height: 18px; }
.up { color: var(--up); } .down { color: var(--down); }

/* 気づき */
.insight-title { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 10px; }
.insights { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; color: #D4D8E2; }

/* グラフ */
.chart-scroll { overflow-x: auto; }
.chart { display: flex; align-items: flex-end; gap: 8px; height: 220px; border-bottom: 1px solid var(--line3); }
.chart-col { flex: 1 1 0; min-width: 28px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.chart-v { font-family: var(--num); font-size: 11px; color: #D4D8E2; white-space: nowrap; }
.chart-bar { width: 100%; max-width: 64px; border-radius: 6px 6px 0 0; background: var(--accent); }
.chart-bar.zero { background: #2A2F3B; }
.chart-labels { display: flex; gap: 8px; margin-top: 8px; }
.chart-labels div { flex: 1 1 0; min-width: 28px; text-align: center; font-size: 11px; color: var(--muted); white-space: nowrap; }

/* 視聴者リスト */
.vlist { display: flex; flex-direction: column; max-height: 560px; overflow-y: auto; }
.vrow { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line2); }
.vrank { width: 28px; font-family: var(--num); color: var(--muted); }
.vmain { flex: 1 1 auto; min-width: 0; }
.vname { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vgift { width: 84px; text-align: right; font-family: var(--num); font-weight: 700; color: var(--accent); }
.tag { font-size: 11px; border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.tag-常連 { background: #3A3220; color: #F5D78A; }
.tag-リピーター { background: #24304A; color: #A9C2FF; }
.tag-新規 { background: #23362E; color: #9BE3BD; }
.memo-btn { background: transparent; border: 1px solid var(--line3); color: var(--muted); border-radius: 8px; min-width: 44px; min-height: 36px; cursor: pointer; font-size: 12px; }
.memo-btn.has { color: var(--accent); border-color: #5A4A20; }
.memo-box { display: flex; gap: 8px; padding: 0 0 10px 40px; }
.memo-box textarea { flex: 1; min-height: 60px; background: var(--bar); color: var(--text); border: 1px solid var(--line3); border-radius: 8px; padding: 8px; resize: vertical; }

/* 内訳 */
.stack { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--line2); }
.stack div:nth-child(1) { background: var(--blue); }
.stack div:nth-child(2) { background: var(--accent); }
.stack div:nth-child(3) { background: #4A5266; }
.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; font-size: 13px; }
.trio-v { font-family: var(--num); font-size: 22px; font-weight: 700; }

/* 表 */
.table-scroll { overflow-x: auto; }
table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 14px; }
th { padding: 10px 8px; font-weight: 500; color: var(--muted); text-align: left; border-bottom: 1px solid #2A2F3B; }
td { padding: 12px 8px; border-bottom: 1px solid var(--line2); }
.r { text-align: right; }
td.num.dia { color: var(--accent); }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* ログイン */
.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 48px 16px; }
.login-card { width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 40px 32px; display: flex; flex-direction: column; gap: 24px; text-align: center; }
.login-card .logo { font-size: 28px; }
.tiktok-btn { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; border-radius: 12px; background: #F2F3F6; color: #111318; font-weight: 700; font-size: 16px; text-decoration: none; }
.tiktok-btn:hover { background: #fff; color: #111318; }
.notice { font-size: 12px; color: var(--muted); line-height: 1.7; text-align: left; background: var(--bar); border-radius: 10px; padding: 12px 14px; }
.error { background: #3A2226; color: #FFC2BA; border-radius: 10px; padding: 12px 14px; font-size: 14px; text-align: left; }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field input, .field select { min-height: 44px; background: var(--bar); color: var(--text); border: 1px solid var(--line3); border-radius: 10px; padding: 8px 12px; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.form-row .field { flex: 1 1 200px; }

/* 管理画面 */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #4A5266; margin-right: 6px; }
.status-dot.live { background: #FF5C5C; }
.logs { font-size: 12px; color: var(--muted); max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; font-family: ui-monospace, monospace; }
.logs .error { padding: 2px 6px; }
.admin-banner { background: #24304A; color: #C9D7FF; text-align: center; font-size: 13px; padding: 8px; }

/* 文書ページ */
.doc { max-width: 760px; margin: 0 auto; padding: 48px 24px 80px; }
.doc h1 { font-size: 24px; margin-bottom: 24px; }
.doc h2 { font-size: 17px; margin: 28px 0 8px; }
.doc p, .doc li { color: var(--sub); }

@media (max-width: 600px) {
  main.wrap { padding: 24px 16px 48px; }
  .topbar-in { padding: 12px 16px; }
  .card { padding: 18px; }
  .me-text { display: none; }
  h1 { font-size: 22px; }
}
