* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: 'Segoe UI', 'Assistant', Arial, sans-serif; background: #f1f5f9; color: #1e293b; }

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

/* ===== Sidebar (right side, RTL) ===== */
.sidebar {
  width: 240px; min-width: 240px; background: #fff; border-left: 1px solid #e2e8f0;
  display: flex; flex-direction: column; height: 100vh; position: sticky; top: 0;
}
.brand {
  display: flex; flex-direction: column; align-items: stretch; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid #e2e8f0;
}
.brand-logo {
  width: 100%; max-width: 200px; height: auto;
  display: block; margin: 0 auto;
}
.brand-info { font-size: 13px; text-align: right; }
.brand-name { font-weight: 600; color: #1e293b; }
.brand-role { color: #94a3b8; font-size: 11px; }

nav { display: flex; flex-direction: column; padding: 10px 0; flex: 1; overflow-y: auto; }
.nav-section {
  padding: 14px 18px 6px; font-size: 11px; color: #94a3b8;
  text-transform: none; letter-spacing: 0.5px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 18px; font-size: 13.5px; color: #475569;
  text-decoration: none; cursor: pointer; border-right: 3px solid transparent;
}
.nav-item:hover { background: #f8fafc; color: #1e293b; }
.nav-item.active {
  background: #f5f3ff; color: #6d28d9; font-weight: 600;
  border-right-color: #6d28d9;
}
.nav-item .ic { font-size: 16px; width: 20px; text-align: center; }

/* ===== Main ===== */
main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; background: #fff; border-bottom: 1px solid #e2e8f0;
  position: sticky; top: 0; z-index: 5;
}
.topbar-brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.topbar-logo { height: 30px; width: auto; max-width: 160px; display: block; flex-shrink: 0; }
.topbar-title { font-size: 17px; font-weight: 600; color: #1e293b; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 12px; border-right: 1px solid #e2e8f0; }
.topbar-menu { font-size: 22px; color: #64748b; cursor: pointer; display: none; line-height: 1; padding: 4px 8px; }

/* drawer overlay (mobile only) */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.45); z-index: 40;
}
.sidebar-overlay.show { display: block; }

.view { padding: 18px 22px 40px; }
.view.hidden { display: none; }

/* ===== Stats ===== */
.stats {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 12px; margin-bottom: 18px;
}
.stat-card {
  background: #fff; border-radius: 10px; padding: 14px 16px;
  display: flex; align-items: center; gap: 14px; cursor: pointer;
  border: 2px solid transparent; transition: all 0.15s;
  flex-direction: row-reverse;
}
.stat-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.06); }
.stat-icon {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #fff;
}
.stat-icon-all      { background: #8b5cf6; }
.stat-icon-open     { background: #3b82f6; }
.stat-icon-overdue  { background: #ef4444; }
.stat-icon-near     { background: #f59e0b; }
.stat-icon-done     { background: #10b981; }

.stat-content { text-align: right; }
.stat-num { font-size: 26px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: #64748b; margin-top: 4px; }

.stat-all     { border-color: #c4b5fd; }
.stat-open    { border-color: #bfdbfe; }
.stat-overdue { border-color: #fecaca; }
.stat-near    { border-color: #fed7aa; }
.stat-done    { border-color: #a7f3d0; }

/* ===== Toolbar ===== */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; flex-direction: row-reverse;
}
.btn-primary {
  background: #2563eb; color: #fff; border: 0;
  padding: 9px 16px; border-radius: 6px; font-size: 13.5px;
  font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: #1d4ed8; }

.period-filter { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.period-filter select {
  padding: 7px 10px; border-radius: 6px; border: 1px solid #cbd5e1;
  background: #fff; font-size: 13px; min-width: 160px;
}

/* ===== Table ===== */
.table-wrap {
  background: #fff; border-radius: 10px; overflow: auto;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.table-header-banner {
  padding: 8px 14px; background: #f1f5f9;
  text-align: center; font-size: 12px; color: #64748b;
  border-bottom: 1px solid #e2e8f0;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  padding: 10px 12px; text-align: right; font-weight: 600;
  background: #f8fafc; color: #475569; border-bottom: 1px solid #e2e8f0;
  white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.filter-ic { color: #94a3b8; font-size: 10px; margin-right: 4px; }
.filter-row th { padding: 4px 8px; background: #fff; border-bottom: 1px solid #e2e8f0; }
.filter-row input, .filter-row select {
  width: 100%; padding: 5px 8px; font-size: 12px;
  border: 1px solid #e2e8f0; border-radius: 4px; outline: none;
  background: #fff; font-family: inherit;
}
.filter-row input:focus, .filter-row select:focus { border-color: #6366f1; }

tbody td {
  padding: 10px 12px; border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
tbody tr:hover { background: #fafbfc; }

.status-badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; color: #fff; white-space: nowrap;
}
.risk-badge {
  display: inline-flex; width: 22px; height: 22px; border-radius: 50%;
  align-items: center; justify-content: center; color: #fff; font-size: 12px;
}
.risk-ok      { background: #10b981; }
.risk-warning { background: #f59e0b; }
.risk-danger  { background: #ef4444; }
.risk-none    { background: #cbd5e1; color: #64748b; }

.comment-count {
  display: inline-block; min-width: 22px; height: 22px; padding: 0 6px;
  background: #3b82f6; color: #fff; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; text-align: center; line-height: 22px;
}
.client-link {
  font-weight: 600; color: #1e293b; cursor: pointer; text-decoration: none;
  border-bottom: 1px dashed transparent;
}
.client-link:hover { color: #2563eb; border-bottom-color: #2563eb; }

.last-comment-cell {
  max-width: 200px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; border-bottom: 1px dashed #e2e8f0;
}
.row-action {
  background: #eff6ff; color: #2563eb; border: 0; padding: 4px 8px;
  border-radius: 4px; cursor: pointer; font-size: 11px;
}
.row-action:hover { background: #dbeafe; }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: #fff; width: 100%; max-width: 720px; max-height: 90vh;
  border-radius: 12px; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
  padding: 14px 20px; border-bottom: 1px solid #e2e8f0;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { margin: 0; font-size: 17px; }
.modal-close {
  background: transparent; border: 0; font-size: 18px; cursor: pointer; color: #64748b;
}
.modal-body { padding: 20px; overflow-y: auto; }

.form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-group label {
  display: block; font-size: 12px; color: #475569; margin-bottom: 5px; font-weight: 500;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 8px 10px; font-size: 13px;
  border: 1px solid #cbd5e1; border-radius: 6px; outline: none;
  font-family: inherit; background: #fff;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.form-group textarea { resize: vertical; min-height: 70px; }

.modal-footer {
  padding: 14px 20px; border-top: 1px solid #e2e8f0;
  display: flex; gap: 10px; justify-content: flex-start; background: #f8fafc;
}
.btn-secondary {
  background: #fff; color: #475569; border: 1px solid #cbd5e1;
  padding: 8px 14px; border-radius: 6px; font-size: 13px; cursor: pointer;
}
.btn-secondary:hover { background: #f1f5f9; }
.btn-danger {
  background: #dc2626; color: #fff; border: 0;
  padding: 8px 14px; border-radius: 6px; font-size: 13px; cursor: pointer;
}
.btn-danger:hover { background: #b91c1c; }

.multi-select-wrap {
  border: 1px solid #cbd5e1; border-radius: 6px; padding: 6px; max-height: 110px; overflow-y: auto; background: #fff;
}
.multi-select-wrap label {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px; font-size: 12.5px;
  cursor: pointer; color: #1e293b; font-weight: normal;
}
.multi-select-wrap label:hover { background: #f1f5f9; }
.multi-select-wrap input { margin: 0; flex-shrink: 0; width: 15px; height: 15px; cursor: pointer; }

/* ===== Comments inside task modal ===== */
.comments-section { margin-top: 18px; border-top: 1px solid #e2e8f0; padding-top: 14px; }
.comments-section h4 { margin: 0 0 10px; font-size: 14px; color: #334155; }
.comment-item { padding: 8px 10px; background: #f8fafc; border-radius: 6px; margin-bottom: 6px; font-size: 13px; }
.comment-meta { font-size: 11px; color: #94a3b8; margin-top: 4px; }
.new-comment { display: flex; gap: 8px; margin-top: 10px; }
.new-comment input { flex: 1; padding: 8px; border: 1px solid #cbd5e1; border-radius: 6px; font-family: inherit; }

/* ===== Generic Entity tables ===== */
.entity-view h2 { margin: 0 0 14px; font-size: 20px; }
.entity-view .toolbar { margin-bottom: 14px; }
.entity-table { background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.entity-table table { width: 100%; }

/* ===== Reports view ===== */
.reports-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px;
}
.rep-card {
  background: #fff; border-radius: 10px; padding: 16px 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.rep-card-wide { grid-column: 1 / -1; }
.rep-card h3 {
  margin: 0 0 14px; font-size: 15px; color: #1e293b;
  display: flex; align-items: center; gap: 8px;
}
.rep-empty { color: #94a3b8; font-size: 13px; padding: 8px 0; }

.rep-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.rep-bar-label {
  width: 120px; min-width: 120px; font-size: 12.5px; color: #475569;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
}
.rep-bar-track { flex: 1; background: #f1f5f9; border-radius: 6px; height: 18px; overflow: hidden; }
.rep-bar-fill { height: 100%; border-radius: 6px; min-width: 2px; transition: width 0.3s; }
.rep-bar-count { width: 34px; text-align: center; font-size: 13px; font-weight: 600; color: #1e293b; }

.risk-summary { display: flex; gap: 12px; }
.risk-box {
  flex: 1; border-radius: 8px; padding: 16px 8px; text-align: center;
  font-size: 12.5px; color: #334155;
}
.risk-num { font-size: 28px; font-weight: 700; line-height: 1; margin-bottom: 4px; }

.rep-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rep-table thead th {
  text-align: right; padding: 8px 10px; background: #f8fafc; color: #475569;
  font-weight: 600; border-bottom: 1px solid #e2e8f0; position: static;
}
.rep-table tbody td { padding: 8px 10px; border-bottom: 1px solid #f1f5f9; }
.rep-table tbody tr:hover { background: #f8fafc; }

.rep-pill {
  display: inline-block; min-width: 22px; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 700; text-align: center;
}
.rep-pill-red { background: #fee2e2; color: #b91c1c; }
.rep-pill-amber { background: #fef3c7; color: #92400e; }

@media (max-width: 900px) {
  .reports-grid { grid-template-columns: 1fr; }
}

/* ===== Empty / change pw ===== */
.empty-state { background: #fff; padding: 40px; border-radius: 10px; text-align: center; color: #64748b; }
.empty-state h2 { color: #1e293b; }

.change-pw-card { background: #fff; max-width: 460px; padding: 24px; border-radius: 10px; }
.change-pw-card h2 { margin: 0 0 14px; font-size: 18px; }
.change-pw-card .form-group { margin-bottom: 12px; }

/* ===== Toast ===== */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 4px 20px rgba(0,0,0,0.3); z-index: 100;
}
#toast.hidden { display: none; }
#toast.error { background: #dc2626; }
#toast.success { background: #059669; }

/* ===== Color dot for status type ===== */
.color-dot { display: inline-block; width: 14px; height: 14px; border-radius: 4px; margin-left: 6px; vertical-align: middle; }

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Mobile (phones / tablets) ===== */
@media (max-width: 820px) {
  /* safety net: never let the page scroll horizontally */
  html, body { overflow-x: hidden; max-width: 100vw; }

  /* hamburger shows, sidebar becomes a slide-in drawer from the right (RTL) */
  .topbar-menu { display: block; }

  .sidebar {
    position: fixed; top: 0; right: 0; height: 100vh; width: 250px; min-width: 250px;
    transform: translateX(100%); transition: transform 0.25s ease; z-index: 50;
    box-shadow: -4px 0 24px rgba(0,0,0,0.15);
  }
  .sidebar.open { transform: translateX(0); }

  .topbar { position: sticky; top: 0; }
  .view { padding: 12px; }

  /* stats: "כל המשימות" wide on top, then a tidy 2x2 of the rest */
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .stat-card:first-child { grid-column: 1 / -1; }
  .stat-card { padding: 12px 14px; gap: 10px; border-width: 1px; }
  .stat-num { font-size: 22px; }
  .stat-label { font-size: 11.5px; }
  .stat-icon { width: 32px; height: 32px; font-size: 15px; }

  .toolbar { flex-direction: column-reverse; align-items: stretch; gap: 8px; }
  .toolbar .btn-primary { width: 100%; }
  .period-filter { justify-content: space-between; }
  .period-filter select { flex: 1; }

  /* main tasks table scrolls horizontally inside its wrapper - touch-friendly */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  #tasks-table { min-width: 760px; }

  /* reports tables: compact, fit narrow screens (don't force horizontal scroll) */
  .rep-table { font-size: 12px; }
  .rep-table thead th, .rep-table tbody td { padding: 6px 7px; }

  /* modals go (almost) full-screen */
  .modal { max-width: 100%; width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
  .modal-backdrop { padding: 0; }
  .form-grid { grid-template-columns: 1fr; }

  .reports-grid { grid-template-columns: 1fr; gap: 10px; }
  .rep-card { padding: 14px 12px; }
  .rep-card h3 { font-size: 14px; margin-bottom: 10px; }
  .rep-bar-row { gap: 8px; }
  .rep-bar-label { width: 80px; min-width: 80px; font-size: 12px; }
  .rep-bar-count { width: 28px; font-size: 12.5px; }
  .risk-summary { gap: 6px; }
  .risk-box { padding: 12px 6px; font-size: 11.5px; }
  .risk-num { font-size: 22px; }

  .change-pw-card { max-width: 100%; }
}

/* slightly smaller phones - keep the 2x2 stats, just tighten */
@media (max-width: 460px) {
  .stats { gap: 8px; }
  .stat-card { padding: 10px; gap: 8px; }
  .stat-num { font-size: 20px; }
  .stat-icon { width: 30px; height: 30px; font-size: 14px; }
  .topbar-title { font-size: 15px; }
}
