/* Segment Builder Demo - Google Sheets風UI */
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #e3e6ee;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #1f9d72;
  --green-dark: #178060;
  --green-light: #e6f4ee;
  --bdash: #ea580c;
  --yappli: #2563eb;
  --code-bg: #0f172a;
  --code-fg: #e5e7eb;
  --selected-blue: #1a73e8;
  --gs-header-bg: #f8f9fa;
  --gs-header-fg: #5f6368;
  --gs-border: #c5c8ce;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Yu Gothic UI", Meiryo, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
}

/* ===== Topbar ===== */
.topbar {
  background: linear-gradient(135deg, #0f766e, #1f9d72);
  color: white;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { font-size: 30px; }
.brand-title { font-size: 17px; font-weight: 700; }
.brand-sub { font-size: 11.5px; opacity: .9; }
.topnav { display: flex; gap: 6px; flex-wrap: wrap; }
.topnav a {
  color: white; text-decoration: none; font-size: 12.5px;
  padding: 6px 12px; border-radius: 6px; transition: background .15s;
  white-space: nowrap;
}
.topnav a:hover { background: rgba(255,255,255,.18); }

/* ===== Layout ===== */
.container { max-width: 1280px; margin: 0 auto; padding: 24px; }

.hero {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  margin-bottom: 20px;
  text-align: center;
}
.hero h1 {
  margin: 0 0 24px;
  font-size: 22px;
  line-height: 1.5;
  color: #111827;
}
.flow {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}
.flow-step {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  min-width: 180px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
}
.flow-num {
  background: var(--green);
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.flow-label { font-size: 12.5px; color: var(--text); font-weight: 500; }
.flow-arrow { color: var(--green); font-weight: 700; }

/* ===== Card ===== */
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 20px;
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: #fafbfd;
}
.green-heading {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #111827;
  position: relative;
  padding-bottom: 6px;
}
.green-heading::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 60px;
  height: 2px;
  background: var(--green);
}
.badges { display: flex; gap: 6px; }
.badge {
  background: #eef2ff;
  color: #1e3a8a;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
}
.badge.ok { background: var(--green-light); color: var(--green-dark); }

/* ===== Google Sheets 風シート ===== */
.sheet-card { background: white; }
.sheet-area {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 20px;
  padding: 24px;
  align-items: start;
}
@media (max-width: 900px) { .sheet-area { grid-template-columns: 1fr; } }

.sheet-frame {
  border: 1px solid var(--gs-border);
  border-radius: 4px;
  overflow: hidden;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.gs-sheet {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.gs-sheet thead th {
  background: var(--gs-header-bg);
  color: var(--gs-header-fg);
  font-weight: 500;
  font-size: 11.5px;
  padding: 4px 0;
  border: 1px solid var(--gs-border);
  text-align: center;
  height: 22px;
}
.gs-sheet thead th.row-num { width: 36px; }
.gs-sheet thead th.col-letter { min-width: 180px; }
.gs-sheet thead th.actions-col { width: 36px; min-width: 36px; }

.gs-sheet td {
  border: 1px solid var(--gs-border);
  padding: 0;
  background: white;
  height: 30px;
}
.gs-sheet td.row-num {
  background: var(--gs-header-bg);
  color: var(--gs-header-fg);
  text-align: center;
  font-size: 11.5px;
  font-weight: 500;
  width: 36px;
}
.gs-sheet td.label-cell {
  font-weight: 700;
  padding: 0 8px;
  background: white;
  font-size: 13px;
}
.gs-sheet td.value-cell {
  padding: 0;
  background: white;
}
.gs-sheet td.value-cell input {
  width: 100%;
  border: none;
  outline: none;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13.5px;
  background: transparent;
}
.gs-sheet td.value-cell.selected {
  outline: 2px solid var(--selected-blue);
  outline-offset: -2px;
}
.gs-sheet td.value-cell input:focus {
  outline: 2px solid var(--selected-blue);
  outline-offset: -2px;
  background: white;
}
.gs-sheet td.actions-cell {
  text-align: center;
  background: var(--gs-header-bg);
}
.gs-sheet td.actions-cell button {
  border: none;
  background: transparent;
  color: #b91c1c;
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 4px;
}
.gs-sheet td.actions-cell button:hover { background: rgba(185,28,28,.1); }

/* ===== シート右側：操作パネル ===== */
.sheet-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.btn-generate {
  background: var(--green);
  color: white;
  border: none;
  padding: 14px 18px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(31,157,114,.35);
  transition: all .15s;
  font-family: inherit;
}
.btn-generate:hover {
  background: var(--green-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(31,157,114,.45);
}
.btn-generate:active { transform: translateY(0); }

.side-hint {
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.side-hint p { margin: 0 0 8px; }
.side-hint p:last-child { margin: 0; }
.side-hint code {
  background: #1f2937;
  color: #fbbf24;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  display: inline-block;
  margin-top: 2px;
}

/* ===== SQL 出力 ===== */
.sql-output {
  margin: 0;
  padding: 16px 20px;
  background: var(--code-bg);
  color: var(--code-fg);
  font-family: "JetBrains Mono", Consolas, Monaco, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  overflow-x: auto;
  max-height: 480px;
  white-space: pre-wrap;
  word-break: break-all;
}
.sql-actions {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: #fafbfd;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
  color: var(--text);
  text-decoration: none;
}
.btn:hover { background: #f3f4f6; }
.btn.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost {
  background: white;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
  padding: 8px 12px;
}
.btn.ghost:hover { background: #f3f4f6; color: var(--text); }
.btn.small { padding: 4px 10px; font-size: 12px; }

/* ===== BigQuery 結果 ===== */
.bq-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 16px 20px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
@media (max-width: 700px) { .bq-stats { grid-template-columns: repeat(2, 1fr); } }

.stat {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.stat-label {
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 4px;
}
.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.stat-value.primary { color: var(--green); }

.result-table-wrap { overflow: auto; max-height: 420px; }
.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.result-table th {
  background: #f8fafc;
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  text-align: left;
  font-size: 11.5px;
  color: var(--muted);
}
.result-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.result-table tbody tr:hover { background: #fafbfd; }
.result-table .empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
  font-size: 13px;
}
.result-table td.amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--green-dark);
}

/* ===== Integration ===== */
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 20px;
}
@media (max-width: 768px) { .grid2 { grid-template-columns: 1fr; } }
.panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  background: #fafbfd;
}
.panel.bdash-panel { border-left: 4px solid var(--bdash); }
.panel.yappli-panel { border-left: 4px solid var(--yappli); }
.panel-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}
.panel-head h3 { margin: 0; font-size: 16px; }
.panel-head .muted { font-size: 11.5px; }
.panel .muted { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 12.5px; }

.result-box {
  margin: 12px 0 0;
  padding: 12px;
  background: var(--code-bg);
  color: var(--code-fg);
  font-family: "JetBrains Mono", Consolas, Monaco, monospace;
  font-size: 11.5px;
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 300px;
  overflow: auto;
  line-height: 1.5;
}

.appscript-actions {
  padding: 16px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.appscript-actions p { flex: 1 1 280px; margin: 0; }
.appscript-actions code {
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

details { padding: 0 20px 16px; }
details summary { cursor: pointer; padding: 8px 0; font-weight: 600; color: var(--green-dark); }

.footer { text-align: center; padding: 24px; color: var(--muted); font-size: 12px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #111827;
  color: white;
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
  z-index: 100;
  font-size: 13px;
  opacity: 0;
  transform: translateY(10px);
  transition: all .25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #b91c1c; }
.toast.success { background: var(--green); }
