:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --border: #e6e9f0;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --accent-soft: #eff4ff;
  --green: #16a34a;
  --green-soft: #ecfdf3;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --purple: #7c3aed;
  --purple-soft: #f5f3ff;
  --teal: #0d9488;
  --teal-soft: #f0fdfa;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 36, 48, .05), 0 4px 16px rgba(31, 36, 48, .06);
  --shadow-lg: 0 8px 30px rgba(31, 36, 48, .12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; color: var(--text); }

a { color: var(--accent); text-decoration: none; }

/* ---------- Layout ---------- */
.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0 8px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 18px;
}
.brand h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.brand small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }

.topbar-actions { display: flex; gap: 10px; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  transition: all .15s ease;
  white-space: nowrap;
}
.btn:hover { background: #f8fafc; border-color: #d3d9e4; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { color: var(--red); border-color: #f3c2c2; }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f1f3f8; color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-icon { padding: 6px 9px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Dashboard ---------- */
.search-row { display: flex; gap: 12px; margin: 18px 0 20px; }
.search-input {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  box-shadow: var(--shadow);
  outline: none;
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat { padding: 16px 18px; }
.stat .num { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }
.stat .lbl { color: var(--muted); font-size: 13px; margin-top: 2px; }

.grid-events { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }

.event-card {
  position: relative;
  padding: 18px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
  overflow: hidden;
}
.event-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.event-card .bar { position: absolute; inset: 0 0 auto 0; height: 4px; border-radius: var(--radius) var(--radius) 0 0; }
.event-card h3 { font-size: 17px; font-weight: 700; margin: 4px 0 6px; letter-spacing: -0.2px; }
.event-card .meta { color: var(--muted); font-size: 13px; display: flex; flex-direction: column; gap: 3px; margin-bottom: 12px; }
.event-card .meta span { display: flex; align-items: center; gap: 6px; }
.event-card .desc { color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: 14px; }
.event-stats { display: flex; gap: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.event-stats div { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.event-stats b { color: var(--text); font-size: 14px; }

.status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 20px;
  text-transform: capitalize;
}
.status-upcoming { background: var(--accent-soft); color: var(--accent-dark); }
.status-ongoing { background: var(--amber-soft); color: var(--amber); }
.status-completed { background: var(--green-soft); color: var(--green); }
.status-draft { background: #f1f3f8; color: var(--muted); }

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty .big { font-size: 40px; margin-bottom: 10px; }
.empty h3 { color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* ---------- Event detail ---------- */
.event-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 20px 0 18px; flex-wrap: wrap; }
.event-title-block h2 { font-size: 24px; font-weight: 700; letter-spacing: -0.4px; }
.event-title-block .sub { color: var(--muted); font-size: 14px; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 14px; }
.event-title-block .sub span { display: inline-flex; align-items: center; gap: 6px; }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tab {
  border: none; background: none;
  padding: 11px 16px;
  font-size: 14.5px; font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  display: inline-flex; align-items: center; gap: 7px;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-dark); border-bottom-color: var(--accent); }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-head h3 { font-size: 16px; font-weight: 700; }

/* ---------- Overview ---------- */
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-bottom: 18px; }
.info-item { padding: 14px 16px; }
.info-item .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.info-item .val { font-weight: 600; font-size: 15px; word-break: break-word; }

.critical-box {
  background: var(--amber-soft);
  border: 1px solid #f5dfa8;
  border-radius: var(--radius);
  padding: 18px;
}
.critical-box .lbl { font-weight: 700; color: var(--amber); display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.critical-box .val { white-space: pre-wrap; color: #7c5a12; font-size: 14.5px; }

.editable-field:hover { outline: 1px dashed var(--accent); border-radius: 6px; cursor: text; }

/* ---------- Team ---------- */
.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.member-card { padding: 16px; display: flex; gap: 14px; align-items: flex-start; position: relative; }
.avatar {
  width: 56px; height: 56px; border-radius: 12px;
  object-fit: cover; flex-shrink: 0;
  background: var(--accent-soft);
  color: var(--accent-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 20px;
}
.member-info { flex: 1; min-width: 0; }
.member-info .name { font-weight: 700; font-size: 15.5px; }
.member-info .role { color: var(--accent-dark); background: var(--accent-soft); border-radius: 20px; padding: 1px 8px; font-size: 12px; font-weight: 600; display: inline-block; margin: 3px 0 7px; }
.member-info .detail { color: var(--muted); font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.member-info .detail span { display: flex; align-items: center; gap: 6px; }
.member-actions { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.member-card:hover .member-actions { opacity: 1; }

/* ---------- Team sections ---------- */
.team-section { margin-bottom: 26px; }
.team-section-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.team-section-head h4 { font-size: 15px; font-weight: 700; display: inline-flex; align-items: center; gap: 7px; }
.sec-count { font-size: 12px; color: var(--muted); background: #eef1f6; border-radius: 20px; padding: 2px 9px; font-weight: 600; }
.sec-heads { font-size: 12.5px; color: var(--accent-dark); background: var(--accent-soft); border-radius: 20px; padding: 2px 9px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.sec-tag { display: inline-flex; align-items: center; gap: 5px; color: var(--purple); background: var(--purple-soft); border-radius: 20px; padding: 1px 8px; font-size: 12px; font-weight: 600; margin: 3px 0 7px; }
.member-info .name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.tag-head { background: var(--amber-soft); color: var(--amber); }

/* ---------- Files ---------- */
.file-list { display: flex; flex-direction: column; gap: 10px; }
.file-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; position: relative; }
.file-card:hover { box-shadow: var(--shadow-lg); }
.file-ic { width: 42px; height: 42px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-dark); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-weight: 600; font-size: 14.5px; word-break: break-all; }
.file-meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.file-actions { display: flex; gap: 6px; align-items: center; }

/* ---------- Finances ---------- */
.fin-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 20px; }
.fin-income .num { color: var(--green); }
.fin-expense .num { color: var(--red); }
.fin-bal-pos .num { color: var(--green); }
.fin-bal-neg .num { color: var(--red); }
.fin-list { display: flex; flex-direction: column; gap: 10px; }
.fin-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; position: relative; }
.fin-card:hover { box-shadow: var(--shadow-lg); }
.fin-ic { width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ic-in { background: var(--green-soft); color: var(--green); }
.ic-out { background: var(--red-soft); color: var(--red); }
.fin-info { flex: 1; min-width: 0; }
.fin-title { font-weight: 600; font-size: 14.5px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.fin-meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }
.fin-meta span { display: inline-flex; align-items: center; gap: 4px; }
.fin-type { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.ft-in { background: var(--green-soft); color: var(--green); }
.ft-out { background: var(--red-soft); color: var(--red); }
.fin-amount { font-weight: 700; font-size: 16px; white-space: nowrap; }
.am-in { color: var(--green); }
.am-out { color: var(--red); }
.fin-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.fin-card:hover .fin-actions { opacity: 1; }

/* ---------- Participants & guests ---------- */
.pt-person { background: var(--accent-soft); color: var(--accent-dark); }
.pt-team { background: var(--purple-soft); color: var(--purple); }
.tag-seats { background: var(--teal-soft); color: var(--teal); }
.status-invited { background: var(--accent-soft); color: var(--accent-dark); }
.status-attended { background: var(--teal-soft); color: var(--teal); }

/* ---------- Tasks ---------- */
.task-layout { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-items: start; }
.task-col-head { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 10px; font-weight: 700; font-size: 14px; }
.task-col-head .dot { width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; display: inline-block; }
.task-col-head .count { color: var(--muted); font-weight: 600; background: #eef1f6; border-radius: 20px; padding: 1px 9px; font-size: 12.5px; }
.task-card { padding: 14px; margin-bottom: 12px; position: relative; }
.task-card:hover { box-shadow: var(--shadow-lg); }
.task-card h4 { font-size: 14.5px; font-weight: 700; margin-bottom: 4px; }
.task-card .desc { color: var(--muted); font-size: 13px; margin-bottom: 8px; white-space: pre-wrap; }
.task-card .due { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; margin-bottom: 8px; }
.task-card .assignees { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.task-card .assignee { display: inline-flex; align-items: center; gap: 5px; background: #f1f3f8; border-radius: 20px; padding: 2px 9px 2px 3px; font-size: 12px; font-weight: 600; }
.task-card .assignee .avatar-mini { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; background: var(--accent-soft); color: var(--accent-dark); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; }
.task-card .task-actions { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.task-card:hover .task-actions { opacity: 1; }
.task-card .status-select { margin-top: 10px; width: 100%; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 6px; text-transform: capitalize; }
.imp-low { background: #f1f3f8; color: var(--muted); }
.imp-medium { background: var(--accent-soft); color: var(--accent-dark); }
.imp-high { background: var(--amber-soft); color: var(--amber); }
.imp-critical { background: var(--red-soft); color: var(--red); }

/* ---------- Sponsors ---------- */
.sponsor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.sponsor-card { padding: 16px; position: relative; }
.sponsor-card h4 { font-size: 15.5px; font-weight: 700; }
.sponsor-card .company { color: var(--muted); font-size: 13px; margin: 1px 0 10px; }
.sponsor-card .detail { font-size: 13.5px; color: var(--text); display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.sponsor-card .detail span { display: flex; align-items: center; gap: 7px; }
.sponsor-card .contribution { background: var(--green-soft); border: 1px solid #bfe6cd; border-radius: 10px; padding: 9px 12px; font-size: 13.5px; }
.sponsor-card .contribution b { color: var(--green); }
.sponsor-actions { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.sponsor-card:hover .sponsor-actions { opacity: 1; }
.ct-type { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.ct-money { background: var(--green-soft); color: var(--green); }
.ct-in-kind { background: var(--purple-soft); color: var(--purple); }
.ct-services { background: var(--teal-soft); color: var(--teal); }

/* ---------- Timeline ---------- */
.timeline { position: relative; padding-left: 30px; }
.timeline::before { content: ''; position: absolute; left: 9px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: 20px; }
.tl-item::before {
  content: ''; position: absolute; left: -26px; top: 6px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--card); border: 3px solid var(--accent);
}
.tl-item.done::before { background: var(--green); border-color: var(--green); }
.tl-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; gap: 12px; }
.tl-body { flex: 1; min-width: 0; }
.tl-body h4 { font-size: 14.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.tl-body .desc { color: var(--muted); font-size: 13px; margin-top: 3px; white-space: pre-wrap; }
.tl-date { color: var(--muted); font-size: 12.5px; margin-top: 6px; display: flex; align-items: center; gap: 5px; }
.tl-check { flex-shrink: 0; }
.tl-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.tl-item:hover .tl-actions { opacity: 1; }
.ct-milestone { background: var(--accent-soft); color: var(--accent-dark); }
.ct-prep { background: var(--purple-soft); color: var(--purple); }
.ct-deadline { background: var(--red-soft); color: var(--red); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(31, 36, 48, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px;
  z-index: 100;
  overflow-y: auto;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  padding: 22px;
  animation: slideUp .18s ease;
}
.modal.lg { max-width: 640px; }
.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.modal-close { position: absolute; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 9px;
  background: #fbfcfe; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
  background: #fff;
}
.field textarea { resize: vertical; min-height: 70px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.photo-field { display: flex; align-items: center; gap: 12px; }
.photo-preview { width: 60px; height: 60px; border-radius: 12px; object-fit: cover; border: 1px solid var(--border); background: var(--accent-soft); display: flex; align-items: center; justify-content: center; color: var(--accent-dark); font-weight: 700; }
.photo-remove { color: var(--red); font-size: 12.5px; background: none; border: none; font-weight: 600; }
.photo-remove:hover { text-decoration: underline; }

/* ---------- Misc ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff;
  padding: 10px 18px; border-radius: 10px;
  font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: slideUp .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; font-size: 14px; background: none; border: none; padding: 6px 10px 6px 0; border-radius: 8px; }
.back-link:hover { color: var(--text); background: #eef1f6; }

/* ---------- Timeline progress ---------- */
.tl-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tl-progress { width: 120px; height: 8px; background: #eef1f6; border-radius: 20px; overflow: hidden; }
.tl-progress > span { display: block; height: 100%; background: var(--green); border-radius: 20px; transition: width .3s ease; }
.tl-count { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tl-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 6px;
}
.tl-badge.overdue { background: var(--red-soft); color: var(--red); }
.tl-badge.soon { background: var(--amber-soft); color: var(--amber); }
.tl-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.tl-item.overdue::before { background: var(--red); border-color: var(--red); }
.tl-item.overdue .tl-card { border-color: #f3c2c2; }

/* ---------- Persian / RTL ---------- */
[dir="rtl"] body,
[dir="rtl"] button,
[dir="rtl"] input,
[dir="rtl"] textarea,
[dir="rtl"] select {
  font-family: 'Segoe UI', Tahoma, 'Noto Naskh Arabic', 'Vazirmatn', sans-serif;
}
[dir="rtl"] * { letter-spacing: 0 !important; text-transform: none !important; }
[dir="rtl"] .timeline { padding-left: 0; padding-right: 30px; }
[dir="rtl"] .timeline::before { left: auto; right: 9px; }
[dir="rtl"] .tl-item::before { left: auto; right: -26px; }
[dir="rtl"] .member-actions,
[dir="rtl"] .task-actions,
[dir="rtl"] .sponsor-actions,
[dir="rtl"] .tl-actions { right: auto; left: 10px; }
[dir="rtl"] .back-link { padding: 6px 0 6px 10px; }

.loading { text-align: center; color: var(--muted); padding: 40px; }

.hidden { display: none !important; }

/* --- Users modal --- */
.perm-grid { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 6px; }
.perm-check { display: flex; align-items: center; gap: 5px; font-size: .9rem; cursor: pointer; }
.perm-check input { accent-color: var(--accent); }

/* --- Logout button --- */
#logout-btn { background: none; color: var(--muted); border: 1px solid var(--border); }
#logout-btn:hover { background: #fef2f2; color: #dc2626; border-color: #fecaca; }

/* --- Users button --- */
#users-btn { background: none; color: var(--accent); border: 1px solid var(--border); }
#users-btn:hover { background: var(--accent-soft); }

@media (max-width: 820px) {
  .task-layout { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .fin-summary { grid-template-columns: 1fr; }
  .fin-amount { font-size: 14px; }
}
