/* ============================================================
   Self Monitoring Journal: Windows 3.x theme
   Palette and widgets follow the home dashboard's Win 3.1 shell.
   ============================================================ */

[hidden] { display: none !important; }

:root {
  --wallpaper: linear-gradient(135deg, #008a9a 0%, #006a74 60%, #00535c 100%);
  --window: #c3c3c3;
  --window-light: #dfdfdf;
  --window-lighter: #f7f7f7;
  --window-dark: #7b7b7b;
  --window-darker: #4b4b4b;
  --paper: #ffffff;
  --text: #050505;
  --text-soft: #333333;
  --text-muted: #5b5b5b;
  --accent: #0a64ad;
  --accent-light: #4c94d6;
  --accent-dark: #073c75;
  --accent-soft: #feffc1;
  --ok: #1f7a1f;
  --warn: #b9732f;
  --danger: #9b1a1a;
  --shadow-window: 4px 4px 0 #000;
  --font-ui: "MS Sans Serif", "Tahoma", "Geneva", "Verdana", sans-serif;
  --font-mono: "Fixedsys", "Lucida Console", "Consolas", monospace;
  --taskbar-height: 34px;
}

/* ---------- Base ---------- */

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.35;
  color: var(--text);
  background: var(--wallpaper);
  background-attachment: fixed;
}

h1, h2, h3 { margin: 0 0 6px; font-weight: 700; color: var(--text-soft); }
h1 { font-size: 18px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }
p { margin: 0 0 8px; }

a, a:visited { color: var(--accent-dark); }
a:hover { color: var(--accent); }

::selection { background: var(--accent); color: #fff; }

::-webkit-scrollbar { width: 16px; height: 16px; }
::-webkit-scrollbar-track { background: var(--window-light); }
::-webkit-scrollbar-thumb {
  background: var(--window);
  border: 2px solid;
  border-color: var(--window-lighter) var(--window-darker) var(--window-darker) var(--window-lighter);
}
::-webkit-scrollbar-corner { background: var(--window); }

:focus-visible { outline: 1px dotted #000; outline-offset: 1px; }

.icon { display: inline-flex; width: 16px; height: 16px; flex: 0 0 16px; }
.icon svg { width: 100%; height: 100%; display: block; }

/* ---------- Buttons ---------- */

button, .button {
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.2;
  color: var(--text);
  background: var(--window-light);
  border: 2px solid;
  border-color: var(--window-lighter) var(--window-darker) var(--window-darker) var(--window-lighter);
  box-shadow: 0 0 0 1px #000;
  border-radius: 2px;
  padding: 3px 12px;
  margin: 1px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}
a.button, a.button:visited { color: var(--text); }
button:active:not(:disabled), .button:active, button.pressed, .button.pressed {
  border-color: var(--window-darker) var(--window-lighter) var(--window-lighter) var(--window-darker);
  background: var(--window);
}
button:active:not(:disabled) > *, .button:active > * { transform: translate(1px, 1px); }
button:disabled { color: var(--window-dark); cursor: default; text-shadow: 1px 1px 0 var(--window-lighter); }
button.default { box-shadow: 0 0 0 2px #000; }
button.danger { color: var(--danger); }
button.small { padding: 1px 6px; font-size: 12px; }
button.icon-btn { padding: 2px; min-width: 22px; min-height: 22px; }
button.flat {
  border-color: transparent;
  box-shadow: none;
  background: transparent;
}
button.flat:hover { border-color: var(--window-lighter) var(--window-darker) var(--window-darker) var(--window-lighter); }

/* ---------- Form fields ---------- */

input[type="text"], input[type="password"], input[type="search"], input[type="date"],
input[type="time"], input[type="number"], input[type="month"], textarea, select {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text);
  background: var(--paper);
  border: 2px solid;
  border-color: var(--window-darker) var(--window-lighter) var(--window-lighter) var(--window-darker);
  border-radius: 0;
  padding: 3px 4px;
  width: 100%;
  min-width: 0;
}
input:disabled, textarea:disabled { background: var(--window-light); color: var(--text-muted); }
textarea { resize: vertical; line-height: 1.35; }
input:focus, textarea:focus, select:focus { outline: 1px dotted #000; outline-offset: -4px; }

/* Win 3.1 check boxes draw an X, not a tick. */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  margin: 0;
  background: var(--paper);
  border: 2px solid;
  border-color: var(--window-darker) var(--window-lighter) var(--window-lighter) var(--window-darker);
  box-shadow: inset 1px 1px 0 #000;
  cursor: pointer;
  vertical-align: middle;
  position: relative;
}
input[type="checkbox"]:checked {
  background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M1 1L9 9M9 1L1 9' stroke='%23000' stroke-width='1.6'/%3E%3C/svg%3E") center / 9px 9px no-repeat;
}
input[type="checkbox"]:disabled { background-color: var(--window-light); cursor: default; }

.field-row { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 6px; margin-bottom: 8px; }
.field-row > span { color: var(--text-soft); }
.field-stack { display: flex; flex-direction: column; gap: 3px; margin-bottom: 10px; }
.field-stack > span, .field-label { font-size: 12px; color: var(--text-soft); }
.check-row { display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* Etched Win 3.1 group box */
fieldset, .groupbox {
  border: 1px solid var(--window-dark);
  box-shadow: 1px 1px 0 var(--window-lighter), inset 1px 1px 0 var(--window-lighter);
  margin: 0 0 10px;
  padding: 10px 10px 10px;
  min-width: 0;
}
/* The legend gets the window colour so it hides the etched (box-shadow) line
   behind it. Browsers only gap a fieldset's border for the legend, not its
   shadows; Firefox otherwise draws that line straight through the title. */
legend {
  position: relative;
  padding: 0 4px;
  font-weight: 700;
  color: var(--text-soft);
  background: var(--window);
}

.hint, .muted { color: var(--text-muted); font-size: 12px; }
.msg-error { color: var(--danger); font-weight: 700; }
.msg-empty { color: var(--text-muted); padding: 12px; text-align: center; }

/* ---------- Windows ---------- */

.window {
  background: var(--window);
  border: 2px solid;
  border-color: var(--window-light) var(--window-darker) var(--window-darker) var(--window-light);
  box-shadow: var(--shadow-window), 0 0 0 1px #000;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 22px;
  padding: 1px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  user-select: none;
  border-bottom: 1px solid #000;
}
.titlebar-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 6px;
}
/* Control-menu box (left) and min/max buttons (right). */
.titlebar-box, .titlebar-btn {
  flex: 0 0 auto;
  height: 18px;
  min-width: 20px;
  background: var(--window);
  border: 1px solid #000;
  color: #000;
  font-size: 8px;
  line-height: 16px;
  text-align: center;
  position: relative;
  box-shadow: inset 1px 1px 0 var(--window-lighter), inset -1px -1px 0 var(--window-dark);
}
.titlebar-box::after {
  content: "";
  position: absolute;
  left: 4px; right: 4px; top: 7px;
  height: 3px;
  background: var(--window-lighter);
  border: 1px solid #000;
  box-shadow: 1px 1px 0 var(--window-darker);
}
button.titlebar-btn { padding: 0 3px; margin: 0; border-radius: 0; font-size: 12px; font-weight: 700; line-height: 1; }

.window-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 6px;
  border-bottom: 1px solid var(--window-dark);
  box-shadow: 0 1px 0 var(--window-lighter);
}
.toolbar .spacer { flex: 1; }
.toolbar label { display: inline-flex; align-items: center; gap: 5px; }

.statusbar {
  display: flex;
  gap: 4px;
  padding: 3px 4px;
  font-size: 12px;
  border-top: 1px solid var(--window-lighter);
}
.statusbar > span {
  padding: 1px 6px;
  border: 1px solid;
  border-color: var(--window-dark) var(--window-lighter) var(--window-lighter) var(--window-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.statusbar > .grow { flex: 1; }

/* Sunken white panel, e.g. list boxes and tree views */
.sunken {
  background: var(--paper);
  border: 2px solid;
  border-color: var(--window-darker) var(--window-lighter) var(--window-lighter) var(--window-darker);
  box-shadow: inset 1px 1px 0 #000;
}

/* ---------- Desktop + taskbar ---------- */

.app-body { overflow: hidden; }

#desktop {
  position: fixed;
  inset: 0 0 var(--taskbar-height) 0;
  padding: 8px 12px 12px 8px;
}
.app-window { position: absolute; inset: 8px 12px 12px 8px; }

.taskbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--taskbar-height);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  background: var(--window);
  border-top: 2px solid var(--window-lighter);
  box-shadow: 0 -1px 0 var(--window-dark);
  z-index: 1000;
}
.taskbar-tasks { display: flex; gap: 4px; flex: 1; min-width: 0; }
.task-btn, .task-btn:visited {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text);
  background: var(--window-light);
  border: 2px solid;
  border-color: var(--window-lighter) var(--window-darker) var(--window-darker) var(--window-lighter);
  padding: 2px 10px;
  height: 26px;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  cursor: pointer;
  border-radius: 0;
  box-shadow: none;
  margin: 0;
}
.task-btn.active {
  border-color: var(--window-darker) var(--window-lighter) var(--window-lighter) var(--window-darker);
  background: repeating-conic-gradient(var(--window-lighter) 0 25%, var(--window-light) 0 50%) 0 0 / 2px 2px;
  font-weight: 700;
}
.task-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.taskbar-status { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.taskbar-status.saving { color: var(--warn); font-weight: 700; }
.taskbar-status.error { color: var(--danger); font-weight: 700; }
.taskbar-clock {
  font-size: 12px;
  padding: 2px 8px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  border: 1px solid;
  border-color: var(--window-dark) var(--window-lighter) var(--window-lighter) var(--window-dark);
  white-space: nowrap;
}

/* ---------- Menus ---------- */

.menu {
  position: fixed;
  z-index: 5000;
  min-width: 180px;
  max-width: 320px;
  margin: 0;
  padding: 2px;
  list-style: none;
  background: var(--window);
  border: 2px solid;
  border-color: var(--window-light) var(--window-darker) var(--window-darker) var(--window-light);
  box-shadow: 2px 2px 0 #000, 0 0 0 1px #000;
  font-size: 13px;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 18px 4px 22px;
  white-space: nowrap;
  cursor: default;
  position: relative;
}
.menu-item .menu-key { margin-left: auto; padding-left: 18px; color: inherit; opacity: .75; }
.menu-item.active { background: var(--accent); color: #fff; }
.menu-item.danger.active { background: var(--danger); }
.menu-item.disabled { color: var(--window-dark); text-shadow: 1px 1px 0 var(--window-lighter); }
.menu-item.disabled.active { background: transparent; color: var(--window-dark); }
.menu-item.checked::before { content: "\2713"; position: absolute; left: 7px; }
.menu-sep { height: 0; margin: 3px 2px; border-top: 1px solid var(--window-dark); border-bottom: 1px solid var(--window-lighter); }

/* ---------- Dialogs ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.35);
}
.dialog {
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - 32px);
}
.dialog.wide { max-width: 760px; }
.dialog .dialog-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px 14px 10px;
}
.dialog .dialog-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.dialog .dialog-footer .spacer { flex: 1; }
.dialog .dialog-footer button { min-width: 76px; }

.msgbox { display: flex; gap: 14px; align-items: flex-start; }
.msgbox-icon {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border: 2px solid #000;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 700 20px/1 Georgia, serif;
  background: #fff;
  color: var(--accent);
}
.msgbox-icon.warn { border-radius: 0; background: var(--accent-soft); color: #000; clip-path: polygon(50% 0, 100% 100%, 0 100%); border: 0; padding-top: 8px; font-size: 16px; }
.msgbox-icon.stop { background: var(--danger); color: #fff; border-color: #000; }
.msgbox-text { flex: 1; padding-top: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Color picker */
.swatches { display: grid; grid-template-columns: repeat(8, 28px); gap: 6px; margin-bottom: 12px; }
.swatch {
  width: 28px;
  height: 22px;
  padding: 0;
  margin: 0;
  border-radius: 0;
  border: 2px solid;
  border-color: var(--window-darker) var(--window-lighter) var(--window-lighter) var(--window-darker);
  box-shadow: inset 0 0 0 1px #000;
}
.swatch.selected { outline: 2px solid #000; outline-offset: 2px; }
.swatch-none { background: var(--paper) linear-gradient(to top right, transparent 46%, var(--danger) 47% 53%, transparent 54%); }
.color-custom { display: flex; align-items: center; gap: 8px; }
.color-custom input[type="color"] { width: 48px; height: 26px; padding: 0 2px; border: 2px solid; border-color: var(--window-darker) var(--window-lighter) var(--window-lighter) var(--window-darker); background: var(--window-light); cursor: pointer; }

.color-chip {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 1px solid #000;
  background: var(--paper);
  vertical-align: middle;
}
.color-chip.none { background: var(--paper) linear-gradient(to top right, transparent 44%, var(--danger) 45% 55%, transparent 56%); }

/* ---------- Toasts ---------- */

.toasts {
  position: fixed;
  right: 14px;
  bottom: calc(var(--taskbar-height) + 14px);
  z-index: 6000;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: 360px;
  padding: 6px 10px;
  background: var(--accent-soft);
  border: 1px solid #000;
  box-shadow: 2px 2px 0 #000;
  font-size: 12px;
  animation: toast-in 120ms ease-out;
}
.toast.error { background: #ffd8d8; color: var(--danger); font-weight: 700; }
.toast.ok { background: #e2f6e2; }
@keyframes toast-in { from { transform: translateY(6px); opacity: 0; } }

/* ---------- Progress bar (Win 3.1 Setup style) ---------- */

.progress {
  position: relative;
  height: 18px;
  background: var(--paper);
  border: 1px solid #000;
  box-shadow: inset 1px 1px 0 var(--window-dark);
  overflow: hidden;
  font-size: 11px;
  font-weight: 700;
}
.progress-fill { position: absolute; inset: 0 auto 0 0; background: var(--bar, var(--accent)); }
/* Failed items: a red section after the done part, hatched so it reads in greyscale too. */
.progress-failed {
  position: absolute;
  top: 0;
  bottom: 0;
  background: repeating-linear-gradient(135deg, var(--danger) 0 4px, #c84a4a 4px 6px);
}
.progress-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
}
/* Second copy of the label in white, clipped to the filled part. */
.progress-label.inverse { color: #fff; }
.progress.thin { height: 8px; }
.progress.thin .progress-label { display: none; }
.progress.complete .progress-fill { background: var(--ok); }

/* ---------- Split layout + resizer ---------- */

.split { flex: 1; min-height: 0; display: flex; }
.split-resizer {
  flex: 0 0 6px;
  cursor: col-resize;
  background: var(--window);
  border-left: 1px solid var(--window-lighter);
  border-right: 1px solid var(--window-dark);
}
.split-resizer:hover, .split-resizer.dragging { background: var(--accent); }

/* ============================================================
   NOTES
   ============================================================ */

.notes-sidebar {
  flex: 0 0 auto;
  width: 270px;
  min-width: 180px;
  max-width: 60%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
}
.notes-sidebar .sidebar-buttons { display: flex; gap: 4px; flex-wrap: wrap; }
.notes-sidebar .sidebar-buttons button { flex: 1; }
.notes-search { position: relative; }
.notes-search input { padding-right: 24px; }
.notes-search button {
  position: absolute; right: 3px; top: 3px;
  width: 18px; height: 18px; min-height: 0; min-width: 0;
  padding: 0; margin: 0; font-size: 10px; box-shadow: none;
}
.tree-scroll { flex: 1; min-height: 0; overflow: auto; padding: 2px 0; }
.tree-scroll:focus { outline: none; }

.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin-left: 15px; }
.tree ul > li { position: relative; padding-left: 12px; }
/* File Manager style connector lines */
.tree ul > li::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  border-left: 1px dotted var(--window-darker);
}
.tree ul > li:last-child::before { bottom: auto; height: 11px; }
.tree ul > li::after {
  content: "";
  position: absolute;
  left: 0; top: 11px;
  width: 10px;
  border-top: 1px dotted var(--window-darker);
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 6px 0 2px;
  white-space: nowrap;
  cursor: default;
  user-select: none;
  position: relative;
}
.tree-row .tree-label { overflow: hidden; text-overflow: ellipsis; padding: 1px 2px; }
.tree-row.selected .tree-label { background: var(--accent); color: #fff; }
.tree-scroll:focus-within .tree-row.selected .tree-label { outline: 1px dotted #000; outline-offset: 0; }
.tree-row.notebook { font-weight: 700; }
.tree-row.notebook .tree-label { border-left: 4px solid var(--nb-color, transparent); padding-left: 4px; }
.tree-toggle {
  flex: 0 0 11px;
  width: 11px;
  height: 11px;
  border: 1px solid var(--window-darker);
  background: var(--paper);
  font: 700 10px/9px var(--font-mono);
  text-align: center;
  cursor: pointer;
  color: #000;
}
.tree-toggle.empty { visibility: hidden; }
.tree-row.drop-before { box-shadow: inset 0 2px 0 #000; }
.tree-row.drop-after { box-shadow: inset 0 -2px 0 #000; }
.tree-row.drop-inside .tree-label { background: var(--accent-soft); outline: 1px dashed #000; color: #000; }
.tree-row.dragging { opacity: .45; }
.tree-rename { height: 20px; padding: 1px 3px; font-size: 13px; width: 100%; }

.search-results { list-style: none; margin: 0; padding: 0; }
.search-results li { padding: 5px 8px; border-bottom: 1px dotted var(--window-dark); cursor: pointer; }
.search-results li:hover, .search-results li.active { background: var(--accent); color: #fff; }
.search-results li:hover .muted, .search-results li.active .muted { color: #e6eef7; }
.search-results .result-title { font-weight: 700; display: flex; gap: 5px; align-items: center; }
.search-results mark { background: var(--accent-soft); color: #000; }

.notes-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 6px 6px 6px 4px;
  gap: 6px;
}
.page-header { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.page-crumbs { flex: 1 1 100%; font-size: 12px; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: 2px; align-items: center; min-height: 16px; }
.page-crumbs a { color: var(--text-muted); text-decoration: none; cursor: pointer; }
.page-crumbs a:hover { color: var(--accent); text-decoration: underline; }
.page-title-input {
  flex: 1;
  min-width: 140px;
  font-size: 18px !important;
  font-weight: 700;
  border-left-width: 8px !important;
  border-left-color: var(--page-color, var(--window-darker)) !important;
}
.save-status { font-size: 12px; color: var(--text-muted); min-width: 86px; text-align: right; white-space: nowrap; }
.save-status.dirty { color: var(--warn); }
.save-status.error { color: var(--danger); font-weight: 700; }

.empty-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  text-align: center;
  padding: 20px;
}
.empty-pane .icon { width: 32px; height: 32px; flex-basis: 32px; }

.sidebar-toggle { display: none; }

/* ============================================================
   EDITOR (Quill restyle)
   ============================================================ */

.editor-host { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.editor-host .ql-toolbar.ql-snow {
  font-family: var(--font-ui);
  background: var(--window);
  border: 0;
  border-bottom: 1px solid var(--window-dark);
  padding: 3px 2px 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 3px 0;
}
.editor-host .ql-toolbar.ql-snow .ql-formats {
  margin-right: 6px;
  padding-right: 6px;
  border-right: 1px solid var(--window-dark);
  box-shadow: 1px 0 0 var(--window-lighter);
  display: inline-flex;
  align-items: center;
  gap: 1px;
}
.editor-host .ql-toolbar.ql-snow .ql-formats:last-child { border-right: 0; box-shadow: none; }
.editor-host .ql-toolbar.ql-snow button {
  width: 26px;
  height: 24px;
  padding: 3px 4px;
  margin: 0;
  border: 2px solid;
  border-color: var(--window-lighter) var(--window-darker) var(--window-darker) var(--window-lighter);
  background: var(--window-light);
  box-shadow: none;
  border-radius: 0;
}
.editor-host .ql-toolbar.ql-snow button:hover { background: var(--window-lighter); }
.editor-host .ql-toolbar.ql-snow button.ql-active,
.editor-host .ql-toolbar.ql-snow button:active {
  border-color: var(--window-darker) var(--window-lighter) var(--window-lighter) var(--window-darker);
  background: repeating-conic-gradient(var(--window-lighter) 0 25%, var(--window-light) 0 50%) 0 0 / 2px 2px;
}
.editor-host .ql-snow .ql-stroke { stroke: #000; }
.editor-host .ql-snow .ql-fill { fill: #000; }
.editor-host .ql-snow.ql-toolbar button:hover .ql-stroke,
.editor-host .ql-snow.ql-toolbar button.ql-active .ql-stroke,
.editor-host .ql-snow.ql-toolbar .ql-picker-label:hover .ql-stroke,
.editor-host .ql-snow.ql-toolbar .ql-picker-label.ql-active .ql-stroke,
.editor-host .ql-snow.ql-toolbar .ql-picker-item:hover .ql-stroke { stroke: var(--accent-dark); }
.editor-host .ql-snow.ql-toolbar button:hover .ql-fill,
.editor-host .ql-snow.ql-toolbar button.ql-active .ql-fill,
.editor-host .ql-snow.ql-toolbar .ql-picker-label:hover .ql-fill,
.editor-host .ql-snow.ql-toolbar .ql-picker-label.ql-active .ql-fill { fill: var(--accent-dark); }
.editor-host .ql-snow.ql-toolbar button:hover, .editor-host .ql-snow.ql-toolbar .ql-picker-label:hover,
.editor-host .ql-snow.ql-toolbar .ql-picker-label.ql-active, .editor-host .ql-snow.ql-toolbar button.ql-active { color: var(--accent-dark); }

.editor-host .ql-snow .ql-picker { height: 24px; font-size: 12px; color: #000; }
.editor-host .ql-snow .ql-picker-label {
  border: 2px solid;
  border-color: var(--window-darker) var(--window-lighter) var(--window-lighter) var(--window-darker) !important;
  background: var(--paper);
  padding-left: 4px;
}
.editor-host .ql-snow .ql-color-picker .ql-picker-label,
.editor-host .ql-snow .ql-icon-picker .ql-picker-label {
  background: var(--window-light);
  border-color: var(--window-lighter) var(--window-darker) var(--window-darker) var(--window-lighter) !important;
  padding: 1px 3px;
}
.editor-host .ql-snow .ql-picker.ql-expanded .ql-picker-options {
  border: 1px solid #000 !important;
  box-shadow: 2px 2px 0 #000;
  background: var(--paper);
  padding: 2px;
  z-index: 20;
}
.editor-host .ql-snow .ql-picker-item:hover { color: var(--accent); }
.editor-host .ql-snow .ql-picker.ql-header .ql-picker-options,
.editor-host .ql-snow .ql-picker.ql-font .ql-picker-options,
.editor-host .ql-snow .ql-picker.ql-size .ql-picker-options { max-height: 300px; overflow-y: auto; }
.editor-host .ql-snow .ql-color-picker .ql-picker-item { border: 1px solid var(--window-dark); }
.editor-host .ql-toolbar.ql-snow .ql-disabled-group { opacity: .35; pointer-events: none; }

.editor-host .ql-container.ql-snow {
  flex: 1;
  min-height: 0;
  border: 0;
  background: var(--paper);
  font-family: var(--font-ui);
  font-size: 14px;
  overflow: hidden;
}
.editor-frame {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 2px solid;
  border-color: var(--window-darker) var(--window-lighter) var(--window-lighter) var(--window-darker);
  box-shadow: inset 1px 1px 0 #000;
  background: var(--paper);
}
.editor-host .ql-editor { padding: 14px 18px 40px; line-height: 1.5; overflow-y: auto; height: 100%; }
.editor-host .ql-editor.ql-blank::before { color: var(--window-dark); font-style: normal; left: 18px; }
.editor-host .ql-editor img { max-width: 100%; height: auto; cursor: default; }
.editor-host .ql-editor img.img-selected { outline: 2px dashed var(--accent); outline-offset: 2px; }
.editor-host .ql-editor pre.ql-syntax, .editor-host .ql-editor .ql-code-block-container {
  background: #000; color: #c0c0c0; font-family: var(--font-mono); border-radius: 0; padding: 8px 10px;
}
.editor-host .ql-editor code { background: var(--window-light); padding: 0 3px; font-family: var(--font-mono); border-radius: 0; }
.editor-host .ql-editor blockquote { border-left: 4px solid var(--window-dark); padding-left: 12px; color: var(--text-soft); }
.editor-host .ql-editor hr { border: 0; border-top: 1px solid var(--window-dark); border-bottom: 1px solid var(--window-lighter); margin: 12px 0; }
.editor-host .ql-editor table { border-collapse: collapse; table-layout: fixed; width: 100%; margin: 6px 0; }
.editor-host .ql-editor td { border: 1px solid var(--window-dark); padding: 3px 6px; min-width: 40px; vertical-align: top; }
.editor-host .ql-editor li[data-list="checked"] { color: var(--text-muted); text-decoration: line-through; }
.editor-host .ql-editor a { color: var(--accent-dark); }
.editor-host .ql-snow .ql-tooltip {
  border: 2px solid;
  border-color: var(--window-light) var(--window-darker) var(--window-darker) var(--window-light);
  box-shadow: 2px 2px 0 #000;
  background: var(--window);
  color: #000;
  border-radius: 0;
  z-index: 30;
}
.editor-host .ql-snow .ql-tooltip input[type="text"] { border: 2px solid; border-color: var(--window-darker) var(--window-lighter) var(--window-lighter) var(--window-darker); height: 24px; }
.editor-host .ql-snow .ql-tooltip a.ql-action, .editor-host .ql-snow .ql-tooltip a.ql-remove { color: var(--accent-dark); }

/* Custom toolbar icons (undo, redo, divider, table) are drawn by editor.js. */
.editor-host .ql-toolbar button svg { pointer-events: none; }

/* ============================================================
   GOALS
   ============================================================ */

.goals-scroll { flex: 1; min-height: 0; overflow: auto; padding: 12px; background: var(--window-light); }
.goal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  align-items: start;
}
.goal-card {
  cursor: pointer;
  box-shadow: 3px 3px 0 #000, 0 0 0 1px #000;
  text-align: left;
}
.goal-card:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 #000, 0 0 0 1px #000; }
.goal-card:focus-visible { outline: 2px dotted #000; outline-offset: 3px; }
.goal-card.archived { opacity: .7; }
.goal-card .titlebar { background: var(--goal-color, var(--accent)); color: var(--goal-ink, #fff); }
.goal-card .titlebar-title { text-align: left; }
.goal-card-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 8px; }
.goal-desc {
  margin: 0;
  color: var(--text-soft);
  font-size: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.goal-stages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.goal-stages li { display: grid; grid-template-columns: 18px 1fr 54px 38px; align-items: center; gap: 6px; }
.goal-stages .stage-num {
  width: 16px; height: 16px;
  border: 1px solid #000;
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper);
}
.goal-stages .stage-num.done { background: var(--ok); color: #fff; }
.goal-stages .stage-num.partial { background: linear-gradient(to top, var(--accent-light) 50%, var(--paper) 50%); }
.goal-stages .stage-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.goal-stages .stage-count { text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.goal-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--text-muted); }
.goal-meta .overdue { color: var(--danger); font-weight: 700; }
.goal-new {
  min-height: 140px;
  border: 2px dashed var(--window-dark);
  background: transparent;
  box-shadow: none;
  color: var(--text-soft);
  font-weight: 700;
  flex-direction: column;
  gap: 6px;
}
.goal-new:hover { background: var(--window-lighter); }

/* Board sections (weekly + overall) */
.board-section { margin-bottom: 22px; }
.board-heading {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 12px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--window-dark);
  box-shadow: 0 1px 0 var(--window-lighter);
}
.board-heading h2 { margin: 0 6px 0 0; font-size: 15px; }
.board-heading .week-label { color: var(--text-soft); }
.board-heading .spacer { flex: 1; }
.board-heading button { margin: 0; }
.week-badge {
  flex: 0 0 auto;
  margin-right: 3px;
  padding: 0 5px;
  font-size: 11px;
  background: var(--window);
  color: #000;
  border: 1px solid #000;
  box-shadow: inset 1px 1px 0 var(--window-lighter), inset -1px -1px 0 var(--window-dark);
}

/* Goal dialog: view mode */
.goal-week { margin: 0; color: var(--text-soft); }
.goal-past-note { margin: 0; padding: 6px 8px; background: var(--accent-soft); border: 1px solid var(--window-dark); font-size: 12px; }
.goal-history { display: flex; flex-direction: column; gap: 4px; }
.history-bars { display: flex; gap: 4px; align-items: flex-end; overflow-x: auto; padding-bottom: 2px; }
.history-week {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 2px;
  margin: 0;
  min-width: 30px;
  box-shadow: none;
  border-color: transparent;
  background: transparent;
}
.history-week:hover { border-color: var(--window-lighter) var(--window-darker) var(--window-darker) var(--window-lighter); }
.history-week.current { border-color: var(--window-darker) var(--window-lighter) var(--window-lighter) var(--window-darker); background: var(--window-lighter); }
.history-bar { position: relative; width: 16px; height: 36px; background: var(--paper); border: 1px solid #000; }
.history-fill { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent); }
.history-week.full .history-fill { background: var(--ok); }
.history-failed { position: absolute; left: 0; right: 0; background: var(--danger); }
.history-label { font-size: 10px; }

/* Goal dialog: edit mode, type choice */
.kind-choice { display: flex; flex-wrap: wrap; gap: 6px 20px; }
.kind-option { display: flex; align-items: flex-start; gap: 6px; flex: 1 1 220px; cursor: pointer; }
.kind-option input { margin-top: 2px; }
.kind-change { flex: 1 1 100%; margin: 4px 0 0; padding: 6px 8px; background: var(--accent-soft); border: 1px solid var(--window-dark); font-size: 12px; }

/* Win 3.1 option (radio) buttons */
input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 13px;
  width: 13px;
  height: 13px;
  margin: 0;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid #000;
  box-shadow: inset 1px 1px 0 var(--window-dark);
  cursor: pointer;
  position: relative;
}
input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: #000;
}
.goal-head { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.goal-head .goal-desc-full { white-space: pre-wrap; color: var(--text-soft); margin: 0; }
.goal-head .goal-meta { font-size: 12px; }
.roadmap { list-style: none; margin: 0; padding: 0; }
.roadmap-stage { position: relative; padding: 0 0 14px 36px; }
.roadmap-stage::before {
  content: "";
  position: absolute;
  left: 11px; top: 24px; bottom: 0;
  border-left: 2px dotted var(--window-darker);
}
.roadmap-stage:last-child::before { display: none; }
.roadmap-marker {
  position: absolute;
  left: 0; top: 0;
  width: 24px; height: 24px;
  border: 2px solid #000;
  background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.roadmap-marker.done { background: var(--ok); color: #fff; }
.roadmap-marker.partial { background: linear-gradient(to top, var(--accent-light) var(--pct, 50%), var(--paper) var(--pct, 50%)); }
.roadmap-head { display: flex; align-items: center; gap: 10px; min-height: 24px; margin-bottom: 4px; }
.roadmap-head h3 { margin: 0; flex: 1; font-size: 14px; }
.roadmap-head .progress { width: 120px; flex: 0 0 120px; }
.check-tree, .check-tree ul { list-style: none; margin: 0; padding: 0; }
.check-tree ul { padding-left: 22px; }
.check-item { display: flex; align-items: flex-start; gap: 7px; padding: 2px 0; }
.check-item input { margin-top: 2px; }
.check-item label { cursor: pointer; overflow-wrap: anywhere; }
.check-item.done > label { color: var(--text-muted); text-decoration: line-through; }
.check-item.parent > label { font-weight: 700; }
.check-tree .busy { opacity: .6; }
.check-item.failed > label { color: var(--danger); }
.check-item.failed > input[type="checkbox"] { background-color: #ffd8d8; }

/* The ✗ "mark failed" button next to each item (view and edit mode). */
.fail-btn {
  flex: 0 0 auto;
  min-width: 0;
  height: 18px;
  padding: 0 4px;
  margin: 0 0 0 4px;
  font-size: 11px;
  line-height: 1;
  box-shadow: none;
  opacity: .45;
}
.check-item:hover > .fail-btn, .edit-row:hover > .fail-btn, .fail-btn:focus-visible { opacity: 1; }
.fail-btn.on {
  opacity: 1;
  background: var(--danger);
  color: #fff;
  border-color: #5c0e0e #e08a8a #e08a8a #5c0e0e;
}
.fail-btn:disabled { opacity: .25; }
.edit-row .fail-btn { margin: 0; }
.edit-row.failed input[type="text"] { color: var(--danger); }

/* Goal dialog: edit mode */
.goal-form-grid { display: grid; grid-template-columns: 1fr 160px; gap: 0 12px; }
.goal-form-grid .span-2 { grid-column: 1 / -1; }
.color-field { display: flex; align-items: center; gap: 6px; }
.edit-list { margin-bottom: 12px; }
.edit-list legend { display: flex; align-items: center; gap: 6px; }
.edit-list-head { display: flex; gap: 4px; align-items: center; margin-bottom: 8px; }
.edit-list-head .stage-label { font-weight: 700; white-space: nowrap; }
.edit-list-head input { font-weight: 700; }
.edit-rows { display: flex; flex-direction: column; gap: 3px; }
.edit-row { display: flex; align-items: center; gap: 4px; }
.edit-row input[type="text"] { flex: 1; padding: 2px 4px; }
.edit-row .row-btns { display: flex; gap: 0; }
.edit-row .row-btns button { min-width: 22px; height: 22px; padding: 0 3px; margin: 0 0 0 2px; font-size: 11px; box-shadow: none; }
.edit-row.has-children input[type="text"] { font-weight: 700; }
.edit-help { font-size: 11px; color: var(--text-muted); margin: 6px 0 0; }

/* ============================================================
   JOURNAL
   ============================================================ */

.journal-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 430px) minmax(0, 1fr);
}
.journal-cal { padding: 8px; overflow: auto; border-right: 1px solid var(--window-dark); box-shadow: 1px 0 0 var(--window-lighter); }
.cal-nav { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.cal-nav .cal-title { flex: 1; text-align: center; font-weight: 700; font-size: 15px; }
.calendar { width: 100%; border-collapse: collapse; table-layout: fixed; background: var(--paper); border: 2px solid; border-color: var(--window-darker) var(--window-lighter) var(--window-lighter) var(--window-darker); }
.calendar th {
  background: var(--window-dark);
  color: #fff;
  font-size: 12px;
  padding: 3px 0;
  border: 1px solid var(--window-darker);
}
.calendar td {
  height: 58px;
  border: 1px solid var(--window-dark);
  vertical-align: top;
  padding: 0;
}
.cal-day {
  width: 100%;
  height: 100%;
  min-height: 56px;
  margin: 0;
  padding: 2px 3px;
  border: 0;
  box-shadow: none;
  border-radius: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 2px;
  font-size: 12px;
  position: relative;
}
.cal-day:active:not(:disabled) > * { transform: none; }
.cal-day .cal-num { font-weight: 700; text-align: left; }
.cal-day.other { color: var(--window-dark); background: var(--window-lighter); }
.cal-day.today .cal-num::before { content: ">"; }
.cal-day.today .cal-num::after { content: "<"; }
.cal-day.selected { background: var(--accent); color: #fff; }
.cal-day.overage { box-shadow: inset 0 0 0 2px var(--danger); }
.cal-day.selected.overage { box-shadow: inset 0 0 0 2px var(--danger), inset 0 0 0 4px #fff; }
.cal-pips { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; }
.pip { width: 6px; height: 6px; border: 1px solid currentColor; display: inline-block; opacity: .55; }
.pip.snack { border-radius: 50%; }
.pip.on { background: var(--ok); border-color: #000; opacity: 1; }
.cal-day.selected .pip.on { background: #7ee07e; }
.pip-over { color: #fff; background: var(--danger); font-size: 9px; line-height: 9px; padding: 0 2px; font-weight: 700; border: 1px solid #000; }
.cal-note { position: absolute; top: 2px; right: 3px; width: 10px; height: 12px; }
.cal-note svg { width: 100%; height: 100%; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11px; color: var(--text-soft); margin: 8px 0; }
.cal-legend span { display: inline-flex; align-items: center; gap: 4px; }
.cal-legend .pip { opacity: 1; }
.cal-stats { font-size: 12px; }
.cal-stats .stats-grid { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.cal-stats .stats-grid b { text-align: right; font-variant-numeric: tabular-nums; }
.cal-actions { display: flex; justify-content: flex-end; margin-top: 8px; }

.export-range { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.export-presets { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 12px; }
.export-opts { display: flex; flex-direction: column; gap: 6px; }
.export-sub { margin-left: 20px; }
.export-sub .export-presets { margin-bottom: 4px; }

.journal-day { overflow: auto; padding: 8px 10px 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.day-nav { display: flex; align-items: center; gap: 4px; }
.day-nav h2 { flex: 1; margin: 0; text-align: center; font-size: 16px; }
.day-note fieldset { margin: 0; }
.day-note .editor-host { min-height: 230px; height: 34vh; max-height: 520px; }
.day-note .editor-host .ql-editor { padding: 10px 12px 24px; }
.day-note .note-foot { display: flex; justify-content: flex-end; margin-top: 4px; }

.meal-rows { display: flex; flex-direction: column; gap: 6px; }
.meal-row { display: grid; grid-template-columns: 96px 128px minmax(0, 1fr) 54px; gap: 6px; align-items: start; }
.meal-row .meal-label { font-weight: 700; padding-top: 5px; display: flex; align-items: center; gap: 5px; }
.meal-row .meal-time { display: flex; gap: 2px; }
.meal-row .meal-time input { padding: 2px 3px; }
.meal-row .meal-time button { padding: 0 4px; margin: 1px 0 1px 2px; font-size: 11px; box-shadow: none; min-width: 0; }
.meal-row textarea { min-height: 28px; height: 28px; resize: none; overflow: hidden; }
.meal-row .meal-state { font-size: 11px; color: var(--text-muted); padding-top: 6px; white-space: nowrap; }
.meal-row .meal-state.saving { color: var(--warn); }
.meal-row .meal-state.error { color: var(--danger); font-weight: 700; }
.meal-row.overage .meal-label { color: var(--danger); }
/* Overages: a heading with "+ Add Overage", then one row per entry. */
.over-head { display: flex; align-items: center; gap: 8px; margin: 10px 0 4px; }
.over-head .meal-label { flex: 0 0 96px; display: flex; align-items: center; gap: 5px; padding-top: 0; font-weight: 700; color: var(--danger); }
.over-head button { margin-left: auto; }
.over-rows:empty { display: none; }
.over-remove { min-width: 0; height: 18px; padding: 0 4px; margin: 0 0 0 auto; font-size: 10px; box-shadow: none; }
.meal-row.overage textarea { background: #fff4f4; }
.meal-row.filled .meal-label .pip { background: var(--ok); border-color: #000; opacity: 1; }
.meal-sep { border: 0; border-top: 1px solid var(--window-dark); border-bottom: 1px solid var(--window-lighter); margin: 2px 0; }

/* ---------- Settings dialog ---------- */

.settings-dialog { max-width: 520px; }
.settings-dialog .field-row { grid-template-columns: 120px 1fr; margin-bottom: 0; }
.slot-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.slot-row { display: grid; grid-template-columns: minmax(0, 1fr) 100px 24px 24px 24px; gap: 4px; align-items: center; }
.slot-row .icon-btn { margin: 0; box-shadow: none; font-size: 11px; }
.slot-hidden { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.slot-row.hidden-slot { grid-template-columns: minmax(0, 1fr) auto; color: var(--text-muted); }
.slot-hidden-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

/* ============================================================
   LOGIN
   ============================================================ */

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-window { width: 100%; max-width: 440px; }
.login-content { display: grid; grid-template-columns: 48px 1fr; gap: 14px; padding: 16px; }
.login-icon { image-rendering: pixelated; }
.login-fields .field-row { grid-template-columns: 80px 1fr; }
.login-buttons { grid-column: 1 / -1; display: flex; justify-content: center; gap: 10px; }
.login-buttons button, .login-buttons .button { min-width: 80px; }

/* ============================================================
   SMALL SCREENS
   ============================================================ */

@media (max-width: 820px) {
  #desktop { padding: 0; }
  .app-window { inset: 0; box-shadow: none; }
  .app-window > .titlebar .titlebar-btn { display: none; }

  .notes-layout { position: relative; }
  .notes-sidebar {
    position: absolute;
    z-index: 40;
    left: 0; top: 0; bottom: 0;
    width: min(86vw, 320px) !important;
    max-width: none;
    background: var(--window);
    box-shadow: 3px 0 0 #000;
  }
  .notes-layout.sidebar-hidden .notes-sidebar { display: none; }
  .notes-layout .split-resizer { display: none; }
  .sidebar-toggle { display: inline-flex; }

  /* Phones: the day (and its meal log) first, the calendar below it. */
  .journal-layout { display: flex; flex-direction: column; overflow: auto; }
  .journal-layout > * { flex: 0 0 auto; }
  .journal-day { order: -1; overflow: visible; border-bottom: 1px solid var(--window-dark); }
  .journal-cal { border-right: 0; box-shadow: none; }
  .day-note .editor-host { height: 220px; min-height: 160px; }

  /* Notes: the title gets its own full-width row. */
  .page-header .page-title-input { order: 1; flex: 1 1 100%; }
  .page-header > :not(.page-crumbs):not(.page-title-input) { order: 2; }
  .page-header .save-status { flex: 1; text-align: right; }
  .meal-row { grid-template-columns: 1fr 128px; }
  .meal-row .meal-label { grid-column: 1; }
  .meal-row .meal-time { grid-column: 2; }
  .meal-row textarea { grid-column: 1 / -1; }
  .meal-row .meal-state { display: none; }

  .goal-form-grid { grid-template-columns: 1fr; }
  .task-btn { padding: 2px 6px; }
  .taskbar-clock, .taskbar-status { display: none; }
}

@media (max-width: 480px) {
  .task-btn .task-label { display: none; }
  .account-btn .task-label { display: none; }
  .taskbar-tasks { gap: 2px; }
  .dialog .dialog-body { padding: 10px; }
  .edit-row .row-btns button.opt { display: none; }
}
