/* הצבעים נדגמו מהאייקון: כחול-נפט עמוק (#0D4E64) וירוק התפוח (#85C65E). */
:root {
  --bg: #f1f5f7;
  --card: #ffffff;
  --text: #0d212a;
  --muted: #566c76;
  --line: #d8e3e8;
  --topbar: #0d4e64;
  --accent: #0f5e79;
  --accent-bright: #0f5e79;
  --accent-soft: #d7e7ee;
  --food: #42852a;
  --workout: #0f5e79;
  --danger: #b91c1c;
  --warn: #92400e;
  --warn-bg: #fdf0cd;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(6, 40, 52, .07), 0 8px 24px rgba(6, 40, 52, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a151a;
    --card: #122229;
    --text: #e5eef2;
    --muted: #96aeb8;
    --line: #22363f;
    --topbar: #082f3e;
    --accent: #12647d;
    --accent-bright: #5cc4e0;
    --accent-soft: #0d2a35;
    --food: #85c65e;
    --workout: #5cc4e0;
    --danger: #f87171;
    --warn: #fcd34d;
    --warn-bg: #3a2f10;
    --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 10px 28px rgba(0, 0, 0, .38);
  }
}

* { box-sizing: border-box; }

/* כללי ה-display שבהמשך חזקים יותר מברירת המחדל של [hidden], ולכן נדרש כאן !important. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

html { overflow-x: hidden; }

body {
  margin: 0;
  /* שום תוכן ארוך לא אמור למשוך את הדף לרוחב ולהוציא כפתורים מהמסך. */
  overflow-x: hidden;
  padding: 0 0 env(safe-area-inset-bottom);
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Assistant", "Heebo", system-ui, -apple-system, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ─────────── כותרת ─────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 14px;
  background: var(--topbar);
  color: #fff;
}

.topbar h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 0;
}

/* הלוגו נחתך מהאייקון עם רקע שקוף, ולכן הוא יושב ישירות על סרגל הכותרת. */
.logo {
  height: 32px;
  width: auto;
  display: block;
}

.topbar-sub {
  margin: 2px 0 0;
  font-size: .82rem;
  opacity: .85;
}

.topbar-main { flex: 1; min-width: 0; }

.icon-btn {
  flex: none;
  width: 40px; height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover { background: rgba(255, 255, 255, .3); }

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 12px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ─────────── כרטיסים ─────────── */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.card-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 600;
}

.pill {
  font-size: .76rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
}

.pill:empty { display: none; }

/* ─────────── פס עדכון ─────────── */

/* נצמד לראש המסך ובצבע מלא: עדכון שלא רואים הוא עדכון שלא מתקינים. */
.update-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
}

.update-bar-text {
  flex: 1;
  min-width: 0;
  font-size: .92rem;
  font-weight: 600;
}

.update-bar .primary-btn {
  background: #fff;
  color: var(--accent);
}

.update-bar .update-bar-close { color: rgba(255, 255, 255, .85); }
.update-bar .update-bar-close:hover { background: rgba(255, 255, 255, .18); color: #fff; }

.update-bar-close {
  flex: none;
  width: 28px; height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.update-bar-close:hover { background: var(--card); color: var(--text); }

.update-bar.is-error {
  border: 1px solid var(--warn);
  background: var(--warn-bg);
  color: var(--warn);
}

.update-bar.is-error .update-bar-close { color: var(--warn); }

.diag-log {
  width: 100%;
  min-height: 120px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  font-size: .72rem;
  line-height: 1.45;
  direction: ltr;
  text-align: left;
  white-space: pre;
  overflow: auto;
}

/* ─────────── קלט ─────────── */

.capture-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

textarea#entryInput {
  flex: 1;
  min-width: 0;
  resize: vertical;
  min-height: 62px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  line-height: 1.45;
}

textarea#entryInput:focus, input:focus, select:focus { outline: 2px solid var(--accent-bright); outline-offset: 1px; }

.capture-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: none;
}

.mic-btn {
  width: 56px; height: 56px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--accent-soft);
  /* הסמל יורש את הצבע: שחור על רקע בהיר, בהיר במצב כהה, ולבן בזמן הקלטה. */
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .12s ease, background .12s ease;
}

.mic-icon {
  width: 26px;
  height: 26px;
  fill: currentColor;
  display: block;
}

/* בזמן הקלטה המיקרופון מתחלף בריבוע עצירה. */
.mic-btn .stop-glyph { display: none; }
.mic-btn.is-listening .mic-glyph { display: none; }
.mic-btn.is-listening .stop-glyph { display: block; }

.mic-btn:hover:not(:disabled) { transform: scale(1.04); }
.mic-btn:disabled { opacity: .45; cursor: not-allowed; }

.mic-btn.is-listening {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  animation: pulse 1.3s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(185, 28, 28, .45); }
  50% { box-shadow: 0 0 0 10px rgba(185, 28, 28, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .mic-btn.is-listening { animation: none; }
  .mic-btn:hover:not(:disabled) { transform: none; }
}

.mic-status {
  margin: 8px 0 0;
  min-height: 1.2em;
  font-size: .82rem;
  color: var(--muted);
}

.mic-status.is-warn { color: var(--warn); }

.primary-btn, .ghost-btn, .danger-btn {
  border-radius: 10px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}

.primary-btn { background: var(--accent); color: #fff; }
.primary-btn:hover { filter: brightness(1.08); }

.ghost-btn { background: transparent; color: var(--text); border-color: var(--line); }
.ghost-btn:hover { background: var(--bg); }

.danger-btn { background: transparent; color: var(--danger); border-color: var(--line); }
.danger-btn:hover { background: var(--bg); }

.primary-btn:disabled, .ghost-btn:disabled, .danger-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  filter: none;
}

.primary-btn.small, .ghost-btn.small, .danger-btn.small {
  padding: 6px 11px;
  font-size: .85rem;
  font-weight: 500;
}

.hints {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}

.hint-label {
  font-size: .78rem;
  color: var(--muted);
}

.chip {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
  /* תקרה קבועה, לא 100%: ההורה הוא inline-flex שמתרחב לפי התוכן, ולכן
     אחוזים לא היו מגבילים שם דבר ושם ארוך מתח את הדף כולו. */
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip:hover { border-color: var(--accent-bright); }
.chip-mini { padding: 3px 9px; font-size: .78rem; }

.recent-chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 100%;
  overflow: hidden;
}

/* טקסט ארוך במיוחד — למשל רשומה שנוצרה מהכפלה של ההכתבה — חייב להישבר. */
.entry-name,
.raw-line,
.dialog-note,
.update-bar-text,
.draft-ask,
.day-head,
.empty {
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* ─────────── כרטיסי השלמה ─────────── */

.drafts { border-color: var(--accent); }

.drafts-note, .dialog-note {
  margin: 0 0 10px;
  font-size: .84rem;
  color: var(--muted);
}

.draft-list { display: flex; flex-direction: column; gap: 10px; }

.draft {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: var(--bg);
}

.draft.is-missing {
  border-color: var(--warn);
  background: var(--warn-bg);
}

.draft-top {
  display: flex;
  gap: 8px;
  align-items: center;
}

.type-toggle { display: flex; flex: none; }

.type-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: .8rem;
  padding: 5px 9px;
  cursor: pointer;
}

.type-btn:first-child { border-radius: 0 9px 9px 0; }
.type-btn:last-child { border-radius: 9px 0 0 9px; border-inline-start: 0; }

.type-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.draft-name {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}

.draft-ask {
  margin: 8px 0 6px;
  font-size: .86rem;
  font-weight: 600;
  color: var(--warn);
}

.draft-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.field-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.inline-label { font-size: .8rem; color: var(--muted); }

.draft-end { font-size: .82rem; color: var(--muted); align-self: center; }

input.num, input.time, input.date, select.unit {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: .9rem;
}

/* רוחב לפי התוכן ולא ברירת המחדל של שדה טקסט: בטלפון שדה תאריך ברוחב מלא
   דחק את שאר השדות לשורות נפרדות. */
input.num { width: 76px; }
input.date { width: 7.4em; flex: none; }
input.time { width: 5.2em; flex: none; }

input.num.needs {
  border-color: var(--warn);
  box-shadow: 0 0 0 2px rgba(146, 64, 14, .12);
}

.quick { display: flex; flex-wrap: wrap; gap: 5px; }

.draft-time {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.draft-time-label { font-size: .8rem; color: var(--muted); }

.draft-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.drafts-footer {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.raw-line {
  margin: 8px 0 0;
  font-size: .8rem;
  color: var(--muted);
  font-style: italic;
}

/* ─────────── סיכום ─────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}

.stat-num { font-size: 1.3rem; font-weight: 700; }
.stat-label { font-size: .74rem; color: var(--muted); text-align: center; }

.week-bars { margin-top: 12px; }

.week-bars-inner {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 64px;
}

.bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  height: 100%;
}

.bar-fill {
  width: 100%;
  border-radius: 6px 6px 0 0;
  background: var(--line);
  min-height: 3px;
}

.bar.has-value .bar-fill { background: var(--workout); }

.bar-label { font-size: .7rem; color: var(--muted); }

.week-caption {
  margin: 6px 0 0;
  font-size: .76rem;
  color: var(--muted);
  text-align: center;
}

/* ─────────── יומן ─────────── */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.tabs { display: flex; }

.tab {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  font-size: .86rem;
  padding: 6px 12px;
  cursor: pointer;
}

.tab:first-child { border-radius: 0 10px 10px 0; }
.tab:last-child { border-radius: 10px 0 0 10px; }
.tab:not(:first-child) { border-inline-start: 0; }

.tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.search, .range {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: .88rem;
}

.search { flex: 1; min-width: 130px; }

.log-list { display: flex; flex-direction: column; }

.day-head {
  margin: 14px 0 6px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.day-head:first-child { margin-top: 0; }

.entry {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: start;
  padding: 9px 6px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.entry:hover { background: var(--bg); }

.entry-time {
  flex: none;
  width: 44px;
  font-variant-numeric: tabular-nums;
  font-size: .84rem;
  color: var(--muted);
}

.entry-icon { flex: none; font-size: 1.05rem; }

.entry-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.entry-name { font-weight: 600; }

.entry-meta {
  font-size: .82rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-food .entry-name { color: var(--food); }
.entry-workout .entry-name { color: var(--workout); }

.entry-edit { flex: none; color: var(--muted); font-size: .9rem; }

.empty {
  margin: 12px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: .88rem;
}

/* ─────────── דיאלוגים ─────────── */

.sheet {
  width: min(520px, calc(100vw - 24px));
  max-height: 88vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  padding: 16px;
}

.sheet::backdrop { background: rgba(10, 18, 17, .5); }

/* דפדפן שאינו תומך ב-<dialog> מתייחס אליו כאל אלמנט רגיל, ולכן הוא היה מוצג
   תמיד. שתי השורות הבאות נותנות לו התנהגות של חלון גם שם. */
.sheet:not([open]) { display: none; }

/* במסלול הזה לא מנסים למרכז חלון צף: מסך מלא שנגלל, בלי חישובי מיקום
   ובלי גלילה בתוך אלמנט קבוע, שני דברים ששבורים בדפדפנים ישנים. */
.sheet.is-fallback[open] {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 16px;
  padding-top: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  z-index: 60;
  /* מקום לכפתור הסגירה המקובע */
  padding-top: 62px;
}

/* כפתור סגירה שנוסף רק במסלול הזה. הוא מקובע לפינת המסך, כדי ששום תוכן
   רחב לא יוכל לדחוף אותו אל מחוץ לתצוגה. */
.sheet-close {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 70;
  width: 44px;
  height: 44px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.sheet.is-fallback .sheet-close { display: block; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; flex: 1; }

.field label { font-size: .8rem; color: var(--muted); }

.field input, .field select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.field-row { display: flex; gap: 10px; }

/* גם בחלון העריכה השדות נמדדים לפי מה שנכנס בהם, ולא נמתחים על כל הטור. */
#editDate, #exportFrom, #exportTo { max-width: 8.6em; }
#editTime { max-width: 6.2em; }
#editAmount, #editCalories, #editDuration, #editDistance, #editSets, #editReps { max-width: 7.5em; }

.field-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px 2px;
  margin: 0 0 12px;
}

.field-group legend { font-size: .8rem; color: var(--muted); padding: 0 4px; }

.sheet-footer, .data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.data-actions { flex-direction: column; }

.file-btn {
  text-align: center;
  display: block;
}

.toast {
  position: fixed;
  inset-block-end: 18px;
  inset-inline-start: 50%;
  transform: translateX(50%) translateY(10px);
  max-width: calc(100vw - 32px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: .88rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 50;
}

.toast.is-visible { opacity: 1; transform: translateX(50%) translateY(0); }

@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  /* בטלפון תיבת הטקסט תופסת שורה שלמה, והכפתורים יושבים מתחתיה. */
  .capture-row { flex-direction: column; }
  .capture-actions { flex-direction: row; align-items: center; }
  .capture-actions .primary-btn { flex: 1; }
  .mic-btn { width: 52px; height: 52px; }
  .search { min-width: 100%; order: 3; }
}
