:root {
  --icon-bar-width: 48px;
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #081012;
  color: #e8f7ef;
  accent-color: #00d19a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, rgba(0, 209, 154, 0.14), transparent 25%),
    radial-gradient(circle at bottom right, rgba(27, 231, 161, 0.08), transparent 20%),
    #071014;
}

button,
textarea {
  font: inherit;
}

button {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 60px minmax(220px, 260px) minmax(0, 1fr);
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns 0.25s ease;
}

@media (min-width: 981px) {
  .app-shell.sidebar-collapsed {
    grid-template-columns: 60px 0 minmax(0, 1fr);
  }

  .sidebar {
    transform: none;
    transition: opacity 0.25s ease, padding 0.25s ease, border-right-color 0.25s ease;
  }

  .sidebar.closed {
    transform: none;
  }

  .app-shell.sidebar-collapsed .sidebar {
    padding-left: 0;
    padding-right: 0;
    border-right-color: transparent;
    overflow: hidden;
  }
}

.icon-bar {
  position: relative;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 18px 0;
  background: rgba(8, 16, 18, 0.98);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.icon-spacer {
  flex: 1;
  width: 100%;
}

.icon-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: transparent;
}

.icon-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  transition: background 0.24s ease, transform 0.2s ease;
}

.icon-bar .icon-button:last-child {
  margin-top: auto;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: rgba(0, 209, 154, 0.12);
  transform: translateY(-1px);
}

.icon-button.active {
  background: rgba(0, 209, 154, 0.18);
}

.icon-button .icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.icon {
  font-size: 1.2rem;
}

.sidebar {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: rgba(10, 20, 24, 0.95);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  transition: transform 0.25s ease, opacity 0.25s ease, padding 0.25s ease, border-right-color 0.25s ease;
  transform-origin: left center;
  min-height: 0;
  height: 100%;
}

.sidebar.closed {
  transform: translateX(calc(-100% + var(--icon-bar-width)));
  opacity: 0;
  pointer-events: none;
}

.sidebar-header h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.sidebar-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
  align-items: center;
}

.sidebar-icon-button,
.sidebar-action {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(0, 209, 154, 0.12);
  color: inherit;
  font-weight: 700;
  cursor: pointer;
}

.sidebar-icon-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  position: relative;
  border-radius: 12px;
}

.sidebar-icon-button .icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.sidebar-icon-button::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(8, 16, 18, 0.96);
  color: #e8f7ef;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  transform-origin: center top;
  transform: translateX(-50%) translateY(4px);
}

.sidebar-icon-button:hover::after,
.sidebar-icon-button:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.sidebar-icon-button .icon {
  font-size: 1.2rem;
}

.sidebar-tree {
  overflow-y: auto;
  padding-right: 4px;
  flex: 1;
  min-height: 0;
  overscroll-behavior: contain;
}

.sidebar-content[hidden] {
  display: none !important;
}

.sidebar-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  flex: 1;
  min-height: 0;
  overscroll-behavior: contain;
}

.history-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.history-item {
  position: relative;
  border-radius: 12px;
  background: rgba(11, 19, 23, 0.92);
}

.history-item + .history-item::before {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: -5px;
  height: 1px;
  background: rgba(232, 247, 239, 0.14);
}

.history-item-button {
  width: 100%;
  padding: 6px 8px;
  border-radius: 12px;
  background: transparent;
  border-bottom: #00d19a;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  cursor: pointer;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.history-item-button:hover,
.history-item-button:focus-visible {
  background: rgba(0, 209, 154, 0.08);
}

.history-label {
  font-weight: 400;
  word-break: break-word;
}

.history-time {
  color: rgba(232, 247, 239, 0.72);
  font-size: 0.75rem;
}

.tree-root,
.tree-children {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-root {
  display: grid;
  gap: 2px;
}

.tree-children {
  display: grid;
  gap: 1px;
  margin-top: 2px;
  padding-left: 10px;
}

.tree-node {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 4px;
  border-radius: 8px;
  background: rgba(11, 19, 23, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.06);
  cursor: grab;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.tree-node:hover {
  background: rgba(15, 26, 32, 0.96);
}

.tree-node.dragging {
  opacity: 0.5;
}

.tree-node.folder > .node-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px;
}

.node-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.node-label {
  font-size: 0.92rem;
  line-height: 1.4;
  color: #edf7ee;
}

.tree-node.folder .node-label {
  font-weight: 600;
}

.tree-node.template .node-label {
  color: rgba(237, 247, 238, 0.88);
}

.folder-toggle {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(0, 209, 154, 0.08);
  color: #9fead8;
  border: none;
  cursor: pointer;
}

.tree-node.template {
  padding-left: 8px;
}

.tree-node.drop-target {
  border-color: rgba(0, 209, 154, 0.45);
  box-shadow: 0 0 0 2px rgba(0, 209, 154, 0.12);
}

.tree-root.drop-target {
  outline: 2px dashed rgba(0, 209, 154, 0.35);
  outline-offset: 4px;
}

.hover-preview {
  position: fixed;
  z-index: 15;
  width: min(360px, 45vw);
  max-width: 420px;
  padding: 18px;
  border-radius: 20px;
  background: rgba(8, 16, 18, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.hover-preview.open {
  opacity: 1;
  transform: translateY(0);
}

.hover-preview .preview-label {
  margin: 0 0 8px;
  color: rgba(255, 255, 255, 0.64);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.hover-preview h3 {
  margin: 0 0 12px;
  font-size: 1rem;
  line-height: 1.3;
}

.hover-preview pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 0.94rem;
  line-height: 1.55;
  color: #d9f7ea;
}

.hover-preview.empty::before {
  content: 'No preview available.';
  display: block;
  color: rgba(255, 255, 255, 0.6);
}

.sidebar.drop-target {
  outline: 2px dashed rgba(0, 209, 154, 0.35);
  outline-offset: -4px;
}

.sidebar-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.template-card {
  padding: 14px;
  border-radius: 16px;
  background: rgba(14, 30, 36, 0.82);
  border: 1px solid rgba(0, 209, 154, 0.12);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.template-card:hover {
  transform: translateY(-1px);
  border-color: rgba(0, 209, 154, 0.18);
}

.template-card.active {
  border-color: #00d19a;
  box-shadow: 0 12px 28px rgba(0, 209, 154, 0.11);
}

.template-card h2 {
  margin: 0 0 6px;
  font-size: 0.98rem;
}

.template-card p {
  margin: 0;
  color: #b7e7ce;
  line-height: 1.4;
  font-size: 0.94rem;
}

.main-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 32px;
  min-height: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.label {
  margin: 0 0 6px;
  color: #7dcfa6;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.75rem;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.75rem;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.action-button {
  padding: 12px 20px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(0, 209, 154, 0.95), rgba(10, 188, 143, 0.92));
  color: #02110d;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.action-button:hover,
.action-button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.34), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.action-button-secondary {
  background: rgba(0, 209, 154, 0.16);
  color: #d8ffef;
}

#copyTemplateButton {
  min-width: 9.5rem;
}

.action-button.copied {
  animation: copySheen 0.55s ease-out;
  background: linear-gradient(135deg, rgba(44, 224, 162, 0.95), rgba(19, 186, 131, 0.93));
  background-size: 160% 160%;
  color: #022114;
}

@keyframes copySheen {
  0% {
    background-position: 45% 50%;
    filter: brightness(1);
  }
  55% {
    background-position: 58% 50%;
    filter: brightness(1.05);
  }
  100% {
    background-position: 50% 50%;
    filter: brightness(1);
  }
}

.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
}

textarea {
  width: 100%;
  flex: 1;
  min-height: 0;
  padding: 22px;
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(6, 13, 16, 0.96);
  color: #e8f7ef;
  resize: vertical;
  line-height: 1.75;
  outline: none;
  overflow: auto;
}

textarea::placeholder {
  color: #6a8d7b;
}

textarea,
.sidebar-tree,
.history-list,
.modal-textarea {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 209, 154, 0.22) rgba(255, 255, 255, 0.06);
}

textarea::-webkit-scrollbar,
.sidebar-tree::-webkit-scrollbar,
.history-list::-webkit-scrollbar,
.modal-textarea::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

textarea::-webkit-scrollbar-track,
.sidebar-tree::-webkit-scrollbar-track,
.history-list::-webkit-scrollbar-track,
.modal-textarea::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 999px;
}

textarea::-webkit-scrollbar-thumb,
.sidebar-tree::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb,
.modal-textarea::-webkit-scrollbar-thumb {
  background: rgba(0, 209, 154, 0.24);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

textarea::-webkit-scrollbar-thumb:hover,
.sidebar-tree::-webkit-scrollbar-thumb:hover,
.modal-textarea::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 209, 154, 0.55);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(1, 10, 16, 0.76);
  z-index: 20;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.context-menu {
  position: fixed;
  z-index: 25;
  min-width: 180px;
  border-radius: 18px;
  overflow: hidden;
  background: rgba(8, 16, 18, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 24px 56px rgba(0, 0, 0, 0.32);
  padding: 8px 0;
  display: none;
}

.context-menu.open {
  display: block;
}

.context-menu button {
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  font-size: 0.95rem;
  cursor: pointer;
}

.context-menu button:hover,
.context-menu button:focus-visible {
  background: rgba(0, 209, 154, 0.12);
}

.modal {
  width: min(100%, 520px);
  max-height: 90vh;
  overflow: hidden;
  border-radius: 28px;
  background: rgba(8, 16, 18, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.35);
}

.modal-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 36px;
  height: 36px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  border: none;
  cursor: pointer;
}

.modal-body {
  min-height: 220px;
  max-height: calc(90vh - 56px);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.modal-form {
  display: grid;
  gap: 12px;
}

#modalTitle {
  margin: 0 0 4px;
}

.modal-label {
  display: block;
  color: #b7e7ce;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.modal-text {
  color: #d5f5dd;
  line-height: 1.6;
}

.modal-textarea {
  width: 100%;
  min-height: 160px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(6, 13, 16, 0.96);
  color: #e8f7ef;
  outline: none;
  resize: vertical;
}

.import-drop-zone {
  min-height: 140px;
  border: 2px dashed rgba(0, 209, 154, 0.35);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 22px;
  color: rgba(232, 247, 239, 0.78);
  transition: background 0.2s ease, border-color 0.2s ease;
  cursor: pointer;
}

.import-drop-zone.drag-over {
  background: rgba(0, 209, 154, 0.08);
  border-color: rgba(0, 209, 154, 0.75);
}

.import-error-message {
  margin: 0;
}

.modal-textarea:focus {
  border-color: rgba(0, 209, 154, 0.55);
  box-shadow: 0 0 0 4px rgba(0, 209, 154, 0.09);
}

.modal-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(6, 13, 16, 0.96);
  color: #e8f7ef;
  outline: none;
}

.modal-input:focus {
  border-color: rgba(0, 209, 154, 0.55);
  box-shadow: 0 0 0 4px rgba(0, 209, 154, 0.09);
}

.github-repo-row {
  display: grid;
  gap: 6px;
}

.github-repo-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.github-refresh-button,
.github-sync-now {
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(0, 209, 154, 0.15);
  color: inherit;
  font-weight: 700;
}

.github-status {
  min-height: 24px;
  color: #9bffb3;
  font-size: 0.95rem;
}

.settings-section {
  border: 1px solid rgba(0, 209, 154, 0.12);
  border-radius: 20px;
  background: rgba(10, 18, 24, 0.94);
  overflow: hidden;
}

.settings-section summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  color: #e8f7ef;
  font-weight: 700;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.settings-section summary::-webkit-details-marker {
  display: none;
}

.settings-section summary::after {
  content: '▾';
  transition: transform 0.2s ease;
}

.settings-section[open] summary::after {
  transform: rotate(180deg);
}

.settings-section-body {
  display: grid;
  gap: 12px;
  padding: 16px 18px 18px;
}

.settings-actions {
  justify-content: flex-end;
}

.export-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-submit,
.modal-cancel {
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(0, 209, 154, 0.15);
  color: inherit;
  font-weight: 700;
}

.modal-cancel {
  background: rgba(255, 255, 255, 0.08);
}

.modal-submit:hover,
.modal-cancel:hover {
  transform: translateY(-1px);
}

@media (max-width: 980px) {
  :root {
    --icon-bar-width: 48px;
  }

  .app-shell {
    grid-template-columns: 48px 1fr;
  }

  .sidebar {
    position: absolute;
    left: 48px;
    top: 0;
    bottom: 0;
    width: min(78vw, 320px);
    z-index: 10;
  }

  .main-panel {
    padding: 24px;
    gap: 18px;
  }

  .panel-header {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 14px;
  }

  .action-button {
    width: 100%;
    max-width: 240px;
  }

  .panel-actions {
    width: 100%;
    max-width: 500px;
  }

  .panel-actions .action-button {
    flex: 1;
    max-width: none;
  }
}

@media (max-width: 720px) {
  :root {
    --icon-bar-width: 0px;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    min-height: 100dvh;
    height: 100dvh;
  }

  .icon-bar {
    grid-row: 2;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-right: none;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }

  .icon-logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex: 0 0 auto;
  }

  .icon-spacer {
    display: none;
  }

  .icon-bar .icon-button:last-child {
    margin-top: 0;
  }

  .sidebar {
    left: 0;
    top: 0;
    bottom: 66px;
    width: min(88vw, 360px);
    padding: 14px;
    box-shadow: 0 0 0 100vmax rgba(1, 8, 13, 0.45), 18px 0 40px rgba(0, 0, 0, 0.28);
    transition: transform 0.25s ease, opacity 0.25s ease, padding 0.25s ease, border-right-color 0.25s ease, box-shadow 0.25s ease;
  }

  .sidebar.closed {
    transform: translateX(-100%);
    box-shadow: none;
  }

  .main-panel {
    grid-row: 1;
    padding: 16px;
    gap: 14px;
    overflow: auto;
  }

  .panel-header h2 {
    font-size: 1.45rem;
  }

  .action-button {
    max-width: none;
    width: 100%;
    padding: 11px 16px;
  }

  .panel-actions {
    gap: 8px;
  }

  .editor-panel {
    min-height: 0;
  }

  .main-panel {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  textarea {
    border-radius: 20px;
    padding: 16px;
    min-height: 300px;
    line-height: 1.6;
  }

  .hover-preview {
    display: none;
  }

  .sidebar-icon-button::after {
    display: none;
  }

  .modal-overlay {
    padding: 12px;
  }

  .modal {
    border-radius: 20px;
  }

  .modal-body {
    padding: 16px;
    max-height: calc(92vh - 52px);
  }
}
