:root {
  --bg: #ffffff;
  --text: #111111;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #e11d2e; /* red */
  --primary-600: #c51625;
  --secondary: #000000; /* black */
}

/* Custom Fonts */
@font-face {
  font-family: 'PeydaWebFaNum';
  src: url('fonts/PeydaWebFaNum-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'PeydaWebFaNum';
  src: url('fonts/PeydaWebFaNum-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'PeydaWebFaNum', system-ui, -apple-system, Segoe UI, Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  direction: rtl;
}

/* Ensure custom font applies to interactive controls and tabs */
button, input, select, textarea {
  font-family: 'PeydaWebFaNum', system-ui, -apple-system, Segoe UI, Tahoma, Arial, sans-serif;
}
input::placeholder, textarea::placeholder { font-family: inherit; }

.hidden { display: none !important; }

/* Auth */
.auth-card {
  max-width: 400px;
  margin: 8vh auto;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.06);
  background: var(--bg);
}
.brand { text-align: center; margin-bottom: 16px; }
.brand .logo {
  width: 56px; height: 56px; margin: 0 auto 8px;
  border-radius: 12px;
  background: var(--secondary);
  color: #fff; display: grid; place-items: center;
  font-weight: 700;
}
.brand h1 { margin: 4px 0; font-size: 22px; }
.muted { color: var(--muted); }

.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field span { font-size: 14px; color: var(--muted); }
.field > span:empty { display: none; }
input[type="text"], input[type="password"], input[type="email"], input[type="search"], select {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
}
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(225,29,46,0.12); }
select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(225,29,46,0.12); }

/* Period dropdown alignment */
#period-select { min-width: 220px; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .02s ease, background .2s ease, border-color .2s ease;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn.ghost { background: transparent; }

.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.error { color: var(--primary); margin-top: 8px; text-align: center; min-height: 20px; }

/* App shell */
#app-view {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* Collapsed sidebar state */
#app-view.collapsed { grid-template-columns: 72px 1fr; }
#app-view.collapsed .sidebar .title,
#app-view.collapsed .nav-item span:not(.icon) { display: none; }
#app-view.collapsed .sidebar { padding: 16px 8px; overflow: hidden; }
#app-view.collapsed .nav-item { justify-content: center; overflow: hidden; gap: 0; }
#app-view.collapsed .nav-item span { width: 0; opacity: 0; pointer-events: none; }
#app-view.collapsed .sidebar-header .title { width: 0; opacity: 0; pointer-events: none; }
#app-view.collapsed .nav { align-items: center; }
/* Center brand in collapsed header */
#app-view.collapsed .sidebar-header { justify-content: center; }
/* Icon-only logout + hide profile name in collapsed */
#app-view.collapsed .profile-box { border: none; padding: 0; background: transparent; }
#app-view.collapsed .profile-box .profile-name { display: none; }
#app-view.collapsed .profile-box .label { display: none; }
#app-view.collapsed #logout { width: 40px; height: 40px; padding: 8px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; }
#app-view.collapsed #logout .icon { font-size: 20px; }
/* In collapsed mode, remove active bg and center footer button */
#app-view.collapsed .nav-item.active { background: transparent; border-color: transparent; color: inherit; }
#app-view.collapsed .sidebar-footer { display: flex; justify-content: center; }
/* Collapsed: highlight active icon and add a slim accent bar */
#app-view.collapsed .nav-item { position: relative; }
#app-view.collapsed .nav-item .icon { opacity: 0.9; }
#app-view.collapsed .nav-item.active .icon { color: var(--primary-600); }
#app-view.collapsed .nav-item.active::before {
  content: '';
  position: absolute;
  inset-inline-start: 6px;
  top: 50%;
  translate: 0 -50%;
  width: 3px;
  height: 22px;
  border-radius: 2px;
  background: var(--primary-600);
}

.sidebar {
  border-left: 1px solid var(--border);
  padding: 16px 12px;
  display: grid; grid-template-rows: auto 1fr auto;
  gap: 12px;
  background: #fff;
}
.sidebar-header { display: flex; align-items: center; gap: 10px; padding: 6px 8px; justify-content: flex-start; }
.logo.small { width: 36px; height: 36px; border-radius: 8px; background: var(--secondary); color: #fff; display: grid; place-items: center; font-weight: 700; }
.sidebar .title { font-weight: 600; }
/* Sidebar favicon presentation */
.sidebar-header img#sidebar-favicon { width:24px; height:24px; border-radius:6px; object-fit: contain; background: transparent; }

.nav { display: grid; gap: 6px; align-content: start; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
}
.nav-item .icon { width: 20px; text-align: center; }
.nav-item i.icon { font-size: 20px; line-height: 1; }
.nav-item:hover { background: #fafafa; border-color: var(--border); }
.nav-item.active { background: rgba(225,29,46,0.08); border-color: rgba(225,29,46,0.22); color: var(--primary-600); }

.sidebar-footer { padding: 6px 8px; }

/* Profile box at sidebar bottom */
.profile-box { border: 1px solid var(--border); border-radius: 12px; padding: 10px; background: #fff; display: grid; gap: 8px; }
.profile-name { font-weight: 600; font-size: 14px; }

.content { padding: 20px; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 0 18px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.icon-btn { background: transparent; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; cursor: pointer; }
/* Topbar extras */
.topbar .spacer { flex: 1; }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; display:flex; gap:10px; align-items:baseline; }
.clock .time { color: var(--primary); font-weight: 700; font-size: 16px; }
.clock .date { opacity: .8; direction: rtl; unicode-bidi: isolate; }
/* User name pill next to clock */
.user-pill { display:flex; align-items:center; gap:8px; margin-inline-start: 10px; padding:6px 10px; border:1px solid var(--border); border-radius:999px; background:#fff; color: var(--text); font-size:14px; }
.user-pill .avatar { width:22px; height:22px; border-radius:50%; background: rgba(225,29,46,0.12); color: var(--primary-600); display:grid; place-items:center; font-size:12px; font-weight:700; }

.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.card { border: 1px solid var(--border); border-radius: 14px; padding: 16px; background: #fff; box-shadow: 0 6px 24px rgba(0,0,0,0.04); }
/* Add spacing between stacked cards on Home */
#tab-home .card + .card { margin-top: 14px; }
.card h3 { margin: 0 0 8px; font-size: 16px; }

.kpi { display: grid; gap: 6px; }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--secondary); }

.tab { display: none; }
.tab.active { display: block; }

.table-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.table-wrapper { overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { background: #fafafa; color: var(--muted); font-weight: 600; text-align: right; }
th, td { padding: 12px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: #fff5f6; }

.switch { display: flex; align-items: center; gap: 10px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.full { grid-column: 1 / -1; }

/* Responsive */
@media (max-width: 900px) {
  #app-view { grid-template-columns: 72px 1fr; }
  .sidebar .title, .nav-item span:not(.icon) { display: none; }
}
@media (max-width: 640px) {
  .cards { grid-template-columns: 1fr; }
}

/* Modal */
.modal.hidden { display: none; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.35); display: grid; place-items: center; z-index: 50; }
.modal-card { width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); padding: 16px; }
.modal-card h3 { margin: 0 0 12px; font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* Large modal for permissions */
.modal-card.large { max-width: 920px; }
.perm-row { display: grid; grid-template-columns: 1fr; gap: 10px; }
.perm-row .field { margin: 0; }
select[multiple] { min-height: 140px; padding: 8px; }

/* Inner (tab) sidebar for شعب management */
.sub-layout { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }
.sub-sidebar { border-left: 1px solid var(--border); background: #fff; border-radius: 12px; padding: 12px; height: fit-content; align-self: start; }
.sub-header { font-weight: 700; padding: 6px 8px 10px; }
.sub-nav { display: grid; gap: 6px; }
.sub-item { display: block; width: 100%; text-align: right; padding: 10px 12px; border-radius: 10px; border: 1px solid transparent; background: transparent; cursor: pointer; }
.sub-item:hover { background: #fafafa; border-color: var(--border); }
.sub-item.active { background: rgba(225,29,46,0.08); border-color: rgba(225,29,46,0.22); color: var(--primary-600); }
.sub-content { display: grid; gap: 12px; }

/* Branch inner top tabs */
.branch-tabs { display: flex; gap: 8px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.branch-tab-btn { padding: 10px 12px; border: 1px solid transparent; border-radius: 10px 10px 0 0; background: transparent; cursor: pointer; }
.branch-tab-btn.active { background: #fff; border-color: var(--border); border-bottom-color: #fff; }
.branch-tab-section.hidden { display: none; }

/* Bulk bar for systems */
.bulk-bar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin: 8px 0 12px; flex-wrap: wrap; }
.bulk-left { display: flex; align-items: center; gap: 10px; }
.chk { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.bulk-form { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(120px, 1fr); gap: 8px; align-items: end; }
.bulk-form input[type="text"] { min-width: 120px; }

/* Hide number arrows globally if any are used */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

/* Periods */
.period-toolbar { display: flex; gap: 8px; align-items: center; }
.periods-list { display: grid; gap: 10px; margin: 6px 0; }
.period-row { display: grid; grid-template-columns: repeat(2, 1fr) max-content; gap: 8px; align-items: end; }
.period-row .field { margin: 0; }
.period-row input[type="time"] { width: 100%; }

/* Timeline editor */
.timeline { display: grid; gap: 8px; margin: 10px 0; }
.timeline-scale { position: relative; height: 16px; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 11px; }
.timeline-scale::before { content: ''; position: absolute; inset: auto 0 0 0; height: 1px; background: var(--border); }
.timeline-scale .tick { position: absolute; bottom: 0; width: 1px; height: 6px; background: var(--border); }
.timeline-scale .label { position: absolute; bottom: 6px; transform: translateX(-50%); }

.timeline-track { position: relative; height: 36px; border: 1px solid var(--border); border-radius: 10px; background: #fafafa; overflow: hidden; }
.timeline-segment { position: absolute; top: 0; bottom: 0; background: rgba(225,29,46,0.12); border-right: 1px solid rgba(0,0,0,0.04); display: flex; align-items: center; justify-content: center; color: #991b1b; font-size: 12px; }
.timeline-segment.alt { background: rgba(0,0,0,0.06); color: #111; }
.timeline-segment .seg-del { position: absolute; top: 4px; inset-inline-end: 6px; font-size: 11px; padding: 2px 6px; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: pointer; }
.timeline-segment .seg-del:hover { background: #fff5f6; }

.timeline-handle { position: absolute; top: -6px; width: 10px; height: 48px; margin-inline-start: -5px; background: var(--secondary); border-radius: 3px; cursor: ew-resize; box-shadow: 0 2px 6px rgba(0,0,0,0.15); }
.timeline-handle.locked { background: #cbd5e1; cursor: not-allowed; }
.timeline-handle.new { background: var(--primary); }
.timeline-handle::after { content: ''; position: absolute; inset: 6px 2px; border-radius: 2px; background: rgba(255,255,255,0.7); }

/* Danger button */
.btn.danger { color: #b91c1c; border-color: #fecaca; background: #fff5f5; }
.btn.danger:hover { background: #fee2e2; border-color: #fca5a5; }

/* Roles multiselect pills */
.roles-boxes { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0; }
.role-pill {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
}
.role-pill.selected { background: rgba(225,29,46,0.10); border-color: var(--primary); color: var(--primary-600); }

/* Toast (undo) */
/* A small floating pill with slide-up "blub" entrance and 3s timer bar */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  padding: 10px 14px 14px; /* extra for progress bar */
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.28);
  z-index: 60;
  cursor: pointer;
  max-width: min(92vw, 560px);
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
  will-change: transform, opacity;
  animation: toast-in 220ms cubic-bezier(.22,.9,.25,1.05);
}
.toast.hidden { display: none; }
/* subtle hover */
.toast:hover { background: #0e0e0e; }
/* progress track */
.toast::after {
  content: '';
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 8px;
  height: 3px;
  background: rgba(255,255,255,0.18);
  border-radius: 99px;
}
/* progress fill animates from 100% to 0 in 3s when visible */
.toast:not(.hidden)::before {
  content: '';
  position: absolute;
  left: 10px;
  bottom: 8px;
  height: 3px;
  width: 100%;
  background: var(--primary);
  border-radius: 99px;
  animation: toast-progress 3s linear forwards;
}
/* leaving state for a smooth fade down */
.toast.leaving {
  animation: toast-out 160ms ease forwards;
}

@keyframes toast-in {
  0% { opacity: 0; transform: translateX(-50%) translateY(14px) scale(0.96); }
  60% { opacity: 1; transform: translateX(-50%) translateY(-2px) scale(1.02); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
@keyframes toast-out {
  0% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(10px) scale(0.98); }
}
@keyframes toast-progress {
  from { width: 100%; }
  to { width: 0%; }
}
