@import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;1,9..40,300;1,9..40,400&display=swap');

:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface2: #f0efe9;
  --border: #e2e0d8;
  --border-strong: #c8c5b8;
  --text: #1a1916;
  --text-2: #6b6860;
  --text-3: #9e9b93;
  --accent: #2a2a27;
  --accent-fg: #ffffff;
  --highlight: #e8f0fe;
  --highlight-border: #4a7cf7;
  --success: #d1fae5;
  --success-text: #065f46;
  --mono: 'DM Mono', monospace;
  --sans: 'DM Sans', sans-serif;
  --radius: 6px;
  --radius-lg: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text);
}

.logo span { color: var(--text-3); }

.header-actions { display: flex; gap: 8px; align-items: center; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 52px);
}

aside {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.section-label {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 12px;
}

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }

input[type=text], input[type=number], select {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

input[type=text]:focus, input[type=number]:focus, select:focus {
  border-color: var(--highlight-border);
  background: var(--surface);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.toggle-row:last-child { border-bottom: none; }
.toggle-label { font-size: 12px; color: var(--text-2); }

.toggle {
  position: relative;
  width: 32px;
  height: 18px;
  cursor: pointer;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: 9px;
  transition: background 0.2s;
}

.toggle input:checked + .toggle-track { background: var(--accent); }

.toggle-thumb {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: white;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
  pointer-events: none;
}

.toggle input:checked ~ .toggle-thumb { transform: translateX(14px); }

.scale-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.scale-pill {
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
  text-align: center;
  transition: all 0.15s;
  user-select: none;
}

.scale-pill:hover { border-color: var(--border-strong); color: var(--text); }
.scale-pill.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

.scale-pill .ratio { font-size: 10px; opacity: 0.7; display: block; margin-top: 1px; }

main {
  padding: 24px 32px;
  overflow-x: auto;
}

.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 4px;
  width: fit-content;
}

.tab-btn {
  padding: 6px 16px;
  border-radius: 7px;
  border: none;
  background: transparent;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--accent); color: var(--accent-fg); }

.sheet { display: none; }
.sheet.active { display: block; }

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

thead th {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  text-align: left;
  padding: 0 10px 10px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }

td {
  padding: 0;
  vertical-align: middle;
}

td.style-name {
  font-size: 13px;
  font-weight: 500;
  padding: 10px 10px;
  white-space: nowrap;
  color: var(--text);
  width: 130px;
}

td.style-name .preview-text {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-3);
  font-family: var(--mono);
  margin-top: 1px;
}

.cell-input {
  width: 100%;
  height: 42px;
  padding: 0 10px;
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  outline: none;
  transition: background 0.1s;
  min-width: 90px;
}

.cell-input:focus {
  background: var(--highlight);
  border-left-color: var(--highlight-border);
}

.cell-derived {
  padding: 0 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  border-left: 1px solid var(--border);
  white-space: nowrap;
  height: 42px;
  display: flex;
  align-items: center;
  min-width: 110px;
}

.ls-cell {
  padding: 0 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
  border-left: 1px solid var(--border);
  white-space: nowrap;
  height: 42px;
  display: flex;
  align-items: center;
  min-width: 130px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover { border-color: var(--border-strong); color: var(--text); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:hover { background: #3d3d38; border-color: #3d3d38; color: var(--accent-fg); }

.export-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.badge {
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--surface2);
  color: var(--text-3);
  border: 1px solid var(--border);
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  font-family: var(--mono);
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.25s;
  pointer-events: none;
  z-index: 999;
}

.toast.show { opacity: 1; transform: translateY(0); }

.group-header td {
  background: var(--bg);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 8px 10px 4px;
  border-bottom: 1px solid var(--border);
}

.divider { border-top: 1px solid var(--border); padding-top: 20px; }

select option { font-family: monospace; }

.style-name-cell {
  padding: 6px 10px;
  vertical-align: middle;
  min-width: 160px;
}

.name-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px dashed transparent;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  outline: none;
  padding: 2px 0;
  cursor: text;
  transition: border-color 0.15s;
}

.name-input:hover { border-bottom-color: var(--border-strong); }
.name-input:focus { border-bottom-color: var(--highlight-border); border-bottom-style: solid; }

.row-meta {
  display: flex;
  gap: 4px;
  margin-top: 3px;
}

.meta-select {
  height: 22px;
  padding: 0 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-2);
  outline: none;
  cursor: pointer;
  max-width: 110px;
}

.meta-select:focus { border-color: var(--highlight-border); }

.del-btn {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-3);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.15s;
  padding: 0;
}

.style-row:hover .del-btn { opacity: 1; }
.del-btn:hover { background: #fee2e2; border-color: #fca5a5; color: #dc2626; }

.add-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius);
  border: 1px dashed var(--border-strong);
  background: transparent;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  cursor: pointer;
  transition: all 0.15s;
}

.add-btn:hover { border-color: var(--highlight-border); color: var(--highlight-border); background: var(--highlight); }

.cell-derived, .ls-cell {
  cursor: pointer;
  position: relative;
  transition: background 0.1s, color 0.1s;
  border-radius: 0;
}

.cell-derived:hover, .ls-cell:hover {
  background: var(--highlight);
  color: var(--highlight-border);
}

.cell-derived.copied, .ls-cell.copied {
  background: #d1fae5;
  color: #065f46;
}

.cell-derived.copied::after, .ls-cell.copied::after {
  content: '✓';
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: #065f46;
}

.cell-input {
  cursor: text;
}

.cell-input.copied {
  background: #d1fae5 !important;
  border-left-color: #34d399 !important;
  color: #065f46 !important;
  transition: background 0.1s, color 0.1s;
}

.lh-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}
.lh-label { font-size: 12px; color: var(--text-2); }
.lh-input {
  width: 64px;
  height: 28px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  outline: none;
  text-align: right;
}
.lh-input:focus { border-color: var(--highlight-border); background: var(--surface); }
