:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --text: #22302a;
  --muted: #5f6f67;
  --border: #d5ddd8;
  --accent: #4f7a66;
  --accent-hover: #426a58;
  --selected-bg: #e1ece6;
  --error: #b3261e;
  --error-bg: #fbeeed;
  --warning: #c08a1e;
  --warning-bg: #fdf6e6;
  --warning-text: #7a5410;
  --code-bg: #1f2a25;
  --code-text: #e2ebe6;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161c19;
    --surface: #1f2723;
    --text: #e2ebe6;
    --muted: #9aaba2;
    --border: #34413a;
    --accent: #7fae97;
    --accent-hover: #93bea9;
    --selected-bg: #2a3a32;
    --error: #f2b8b5;
    --error-bg: #3a2120;
    --warning: #d9a441;
    --warning-bg: #352b17;
    --warning-text: #ecc674;
    --code-bg: #111613;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* display を指定したクラスがあっても、hidden 属性の要素は必ず隠す */
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.6;
}

.site-header {
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px 16px 4px;
}

/* 注意書き: 要約の 1 行は常に表示し、詳細は展開して読む */
.notice-details {
  margin-top: 10px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  font-size: 0.85rem;
}
.notice-details summary { cursor: pointer; }
.notice-details summary strong { color: var(--accent); }
.notice-more { color: var(--accent); text-decoration: underline; white-space: nowrap; }
.notice-details[open] .notice-more { display: none; }
.notice-details .notice-box { margin-top: 8px; padding: 0; border: none; background: none; }
.site-header h1 { margin: 0; font-size: 1.5rem; }
.site-header p { margin: 4px 0 0; color: var(--muted); }
.version { font-size: 0.9rem; color: var(--muted); font-weight: normal; }
.beta-badge {
  display: inline-block;
  padding: 1px 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  vertical-align: middle;
}

/* Public Beta / データの扱いの注意書き（落ち着いた情報表示にする） */
.notice-box {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 4px 24px;
  margin-top: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  font-size: 0.85rem;
}
.notice-section h2 { margin: 0 0 2px; font-size: 0.9rem; color: var(--accent); }
.notice-section ul { margin: 0; padding-left: 1.2em; color: var(--text); }
.notice-section li { margin: 1px 0; }

/* ---- 画面全体: Navigation | Settings | Preview ---- */
.app-layout {
  max-width: 1480px;
  margin: 0 auto;
  padding: 12px 16px 24px;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) minmax(0, 1.2fr);
  grid-template-areas: "nav settings preview";
  gap: 16px;
  align-items: start;
}
.app-nav { grid-area: nav; position: sticky; top: 12px; }
.settings-panel { grid-area: settings; }
/* Preview は画面に固定し、中身が長いときは Preview の中だけをスクロールする */
.preview-panel {
  grid-area: preview;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  container-type: inline-size;
}

/* 中くらいの幅: Navigation を上の横並びにし、Settings と Preview の 2 列 */
@media (max-width: 1199px) {
  .app-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "nav nav" "settings preview";
  }
  .app-nav { position: static; }
  .app-nav .nav-list { display: flex; flex-wrap: wrap; gap: 6px; }
  .app-nav .nav-children, .nav-title, .nav-hint { display: none; }
}
/* 狭い幅: すべて縦に並べる（横スクロールさせない） */
@media (max-width: 899px) {
  .app-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "nav" "settings" "preview";
  }
  .preview-panel { position: static; max-height: none; overflow: visible; }
}

/* ---- Navigation ---- */
.nav-title { margin: 0 0 6px; font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.nav-list, .nav-children { list-style: none; margin: 0; padding: 0; }
.nav-children { margin: 2px 0 6px 12px; padding-left: 6px; border-left: 1px solid var(--border); }
.app-nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
}
.app-nav button:hover { background: color-mix(in srgb, var(--selected-bg) 60%, transparent); }
.app-nav .nav-section { font-weight: 600; }
.app-nav .nav-section.is-active { color: var(--accent); }
.app-nav .nav-child { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; min-height: 32px; }
.app-nav [aria-current="page"] {
  background: var(--selected-bg);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.nav-label { overflow-wrap: anywhere; }
.nav-hint { margin: 8px 0 0; font-size: 0.75rem; color: var(--muted); }
@media (max-width: 1199px) {
  .app-nav button { width: auto; border-color: var(--border); background: var(--surface); }
}

/* エラー ✕ / 警告 ⚠ の印（色と記号の両方で区別する） */
.status-mark { flex: none; font-weight: 700; }
.status-error { color: var(--error); }
.status-warning { color: var(--warning); }

/* ---- Settings ---- */
.settings-title { font-size: 1.1rem; }
.settings-title:focus { outline: none; }
.settings-title:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.back-button { margin-bottom: 12px; padding: 4px 12px; font-size: 0.85rem; }
.link-button { padding: 0 6px; border: none; background: none; color: inherit; text-decoration: underline; font-size: 0.85rem; }

/* 一覧の行（1 行 = 1 つの Subnet / EC2。選ぶと編集画面に移る） */
.resource-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.resource-row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  text-align: left;
  background: var(--bg);
}
.resource-row:hover { border-color: var(--accent); }
.row-name { font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.row-meta { font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }

/* Basic / Advanced Settings */
details.advanced {
  margin: 4px 0 14px;
  padding: 8px 12px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
}
details.advanced > summary { margin-bottom: 8px; font-weight: 600; cursor: pointer; color: var(--accent); }
details.advanced:not([open]) { padding-bottom: 0; }
details.advanced:not([open]) > summary { margin-bottom: 8px; }

.review-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; margin: 0 0 16px; }
.review-list dt { font-weight: 600; color: var(--muted); }
.review-list dd { margin: 0; overflow-wrap: anywhere; }

/* ---- Preview ---- */
.preview-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.preview-header h2 { margin: 0; }
.preview-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.preview-tabs [role="tab"] {
  margin-bottom: -1px;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--muted);
}
.preview-tabs [role="tab"][aria-selected="true"] {
  border-color: var(--border);
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 0 3px 0 var(--accent);
}
.preview-tabpanel:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Summary: 構成の階層を罫線つきの木で表示する */
.summary-tree { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.summary-tree .summary-tree { margin-left: 8px; padding-left: 14px; border-left: 1px solid var(--border); }
.summary-tree li { margin: 4px 0; }
.summary-tree .summary-tree > li { position: relative; }
.summary-tree .summary-tree > li::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 0.8em;
  width: 10px;
  border-top: 1px solid var(--border);
}
.summary-label { font-weight: 600; }
.summary-detail { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }

/* Warnings */
.warning-heading { margin: 0 0 8px; font-weight: 600; color: var(--warning-text); }
.warning-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.warning-items li {
  padding: 8px 12px;
  border: 1px solid var(--warning);
  border-left-width: 4px;
  border-radius: 6px;
  background: var(--warning-bg);
}
.no-warnings { color: var(--accent); font-weight: 600; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}
.panel h2 { margin: 0 0 12px; font-size: 1.1rem; }

.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field label.check { display: flex; align-items: center; gap: 8px; font-weight: normal; }

input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
input:focus-visible, select:focus-visible, button:focus-visible, .output:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--error); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

.hint { margin: 4px 0 0; font-size: 0.85rem; color: var(--muted); }

.form-note { margin: 0 0 16px; font-size: 0.85rem; color: var(--muted); }

.var-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 12px; margin-bottom: 12px; }
.var-grid label.check { display: flex; align-items: center; gap: 6px; font-weight: normal; }
.var-grid label.check:has(input:disabled) { color: var(--muted); }

.field-error { margin: 4px 0 0; font-size: 0.85rem; color: var(--error); }
.field-error:empty { display: none; }

.error-summary {
  border: 1px solid var(--error);
  background: var(--error-bg);
  color: var(--error);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 16px;
}
.error-summary p { margin: 0; font-weight: 600; }
.error-summary ul { margin: 4px 0 0; padding-left: 1.2em; }

/* ---- 追加・削除できる一覧（Subnet / EC2） ---- */

.count { font-size: 0.85rem; font-weight: normal; color: var(--muted); }
.list-hint { margin: -4px 0 8px; }
/* 選択した 1 件の編集画面 */
.list-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px 2px;
  background: var(--bg);
}
.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
}
.editor-title { margin: 0; font-size: 1rem; color: var(--accent); overflow-wrap: anywhere; }
.editor-summary { margin: 2px 0 0; font-size: 0.85rem; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.card-actions { display: flex; gap: 6px; flex: none; }
.small-button { padding: 2px 10px; font-size: 0.8rem; }
/* 削除は取り消せない操作なので色で区別する */
.small-button[data-action="remove"] { color: var(--error); border-color: color-mix(in srgb, var(--error) 40%, var(--border)); }
.small-button[data-action="remove"]:disabled { color: var(--muted); border-color: var(--border); }
.add-button { margin-bottom: 4px; border-style: dashed; color: var(--accent); }
.list-status { margin: 0 0 8px; font-size: 0.85rem; color: var(--warning-text); }
.list-status:empty { display: none; }


button {
  font: inherit;
  padding: 8px 18px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.primary:hover { background: var(--accent-hover); }

fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 0 0 16px;
  padding: 8px 14px 2px;
}
legend { padding: 0 6px; font-weight: 600; color: var(--accent); }

/* 生成成功（エラー = 赤、警告 = 黄、成功 = 緑で区別する） */
.success-status {
  margin: 0 0 12px;
  padding: 8px 14px;
  border: 1px solid var(--accent);
  border-left-width: 4px;
  border-radius: 6px;
  background: var(--selected-bg);
  font-size: 0.9rem;
}
.success-status[hidden] { display: none; }
fieldset.plain { border: none; margin: 0; padding: 0; min-width: 0; }
fieldset.plain[hidden] { display: none; }

.subsection {
  margin: 18px 0 8px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  font-size: 0.95rem;
}
fieldset.plain > .subsection:first-child { margin-top: 4px; }
.field-label { display: block; font-weight: 600; margin-bottom: 4px; }
.check-group { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.field .check-group label.check { margin-bottom: 0; }
input:disabled { opacity: 0.55; cursor: not-allowed; }
fieldset.plain > .hint { margin: -6px 0 12px; }

.actions { display: flex; align-items: center; gap: 8px; }
.action-status { font-size: 0.85rem; color: var(--accent); font-weight: 600; }

/* ---- Terraform Project（ファイルツリー + コード表示） ---- */

.project-view {
  display: grid;
  grid-template-columns: minmax(150px, 200px) minmax(0, 1fr);
  gap: 12px;
}
/* Preview 領域が狭いときはツリーをコードの上に置く */
@container (max-width: 520px) {
  .project-view { grid-template-columns: minmax(0, 1fr); }
  .tree-pane { min-height: 0; }
}

.tree-pane {
  min-height: 240px;
  padding: 8px 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
}
.tree-placeholder { margin: 4px 8px; font-size: 0.85rem; color: var(--muted); }
.tree-placeholder[hidden] { display: none; }

.file-tree, .file-tree ul { list-style: none; margin: 0; padding: 0; }
.file-tree [role="group"] { margin-left: 13px; padding-left: 4px; border-left: 1px solid var(--border); }
.file-tree [role="group"][hidden] { display: none; }
.file-tree [role="treeitem"] { outline: none; }

.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px 5px;
  border-left: 3px solid transparent;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  white-space: nowrap;
  cursor: pointer;
}
.tree-row:hover { background: color-mix(in srgb, var(--selected-bg) 60%, transparent); }
[role="treeitem"]:focus-visible > .tree-row { outline: 2px solid var(--accent); outline-offset: -2px; }
[role="treeitem"][aria-selected="true"] > .tree-row {
  background: var(--selected-bg);
  border-left-color: var(--accent);
  font-weight: 600;
}

.tree-icon { flex: none; width: 1em; text-align: center; color: var(--muted); }
[data-type="directory"] > .tree-row { color: var(--accent); font-weight: 600; }
[data-type="directory"] > .tree-row .tree-icon::before { content: "▸"; }
[data-type="directory"][aria-expanded="true"] > .tree-row .tree-icon::before { content: "▾"; }

.code-pane { display: flex; flex-direction: column; min-width: 0; }
.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 36px;
  margin-bottom: 8px;
}
.current-file {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.code-pane .output { flex: 1; }

.output {
  margin: 0;
  min-height: 240px;
  padding: 16px;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 6px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
}
.output.empty::before { content: attr(data-placeholder); color: #8a9a91; font-family: inherit; }

/* ---- スマートフォン幅 ---- */
@media (max-width: 520px) {
  .site-header h1 { font-size: 1.25rem; }
  .panel { padding: 14px; }
  .field-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .editor-head { flex-wrap: wrap; }
  .card-actions { margin-left: auto; }
  .card-actions .small-button { min-height: 40px; padding: 6px 14px; }
  .actions { flex-wrap: wrap; }
  fieldset { padding: 8px 10px 2px; }
  .resource-row { grid-template-columns: minmax(0, 1fr) auto; }
  .resource-row .row-meta { grid-column: 1; }
  .review-list { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .review-list dd { margin-bottom: 8px; }
  .preview-tabs [role="tab"] { padding: 6px 10px; }
  .add-button, .back-button { min-height: 44px; }
}
