html,
body {
  height: 100%;
  margin: 0;
  font-family: sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  margin: 0;
  font-family: sans-serif;
}

#main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}

#toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid #ccc;
  /* background:#fff; */
  box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
  flex: 0 0 auto;
  /* only as tall as content */
}

#toolbar input {
  padding: 4px;
  font-size: 14px;
}

#scene {
  flex: 1 1 0;
  height: 85vh;
  min-height: 350px;
  border: 1px solid #ced4da;
}


#workspace {
  flex: 1;
  display: flex;
  gap: 0.1rem;
  align-items: stretch;
  width: 100%;
  margin-top: 0.1rem;
  overflow: hidden;
}

*/ #toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-start;
  padding: 8px;
  border-bottom: 1px solid #ccc;
  /* background:#fff; */
  box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
}

#toolbar summary {
  list-style: none;
  cursor: pointer;
  /* background:#f3f3f3;  */
  border: 1px solid #bbb;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 14px;
  white-space: nowrap;
  user-select: none;
}


#yarn-graph-section {
  display: none;
  flex: 1 1 0;
  padding: 0.5rem 1rem;
  border: 1px solid #ced4da;
  border-radius: 0.4rem;
  box-sizing: border-box;
  overflow: auto;
  flex-direction: column;
}

#yarn-graph-section>div {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}


#download-svg-btn {
  padding: 6px 14px;
  font-size: 14px;
  cursor: pointer;
}

/* === Sidebar styles === */
#sidebar {
  position: fixed;
  position: absolute;
  top: 56px;
  width: 250px;
  height: 100%;
  color: white;
  padding: 12px;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
  overflow-y: auto;
  transform: translateX(0);
  transition: transform 0.3s ease-in-out;
  z-index: 1001;
}

#sidebar.hidden {
  transform: translateX(-100%);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.sidebar-header h2 {
  font-size: 18px;
  margin: 0;
}

#close-sidebar {
  background: none;
  border: none;
  font-size: 20px;
  color: white;
  cursor: pointer;
}


#sidebar-search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  border: 1px solid #ced4da;
  border-radius: 0.375rem;
}

#sidebar .yt-dropdown>summary,
.yarn-toolbar>.yt-dropdown>summary {
  font-size: 16px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

#sidebar .yt-dropdown>summary:focus-visible {
  outline: 2px solid var(--ui-accent, #007ee5);
  outline-offset: 2px;
}

#sample-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

#sample-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid #e0e0e0;
  font-size: 14px;
  transition: background 0.2s;
}

.sample-label {
  flex-grow: 1;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sample-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.delete-sample-btn {
  background-color: transparent;
  border: none;
  color: #c0392b;
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  border-radius: 4px;
  transition: background 0.2s, transform 0.1s;
}

.delete-sample-btn:hover {
  background-color: #fdd;
  transform: scale(1.1);
}

.edit-sample-btn {
  margin-left: 5px;
  font-size: 0.8em;
  background: none;
  border: none;
  cursor: pointer;
}


.cmd-group strong {
  margin-right: 4px;
  font-size: 0.9rem;
}

.cmd-group select,
.cmd-group input {
  font-size: 0.85rem;
  padding: 3px 4px;
}

.cmd-group button {
  font-size: 0.85rem;
  padding: 3px 8px;
}

#toolbar {
  display: flex;
  justify-content: space-between;
  flex-direction: row;
  gap: 0.5rem;
  padding: 0.5rem;
  background: #f8f8f8;
  border-bottom: 1px solid #ccc;
}

#command-panels {
  margin-left: 5px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-start;
  padding: 0.2rem;
  box-sizing: border-box;
  background: #fff;
}


.cmd-group {
  margin: 1px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.1rem;
  padding: 0.1rem;
  border-radius: 4px;
}

.cmd-group input,

.cmd-group select {
  max-width: 90px;
  padding: 3px 6px;
  font-size: 0.85em;
}

.cmd-group button {
  padding: 4px 10px;
  font-size: 0.85em;
}

.edge-switch {
  --track-w: 42px;
  --track-h: 22px;
  --knob-d: 18px;

  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  font: 14px/1 sans-serif;
}

.edge-switch>input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.edge-switch .slider {
  position: relative;
  width: var(--track-w);
  height: var(--track-h);
  background: #ccc;
  border-radius: var(--track-h);
  transition: background 0.2s;
}

.edge-switch .slider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 2px;
  width: var(--knob-d);
  height: var(--knob-d);
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.4);
  transform: translateY(-50%);
  transition: left 0.2s;
}

.edge-switch>input:checked+.slider {
  background: #42b983;
}

.edge-switch>input:checked+.slider::before {
  left: calc(100% - var(--knob-d) - 2px);
}

.edge-switch>input:focus+.slider {
  outline: 2px solid #42b983;
  outline-offset: 2px;
}

.edge-switch__label {
  white-space: nowrap;
}


.cmd-group {
  display: flex;
  gap: 0.25rem;
  align-items: center;

  font: 600 16px/1.25;
}

.cmd-group input[list] {
  border: 0.5px solid #666;
  border-radius: 4px;
  min-width: 10ch;
}

.cmd-group input[list]::-webkit-calendar-picker-indicator {
  opacity: 0.35;
}

.cmd-group input[list]:hover::-webkit-calendar-picker-indicator {
  opacity: 0.7;
}


.sentence-box {
  background: #f9f9f9;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: .6rem;
  min-width: 240px;
  max-width: 300px;
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width:600px) {
  .cmd-column {
    flex: 1 1 100%;
    max-width: 100%;
  }
}

.yarn-editor {
  white-space: pre-wrap;
  outline: none;
  resize: vertical;
  border: 1px solid var(--ui-border, #7b8994);
  border-radius: 4px;
  padding: 8px;
  font-family: monospace;
  line-height: 1.4;
  min-height: 8rem;
  background: #fff;
  color: var(--ui-text, #47525d);
}

.yarn-editor.invalid {
  border-color: #c0392b;
  background: #ffeeee30;
}

.yarn-error {
  color: #c0392b;
  font-size: .85em;
  margin: 4px 0 0;
}

.string {
  color: #1b2ce3;
}

.key {
  color: #d90606;
}

.number {
  color: #9d4edd;
}

.boolean {
  color: #15803d;
}

.null {
  color: #47525d;
  font-style: italic;
}

#error-box {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
}

dialog {
  border: none;
  border-radius: 8px;
  padding: 1.5rem 2rem;
  max-width: 420px;
  box-shadow: 0 10px 32px rgb(0 0 0 / .35);
}

.dlg label {
  display: block;
  margin: 1rem 0 .5rem;
  font-weight: 600;
}

.dlg input,
.dlg textarea {
  width: 100%;
  padding: .5rem;
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  font-family: inherit;
}

.dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  margin-top: 1rem;
}

.dlg-actions .primary {
  background: var(--ui-accent);
  color: #fff;
  border: none;
  padding: .5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
}

#yarn {
  min-height: 0;
  flex: 1;
  margin: 0;
  padding: .5rem;
  border: 1px solid #d0d7de;
  border-radius: 0 0 .4rem .4rem;
  font-family: monospace;
  font-size: .85rem;
  line-height: 1.25;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

.yarn-editor-panel {
  flex: 0 0 25%;
  display: flex;
  flex-direction: column;
}

.yarn-toolbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem .6rem;
  background: #f6f8fa;
  border: 1px solid #d0d7de;
  border-bottom: none;
}

.yarn-toolbar .spacer {
  flex: 1;
}

.yarn-toolbar button,
#sentence-view button {
  font: inherit;
  line-height: 1.15;
  padding: .25rem .5rem;
  cursor: pointer;
}

.yarn-toolbar button:disabled,
#sentence-view button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.yt-dropdown {
  position: relative;
  display: inline-block;
}

.yt-dropdown>summary {
  list-style: none;
  cursor: pointer;
  padding: var(--ui-pad);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  background: var(--ui-bg);
  color: var(--ui-text);
  transition: background-color .15s, border-color .15s;
  user-select: none;
}

.yt-dropdown>summary:hover,
.yt-dropdown[open]>summary {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: var(--ui-bg);
}

.yt-dropdown[open]>summary {
  outline: none;
}

.yt-dropdown-menu,
.yt-menu {
  position: absolute;
  right: 0;
  top: calc(100% + .25rem);
  min-width: 140px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .08);
  padding: .25rem 0;
  z-index: 1000;
}

.yt-item {
  display: block;
  min-width: 12rem;
  text-align: left;
  padding: .35rem 1rem;
  border: none;
  background: none;
  font: inherit;
  color: var(--ui-text);
  cursor: pointer;
}

.yt-item:hover {
  background: var(--ui-accent);
  color: var(--ui-bg);
}

.yt-item:focus-visible,
.yt-dropdown>summary:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
}

.yt-item[data-export] {
  font-size: 1rem;
}

.yt-subheader {
  margin: 0;
  padding: .45rem 1rem .25rem;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #374151;
  border-top: 1px solid var(--ui-border);
}

.file-label {
  display: flex;
  align-items: center;
}

.sample-actions {
  margin-left: auto;
}

/* Inactivate input if S node type is selected */
#add-node-form input[name="n-label"] {
  pointer-events: auto;
  opacity: 1;
}

#add-node-form:has(select[name="n-type"] option[value="s"]:checked) input[name="n-label"] {
  pointer-events: none;
  opacity: .45;
  background: #f4f4f4;
}

.rel-wrapper {
  position: relative;
  display: inline-block;
}

.rel-wrapper input {
  padding-right: 1.5rem;
}

.rel-wrapper .caret {
  position: absolute;
  right: .5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: .72rem;
  cursor: pointer;
  color: #666;
  user-select: none;
}

ul.dl-box {
  position: absolute;
  z-index: 9999;
  border: 1px solid #cbd5e1;
  background: #fff;
  list-style: none;
  margin: 0;
  padding: 3px 0;
  max-height: 220px;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 200px;
  max-width: 280px;
  width: max-content;
  box-sizing: border-box;
}

ul.dl-box li {
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
}

ul.dl-box li:hover {
  background: #e8ecf1;
}


.cmd-group input,
.cmd-group select,
.cmd-group button {
  font-size: .85rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #fff;
}

.cmd-group :is(input, select, button):focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

select.type-selector {
  width: 3rem;
  min-width: 3rem;
  text-align: center;
  background-position: right .4rem center;
  background-size: 8px 5px;
  padding-right: 1.3rem;
}

.cmd-group select {
  appearance: none;
  -moz-appearance: none;
  background-repeat: no-repeat;
  background-position: right .5rem center;
  background-size: 10px 6px;
  padding-right: 1.7rem;
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6' stroke='%23000' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'><path d='M1 1l4 4 4-4'/></svg>")
}

#save-sentence-btn {
  font-size: .85rem;
  padding: .35rem .6rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
}

#save-sentence-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.selection-view {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  min-width: 0;
}

.selection-view code {
  max-width: 140px;
  display: inline-block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}