/*
 * Notes - browser-only, encrypted, plain-text note keeper.
 * File:    app.css
 * Version: 1.0.2
 *
 * Layout:
 *   - Wide screens (>= 760px): two panes, list left, editor right.
 *   - Narrow screens: one pane at a time. #layout gets the class
 *     "editing" (set by app.js) when the editor should be shown.
 * Colours follow the system light / dark setting via CSS variables.
 * All text, including the editor, uses the system monospace font, so no
 * web font is downloaded and the CSP can stay at 'self'.
 */

/* ---------- Theme ---------- */
:root {
  --bg: #ffffff;
  --bg-alt: #f4f5f7;
  --fg: #1d1f23;
  --muted: #6a6f78;
  --border: #d6d9de;
  --accent: #2b62c9;
  --accent-fg: #ffffff;
  --selected: #e3ecfb;
  --danger: #b3261e;
  --amber: #a15c00;
  --amber-bg: #fff3dc;
  --mark: #ffe38a;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", "DejaVu Sans Mono", monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191d;
    --bg-alt: #1f2227;
    --fg: #e4e6ea;
    --muted: #9399a3;
    --border: #353a42;
    --accent: #6d9cf0;
    --accent-fg: #0d1117;
    --selected: #253552;
    --danger: #f2827a;
    --amber: #f0b351;
    --amber-bg: #3a2c12;
    --mark: #6b5a12;
  }
}

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

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.45;
}

#app {
  height: 100%;
}

h1 {
  font-size: 1.15rem;
  margin: 0;
  white-space: nowrap;
}

.version {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: normal;
}

.muted {
  color: var(--muted);
}

.error {
  color: var(--danger);
  min-height: 1.2em;
  margin: 0.4rem 0;
}

.warning {
  background: var(--amber-bg);
  color: var(--amber);
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
}

.fatal {
  margin: 2rem 1rem;
  padding: 1rem;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 6px;
}

/* ---------- Controls ---------- */
button,
input,
textarea,
summary {
  font: inherit;
  color: inherit;
}

button,
summary {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
summary:hover {
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

button.danger {
  color: var(--danger);
}

input[type="password"],
input[type="search"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 16px; /* 16px or more stops iOS zooming in on focus */
  min-width: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Set-up and unlock screens ---------- */
.gate {
  max-width: 26rem;
  margin: 3rem auto;
  padding: 0 1rem;
}

.gate h1 {
  margin-bottom: 1rem;
}

.gate form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.gate label {
  margin-top: 0.5rem;
}

.gate button {
  align-self: flex-start;
  margin-top: 0.4rem;
}

/* ---------- Main screen ---------- */
#screen-main {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topbar {
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  background: var(--bg);
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-row #search {
  flex: 1;
}

.topbar-row.small {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.3rem;
}

#last-exported.stale {
  color: var(--amber);
}

.notice {
  margin: 0.4rem 0 0;
  padding: 0.35rem 0.6rem;
  background: var(--selected);
  border-radius: 6px;
  font-size: 0.85rem;
}

/* "..." drop-down menu */
.menu {
  position: relative;
}

.menu summary {
  list-style: none;
}

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

.menu-items {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.4rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  min-width: 13rem;
}

.menu-items button {
  text-align: left;
}

/* ---------- Two-pane layout ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(16rem, 22rem) 1fr;
  min-height: 0; /* lets panes scroll instead of growing the page */
}

.list-pane,
.editor-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.list-pane {
  border-right: 1px solid var(--border);
}

.pane-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.pane-toolbar button {
  font-size: 0.85rem;
  padding: 0.2rem 0.55rem;
}

.empty {
  padding: 1rem 0.75rem;
  margin: 0;
}

/* The back button only matters on phones. */
.back {
  visibility: hidden;
}

/* ---------- Note list ---------- */
.note-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.note-item {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 0.55rem 0.75rem;
  white-space: normal;
}

.note-item:hover {
  background: var(--bg-alt);
}

.note-item[aria-current="true"] {
  background: var(--selected);
}

.note-title {
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-snippet {
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-date {
  color: var(--muted);
  font-size: 0.75rem;
}

mark {
  background: var(--mark);
  color: inherit;
  border-radius: 2px;
}

/* ---------- Editor ---------- */
.editor {
  flex: 1;
  width: 100%;
  min-height: 0;
  resize: none;
  border: 0;
  padding: 0.75rem;
  background: var(--bg);
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1.5;
  tab-size: 4;
  -moz-tab-size: 4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.editor:focus-visible {
  outline: none;
}

/* Wrap off: keep long lines intact and scroll sideways. */
.editor.nowrap {
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

.editor-footer {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.35rem 0.75rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
}

/* ---------- Conflict banner ---------- */
.conflict {
  background: var(--amber-bg);
  color: var(--amber);
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.conflict p {
  margin: 0 0 0.5rem;
}

.conflict-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* ---------- Passphrase dialog ---------- */
dialog {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: min(28rem, calc(100vw - 2rem));
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

dialog input {
  width: 100%;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ---------- Phones / narrow windows ---------- */
@media (max-width: 759px) {
  .topbar-row {
    flex-wrap: wrap;
  }

  .topbar-row #search {
    order: 10;           /* search drops to its own full-width line */
    flex-basis: 100%;
  }

  .topbar-row h1 {
    flex: 1;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .list-pane {
    border-right: 0;
  }

  /* One pane at a time. */
  .layout .editor-pane {
    display: none;
  }

  .layout.editing .list-pane {
    display: none;
  }

  .layout.editing .editor-pane {
    display: flex;
  }

  .back {
    visibility: visible;
  }
}

/* ---------- Test harness page (tests.html only) ---------- */
.test-page {
  max-width: 52rem;
}

.test-results {
  padding-left: 1.6rem;
}

.test-results li {
  margin: 0.2rem 0;
}

.test-pass {
  color: #1e7b34;
}

.test-fail {
  color: var(--danger);
  font-weight: bold;
}

.test-detail {
  display: block;
  font-weight: normal;
  font-size: 0.85rem;
  white-space: pre-wrap;
}

@media (prefers-color-scheme: dark) {
  .test-pass {
    color: #6fd08a;
  }
}

/* ---------- Storage / security explanation (set-up and unlock) ---------- */
.info {
  margin-top: 1.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.info h2 {
  font-size: 0.95rem;
  color: var(--fg);
  margin: 1rem 0 0.3rem;
}

.info p,
.info ul {
  margin: 0.3rem 0;
}

.info ul {
  padding-left: 1.2rem;
}

.info li {
  margin: 0.2rem 0;
}

/* Collapsible version on the unlock screen: a plain link-style toggle. */
.info-toggle {
  margin-top: 1.5rem;
}

.info-toggle summary {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-size: 0.85rem;
}

.info-toggle .info {
  margin-top: 0.5rem;
}
