/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", "Hiragino Sans", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #333;
  background: #f0f2f5;
}

/* ===== Header ===== */
header {
  background: linear-gradient(135deg, #1a2a4a 0%, #2c4a7c 100%);
  color: white;
  padding: 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
}

.back-link {
  display: inline-block;
  color: rgba(255,255,255,0.8);
  font-size: 0.85rem;
  text-decoration: none;
  margin-bottom: 0.5rem;
  min-height: 44px;
  line-height: 44px;
  padding: 0 0.25rem;
  transition: color 0.2s;
}

.back-link:hover {
  color: white;
}

header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.3;
}

.subtitle {
  font-size: 0.85rem;
  opacity: 0.8;
  margin-top: 0.25rem;
}

/* ===== Main ===== */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
}

/* ===== Ad Units ===== */
.ad-unit {
  margin: 1.25rem 0;
}

/* ===== Tool Section ===== */
.tool-section {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  overflow: hidden;
}

/* ===== App Layout ===== */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 500px;
}

/* ===== Tool Panel ===== */
.tool-panel {
  background: #f8f9fc;
  border-bottom: 1px solid #e2e6ee;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: #1a2a4a;
  border-bottom: 2px solid #2c4a7c;
  padding-bottom: 0.5rem;
}

/* Legend */
.legend-section h3,
.add-node-section h3,
.export-section h3 {
  font-size: 0.8rem;
  font-weight: 700;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.legend-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: #555;
}

/* Type Badges */
.type-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 22px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
  white-space: nowrap;
}

.type-top     { background: #e74c3c; }
.type-list    { background: #3498db; }
.type-detail  { background: #27ae60; }
.type-form    { background: #9b59b6; }
.type-feature { background: #e67e22; }
.type-lp      { background: #c0392b; }

/* Add Node */
.add-node-section label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #444;
  margin-bottom: 0.25rem;
  margin-top: 0.5rem;
}

.add-node-section input,
.add-node-section select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  border: 1px solid #d0d5e0;
  border-radius: 6px;
  background: white;
  min-height: 44px;
}

.add-node-section input:focus,
.add-node-section select:focus {
  outline: 2px solid #2c4a7c;
  outline-offset: 1px;
}

.add-hint {
  font-size: 0.75rem;
  color: #888;
  margin-top: 0.4rem;
}

/* Buttons */
.btn-primary {
  display: block;
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  font-weight: 700;
  background: #2c4a7c;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  min-height: 44px;
}

.btn-primary:hover {
  background: #3a5fa0;
}

.btn-primary:active {
  background: #1e3560;
}

.btn-secondary {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: white;
  color: #2c4a7c;
  border: 1.5px solid #2c4a7c;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  min-height: 44px;
  text-align: center;
}

.btn-secondary:hover {
  background: #2c4a7c;
  color: white;
}

.btn-file-label {
  cursor: pointer;
}

.btn-file-label input[type="file"] {
  display: none;
}

.btn-danger {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: white;
  color: #c0392b;
  border: 1.5px solid #c0392b;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  min-height: 44px;
}

.btn-danger:hover {
  background: #c0392b;
  color: white;
}

/* ===== Tree Area ===== */
.tree-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 480px;
}

.tree-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: #f0f2f5;
  border-bottom: 1px solid #e2e6ee;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tree-hint {
  font-size: 0.75rem;
  color: #888;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-zoom {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: white;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  min-height: 44px;
  padding: 0;
}

.btn-zoom:hover {
  background: #e8ecf5;
}

#zoom-label {
  font-size: 0.8rem;
  color: #666;
  min-width: 40px;
  text-align: center;
}

/* Tree Container */
#tree-container {
  flex: 1;
  position: relative;
  overflow: auto;
  min-height: 400px;
  cursor: default;
  background: #fafbfd;
}

#tree-svg {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
}

#tree-nodes {
  position: relative;
}

/* ===== Tree Nodes ===== */
.tree-node {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 4px;
  background: white;
  border: 2px solid #d0d5e0;
  border-radius: 8px;
  padding: 6px 10px 6px 8px;
  min-width: 110px;
  max-width: 180px;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  transition: box-shadow 0.15s, border-color 0.15s;
}

.tree-node:hover {
  box-shadow: 0 3px 10px rgba(0,0,0,0.12);
}

.tree-node.selected {
  border-color: #2c4a7c;
  box-shadow: 0 0 0 2px rgba(44,74,124,0.25);
}

/* Node badge */
.node-badge {
  flex-shrink: 0;
  width: 26px;
  height: 20px;
  border-radius: 4px;
  font-size: 0.62rem;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Node label */
.node-label {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 600;
  color: #222;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}

/* Node edit input */
.node-edit-input {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 600;
  color: #222;
  border: none;
  outline: none;
  background: transparent;
  min-width: 0;
  width: 100%;
}

/* Collapse button */
.node-collapse-btn {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.6rem;
  color: #aaa;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  transition: background 0.15s;
  min-height: 18px;
}

.node-collapse-btn:hover {
  background: #eee;
  color: #555;
}

/* Delete button */
.node-delete-btn {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.7rem;
  color: #bbb;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  transition: background 0.15s, color 0.15s;
  min-height: 20px;
}

.node-delete-btn:hover {
  background: #fee;
  color: #c0392b;
}

/* SVG lines */
.tree-line {
  stroke: #b0bac8;
  stroke-width: 1.5;
  fill: none;
}

/* ===== Howto Section ===== */
.howto-section {
  margin-top: 1.5rem;
  padding: 1.5rem;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.howto-section h2 {
  font-size: 1.05rem;
  color: #1a2a4a;
  margin-bottom: 0.75rem;
  margin-top: 1.25rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid #e8ecf5;
}

.howto-section h2:first-child {
  margin-top: 0;
}

.howto-section ol {
  padding-left: 1.25rem;
  font-size: 0.9rem;
  color: #555;
}

.howto-section li {
  margin-bottom: 0.5rem;
}

.howto-section p {
  font-size: 0.9rem;
  color: #555;
  line-height: 1.7;
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.85rem;
  color: #888;
}

footer a {
  color: #666;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1a2a4a;
  color: white;
  padding: 0.7rem 1.5rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  transition: transform 0.3s ease;
  z-index: 1000;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ===== Desktop Layout ===== */
@media (min-width: 768px) {
  header {
    padding: 1.25rem 2rem;
  }

  header h1 {
    font-size: 1.6rem;
  }

  main {
    padding: 1.5rem 2rem;
  }

  .app-layout {
    flex-direction: row;
    min-height: 600px;
  }

  .tool-panel {
    width: 220px;
    min-width: 220px;
    border-bottom: none;
    border-right: 1px solid #e2e6ee;
    overflow-y: auto;
    max-height: 700px;
  }

  .tree-area {
    min-height: 600px;
  }

  #tree-container {
    min-height: 550px;
  }
}

@media (min-width: 1024px) {
  .tool-panel {
    width: 240px;
    min-width: 240px;
  }
}
