/* ═══════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:      #1E3A5F;
  --navy2:     #2A5082;
  --navy-dk:   #122440;
  --gold:      #C9A84C;
  --gold-lt:   #E2C87A;
  --white:     #FFFFFF;
  --bg:        #F0F4F9;
  --card:      #FFFFFF;
  --border:    #E2EAF4;
  --muted:     #8DA4BE;
  --text:      #1A2B3C;
  --text2:     #4A6580;
  --success:   #3D9970;
  --error:     #E05252;
  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 2px 12px rgba(30,58,95,.08);
  --shadow-md: 0 4px 24px rgba(30,58,95,.12);
  --tr:        180ms ease;
}

html { font-size: 15px; }
body {
  font-family: 'Cairo', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  direction: rtl;
}

/* ═══════════════════════════════════════════════
   LAYOUT
═══════════════════════════════════════════════ */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ═══════════════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════════════ */
.sidebar {
  width: 220px;
  background: var(--navy-dk);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-icon {
  width: 36px; height: 36px;
  background: var(--gold);
  border-radius: 8px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.brand-icon svg { width: 20px; height: 20px; fill: var(--navy-dk); }
.brand-name { font-size: .9rem; font-weight: 900; color: var(--white); }
.brand-sub  { font-size: .7rem; color: rgba(255,255,255,.4); margin-top: 1px; }

.sidebar-nav { padding: 12px 10px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.55);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--tr);
  margin-bottom: 2px;
  text-decoration: none;
  user-select: none;
}
.nav-item svg { width: 16px; height: 16px; fill: currentColor; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.06); color: rgba(255,255,255,.85); }
.nav-item.active { background: var(--gold); color: var(--navy-dk); font-weight: 700; }
.nav-item.active svg { fill: var(--navy-dk); }
.nav-badge {
  margin-right: auto;
  background: rgba(255,255,255,.15);
  color: rgba(255,255,255,.7);
  font-size: .65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 100px;
}
.nav-item.active .nav-badge { background: rgba(30,58,95,.2); color: var(--navy-dk); }

.sidebar-footer {
  padding: 14px 16px;
  font-size: .65rem;
  color: rgba(255,255,255,.25);
  border-top: 1px solid rgba(255,255,255,.06);
  text-align: center;
}

/* ═══════════════════════════════════════════════
   MAIN CONTENT
═══════════════════════════════════════════════ */
.main-content {
  flex: 1;
  margin-right: 220px;
  padding: 16px 24px;
  min-height: 100vh;
}

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

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-title { font-size: 1.25rem; font-weight: 900; color: var(--navy); }
.page-sub   { font-size: .78rem; color: var(--muted); margin-top: 3px; }

/* ═══════════════════════════════════════════════
   FORM
═══════════════════════════════════════════════ */
.form-sections { display: flex; flex-direction: column; gap: 12px; }

.form-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(135deg, var(--navy-dk), var(--navy));
  font-size: .75rem;
  font-weight: 700;
  color: rgba(255,255,255,.85);
  letter-spacing: .04em;
}
.section-num {
  width: 20px; height: 20px;
  background: var(--gold);
  color: var(--navy-dk);
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: .7rem;
  font-weight: 900;
  flex-shrink: 0;
}

.fields-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 16px;
}

.field { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 4px; }
.field.sm { flex: 0 0 160px; }

label {
  font-size: .72rem;
  font-weight: 700;
  color: var(--text2);
  letter-spacing: .02em;
}
.req  { color: var(--gold); }
.note { font-weight: 400; color: var(--muted); font-size: .68rem; margin-right: 4px; }

input, select {
  width: 100%;
  padding: 8px 11px;
  font-family: 'Cairo', sans-serif;
  font-size: .82rem;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--tr), box-shadow var(--tr);
  appearance: none;
  direction: rtl;
}
input::placeholder { color: var(--muted); font-weight: 400; font-size: .78rem; }
input:focus, select:focus {
  border-color: var(--gold);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(201,168,76,.12);
}
input.error, select.error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(224,82,82,.1);
}
input[readonly] {
  background: rgba(30,58,95,.04);
  color: var(--navy2);
  font-weight: 700;
  cursor: not-allowed;
}
input[type="date"] { font-family: 'Cairo', sans-serif; }

.sel-wrap { position: relative; }
.sel-wrap select { padding-left: 28px; cursor: pointer; }
.sel-wrap svg {
  position: absolute;
  left: 8px; top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  fill: var(--muted);
  pointer-events: none;
}

.ferr { font-size: .68rem; color: var(--error); font-weight: 600; min-height: 14px; }

/* ═══════════════════════════════════════════════
   FORM ACTIONS
═══════════════════════════════════════════════ */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  font-family: 'Cairo', sans-serif;
  font-size: .82rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--tr);
}
.btn svg { width: 15px; height: 15px; fill: currentColor; }

.btn-primary {
  background: linear-gradient(135deg, var(--navy), var(--navy2));
  color: var(--white);
  box-shadow: 0 3px 10px rgba(30,58,95,.25);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 5px 16px rgba(30,58,95,.3); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text2); }

.btn-export {
  background: #1D6F42;
  color: var(--white);
  box-shadow: 0 3px 10px rgba(29,111,66,.2);
}
.btn-export:hover { background: #155233; transform: translateY(-1px); }

.btn:disabled { opacity: .6; cursor: not-allowed; transform: none !important; }

/* ═══════════════════════════════════════════════
   FORM STATUS
═══════════════════════════════════════════════ */
.form-status {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: .78rem;
  font-weight: 600;
}
.form-status.success { background: rgba(61,153,112,.08); color: var(--success); border: 1px solid rgba(61,153,112,.2); }
.form-status.error   { background: rgba(224,82,82,.07);  color: var(--error);   border: 1px solid rgba(224,82,82,.2);  }
.hidden { display: none !important; }

/* ═══════════════════════════════════════════════
   TABLE
═══════════════════════════════════════════════ */
.table-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: .75rem; }

thead th {
  padding: 9px 12px;
  text-align: right;
  background: var(--navy-dk);
  color: rgba(255,255,255,.8);
  font-weight: 700;
  font-size: .7rem;
  letter-spacing: .03em;
  white-space: nowrap;
}
thead th:first-child { border-radius: 0 0 0 0; }

tbody tr { border-bottom: 1px solid var(--bg); transition: background var(--tr); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(201,168,76,.04); }
tbody td {
  padding: 8px 12px;
  color: var(--text);
  white-space: nowrap;
  font-size: .75rem;
}
tbody td:first-child { color: var(--muted); font-weight: 700; font-size: .7rem; text-align: center; }

.code-tag {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(201,168,76,.1);
  color: #9A7530;
  border-radius: 4px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
}
.dept-tag {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(30,58,95,.07);
  color: var(--navy2);
  border-radius: 4px;
  font-size: .68rem;
  font-weight: 700;
}
.active-tag {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(61,153,112,.1);
  color: #2E7D55;
  border-radius: 4px;
  font-size: .68rem;
  font-weight: 700;
}
.num-td { font-weight: 700; color: var(--navy2); direction: ltr; text-align: left; }

/* ═══════════════════════════════════════════════
   EMPTY STATE
═══════════════════════════════════════════════ */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding: 48px 24px;
  color: var(--muted); font-size: .82rem;
}
.empty-state svg { width: 40px; height: 40px; fill: var(--border); }

/* ═══════════════════════════════════════════════
   TOAST
═══════════════════════════════════════════════ */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--navy-dk);
  color: var(--white);
  padding: 10px 20px;
  border-radius: 100px;
  display: flex; align-items: center; gap: 8px;
  font-size: .8rem; font-weight: 600;
  box-shadow: var(--shadow-md);
  z-index: 999; opacity: 0;
  transition: all .3s cubic-bezier(.175,.885,.32,1.275);
  pointer-events: none;
  border-right: 3px solid var(--gold);
}
.toast svg { width: 15px; height: 15px; fill: var(--gold); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ═══════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .brand-name, .brand-sub, .nav-item span, .sidebar-footer { display: none; }
  .sidebar-brand { justify-content: center; padding: 16px 0; }
  .nav-item { justify-content: center; padding: 12px; }
  .nav-badge { display: none; }
  .main-content { margin-right: 60px; margin-left: 0; padding: 20px 16px; }
  .field.sm { flex: 1; min-width: 140px; }
}

/* ═══ TWO COL LAYOUT ═══ */
.two-col {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ═══ PROJECT BADGE ═══ */
.proj-tag {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(42,80,130,.1);
  color: var(--navy2);
  border-radius: 4px;
  font-size: .68rem;
  font-weight: 700;
}

/* ═══ DELETE BUTTON ═══ */
.btn-del {
  background: rgba(224,82,82,.08);
  border: 1px solid rgba(224,82,82,.2);
  color: var(--error);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: all var(--tr);
}
.btn-del:hover { background: rgba(224,82,82,.15); }
.btn-del svg { width: 14px; height: 14px; fill: currentColor; }

/* ═══ DANGER BUTTON ═══ */
.btn-danger {
  background: var(--error);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 20px;
  font-family: 'Cairo', sans-serif;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--tr);
}
.btn-danger:hover { background: #c94444; }

/* ═══ CONFIRM OVERLAY ═══ */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 500;
  display: grid; place-items: center;
  backdrop-filter: blur(2px);
}
.confirm-box {
  background: var(--white);
  border-radius: var(--radius);
  padding: 28px 32px;
  box-shadow: var(--shadow-md);
  min-width: 300px;
  text-align: center;
}
.confirm-box p { font-weight: 700; color: var(--navy); font-size: .95rem; }

/* ═══ NAV GROUP LABEL ═══ */
.nav-group-label {
  font-size: .62rem;
  font-weight: 900;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.25);
  padding: 14px 12px 4px;
  margin-top: 4px;
}

/* ═══ EXTRA FIELD SIZES ═══ */
.field.xs { flex: 0 0 120px; min-width: 100px; }

/* ═══ TEXTAREA ═══ */
.textarea-field {
  width: 100%;
  padding: 8px 11px;
  font-family: 'Cairo', sans-serif;
  font-size: .82rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  resize: vertical;
  outline: none;
  direction: rtl;
  color: var(--text);
  transition: border-color var(--tr), box-shadow var(--tr);
}
.textarea-field:focus {
  border-color: var(--gold);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(201,168,76,.12);
}

/* ═══ PROGRESS BADGE ═══ */
.progress-badge {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(61,153,112,.1);
  color: #2E7D55;
  border-radius: 4px;
  font-size: .7rem;
  font-weight: 700;
}

/* ═══ BPO TOOL ═══ */
.bpo-out {
  min-height: 120px;
  height: auto;
  resize: none;
  overflow: hidden;
  white-space: pre;
  word-break: break-all;
  font-family: 'Courier New', monospace;
  font-size: .82rem;
  line-height: 1.6;
}


/* ═══ BPO TOOL ═══ */
.bpo-wrapper {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#bpoInput { height: 90px !important; resize: vertical; }
#bpoOutput, #poOutput { height: 70px !important; font-family: monospace; font-size: .8rem; }
