:root {
  --bg: #0f1420;
  --bg-2: #161c2b;
  --card: #1c2433;
  --card-2: #222b3d;
  --border: #2c3648;
  --text: #e7ecf3;
  --muted: #93a0b5;
  --accent: #4f8cff;
  --accent-2: #34d399;
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 12px;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}
.brand { padding: 6px 10px 20px; }
.brand-mark {
  display: inline-block;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 1px;
  color: var(--accent);
}
.brand-sub {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-item span { font-size: 17px; }
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--card-2); color: var(--text); }
.sidebar-footer {
  display: flex;
  gap: 12px;
  padding: 12px 10px 0;
  border-top: 1px solid var(--border);
}
.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 4px;
}
.link-btn:hover { color: var(--accent); }

/* Content */
.content { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
}
.today-greg { font-size: 18px; font-weight: 600; }
.today-heb { font-size: 13px; color: var(--muted); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.08); }

.view { padding: 24px 28px; overflow-y: auto; }

/* Section headers */
.section-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
}
.section-sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

/* Cards & lists */
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.card-title { font-weight: 650; font-size: 16px; }
.card-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-notes { margin-top: 10px; font-size: 14px; color: #cdd6e4; white-space: pre-wrap; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--card-2);
  color: var(--muted);
}
.badge.soon { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.badge.today { background: rgba(79, 140, 255, 0.18); color: var(--accent); }
.badge.done { background: rgba(52, 211, 153, 0.15); color: var(--accent-2); }

.row-actions { display: flex; gap: 8px; }
.icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 13px;
}
.icon-btn:hover { color: var(--text); border-color: var(--border); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 40px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* Avatars & photo picker */
.avatar {
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--card-2);
}
.avatar.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #4f8cff, #34d399);
}
.bday-head { display: flex; align-items: center; gap: 14px; }
.photo-field { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.photo-preview {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--border);
}
.photo-preview.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  background: var(--card-2);
}
.photo-actions { display: flex; gap: 10px; }
.photo-pick { cursor: pointer; text-align: center; }

/* Avatar cropper */
.cropper { width: 100%; }
.crop-view {
  width: 240px;
  height: 240px;
  max-width: 100%;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  margin: 0 auto;
  background: var(--card-2);
  border: 2px solid var(--accent);
  touch-action: none;
  cursor: grab;
}
.crop-view:active { cursor: grabbing; }
#crop-img {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.crop-zoom-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.crop-zoom-row input[type=range] { flex: 1; accent-color: var(--accent); }
.cropper .hint { text-align: center; margin-top: 6px; }

/* Flight card specifics */
.flight-route {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 22px;
  font-weight: 700;
  margin: 8px 0;
}
.flight-route .arrow { color: var(--accent); font-size: 18px; }
.flight-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px 16px;
  margin-top: 10px;
}
.detail-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.detail-value { font-size: 15px; font-weight: 600; }

/* Dashboard hero: greeting + live clock */
.hero { margin-bottom: 22px; }
.hero-greet { font-size: 16px; color: var(--muted); }
.hero-name { font-size: 34px; font-weight: 800; margin: 0 0 8px; line-height: 1.1; }
.hero-clock {
  font-size: 42px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
@media (max-width: 720px) {
  .hero-name { font-size: 28px; }
  .hero-clock { font-size: 36px; }
}

/* Daf Yomi card */
.daf-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: linear-gradient(135deg, #223056, #1a2338);
  border: 1px solid #35507f;
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 22px;
}
.daf-card.done { border-color: var(--accent-2); background: linear-gradient(135deg, #1c3a30, #17281f); }
.daf-info { flex: 1; }
.daf-label { font-size: 13px; color: #9db4e6; font-weight: 600; }
.daf-card.done .daf-label { color: #86e0bd; }
.daf-main { font-size: 30px; font-weight: 800; margin: 2px 0; letter-spacing: 0.5px; }
.daf-date { font-size: 13px; color: var(--muted); }
.daf-check {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 13px;
  border: 2px solid #35507f;
  background: transparent;
  color: transparent;
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s;
}
.daf-check:hover { border-color: var(--accent-2); }
.daf-check.on {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #0f1420;
}

/* Dashboard */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-num { font-size: 26px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 13px; }
.dash-block { margin-bottom: 24px; }
.dash-block h3 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; }
.mini {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
}
.mini-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mini-icon { font-size: 16px; }
.mini-text { min-width: 0; }
.mini-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-sub { color: var(--muted); font-size: 12px; }

/* Assistant / chat */
.chat-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 82px - 48px);
  min-height: 420px;
}
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 4px 2px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.bot { justify-content: flex-start; }
.bubble {
  max-width: 78%;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.5;
}
.chat-msg.user .bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.bot .bubble {
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble em { color: var(--accent); font-style: normal; }
.bubble-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.composer {
  display: flex;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.composer input {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
}
.composer input:focus { outline: none; border-color: var(--accent); }

/* Calendar */
.cal-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.cal-modes { display: flex; background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.cal-mode { background: transparent; border: none; color: var(--muted); padding: 8px 16px; cursor: pointer; font-size: 14px; font-weight: 600; }
.cal-mode.active { background: var(--accent); color: #fff; }
.cal-nav { display: flex; gap: 6px; }
.cal-navbtn { background: var(--card); border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 8px 12px; cursor: pointer; font-size: 13px; }
.cal-navbtn:hover { border-color: var(--accent); }
.cal-title { margin-bottom: 16px; }
.cal-title-heb { font-size: 20px; font-weight: 700; }
.cal-title-greg { font-size: 13px; color: var(--muted); }

/* chips */
.cal-chip {
  display: inline-block;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 7px;
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.cal-chip.done { text-decoration: line-through; color: var(--muted); }
.cal-chip.clickable { cursor: pointer; }
.cal-chip.clickable:hover { filter: brightness(1.15); outline: 1px solid var(--accent); }
.cal-agenda.clickable { cursor: pointer; }
.cal-agenda.clickable:hover { outline: 1px solid var(--accent); }
.chip-holiday, .cal-agenda.chip-holiday { background: rgba(251, 191, 36, 0.16); border-color: rgba(251,191,36,0.4); color: #fcd34d; font-weight: 600; }
.chip-holiday.hol-fast { background: rgba(248, 113, 113, 0.15); border-color: rgba(248,113,113,0.4); color: #fca5a5; }
.chip-holiday.hol-minor, .chip-holiday.hol-modern, .chip-holiday.hol-rc { background: rgba(147, 160, 181, 0.14); border-color: var(--border); color: #c3cddd; font-weight: 500; }
.chip-parsha, .cal-agenda.chip-parsha { background: rgba(167, 139, 250, 0.16); border-color: rgba(167,139,250,0.4); color: #c4b5fd; font-weight: 600; }
.chip-meeting, .cal-agenda.chip-meeting { background: rgba(79, 140, 255, 0.14); border-color: rgba(79,140,255,0.35); color: #93c0ff; }
.chip-flight, .cal-agenda.chip-flight { background: rgba(45, 212, 191, 0.14); border-color: rgba(45,212,191,0.35); color: #7ee7d5; }
.chip-reminder, .cal-agenda.chip-reminder { background: rgba(251, 191, 36, 0.12); border-color: rgba(251,191,36,0.3); color: #fcd9a0; }
.chip-birthday, .cal-agenda.chip-birthday { background: rgba(244, 114, 182, 0.14); border-color: rgba(244,114,182,0.35); color: #f7a8d0; }
.chip-daf, .cal-agenda.chip-daf { background: rgba(129, 140, 248, 0.14); border-color: rgba(129,140,248,0.35); color: #b4bcf9; }

/* week view (vertical agenda) */
.cal-week { display: flex; flex-direction: column; gap: 8px; }
.cal-day-row {
  display: flex;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 12px 14px;
  cursor: pointer;
}
.cal-day-row:hover { border-color: var(--accent); }
.cal-day-row.today { border-color: var(--accent); background: rgba(79,140,255,0.07); }
.cal-day-row.shabbat { background: rgba(167,139,250,0.06); }
.cd-date { flex-shrink: 0; width: 92px; text-align: center; }
.cd-wd { font-size: 13px; color: var(--muted); }
.cd-greg { font-size: 20px; font-weight: 800; }
.cd-heb { font-size: 13px; color: #9db4e6; }
.cd-events { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start; }
.cd-empty { color: var(--muted); }

/* month view */
.cal-month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-wd { text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 0; }
.cal-cell {
  min-height: 92px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 6px;
  cursor: pointer;
  overflow: hidden;
}
.cal-cell:hover { border-color: var(--accent); }
.cal-cell.today { border-color: var(--accent); background: rgba(79,140,255,0.09); }
.cal-cell.other { opacity: 0.4; }
.cal-cell.shabbat { background: rgba(167,139,250,0.06); }
.cc-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 3px; }
.cc-greg { font-weight: 700; font-size: 14px; }
.cc-heb { font-size: 11px; color: #9db4e6; }
.cc-events { display: flex; flex-direction: column; gap: 2px; }
.cal-cell .cal-chip { font-size: 10px; padding: 1px 5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-more { font-size: 10px; color: var(--muted); padding-right: 4px; }

/* day view */
.cal-dayview { display: flex; flex-direction: column; gap: 14px; }
.cal-day-special { display: flex; flex-wrap: wrap; gap: 8px; }
.cal-day-special .cal-chip { font-size: 15px; padding: 7px 14px; }
.cal-day-h { font-size: 15px; color: var(--muted); margin: 4px 0 0; }
.cal-agenda { padding: 12px 14px; border-radius: 10px; font-size: 15px; }

@media (max-width: 720px) {
  .cal-cell { min-height: 74px; }
  .cd-date { width: 72px; }
  .cal-title-heb { font-size: 17px; }
}

/* Storage warning banner */
.storage-warn {
  background: rgba(248, 113, 113, 0.15);
  border-bottom: 1px solid rgba(248, 113, 113, 0.4);
  color: #fca5a5;
  font-size: 13px;
  line-height: 1.4;
  padding: 10px 16px;
  text-align: center;
}
.storage-warn.hidden { display: none; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--accent-2);
  color: #06281c;
  font-weight: 700;
  padding: 10px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 90;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (max-width: 720px) { .toast { bottom: 86px; } }

.build-tag { font-size: 10px; color: var(--muted); opacity: 0.6; margin-left: auto; }

/* Login gate */
.login {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 18%, #1a2338, #0f1420);
}
.login.hidden { display: none; }
.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 24px;
  box-shadow: var(--shadow);
}
.login-mark { font-size: 40px; font-weight: 800; color: var(--accent); text-align: center; letter-spacing: 2px; }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.login-card input {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-err { color: var(--danger); font-size: 13px; min-height: 16px; text-align: center; }
.login-card .btn-primary { padding: 12px; font-size: 15px; }

/* Clickable dashboard mini + detail card */
.mini.clickable { cursor: pointer; }
.mini.clickable:hover { border-color: var(--accent); }
.detail .flight-details { margin-top: 6px; }

/* Modal & forms */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 18, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 18px; }

.form { padding: 18px 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.field textarea { resize: vertical; min-height: 70px; }
.checkbox-field { flex-direction: row; align-items: center; gap: 8px; }
.checkbox-field input { width: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 9px 16px;
  border-radius: 10px;
  cursor: pointer;
}
.hint { font-size: 12px; color: var(--muted); }
.form-error { color: var(--danger); font-size: 13px; min-height: 16px; text-align: center; }
.field input.invalid, .field select.invalid, .field textarea.invalid { border-color: var(--danger); }

/* Responsive — app-style bottom tab bar on phones */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .content { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .sidebar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    overflow-x: auto;
    z-index: 60;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .brand { display: none; }
  .nav { flex-direction: row; gap: 2px; flex: 0 0 auto; }
  .nav-item {
    flex-direction: column;
    gap: 3px;
    white-space: nowrap;
    padding: 7px 11px;
    font-size: 10.5px;
    border-radius: 12px;
    min-width: 56px;
    align-items: center;
    color: var(--muted);
  }
  .nav-item span { font-size: 21px; }
  .nav-item:hover { background: transparent; }
  .nav-item.active { background: transparent; color: var(--accent); }
  .sidebar-footer { border: none; padding: 0 10px; flex: 0 0 auto; gap: 12px; align-items: center; }
  .topbar { padding: 14px 16px; position: sticky; top: 0; background: var(--bg); z-index: 30; }
  .view { padding: 16px; }
  .chat-wrap { height: calc(100vh - 210px); }
}
