*, *::before, *::after { box-sizing: border-box; }

body, html {
  margin: 0; padding: 0;
  width: 100vw; height: 100vh;
  overflow: hidden;
  background: #fff;
  color: #333;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 11px;
  line-height: 1.8;
}

/* ===== UTILITY ===== */
.hidden { display: none !important; }

/* ===== TOOLBAR ===== */
#toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  gap: 8px;
  z-index: 100;
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(0,0,0,0.07);
}
#toolbar-left  { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
#toolbar-center { flex: 1; display: flex; justify-content: center; }
#toolbar-right  { display: flex; align-items: center; gap: 5px; flex: 0 0 auto; }

#app-title {
  font-size: 11px;
  font-weight: 600;
  color: #333;
  letter-spacing: 0.3px;
}

.toolbar-btn {
  background: none;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 5px;
  padding: 3px 9px;
  font-size: 10px;
  color: #777;
  cursor: pointer;
  transition: all 0.14s;
  font-family: inherit;
  line-height: 1.5;
  display: flex; align-items: center; gap: 4px;
  white-space: nowrap;
}
.toolbar-btn:hover { background: rgba(0,0,0,0.04); color: #444; border-color: rgba(0,0,0,0.18); }
.toolbar-btn:active { background: rgba(0,0,0,0.08); }

/* ===== PILL LAYOUT TOGGLE ===== */
.pill-toggle {
  background: rgba(0,0,0,0.03) !important;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 20px;
  padding: 1.5px !important;
  gap: 0 !important;
}
.pill-toggle:hover {
  background: rgba(0,0,0,0.06) !important;
  border-color: rgba(0,0,0,0.15);
}
.toggle-option {
  padding: 2.5px 8px;
  font-size: 10px;
  color: #777;
  border-radius: 15px;
  transition: all 0.15s ease;
  line-height: 1.4;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  user-select: none;
}
.toggle-option.active {
  background: #222;
  color: #fff;
}

/* ===== TREE VIEW ===== */
#tree-view {
  position: absolute;
  top: 36px; left: 0; right: 0;
  height: calc(100vh - 36px);
  overflow: auto;
  background: #fff;
}

#tree-lines {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}
#tree-lines path {
  stroke: rgba(0,0,0,0.13);
  stroke-width: 1.2;
}

#tree-container {
  position: relative;
  z-index: 2;
  min-width: 100%;
  min-height: 100%;
}

/* ===== EMPTY STATE ===== */
#empty-state {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: rgba(0,0,0,0.3);
}
#empty-state p {
  margin: 0 0 12px;
  font-size: 12px;
}
#empty-state .hint {
  font-size: 10px;
  color: rgba(0,0,0,0.2);
  margin-top: 8px;
}
#empty-state .hint kbd {
  background: rgba(0,0,0,0.06);
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 9px;
}
#btn-empty-new {
  background: #333;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 20px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.14s;
}
#btn-empty-new:hover { background: #555; }

/* ===== TREE NODE ===== */
.tree-node {
  position: absolute;
  display: flex;
  align-items: center;
  z-index: 2;
}

.node-box {
  border: 1.2px solid rgba(0,0,0,0.1);
  border-radius: 5px;
  padding: 7px 14px;
  background: #fff;
  cursor: default;
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
  position: relative;
}

/* Highlight (keyboard cursor) */
.node-box.highlighted {
  border-color: #333;
  box-shadow: 0 0 0 1.5px rgba(0,0,0,0.08);
}

/* Editing */
.node-box.editing {
  border-color: #555;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.06);
  background: #fafafa;
}

.node-text {
  outline: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.6;
  caret-color: #333;
  min-height: 1.2em;
}
.node-text:empty::before {
  content: attr(data-placeholder);
  color: rgba(0,0,0,0.2);
  pointer-events: none;
}

/* Completed (strikethrough) */
.node-box.completed .node-text {
  text-decoration: line-through;
  color: rgba(0,0,0,0.3);
}
.node-box.completed {
  border-color: rgba(0,0,0,0.06);
  background: rgba(0,0,0,0.01);
}

/* ===== DEPTH-BASED FONT SIZES (shallow hierarchy optimized) ===== */
.depth-0 .node-text { font-size: 15px; font-weight: 600; }
.depth-1 .node-text { font-size: 13px; font-weight: 500; }
.depth-2 .node-text { font-size: 12px; }
.depth-3 .node-text { font-size: 11px; color: #555; }

/* Depth-based max-width */
.depth-1 .node-box { max-width: 250px; }
.depth-2 .node-box { max-width: 230px; }
.depth-3 .node-box { max-width: 210px; }

/* ===== SAVE INDICATOR ===== */
#save-indicator {
  position: fixed; bottom: 10px; right: 14px;
  font-size: 9px; color: rgba(0,0,0,0.2);
  z-index: 200; transition: opacity 0.5s;
}

/* ===== TOAST ===== */
#toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,0.72); color: #fff;
  padding: 6px 18px; border-radius: 6px; font-size: 11px;
  opacity: 0; transition: opacity 0.22s, transform 0.22s;
  z-index: 500; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== HELP MODAL ===== */
#help-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 300;
}
#help-modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  z-index: 310;
  width: 380px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(0,0,0,0.07);
  font-size: 12px;
  font-weight: 600;
  color: #333;
}
.modal-close {
  background: none; border: none;
  cursor: pointer; font-size: 14px;
  color: rgba(0,0,0,0.3);
  padding: 2px 4px; border-radius: 3px;
  transition: color 0.14s;
}
.modal-close:hover { color: #c44; }
.modal-body {
  padding: 12px 16px 20px;
}
.modal-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.modal-body th {
  text-align: left;
  padding: 4px 8px;
  color: #999;
  font-weight: 500;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.modal-body td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  color: #444;
}
.modal-body td:first-child {
  white-space: nowrap;
  color: #666;
}
.modal-body kbd {
  background: rgba(0,0,0,0.06);
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 9px;
}
