*:focus {
  outline-style: dashed;
  outline-color: black;
  outline-width: 2px;
  outline-offset: 2px;
}

body {
  font-family: "Helvetica Neue Regular", sans-serif;
  font-size: 14px;
  margin: 0;
  padding-top: 40px; /* space for fixed menu bar */
  padding-bottom: 24px; /* space for fixed status bar */
}

.hidden {
  display: none !important;
}

.welcome {
  text-align: center;
  padding: 40px;
}

.file-view {
  padding: 20px;
}

.btn {
  padding: 10px 20px;
  font-size: 14px;
  border: 2px solid rgb(178, 178, 253);
  border-radius: 8px;
  background: white;
  cursor: pointer;
}

.btn:hover {
  background: rgb(240, 240, 255);
}

.drop-zone {
  border: 2px dashed rgb(178, 178, 253);
  border-radius: 8px;
  padding: 40px;
  margin: 20px auto;
  max-width: 400px;
}

.drop-zone.drag-over {
  background-color: rgb(240, 240, 255);
}

.welcome-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.flex-container {
  display: flex;
  flex-direction: column;
  margin-left: 20px;
  overflow: hidden;
  align-items: flex-start;
}

.flex-item {
  display: flex;
  flex-direction: column;
  padding: 10px 8px 0 0;
  border-left: 2px solid rgb(178, 178, 253);
  transition: transform 0.2s ease, max-height 0.2s ease;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}

.flex-item:last-child {
  border-left: none;
}

.flex-item-content {
  position: relative;
  min-height: 20px;
  display: flex;
  align-items: center;
  width: fit-content;
  border: 2px solid rgb(178, 178, 253);
  border-radius: 8px;
  padding: 5px 15px 5px 10px;
  margin-left: 10px;
  background-color: rgb(178, 178, 253);
  cursor: pointer;
}

.flex-item-content::before {
  content: '';
  position: absolute;
  left: -12px;
  width: 10px;
  top: 0%;
  transform: translateY(-50%);
  height: 100%;
  border-bottom: 2px solid rgb(178, 178, 253);
  border-left: none;
}

.flex-item:last-child > .flex-item-content::before {
  border-left: 2px solid rgb(178, 178, 253);
  width: 12px;
  margin-left: -2px;
}

.flex-item:last-child > .flex-item-content {
  margin-left: 12px;
}

#tree-container > .flex-item > .flex-item-content::before {
  border: none;
}

.flex-item-content::after {
  content: '+';
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translate(80%, -50%);
  font-size: 16px;
  color: #666;
  border-radius: 50%;
  background-color: #f0f0f0;
  width: 15px;
  height: 15px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgb(178, 178, 253);
  display: none;
}

.flex-item-content:not(:last-child)::after,
.flex-item-content.folded::after {
  display: flex;
}

.flex-item-content:not(.folded)::after {
  content: '-';
}

.flex-item-content.folded::after {
  content: '+';
}

.flex-item-content + .flex-container {
  transition: max-height 0.2s ease;
}

/* ===================================================================
   Selection
   =================================================================== */

.flex-item-content.selected {
  background-color: #d3e9f9;
}

/* ===================================================================
   Drag-and-drop
   =================================================================== */

.flex-item.dragging {
  opacity: 0.5;
  border-left: none;
}

.flex-item[draggable="true"] {
  cursor: move;
}

/* Hide connector line on the dragged item's content */
.flex-item.dragging > .flex-item-content::before {
  border-bottom: none;
}

/* Last-child connector adjustments for dragged items */
.flex-item.dragging:last-child > .flex-item-content::before {
  border-left: none;
}

/* ===================================================================
   Menu Bar
   =================================================================== */

.menu-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  background: #f5f5f5;
  border-bottom: 1px solid #e0e0e0;
  padding: 0 12px;
  user-select: none;
  flex-shrink: 0;
  z-index: 1000;
  min-width: 0;
}

.menu-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.app-name {
  font-weight: 600;
  font-size: 13px;
  color: #007aff;
  letter-spacing: 0.5px;
  text-decoration: none;
}

.menu-bar-center {
  display: flex;
  align-items: center;
  gap: 0;
  min-width: 0;
  flex-shrink: 1;
}

.menu-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  justify-content: flex-end;
  flex-shrink: 1;
}

.file-name {
  font-size: 12px;
  color: #888;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 3px;
  font-weight: 500;
}

.save-status.saved { color: #34c759; }
.save-status.saving { color: #ff9500; }
.save-status.unsaved { color: #666; }
.save-status.error { color: #ff3b30; }

/* Menu Items */

.menu-item {
  position: relative;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
  color: #333;
}

.menu-item:focus,
.menu-item:focus-visible,
.menu-dropdown:focus {
  background: #e0e0e0;
  outline: none;
}

/* Open menu item — needs strong contrast against the #f5f5f5 menu bar
   to be visible on touch devices (iPad/Android) where :hover is excluded
   and the native tap-highlight disappears on release. */
.menu-item.open {
  background: #cccccc;
  outline: none;
}

/* :hover only on devices that truly support hover (mouse/trackpad).
   On touch devices :hover is sticky and cannot be cleared via JS,
   so we rely on .open class only. */
@media (hover: hover) {
  .menu-item:hover,
  .menu-dropdown:hover {
    background: #e0e0e0;
  }
}

.menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 220px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  padding: 4px;
  z-index: 1001;
}

.menu-item.open .menu-dropdown {
  display: block;
}

.menu-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.menu-entry:focus {
  outline: none;
}

.menu-entry:focus-visible {
  background: #007aff;
  color: #fff;
  outline: none;
}

.menu-entry:focus-visible .menu-shortcut {
  color: #fff;
  opacity: 0.7;
}

/* :hover only on devices that truly support hover (mouse/trackpad). */
@media (hover: hover) {
  .menu-entry:hover {
    background: #007aff;
    color: #fff;
  }

  .menu-entry:hover .menu-shortcut {
    color: #fff;
    opacity: 0.7;
  }
}

.menu-label {
  flex: 1;
}

.menu-shortcut {
  font-size: 11px;
  color: #888;
  font-family: monospace;
  margin-left: 24px;
}

.menu-separator {
  height: 1px;
  background: #e0e0e0;
  margin: 4px 8px;
}

/* Checkable menu entries (View → Status Bar, View → Toolbar) */

.menu-entry.checkable {
  position: relative;
  padding-left: 24px;
}

.menu-entry.checkable.checked::before {
  content: "\2713";
  position: absolute;
  left: 4px;
  font-size: 13px;
  color: #333;
}

/* Status Bar */

.status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 24px;
  background: #f5f5f5;
  border-top: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 12px;
  color: #333;
  z-index: 100;
}

.status-item {
  margin-right: 16px;
}

.status-selected-count {
  margin-left: auto;
  margin-right: 0;
  color: #666;
}

/* Responsive */

@media (max-width: 600px) {
  .menu-bar-left .app-name { display: none; }
  .menu-bar-right .file-name { max-width: 80px; }
}


/* About Dialog */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 28px 32px 24px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  color: #333;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e0e0e0;
}

.modal-subtitle {
  margin: 0 0 16px;
  font-size: 13px;
  color: #888;
}

.btn-ghost {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: #888;
  padding: 2px 6px;
  border-radius: 4px;
}

.btn-ghost:hover {
  color: #333;
  background: #f0f0f0;
}

.btn-secondary {
  background: #f5f5f5;
  color: #333;
  border: 1px solid #e0e0e0;
}

.btn-secondary:hover {
  background: #e8e8e8;
}

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.about-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 14px;
}

.about-table td {
  padding: 4px 0;
  vertical-align: top;
}

.about-table td + td {
  padding-left: 16px;
}

.about-label {
  color: #888;
  padding-right: 16px;
  white-space: nowrap;
  width: 1%;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.about-footer {
  margin: 0;
  font-size: 12px;
  color: #888;
  text-align: center;
  user-select: none;
  cursor: default;
}

/* ===================================================================
   PWA: Update Toast, Diagnostics Overlay, Version Footer
   =================================================================== */

.btn-primary {
  background: #007aff;
  color: #fff;
  border: 1px solid #007aff;
}

.btn-primary:hover {
  background: #0066d6;
}

.btn-sm {
  padding: 4px 12px;
  font-size: 13px;
  border-radius: 6px;
}

/* Update Toast */

.update-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  z-index: 3000;
  font-size: 14px;
  color: #333;
}

.update-toast-text {
  white-space: nowrap;
}

/* SW Diagnostics Overlay */

.sw-overlay {
  position: fixed;
  top: 8px;
  right: 8px;
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12px;
  color: #333;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 3100;
  width: 280px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sw-overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e0e0e0;
}

.sw-overlay-row {
  display: flex;
  justify-content: space-between;
}

.sw-overlay-label { color: #888; }
.sw-overlay-value { font-family: monospace; text-align: right; }
.sw-overlay-ok { color: #34c759; }
.sw-overlay-warn { color: #ff9500; }
.sw-overlay-err { color: #ff3b30; }

.sw-overlay-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.sw-overlay-log {
  font-family: monospace;
  font-size: 11px;
  color: #888;
  max-height: 140px;
  overflow-y: auto;
  border-top: 1px solid #e0e0e0;
  padding-top: 6px;
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ------------------------------------------------------------------ */
/* Touch Toolbar (touch devices only)                                 */
/* ------------------------------------------------------------------ */

.touch-toolbar {
    position: fixed;
    bottom: 0; /* JS adjusts this to 24px when status bar is visible */
    left: 0;
    right: 0;
    height: 44px;
    display: flex;
    align-items: center;
    padding: 0 8px;
    background: #f5f5f5;
    border-top: 1px solid #e0e0e0;
    z-index: 100;
    gap: 4px;
    box-sizing: border-box;
}

.touch-toolbar.hidden {
    display: none !important;
}

.touch-toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.touch-toolbar-divider {
    width: 1px;
    height: 28px;
    background: #e0e0e0;
    margin: 0 6px;
    flex-shrink: 0;
    margin-left: auto; /* pin action group to the right */
}

.touch-toolbar-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 16px;
    line-height: 1;
    color: #333;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.touch-toolbar-btn:active {
    background: #d0d0d0;
}

.touch-toolbar-btn:disabled {
    opacity: 0.3;
    pointer-events: none;
}

@media (hover: hover) {
    .touch-toolbar-btn:hover {
        background: #e8e8e8;
    }
}

/* On very narrow screens, shrink labelled buttons to icons only */
@media (max-width: 400px) {
    .touch-toolbar-btn[data-action="add-child"],
    .touch-toolbar-btn[data-action="add-sibling"] {
        font-size: 0;
        min-width: 36px;
        padding: 0;
    }
    .touch-toolbar-btn[data-action="add-child"]::before { content: "+"; font-size: 16px; }
    .touch-toolbar-btn[data-action="add-sibling"]::before { content: "\21B5"; font-size: 16px; }
}

/* ------------------------------------------------------------------ */
/* Disabled menu entries                                              */
/* ------------------------------------------------------------------ */

.menu-entry.disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* ------------------------------------------------------------------ */
/* Search Bar                                                          */
/* ------------------------------------------------------------------ */

.search-bar {
    position: fixed;
    top: 40px;
    left: 0;
    right: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #f5f5f5;
    border-bottom: 1px solid #e0e0e0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    box-sizing: border-box;
}

.search-bar.hidden {
    display: none;
}

.search-icon {
    font-size: 14px;
    opacity: 0.5;
}

.search-input {
    flex: 1;
    min-width: 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 14px;
    outline: none;
    background: #fff;
}

.search-input:focus {
    border-color: #007aff;
}

.search-input.no-results {
    border-color: #ff3b30;
}

.search-scope-btn {
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 12px;
    background: #fff;
    color: #333;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    white-space: nowrap;
}

@media (hover: hover) {
    .search-scope-btn:hover {
        background: #e8e8e8;
    }
}

.search-scope-btn:active {
    background: #d0d0d0;
}

.search-scope-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.search-counter {
    font-size: 12px;
    color: #666;
    min-width: 50px;
    text-align: center;
    white-space: nowrap;
}

.search-nav-btn {
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 28px;
    height: 28px;
    background: #fff;
    color: #333;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

@media (hover: hover) {
    .search-nav-btn:hover {
        background: #e8e8e8;
    }
}

.search-nav-btn:active {
    background: #d0d0d0;
}

.search-nav-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.search-close-btn {
    border: none;
    background: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
    padding: 0 4px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.search-close-btn:active {
    color: #000;
}

.search-match {
    background: #ffeb3b !important;
    box-shadow: 0 0 0 2px #f5a623;
}
