/* mobile/app.css
   Same palette/typeface as the desktop app (app/style.css) so the phone
   reads as the same product, not a reskin — --bg/--bg-soft/--border/--text/
   --primary below are copied verbatim from there. Sizing is the phone's own:
   44px minimum tap targets and >=16px body/input text (§4.2 — below 16px,
   Chrome auto-zooms on input focus, which is jarring on a phone). */
:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f5;
  --border: #e5e5e2;
  --text: #2f3437;
  --text-muted: #6b6f76;
  --primary: #2383e2;
  --primary-text: #ffffff;

  --status-todo-bg: #fff4cc;
  --status-todo-text: #8a6d1d;
  --status-doing-bg: #e6f0ff;
  --status-doing-text: #1c4ed8;
  --status-done-bg: #e7fbe7;
  --status-done-text: #256029;

  /* MOBILE-APP-PROMPT.md §2.3's OPTION_COLOR_PALETTE, copied verbatim so a
     future task's status/select chips (Task 5) can use these classes
     directly instead of inline styles. Unused until then — left here
     because the palette is part of the data model, not the rendering task. */
  --option-gray-bg: #f1f1ef;    --option-gray-text: #787774;
  --option-blue-bg: #e7f3f8;    --option-blue-text: #0b6e99;
  --option-green-bg: #edf5ee;   --option-green-text: #448361;
  --option-yellow-bg: #fbf3db;  --option-yellow-text: #9f6b53;
  --option-orange-bg: #faebdd;  --option-orange-text: #b0651b;
  --option-red-bg: #fbe4e4;     --option-red-text: #c4554d;
  --option-pink-bg: #f9e4ee;    --option-pink-text: #c14c8a;
  --option-purple-bg: #eae4f7;  --option-purple-text: #6940a5;

  --radius: 6px;
  --radius-sm: 4px;
  --top-bar-height: 52px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  direction: rtl;
  background: var(--bg);
  color: var(--text);
  /* iOS/Android safe-area insets (notch, gesture bar) — real handling is
     Task 9's job, but padding-safe from day one costs nothing and avoids a
     re-layout later. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button, input, textarea, select {
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
}

button {
  -webkit-tap-highlight-color: transparent;
  /* §6 Task 9 "no accidental text selection on long-press-to-delete": a
     button's own label text is what a long-press-driven native
     select/callout menu would otherwise grab while attachLongPress.js's
     timer is still running (row-card's Hebrew name, toggle headers, ...). */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

#topBar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--top-bar-height);
  min-height: var(--top-bar-height);
  padding: 0 12px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

#backBtn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 50%;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#backBtn:active {
  background: var(--border);
}

#topBarTitle {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Secondary/caption text, same role thead th and .text-muted play on the
   desktop (app/style.css) — smaller than the 16px body-text floor on
   purpose, since that floor exists to stop Chrome auto-zooming a focused
   *input*, and this line is never editable. */
.sync-status {
  padding: 6px 16px;
  font-size: 14px;
  color: var(--text-muted);
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sync-status button {
  min-height: 32px;
  padding: 4px 12px;
  font-size: 14px;
  border: 1px solid var(--primary);
  color: var(--primary);
  background: transparent;
  border-radius: var(--radius);
}

#screen {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.notice {
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1.6;
  padding: 24px 4px;
  text-align: center;
}

.primary-btn {
  display: block;
  width: 100%;
  min-height: 48px;
  margin: 24px auto 0;
  max-width: 320px;
  padding: 0 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn:active {
  opacity: 0.85;
}

.page-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.page-list-btn {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  text-align: right;
  cursor: pointer;
}

.page-list-btn:active {
  background: var(--bg-soft);
}

.page-list-icon {
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
}

.page-list-title {
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==================================================
   Page screen (§4.1 screen 3) — title header + block tree.
================================================== */

.page-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.page-header-icon {
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
}

.page-header-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  word-break: break-word;
}

/* Title editing (Task 6, §4.3) — an <input> reusing .page-header-title's
   typography so it reads identically to the old plain <h1> until the user
   actually taps in; border/background only show up on focus so an
   untouched title doesn't look like a form field sitting in the middle of
   the page. */
.page-title-input {
  display: block;
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  padding: 2px 6px;
  margin: 0 -6px;
}

.page-title-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-soft);
}

/* Every direct block gets breathing room from its neighbour; nested content
   (list items, toggle children) manages its own spacing instead of
   inheriting this, so it doesn't compound going deeper. */
.block-list-root > * {
  margin-bottom: 12px;
}

/* .block-text/.block-heading are contenteditable elements (Task 6, §4.3 —
   see blockRenderer.js's module header for why contenteditable was chosen
   over a plain <textarea>). white-space:pre-wrap so a stray newline
   (pasted content, or content written by the desktop) still shows as a
   line break instead of collapsing per normal HTML text-flow rules; a
   subtle border only on focus keeps an untouched block looking exactly
   like Task 4/5's read-only rendering did. */
.block-text,
.block-heading {
  margin: 0;
  word-break: break-word;
  white-space: pre-wrap;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 2px 4px;
  margin-inline: -4px;
  /* An empty contenteditable has zero child nodes (appendRuns skips its
     usual filler space for editable fields, see blockRenderer.js) — without
     this the row would collapse to nothing and be untappable. em-relative
     so it scales with each heading level's own font-size. */
  min-height: 1.5em;
}

.block-text:focus,
.block-heading:focus {
  outline: none;
  border-color: var(--border);
  background: var(--bg-soft);
}

.block-heading-1 { font-size: 22px; font-weight: 700; }
.block-heading-2 { font-size: 19px; font-weight: 700; }
.block-heading-3 { font-size: 17px; font-weight: 600; }

.block-list {
  margin: 0;
  padding-right: 22px; /* RTL indent — list markers hang to the right */
  padding-left: 0;
}

.block-list-item {
  margin-bottom: 6px;
  word-break: break-word;
}

.block-list-checklist {
  list-style: none;
  padding-right: 0;
}

.checklist-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 44px; /* §4.2 tap target floor */
}

/* A real <button> (Task 6) sized to the full 44px floor even though the
   glyph itself is small — padding provides the hit area rather than
   inflating the visible checkbox character. */
.checklist-mark {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  padding: 0;
  margin-inline-start: -10px; /* the row's own gap already spaces text from it; this keeps the glyph visually aligned with where the old span sat */
  font-size: 18px;
  line-height: 1.5;
  cursor: pointer;
}

.checklist-text,
.list-item-text {
  flex: 1;
  min-width: 0;
  min-height: 1.5em; /* same empty-contenteditable reasoning as .block-text above */
  white-space: pre-wrap;
  word-break: break-word;
  padding: 2px 4px;
  margin-inline: -4px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  align-self: center;
}

.checklist-text:focus,
.list-item-text:focus {
  outline: none;
  border-color: var(--border);
  background: var(--bg-soft);
}

.checklist-text.checked {
  text-decoration: line-through;
  color: var(--text-muted);
}

.block-toggle-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 4px 0;
  border: none;
  background: transparent;
  text-align: right;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.block-toggle-chevron {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-muted);
}

.block-toggle-title {
  word-break: break-word;
}

.block-toggle-children {
  margin-right: 20px;
  padding-right: 10px;
  border-right: 1px solid var(--border);
}

.block-toggle-children > * {
  margin-bottom: 10px;
}

.block-image img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  display: block;
}

.block-file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

.block-file-icon {
  font-size: 18px;
}

.block-file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.block-file-size {
  color: var(--text-muted);
  font-size: 14px;
  flex-shrink: 0;
}

.block-unknown {
  margin: 0;
  color: var(--text-muted);
  font-style: italic;
}

.table-placeholder {
  padding: 12px 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 15px;
}

.table-placeholder-warning {
  color: #c4554d;
  border-color: #c4554d;
}

/* ==================================================
   Table-as-row-list (§4.1 screen 3, Task 5) — Notion-mobile style: cards,
   not a grid. table-block wraps both a plain `table` block and a resolved
   `linked_table` identically (tableRenderer.js renders both through the
   same function).
================================================== */

.table-block-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.table-empty {
  padding: 12px 4px;
}

.row-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  min-height: 56px; /* comfortably over the 44px tap-target floor (§4.2) — this is the row's only tap target */
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  text-align: right;
  cursor: pointer;
  /* Explicit even though `button` already sets this globally: this is
     specifically the long-press-to-delete target (§6 Task 9), so a stray
     text-selection popup mid-hold would be the most visible place it could
     go wrong. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.row-card:active {
  background: var(--bg-soft);
}

.row-card:disabled {
  opacity: 0.6;
  cursor: default;
}

.row-card-name {
  font-size: 16px;
  font-weight: 600;
  word-break: break-word;
}

.row-card-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.prop-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--bg-soft);
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
  white-space: nowrap;
}

.prop-chip-muted {
  background: var(--bg-soft);
  color: var(--text-muted);
  font-style: italic;
}

/* ==================================================
   Row-page screen (§4.1 screen 4) — properties list (label right, value
   left, per DOM order under RTL — see main.js's renderRowPageScreen), then
   the row-page's own blocks below via the shared block renderer.
================================================== */

.row-page-title {
  margin-bottom: 16px;
}

.row-props-list {
  margin: 0 0 20px;
  padding: 0;
  border-top: 1px solid var(--border);
}

.row-props-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.row-props-label {
  flex-shrink: 0;
  width: 38%;
  color: var(--text-muted);
  font-size: 14px;
}

.row-props-value {
  flex: 1;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-start;
  font-size: 16px;
  word-break: break-word;
}

.row-props-value-muted {
  color: var(--text-muted);
}

/* ==================================================
   Toast (Task 6, §4.3's one-time marks-loss notice) — a fixed banner above
   the safe-area bottom inset, hidden by default via translateY + opacity so
   showToast()'s add/remove of one class is the whole animation.
================================================== */

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--text);
  color: #ffffff;
  font-size: 15px;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}

.toast-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Error tone (§6 Task 9) — same red the desktop's showToast uses for
   {tone: "error"} (app/ui.js), so a Drive sync failure reads as the same
   severity on both apps. */
.toast-error {
  background: #c0392b;
}

/* ==================================================
   Property-list cell editors (Task 7, §4.3) — text/checkbox/date/status/
   select controls filling the same .row-props-value slot the old read-only
   <dd> content used to sit in.
================================================== */

.cell-editor {
  min-height: 44px;
  font-size: 16px;
}

.cell-editor-text {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  background: var(--bg);
}

.cell-editor-text:focus {
  outline: none;
  border-color: var(--primary);
}

.cell-editor-checkbox {
  width: 44px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  border: none;
  background: transparent;
  padding: 0;
  font-size: 20px;
  cursor: pointer;
}

.cell-editor-date {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cell-editor-date-input,
.cell-editor-time-input {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  background: var(--bg);
}

/* §6 Task 9: a plain text field, not <input type="time"> — see
   propertyEditors.js's buildTimeTextEditor for why (native time inputs
   render AM/PM per OS locale and can't be forced to 24h; same reasoning as
   app/helpers.js's timestampToTimeValue24 doc comment on the desktop side).
   Fixed width + ltr + centered digits so "13:07" reads the same as the
   desktop's own time popover search box, inside an otherwise-rtl row. */
.cell-editor-time-input {
  width: 84px;
  flex: 0 0 auto;
  direction: ltr;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.cell-editor-status,
.cell-editor-select {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  background: var(--bg);
  text-align: right;
  cursor: pointer;
}

.cell-editor-placeholder {
  color: var(--text-muted);
}

/* ==================================================
   Choice sheet (Task 7, §4.3) — status (single-choice, closes on pick) and
   select (multi-choice, stays open) cell editors both open this.
================================================== */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}

.sheet-panel {
  width: 100%;
  max-height: 70vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* momentum scrolling (§6 Task 9), same as #screen */
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.sheet-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.sheet-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sheet-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: var(--radius);
  text-align: right;
  font-size: 16px;
  cursor: pointer;
}

.sheet-option:active {
  background: var(--bg-soft);
}

.sheet-option-check {
  flex-shrink: 0;
  width: 20px;
  text-align: center;
  color: var(--primary);
  font-size: 16px;
}

.sheet-done-btn {
  width: 100%;
  min-height: 44px;
  margin-top: 12px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-text);
  font-size: 16px;
  font-weight: 600;
}

/* ==================================================
   "+ שורה" (Task 7, §4.3) — bottom of every row list, plain table or
   resolved linked_table alike.
================================================== */

.add-row-btn {
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
}

.add-row-btn:active {
  background: var(--bg-soft);
}
