:root {
  color-scheme: light;
  --bg: #edebe8;
  --panel: #f7f6f4;
  --panel-soft: #f2f0ed;
  --canvas-bg: #e8e5e0;
  --text: #1c1b19;
  --muted: #6b6860;
  --line: #d8d4ce;
  --line-strong: #b8b4ae;
  --accent: #3a6272;
  --accent-hover: #2d4f5e;
  --accent-light: #ebf2f5;
  --danger: #b04040;
  --shadow: 0 2px 8px rgba(28, 22, 16, 0.08);
  --radius: 4px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select {
  font: inherit;
}

button {
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  min-height: 30px;
  padding: 0 10px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

button:hover {
  background: var(--panel-soft);
  border-color: var(--accent);
}

button:active {
  transform: translateY(1px);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 340px;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  min-height: 620px;
}

.top-bar {
  align-items: center;
  background: rgba(247, 246, 244, 0.94);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 14px;
  grid-column: 1 / -1;
  grid-template-columns: 190px minmax(0, 1fr) auto;
  min-height: 52px;
  padding: 10px 14px;
  position: relative;
  z-index: 2;
}

.brand {
  align-items: center;
  display: flex;
  gap: 9px;
  flex-shrink: 0;
  min-width: 190px;
}

.brand-mark {
  background: linear-gradient(180deg, rgba(58, 98, 114, 0.96), rgba(45, 79, 94, 0.96));
  border-radius: 7px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.16),
    0 1px 3px rgba(28, 22, 16, 0.12);
  flex: 0 0 28px;
  height: 28px;
  overflow: hidden;
  position: relative;
}

.brand-mark::before {
  background:
    linear-gradient(rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.18)) 50% 50% / 1px 14px no-repeat,
    linear-gradient(90deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.18)) 50% 50% / 14px 1px no-repeat;
  content: "";
  inset: 7px;
  position: absolute;
}

.brand-mark::after {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 2px;
  box-shadow:
    8px 0 0 rgba(255, 255, 255, 0.9),
    0 8px 0 rgba(255, 255, 255, 0.9),
    8px 8px 0 rgba(255, 255, 255, 0.45);
  content: "";
  height: 5px;
  left: 7px;
  position: absolute;
  top: 7px;
  width: 5px;
}

.brand h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1;
  margin: 0;
}

.brand p {
  color: var(--muted);
  display: none;
  font-size: 11px;
  margin: 0;
}

.file-actions {
  align-items: center;
  display: flex;
  flex-shrink: 0;
  gap: 6px;
  grid-column: auto;
}

.tool-actions {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-self: start;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tool-actions .tool-button {
  flex: 0 0 auto;
}

#saveJsonButton {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

#saveJsonButton:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.panel {
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: auto;
  padding: 14px;
  z-index: 1;
}

.right-sidebar {
  background: var(--canvas-bg);
  border-left: 1px solid var(--line);
}

section + section {
  margin-top: 20px;
}

h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  margin: 0 0 12px;
  text-transform: uppercase;
}

.section-heading-row {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin: 0 0 12px;
}

.section-heading-row h2 {
  margin: 0;
}

.icon-button {
  align-items: center;
  display: inline-flex;
  font-size: 14px;
  font-weight: 600;
  justify-content: center;
  min-height: 24px;
  padding: 0;
  width: 24px;
}

.category-name {
  border-radius: var(--radius);
  cursor: text;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  min-width: 0;
  overflow: hidden;
  padding: 2px 4px;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.category-name:hover {
  background: rgba(58, 98, 114, 0.08);
}

.category-name-input {
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  min-height: 24px;
  min-width: 0;
  padding: 2px 6px;
  width: 100%;
}

.category-swatch {
  border: 1px solid rgba(28, 22, 16, 0.18);
  border-radius: 2px;
  height: 14px;
  width: 14px;
}

.tool-button {
  align-items: center;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  display: flex;
  font-size: 11px;
  font-weight: 500;
  gap: 5px;
  justify-content: flex-start;
  min-height: 28px;
  padding: 0 8px;
}

.tool-icon {
  align-items: center;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 1.5em;
  justify-content: center;
  line-height: 1;
  width: 1em;
}

.tool-button:hover,
.tool-button.is-active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.secondary-button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 11px;
  font-weight: 500;
  min-height: 28px;
  padding: 0 8px;
}

.secondary-button:hover {
  background: var(--panel-soft);
  border-color: var(--line-strong);
}

.help-copy p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin: 0;
}

.canvas-panel {
  background: var(--canvas-bg);
  min-width: 0;
  overflow: hidden;
  position: relative;
}

#planningCanvas {
  cursor: crosshair;
  display: block;
  height: 100%;
  width: 100%;
}

#planningCanvas.is-panning {
  cursor: grabbing;
}

.canvas-status {
  align-items: center;
  bottom: 14px;
  display: flex;
  gap: 8px;
  left: 14px;
  position: absolute;
}

.canvas-status span {
  background: rgba(247, 246, 244, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 11px;
  padding: 4px 7px;
}

.dashboard {
  background: rgba(247, 246, 244, 0.35);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.dashboard-table {
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
  width: 100%;
}

.dashboard-table th,
.dashboard-table td {
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  padding: 7px 5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-table th:nth-child(1),
.dashboard-table td:nth-child(1) {
  text-align: center;
  width: 34px;
}

.dashboard-table th:nth-child(2),
.dashboard-table td:nth-child(2) {
  width: 88px;
}

.dashboard-table th:nth-child(3),
.dashboard-table td:nth-child(3) {
  width: 58px;
}

.dashboard-table th:nth-child(4),
.dashboard-table td:nth-child(4),
.dashboard-table th:nth-child(5),
.dashboard-table td:nth-child(5) {
  width: 42px;
}

.dashboard-table th {
  background: rgba(242, 240, 237, 0.72);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
}

.dashboard-table tr:last-child td {
  border-bottom: 0;
}

.dashboard-category-row {
  cursor: pointer;
  transition: background 120ms ease, box-shadow 120ms ease;
}

.dashboard-category-row:hover {
  background: var(--panel-soft);
}

.dashboard-category-row.is-active {
  background: var(--accent-light);
}

.dashboard-category-row:focus-visible {
  outline: 2px solid rgba(58, 98, 114, 0.35);
  outline-offset: -2px;
}

.dashboard-color-cell {
  text-align: center;
}

.dashboard-color-swatch {
  border: 1px solid rgba(28, 22, 16, 0.2);
  border-radius: 2px;
  display: inline-block;
  height: 14px;
  vertical-align: middle;
  width: 20px;
}

.dashboard-category-row.is-active .dashboard-color-swatch {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.dashboard-table .number-cell {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
}

.dashboard-category {
  align-items: center;
  display: flex;
  gap: 8px;
  font-weight: 500;
  overflow: hidden;
}

.dashboard-category-label {
  border-radius: var(--radius);
  min-width: 0;
  overflow: hidden;
  padding: 2px 4px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-category-label:hover {
  background: rgba(58, 98, 114, 0.08);
}

.dashboard-category-row.is-unassigned .dashboard-color-swatch {
  opacity: 0.58;
}

.dashboard-category-row.is-unassigned .dashboard-category-label {
  color: var(--muted);
}

.settings-list {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0;
  overflow: hidden;
}

.settings-list div {
  align-items: center;
  display: grid;
  grid-template-columns: 1fr auto;
  min-height: 30px;
  padding: 6px 8px;
}

.settings-list div + div {
  border-top: 1px solid var(--line);
}

.settings-list dt {
  color: var(--muted);
  font-size: 12px;
}

.settings-list dd {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  margin: 0;
  text-align: right;
}

.settings-select {
  appearance: none;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  min-height: 28px;
  min-width: 124px;
  padding: 0 26px 0 8px;
}

#moduleSize {
  text-align: right;
  text-align-last: right;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: minmax(320px, 1fr);
    grid-template-rows: auto minmax(520px, 1fr) auto;
    height: auto;
    min-height: 100vh;
  }

  .top-bar {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .tool-actions,
  .file-actions {
    flex-wrap: wrap;
    grid-column: 1;
    overflow-x: visible;
  }

  .right-sidebar {
    border-left: 0;
    border-top: 1px solid var(--line);
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .right-sidebar {
    border: 0;
  }

  .canvas-panel {
    min-height: 520px;
  }
}
