/* style.css: SQL to ERD のレイアウトと部品 */

:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --line: #d5dbe1;
  --text: #1f2933;
  --muted: #6b7785;
  --accent: #2f3e4e;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --editor-width: 420px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* アプリ本体は 1 画面に収め、説明文はその下にスクロールで現れる */
.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- ヘッダ ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.brand .ti { margin-right: 4px; }
.diagram-tools, .export-tools, .canvas-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}
.export-tools { margin-left: auto; }

/* ---- 部品 ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #f3f5f7; }
.btn .ti { font-size: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: #3f5266; }
.btn-danger:hover { color: var(--danger); border-color: var(--danger); }
.btn kbd {
  font-size: 11px;
  opacity: 0.7;
  margin-left: 4px;
}
.select, .input {
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}
.select { min-width: 180px; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

/* セグメント切替 */
.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.seg button {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 8px;
  font-size: 16px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: #f3f5f7; }
.seg button.active { background: var(--accent); color: var(--accent-text); }

/* ---- 作業領域 ---- */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.editor {
  width: var(--editor-width);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.editor-collapsed .editor { display: none; }
/* ファイルをドラッグしている間、落とし先としてエディタを強調する */
.editor.drop-target { outline: 3px dashed var(--accent); outline-offset: -6px; }
.editor.drop-target .sql { background: #f3f7fb; }
.editor-head, .editor-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.editor-foot { border-bottom: 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.editor-label { color: var(--text); font-size: 12px; letter-spacing: 0.04em; font-weight: 700; }
.editor-label .ti { font-size: 14px; vertical-align: -2px; }
.btn-sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn-sm .ti { font-size: 14px; }
/* サンプル表示中だけ出す案内帯。本文を書き換えた時点で消える */
.sample-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  background: #fff7dc;
  border-bottom: 1px solid #ecd9a0;
  color: #6b5416;
  font-size: 12px;
  line-height: 1.4;
}
.sample-note[hidden] { display: none; }
.legend { display: inline-flex; align-items: center; gap: 4px; }
.legend-mark { color: #8a96a3; }
.sql {
  flex: 1;
  margin: 0;
  padding: 12px;
  border: 0;
  resize: none;
  outline: none;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text);
  tab-size: 2;
}
.errors {
  margin: 0;
  padding: 8px 12px 8px 28px;
  max-height: 160px;
  overflow: auto;
  background: #fff4f2;
  border-top: 1px solid #f0c8c2;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.5;
}

.editor-toggle {
  position: absolute;
  left: var(--editor-width);
  top: 8px;
  z-index: 2;
  width: 24px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 6px 6px 0;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}
.editor-collapsed .editor-toggle { left: 0; }

.canvas-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}
.canvas-wrap:fullscreen { background: var(--bg); }
.canvas-tools {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 2;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.zoom-level {
  min-width: 44px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}
#canvas {
  width: 100%;
  height: 100%;
  display: block;
  background-color: var(--bg);
  background-image: radial-gradient(var(--line) 1px, transparent 1px);
  background-size: 20px 20px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
#canvas.panning { cursor: grabbing; }
.entity { cursor: move; }
.entity.dragging .entity-frame { stroke: #d9534f; stroke-width: 2; }
.entity text { pointer-events: none; }
.empty[hidden] { display: none; }
.empty {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
}

/* ---- ダイアログ ---- */
.dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px 24px;
  min-width: 320px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}
.dialog::backdrop { background: rgba(31, 41, 51, 0.4); }
.dialog h2 { margin: 0 0 12px; font-size: 15px; }
.dialog p { margin: 0 0 16px; }
.dialog .input { width: 100%; }
.dialog-hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ---- 説明ブロック ---- */
.about {
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 48px 24px 64px;
}
.about-inner {
  position: relative;
  max-width: 760px;
  margin: 0 auto;
  line-height: 1.8;
}
.about[hidden] { display: none; }
.notice-local {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 4px solid #b5179e;
  background: #fbf3f9;
  border-radius: 0 6px 6px 0;
}
.notice-local h2 { margin: 0 0 4px; font-size: 16px; }
.notice-local p { margin: 0; }

/* ---- 使い方モーダル ---- */
.guide-dialog {
  width: min(760px, 92vw);
  max-height: 88vh;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.guide-dialog:not([open]) { display: none; }
.guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 12px 24px;
  border-bottom: 1px solid var(--line);
}
.guide-title { font-weight: 700; }
.guide-body {
  overflow: auto;
  padding: 8px 24px 16px;
  line-height: 1.8;
}
.guide-body h2 { font-size: 16px; margin: 20px 0 6px; }
.guide-body h2:first-child { margin-top: 8px; }
.guide-body p { margin: 0 0 6px; }
.guide-body ul, .guide-body ol { margin: 0; padding-left: 1.5em; }
.guide-dialog .dialog-actions {
  margin: 0;
  padding: 12px 24px;
  border-top: 1px solid var(--line);
}
.about h2 {
  font-size: 18px;
  margin: 32px 0 8px;
}
.about h2:first-child { margin-top: 0; }
.about p { margin: 0 0 8px; }
.about ul, .about ol { margin: 0; padding-left: 1.5em; }
.about li { margin: 2px 0; }
a.btn { text-decoration: none; }

/* ---- 提供元（DBC）への導線 ---- */
.brand a {
  color: inherit;
  text-decoration: none;
}
.brand-by {
  margin-left: 8px;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--muted);
}
.brand-by a { color: var(--muted); }
.brand-by a:hover { color: var(--text); }
.about-consult {
  margin-top: 32px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
.about-consult p { margin: 0; }
.site-footer {
  padding: 24px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}
.site-footer a { color: var(--muted); }
@media screen and (max-width: 700px) {
  .brand-by { display: none; }
}

/* ---- 印刷。画面では印刷シートを出さず、印刷時は図だけを用紙に収める ---- */
.print-sheet { display: none; }
@media print {
  @page { size: landscape; margin: 12mm; }
  body { background: #fff; }
  body > :not(.print-sheet) { display: none !important; }
  .print-sheet {
    display: flex;
    flex-direction: column;
    height: 100vh;
  }
  .print-head {
    display: flex;
    justify-content: space-between;
    padding-bottom: 4mm;
    color: var(--muted);
    font-size: 11px;
  }
  .print-sheet svg {
    flex: 1;
    width: 100%;
    min-height: 0;
  }
}
