/* memo-singlerun — RTL-first stylesheet. Hebrew UI, mobile-friendly. */

:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #23211c;
  --ink-soft: #6b675e;
  --line: #e5e1d8;
  --accent: #3f6f8e;
  --accent-dark: #2f5670;
  --accent-tint: #eaf1f6;
  --ok: #2f7d4f;
  --ok-tint: #e8f4ec;
  --warn: #a4681c;
  --warn-tint: #fbf1e2;
  --err: #a83a3a;
  --err-tint: #f9e9e9;
  --ai: #6d5aa8;          /* AI-generated content marker (spec 13.4) */
  --ai-tint: #f0edf8;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(35, 33, 28, .08);
  --bottom-nav-h: 3rem;
  font-size: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Rubik", "Noto Sans Hebrew", system-ui, sans-serif;
  line-height: 1.55;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.15rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }

/* ---------- top bar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: .5rem 1rem;
  display: flex; align-items: center; gap: 1rem;
}
.brand { font-weight: 700; font-size: 1.2rem; color: var(--ink); }
.brand:hover { text-decoration: none; }

#primary-nav { display: flex; flex: 1; align-items: center; justify-content: space-between; gap: 1rem; }
.nav-links, .nav-account { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.nav-links a, .nav-account a {
  padding: .35rem .6rem; border-radius: 8px; color: var(--ink-soft); font-size: .95rem;
}
.nav-links a:hover, .nav-account a:hover { background: var(--accent-tint); text-decoration: none; }
.nav-links a.is-active, .nav-account a.is-active { color: var(--accent-dark); background: var(--accent-tint); font-weight: 600; }

.badge {
  display: inline-block; min-width: 1.3em; padding: 0 .35em;
  background: var(--err); color: #fff; border-radius: 999px;
  font-size: .75rem; text-align: center; line-height: 1.5;
  vertical-align: text-top;
}
.badge.hidden { display: none; }
.nav-bell { position: relative; }

.nav-toggle { display: none; }

@media (max-width: 860px) {
  .nav-toggle {
    display: inline-flex; flex-direction: column; gap: 4px;
    background: none; border: 1px solid var(--line); border-radius: 8px;
    padding: 8px; cursor: pointer; margin-inline-start: auto;
  }
  .nav-toggle span { width: 18px; height: 2px; background: var(--ink); }
  #primary-nav {
    display: none; position: absolute; top: 100%; right: 0; left: 0;
    background: var(--surface); border-bottom: 1px solid var(--line);
    flex-direction: column; align-items: stretch; padding: .5rem 1rem 1rem;
  }
  #primary-nav.open { display: flex; }
  .nav-links, .nav-account { flex-direction: column; align-items: stretch; }
  .nav-links a, .nav-account a { padding: .6rem .5rem; }
}

/* ---------- bottom tab bar (mobile) ---------- */
.bottom-nav { display: none; }

@media (max-width: 860px) {
  body { padding-bottom: calc(var(--bottom-nav-h) + 3.4rem + env(safe-area-inset-bottom, 0px)); }

  .bottom-nav {
    display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 40;
    height: var(--bottom-nav-h);
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 0 .2rem env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -2px 8px rgba(35, 33, 28, .06);
  }
  .bottom-nav a, .bottom-nav button {
    flex: 1; display: flex; align-items: center; justify-content: center;
    background: none; border: none; color: var(--ink-soft); cursor: pointer;
  }
  .bottom-nav a.is-active, .bottom-nav button.is-active { color: var(--accent-dark); }
  .bottom-nav-icon { position: relative; display: inline-flex; line-height: 1; }
  .bottom-nav-icon svg { width: 24px; height: 24px; }
  .bottom-nav-icon .badge {
    position: absolute; top: -.4rem; inset-inline-end: -.6rem;
    min-width: 1.1em; font-size: .62rem; padding: 0 .3em;
  }
}

/* ---------- quick capture ---------- */
.quick-capture-bar {
  max-width: 1080px; margin: .75rem auto 0; padding: 0 1rem;
}
.quick-capture-form { display: flex; gap: .5rem; align-items: flex-end; }
.quick-capture-form textarea {
  flex: 1; padding: .5rem .75rem; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); font: inherit; font-size: .9rem;
}
.quick-capture-form textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* Round icon-only send button, shared by quick-capture and similar composers. */
.btn-send {
  flex: 0 0 auto; width: 2.4rem; height: 2.4rem; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--accent); border-radius: 50%;
  background: var(--accent); color: #fff; cursor: pointer;
}
.btn-send:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-send svg { width: 18px; height: 18px; }

@media (max-width: 860px) {
  .quick-capture-bar {
    position: fixed; inset-inline: 0; bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    z-index: 39; max-width: none; margin: 0; padding: .55rem .75rem;
    background: var(--bg); border-top: 1px solid var(--line);
  }
}

/* ---------- visual map (iter-2: full-viewport app view) ---------- */
.container.map-shell { max-width: none; margin: 0 auto; padding: 0 .6rem 0; }
#map-app { position: relative; }

.map-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; flex-wrap: wrap; padding: .4rem .25rem;
}
.map-title { font-weight: 700; font-size: 1.05rem; }
.map-controls { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.map-controls select {
  width: auto; max-width: 21rem; padding: .3rem .6rem; font-size: .85rem;
}

@media (max-width: 640px) {
  /* Keep the layout dropdown and its buttons on one row on mobile instead of
     each wrapping to its own line — the select shrinks (with ellipsis) to
     make room instead of pushing the buttons down. */
  .map-controls { flex-wrap: nowrap; width: 100%; }
  .map-controls select {
    flex: 1 1 auto; min-width: 0; max-width: none;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .map-controls .btn { flex: 0 0 auto; }
}

#map-container {
  min-height: 360px; border: 1px solid var(--line);
  border-radius: 12px; background: #fdfcf9;
  background-image: radial-gradient(circle, #e8e4da 1px, transparent 1px);
  background-size: 26px 26px;
}
#map-container.map-linking { cursor: crosshair; }

/* three-dot affordance next to the clicked node */
.map-dots {
  position: absolute; z-index: 30;
  width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface);
  box-shadow: var(--shadow); cursor: pointer;
  font-size: .95rem; line-height: 1; padding: 0; color: var(--ink);
}
.map-dots:hover { background: var(--accent-tint); }

/* node action menu */
.map-menu {
  position: absolute; z-index: 40; min-width: 13.5rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 6px 24px rgba(35, 33, 28, .18);
  padding: .3rem; display: flex; flex-direction: column;
}
.map-menu-item {
  display: block; width: 100%; text-align: right; background: none;
  border: none; border-radius: 6px; padding: .45rem .6rem;
  font: inherit; font-size: .9rem; color: var(--ink); cursor: pointer;
}
.map-menu-item:hover { background: var(--accent-tint); }
.map-menu-item.danger { color: var(--err); }
.map-menu-item.danger:hover { background: var(--err-tint); }
.map-menu-divider { height: 1px; background: var(--line); margin: .25rem .3rem; }
.map-menu-header {
  font-size: .78rem; color: var(--ink-soft); padding: .35rem .6rem .15rem;
}

/* floating bar while 2+ nodes are selected */
.map-selection-bar {
  position: absolute; z-index: 30; bottom: 1.1rem; right: 50%;
  transform: translateX(50%);
  display: flex; align-items: center; gap: .6rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; box-shadow: 0 6px 24px rgba(35, 33, 28, .16);
  padding: .4rem .9rem; font-size: .88rem;
  max-width: min(92vw, 52rem); flex-wrap: wrap; justify-content: center;
}
.map-selection-chat {
  display: flex; flex: 1; min-width: 12rem;
}
.map-selection-chat textarea {
  width: 100%; min-width: 10rem; border: 1px solid var(--line);
  border-radius: 1.2rem; padding: .3rem .75rem; font: inherit;
  background: #fff;
}

/* quick-capture relevance banner on the staging chat (iter-3 §7b) */
.capture-relevance {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: .9rem;
}
.capture-relevance-head { display: flex; gap: .6rem; align-items: baseline; margin-bottom: .5rem; flex-wrap: wrap; }
.capture-option-form { margin: 0 0 .4rem; }
.capture-option {
  width: 100%; text-align: right; cursor: pointer; display: flex;
  flex-direction: column; gap: .2rem; align-items: flex-start;
}
.capture-option:hover { border-color: var(--accent); }

/* create-link mode banner */
.map-banner {
  position: absolute; z-index: 30; top: 3.2rem; right: 50%;
  transform: translateX(50%);
  background: var(--warn-tint); color: var(--warn);
  border: 1px solid #ecd9b8; border-radius: 999px;
  padding: .4rem 1rem; font-size: .88rem; box-shadow: var(--shadow);
  white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis;
}

/* single-level undo toast */
.map-toast {
  position: absolute; z-index: 35; bottom: 4.2rem; right: 50%;
  transform: translateX(50%);
  display: flex; align-items: center; gap: .6rem;
  background: var(--ink); color: #fff; border-radius: 10px;
  padding: .45rem .9rem; font-size: .88rem;
  box-shadow: 0 6px 24px rgba(35, 33, 28, .3);
}
.map-toast .btn { background: transparent; color: #fff; border-color: #6b675e; }
.map-toast .btn:hover { background: rgba(255, 255, 255, .12); }

/* ---------- shared delete-consequences modal (iter-2 Q-6/Q-11) ---------- */
.memo-modal-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(35, 33, 28, .45);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.memo-modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(35, 33, 28, .3);
  max-width: 30rem; width: 100%; max-height: 85vh; overflow-y: auto;
  padding: 1.1rem 1.3rem;
}
.memo-modal-title { margin: 0 0 .5rem; font-size: 1.05rem; }
.memo-modal-subtitle { margin: .8rem 0 .25rem; font-size: .9rem; color: var(--warn); }
.memo-modal-intro { color: var(--ink-soft); font-size: .9rem; margin: .25rem 0; }
.memo-modal-list { margin: .25rem 0; padding-inline-start: 1.2rem; font-size: .88rem; }
.memo-modal-list li { margin-bottom: .2rem; }
.memo-modal-actions {
  display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem;
}

/* map "הצג אייטם" preview modal + right-click quick-create (iter-4 §1/§2) */
.map-preview-label {
  margin: .8rem 0 .25rem; font-size: .82rem; color: var(--ink-soft);
}
.map-preview-text {
  font-size: .92rem; white-space: pre-wrap; word-break: break-word;
}
.map-create-input {
  width: 100%; margin-top: .5rem; resize: vertical; font: inherit;
}

.capture-option {
  display: flex; flex-direction: column; align-items: flex-start; gap: .25rem;
  width: 100%; text-align: right; cursor: pointer; font: inherit;
  margin-bottom: .5rem;
}
.capture-option:hover { border-color: var(--accent); }
.capture-snippet { color: var(--muted, #667); }

/* ---------- layout ---------- */
.container { max-width: 1080px; margin: 1rem auto 3rem; padding: 0 1rem; }
.container-narrow { max-width: 720px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem 1.25rem; margin-bottom: 1rem;
}
.center-card { max-width: 420px; margin: 4rem auto; text-align: center; }
.login-tagline { color: var(--ink-soft); }
.login-note { color: var(--ink-soft); font-size: .85rem; margin-top: 1.25rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

.muted { color: var(--ink-soft); font-size: .9rem; }
.small { font-size: .85rem; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; }

/* ---------- flash ---------- */
.flash { padding: .6rem 1rem; border-radius: var(--radius); margin-bottom: .75rem; }
.flash-ok { background: var(--ok-tint); color: var(--ok); border: 1px solid #cbe5d4; }
.flash-error { background: var(--err-tint); color: var(--err); border: 1px solid #ecc9c9; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-block; padding: .45rem 1rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-size: .92rem; cursor: pointer;
}
.btn:hover { background: var(--accent-tint); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn-danger:hover { background: #8e2f2f; }
.btn-quiet { border-color: transparent; background: none; color: var(--ink-soft); }
.btn-sm { padding: .3rem .7rem; font-size: .85rem; }
.inline-form { display: inline; }
.actions-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .5rem; }
.input-sm { padding: .3rem .6rem; font-size: .85rem; border: 1px solid var(--line); border-radius: 8px; min-width: 12rem; }
.filter-row { display: flex; gap: .5rem; flex-wrap: wrap; margin: .75rem 0 1.25rem; }
.filter-row .pill { text-decoration: none; }

input[type="text"], input[type="email"], input[type="datetime-local"],
textarea, select {
  width: 100%; padding: .5rem .7rem; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; background: var(--surface); color: var(--ink);
}
textarea { min-height: 6rem; resize: vertical; }
label { display: block; font-size: .9rem; margin: .6rem 0 .25rem; color: var(--ink-soft); }
.field-inline { display: flex; gap: .5rem; align-items: center; }
.field-inline input, .field-inline select, .field-inline textarea { width: auto; flex: 1; }

/* Auto-growing single-line-style textareas: replaces <input type="text"> for
   free-text fields, so the box grows with the content instead of scrolling
   internally and hiding what was typed earlier. Height is managed in JS
   (app.js); .autogrow-submit additionally sends the form on Enter
   (Shift+Enter inserts a newline), matching the old <input> behavior. */
textarea.autogrow {
  min-height: 2.4rem; max-height: 16rem; resize: none; overflow-y: auto;
  line-height: 1.4;
}

/* ---------- tags / pills ---------- */
.pill {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px;
  font-size: .78rem; background: var(--accent-tint); color: var(--accent-dark);
  border: 1px solid transparent;
}
.pill-ok { background: var(--ok-tint); color: var(--ok); }
.pill-warn { background: var(--warn-tint); color: var(--warn); }
.pill-err { background: var(--err-tint); color: var(--err); }
.pill-ai { background: var(--ai-tint); color: var(--ai); }

/* AI-generated content visual distinction (spec 13.4) */
.ai-content {
  border-inline-start: 3px solid var(--ai);
  background: var(--ai-tint);
  padding: .5rem .75rem; border-radius: 8px;
}
.ai-label { color: var(--ai); font-size: .78rem; font-weight: 600; }

/* ---------- chat ---------- */
.chat-page { display: flex; flex-direction: column; min-height: 70vh; }
.chat-messages { flex: 1; display: flex; flex-direction: column; gap: .6rem; padding-bottom: 1rem; }

.msg { max-width: 46rem; padding: .6rem .9rem; border-radius: var(--radius); position: relative; }
.msg-user { align-self: flex-start; background: var(--accent-tint); border: 1px solid #d3e1ea; }
.msg-system { align-self: flex-end; background: var(--surface); border: 1px solid var(--line); }
/* Message bodies keep their line breaks; bot markdown (iter-5 §3) is
   rendered to real HTML by markdown-lite.js and switches to normal flow. */
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-text.md-rendered { white-space: normal; }
.msg-text.md-rendered p { margin: 0 0 .5rem; }
.msg-text.md-rendered p:last-child { margin-bottom: 0; }
.msg-text.md-rendered ul, .msg-text.md-rendered ol {
  margin: .2rem 0 .5rem; padding-inline-start: 1.4rem;
}
.msg-text.md-rendered li { margin: .15rem 0; }
.msg-text.md-rendered h4, .msg-text.md-rendered h5, .msg-text.md-rendered h6 {
  margin: .6rem 0 .3rem; font-size: .95rem;
}
.msg-text.md-rendered code {
  background: #f0ede5; border-radius: 4px; padding: 0 .3rem;
  font-size: .88em; direction: ltr; unicode-bidi: embed;
}
.msg-text.md-rendered pre {
  background: #f0ede5; border: 1px solid var(--line); border-radius: 6px;
  padding: .5rem .7rem; overflow-x: auto; direction: ltr; text-align: left;
  margin: .3rem 0 .5rem;
}
.msg-text.md-rendered pre code { background: none; padding: 0; }

.msg-meta { font-size: .75rem; color: var(--ink-soft); margin-top: .3rem; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.msg-state { font-size: .75rem; }
.msg-state.processing::before {
  content: ""; display: inline-block; width: .7em; height: .7em; margin-inline-end: .3em;
  border: 2px solid var(--accent); border-top-color: transparent; border-radius: 50%;
  animation: spin 1s linear infinite; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.msg-card { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .7rem; margin-top: .5rem; background: #fbfaf7; }
.msg-card .card-title { font-weight: 600; font-size: .9rem; }
.msg-card .card-actions { display: flex; gap: .4rem; margin-top: .4rem; flex-wrap: wrap; }

/* Inline reply thread on a bot message (iter-3 §6) */
.msg-thread { margin-top: .4rem; }
.msg-thread .thread-body {
  margin-top: .4rem; padding: .5rem .6rem; border-inline-start: 3px solid var(--line);
  background: #faf8f3; border-radius: 8px;
}
.msg-thread .thread-body.hidden { display: none; }
.msg-thread .thread-messages { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .4rem; }
.msg-thread .thread-messages .msg { max-width: 100%; padding: .4rem .6rem; font-size: .9rem; }
.msg-thread .thread-messages .msg-thread { display: none; }
.msg-thread form.js-thread-reply { display: flex; gap: .4rem; }
.msg-thread form.js-thread-reply input { flex: 1; }
.js-thread-promote.hidden { display: none; }

/* Mini-conversation inside a home/attention card (iter-5 topic 1) */
.mini-thread { margin-top: .5rem; }
.mini-thread > .actions-row { margin-bottom: 0; }
.mini-thread form.js-mini-reply { display: flex; gap: .4rem; align-items: flex-end; }
.mini-thread form.js-mini-reply textarea { flex: 1; }
form.js-discuss.hidden { display: none; }

.chat-compose {
  position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0;
  display: flex; gap: .5rem; align-items: flex-end;
}
.chat-compose textarea { min-height: 2.8rem; max-height: 10rem; flex: 1; }

@media (max-width: 860px) {
  /* Pin the compose box just above the bottom tab bar, fully fixed to the
     viewport — not "sticky" within the messages column, so it never scrolls
     with the conversation and always sits flush against the nav. */
  .chat-compose {
    position: fixed; inset-inline: 0; bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    z-index: 39; background: var(--bg); border-top: 1px solid var(--line);
    padding: .5rem .75rem; margin: 0;
  }
  .chat-messages { padding-bottom: 7rem; }
}

/* ---------- item / list cards ---------- */
.item-list { display: flex; flex-direction: column; gap: .6rem; }
.item-row {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .7rem 1rem; display: flex; justify-content: space-between; gap: .75rem; align-items: baseline;
  max-width: 100%; overflow: hidden;
}
.item-row:hover { border-color: var(--accent); }
.item-row > * { min-width: 0; overflow-wrap: anywhere; }
.item-title { font-weight: 600; }
.item-snippet { color: var(--ink-soft); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 32rem; }
/* iter-4 Q-19: the זמנים text renders in FULL in item lists — never
   truncated to an indicator. */
.item-times { display: block; color: var(--ink-soft); font-size: .85rem; white-space: normal; }
@media (max-width: 760px) { .item-row { flex-direction: column; } .item-snippet { white-space: normal; } }

.link-list li { margin-bottom: .3rem; }
.version-block { border-inline-start: 3px solid var(--line); padding-inline-start: .75rem; margin: .6rem 0; }

/* ---------- suggestions / attention ---------- */
.suggestion-card {
  border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem 1rem;
  background: var(--surface); margin-bottom: .6rem;
}
.suggestion-card.attention { border-inline-start: 4px solid var(--warn); }
.suggestion-reason { color: var(--ink-soft); font-size: .85rem; margin-top: .25rem; }

/* ---------- tables ---------- */
table.data { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
table.data th, table.data td { padding: .5rem .75rem; border-bottom: 1px solid var(--line); text-align: right; font-size: .9rem; }
table.data th { background: #faf8f3; color: var(--ink-soft); font-weight: 600; }

/* ---------- empty state ---------- */
.empty-state {
  text-align: center; color: var(--ink-soft); padding: 2.5rem 1rem;
  border: 1px dashed var(--line); border-radius: var(--radius); background: #fbfaf7;
}

/* ---------- footer detail ---------- */
details summary { cursor: pointer; color: var(--accent); font-size: .9rem; }
