/* the Notes app: tab bar, editor, status bar, file lists, close panel */

/* ---------- layout ---------- */

#app-notes {
  display: grid;
  grid-template-rows: var(--bar-h) minmax(0, 1fr) auto var(--status-h);
  min-width: 0;
  min-height: 0;
}

.tabbar { grid-row: 1; }
.editor, .nothing { grid-row: 2; }
.close-panel { grid-row: 3; }
.status { grid-row: 4; }

/* ---------- tab bar ---------- */

.tabbar {
  display: flex;
  min-width: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.tb-add {
  flex: none;
  width: 36px;
  height: auto;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--border);
  font-size: 17px;
}

.tabs {
  flex: 1;
  display: flex;
  min-width: 0;
  overflow: auto hidden;
}

.tab {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 240px;
  padding: 0 4px 0 12px;
  border-top: 2px solid transparent;
  border-right: 1px solid var(--border);
  color: var(--muted);
  cursor: default;
  user-select: none;
}

.tab:hover { background: var(--hover); color: var(--fg); }
.tab.active { background: var(--surface); color: var(--fg); border-top-color: var(--accent); }
.tab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.dirty .tab-name::after { content: " •"; color: var(--accent); }
.tab.err .tab-name { color: var(--danger); }

.tab-x {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  line-height: 1;
  color: var(--muted);
  visibility: hidden;
}

.tab:hover .tab-x, .tab.active .tab-x { visibility: visible; }
.tab-x:hover { background: var(--danger); color: #fff; }

.tab.drop-before { box-shadow: inset 2px 0 0 var(--accent); }
.tab.drop-after { box-shadow: inset -2px 0 0 var(--accent); }

.tab-rename { width: 160px; height: 22px; padding: 0 4px; font-family: var(--mono); }

.nothing {
  overflow: auto;
  padding: 24px 16px;
  background: var(--panel);
}

.nothing-box { max-width: 820px; margin: 0 auto; }
.nothing-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.nothing-title { flex: 1; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.nothing-head button { height: 28px; padding: 0 14px; border-color: var(--border); }
.nothing-head .primary { border-color: var(--accent); }

/* ---------- editor ---------- */

.editor {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
  font: var(--fs, 14px)/1.5 var(--mono);
  tab-size: var(--tab, 4);
}

.gutter {
  overflow: hidden;
  background: var(--gutter);
  border-right: 1px solid var(--border);
  color: var(--gutter-fg);
  text-align: right;
  user-select: none;
}

.gutter-inner { position: relative; padding: 6px 8px 6px 10px; white-space: pre; will-change: transform; }

/* wrap mode: only the visible numbers, placed at measured line tops */
.gutter-inner > div { position: absolute; left: 10px; right: 8px; }

.editor textarea {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 6px 12px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--fg);
  font: inherit;
  tab-size: inherit;
  white-space: pre;
  overflow: auto;
}

.editor.wrap textarea { white-space: pre-wrap; overflow-wrap: break-word; overflow-x: hidden; }
.editor textarea::selection { background: var(--sel); }

.mirror {
  position: absolute;
  top: 0;
  left: 0;
  visibility: hidden;
  pointer-events: none;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

/* ---------- close panel ---------- */

.close-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--panel);
  border-top: 2px solid var(--accent);
}

.close-panel input { flex: 1; min-width: 240px; height: 26px; padding: 0 6px; font-family: var(--mono); }
.close-panel button { height: 26px; border-color: var(--border); }
.close-panel .primary { border-color: var(--accent); }

/* ---------- status bar ---------- */

.status {
  display: flex;
  align-items: stretch;
  overflow: hidden;
  background: var(--panel);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status > * {
  display: flex;
  align-items: center;
  height: auto;
  padding: 0 10px;
  border: 0;
  border-right: 1px solid var(--border);
}

.status > .spacer { flex: 1; padding: 0; }
.status > button { color: var(--fg); }
.status .st-num { min-width: 34px; justify-content: center; font-variant-numeric: tabular-nums; }
.status .toggle.on { background: var(--accent); color: var(--accent-fg); }
.st-save[data-kind="busy"] { color: var(--fg); }
.st-save[data-kind="err"] { color: var(--danger); font-weight: 600; }
.st-field { gap: 6px; }
.st-field input { width: 40px; height: 18px; padding: 0 2px; }

/* files dialog */

.file-filter { width: 100%; height: 28px; margin-bottom: 8px; padding: 0 8px; }
.file-list { border: 1px solid var(--border); background: var(--surface); }

.file-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto 28px;
  gap: 14px;
  align-items: center;
  height: 28px;
  padding-left: 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.file-row:last-child { border-bottom: 0; }
.file-row:hover, .file-row:focus { background: var(--hover); outline: none; }
.fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); }
.file-row.open .fname::before { content: "● "; color: var(--accent); }
.fmeta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.fdel { width: 28px; height: 27px; padding: 0; color: var(--muted); }
.fdel:hover { background: var(--danger); color: #fff; }
.empty { padding: 16px; color: var(--muted); text-align: center; }
