:root {
  --bg: #fff7ed;
  --card: #ffffff;
  --text: #1c1917;
  --text-muted: #78716c;
  --border: #e7e5e4;
  --orange: #f97316;
  --orange-light: #fff7ed;
  --green: #22c55e;
  --green-light: #f0fdf4;
  --pink: #ec4899;
  --pink-light: #fdf2f8;
  --blue: #3b82f6;
  --blue-light: #eff6ff;
  --yellow: #eab308;
  --yellow-light: #fefce8;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Heebo', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  direction: rtl;
  overscroll-behavior: none;
}

/* HEADER */
.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: env(safe-area-inset-top) 0 0;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}
.header-logo { display: flex; align-items: center; gap: 10px; }
.logo-emoji { font-size: 2rem; line-height: 1; }
.logo-title { font-size: 1.3rem; font-weight: 900; color: var(--orange); line-height: 1; }
.logo-sub { font-size: 0.7rem; color: var(--text-muted); }
.header-btn {
  background: var(--orange);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 50px;
  font-family: 'Heebo', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}
.header-btn:active { transform: scale(0.95); filter: brightness(0.9); }

/* TABS */
.tab-bar {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 60px;
  z-index: 99;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  padding: 12px 4px;
  font-family: 'Heebo', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.15s;
}
.tab.active {
  color: var(--orange);
  border-bottom-color: var(--orange);
  font-weight: 700;
}

/* MAIN */
.main-content { padding: 16px; padding-bottom: calc(32px + env(safe-area-inset-bottom)); }

/* VIEWS */
.view { display: none; }
.view.active { display: block; }

/* FEED */
.feed-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  line-height: 1.8;
}
.feed-list { display: flex; flex-direction: column; gap: 12px; }

.entry-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border-right: 4px solid var(--orange);
}
.entry-card:active { transform: scale(0.98); box-shadow: none; }
.entry-card.sev-1 { border-right-color: #86efac; }
.entry-card.sev-2 { border-right-color: #fde047; }
.entry-card.sev-3 { border-right-color: var(--orange); }
.entry-card.sev-4 { border-right-color: #f87171; }
.entry-card.sev-5 { border-right-color: #a855f7; }

.entry-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.entry-name { font-size: 1rem; font-weight: 700; }
.entry-date { font-size: 0.72rem; color: var(--text-muted); }
.entry-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  background: var(--orange-light);
  color: var(--orange);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 50px;
}
.chip.green { background: var(--green-light); color: var(--green); }
.chip.pink { background: var(--pink-light); color: var(--pink); }
.chip.blue { background: var(--blue-light); color: var(--blue); }
.entry-notes { font-size: 0.82rem; color: var(--text-muted); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-has-photo { font-size: 0.75rem; color: var(--blue); margin-top: 4px; }

/* FORM */
.form-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.form-title { font-size: 1.1rem; font-weight: 900; margin-bottom: 20px; color: var(--orange); }
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="text"],
input[type="datetime-local"],
textarea,
select {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: 'Heebo', sans-serif;
  font-size: 0.95rem;
  color: var(--text);
  direction: rtl;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--orange); }
textarea { resize: none; }
select { cursor: pointer; }
input[type="datetime-local"] { direction: ltr; text-align: right; }

/* SEVERITY */
.severity-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.sev-btn {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 2px;
  font-family: 'Heebo', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  line-height: 1.3;
}
.sev-btn span { display: block; font-size: 0.6rem; font-weight: 400; color: var(--text-muted); }
.sev-btn.active { background: var(--orange); border-color: var(--orange); color: white; }
.sev-btn.active span { color: rgba(255,255,255,0.8); }
.sev-btn:nth-child(1).active { background: #86efac; border-color: #86efac; color: #14532d; }
.sev-btn:nth-child(2).active { background: #fde047; border-color: #fde047; color: #713f12; }
.sev-btn:nth-child(4).active { background: #f87171; border-color: #f87171; color: white; }
.sev-btn:nth-child(5).active { background: #a855f7; border-color: #a855f7; color: white; }

/* UPLOAD */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--bg);
}
.upload-area:hover, .upload-area:active { border-color: var(--orange); background: var(--orange-light); }
.upload-icon { font-size: 2rem; display: block; margin-bottom: 6px; }
.upload-text { font-size: 0.9rem; font-weight: 700; color: var(--text-muted); margin: 0; }
.upload-sub { font-size: 0.72rem; color: var(--border); margin: 2px 0 0; }

.photo-preview { position: relative; margin-top: 10px; border-radius: var(--radius-sm); overflow: hidden; }
.photo-preview img { width: 100%; max-height: 220px; object-fit: cover; display: block; border-radius: var(--radius-sm); }
.remove-photo {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 50px;
  padding: 4px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  font-family: 'Heebo', sans-serif;
}
.hidden { display: none !important; }

/* SUBMIT */
.submit-btn {
  width: 100%;
  background: var(--orange);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: 'Heebo', sans-serif;
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
  margin-top: 4px;
}
.submit-btn:active { filter: brightness(0.9); transform: scale(0.98); }
.form-msg { text-align: center; font-size: 0.82rem; margin-top: 10px; min-height: 18px; }
.form-msg.ok { color: var(--green); font-weight: 700; }
.form-msg.err { color: #ef4444; font-weight: 700; }

/* STATS */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card.orange { background: linear-gradient(135deg, #fff7ed, #fed7aa); }
.stat-card.green { background: linear-gradient(135deg, #f0fdf4, #bbf7d0); }
.stat-card.pink { background: linear-gradient(135deg, #fdf2f8, #fbcfe8); }
.stat-num { font-size: 1.8rem; font-weight: 900; color: var(--text); }
.stat-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; margin-top: 4px; }

.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.chart-card h3 { font-size: 0.9rem; font-weight: 700; margin-bottom: 12px; color: var(--text-muted); }
.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; }
.bar-label { width: 60px; text-align: right; font-weight: 500; flex-shrink: 0; }
.bar-track { flex: 1; background: var(--bg); border-radius: 50px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 50px; background: var(--orange); transition: width 0.4s ease; }
.bar-count { width: 20px; text-align: left; color: var(--text-muted); font-size: 0.75rem; }

.danger-btn {
  width: 100%;
  background: #fff1f2;
  color: #ef4444;
  border: 1.5px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: 'Heebo', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1c1917;
  color: white;
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: 'Heebo', sans-serif;
  z-index: 999;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  white-space: nowrap;
  max-width: 90vw;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-overlay.open { display: flex; }
.modal-card {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-close {
  position: absolute;
  top: 16px;
  left: 16px;
  background: var(--bg);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-name { font-size: 1.3rem; font-weight: 900; margin-bottom: 12px; }
.modal-photo { width: 100%; border-radius: var(--radius-sm); margin-bottom: 14px; max-height: 260px; object-fit: cover; }
.modal-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.modal-row:last-child { border-bottom: none; }
.modal-row-label { color: var(--text-muted); font-weight: 500; }
.modal-row-val { font-weight: 700; text-align: left; max-width: 60%; }
.modal-notes-block { background: var(--bg); border-radius: var(--radius-sm); padding: 12px; margin-top: 12px; font-size: 0.88rem; line-height: 1.6; }
.modal-delete-btn {
  width: 100%;
  background: #fff1f2;
  color: #ef4444;
  border: 1.5px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: 'Heebo', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 16px;
}
