/* PALAST v4 - Custom Styles */
:root {
  --primary: #1a5276;
  --primary-light: #2874a6;
  --secondary: #117a65;
  --accent: #f39c12;
  --danger: #e74c3c;
  --success: #27ae60;
  --warning: #f39c12;
  --info: #2980b9;
  --bg: #f0f4f8;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --border: #dce1e7;
  --sidebar-width: 240px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', Tahoma, Arial, sans-serif; background: var(--bg); color: var(--text); direction: rtl; }

/* ── Sidebar ── */
.sidebar {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: var(--sidebar-width); background: var(--primary);
  display: flex; flex-direction: column; z-index: 100;
  box-shadow: -2px 0 12px rgba(0,0,0,0.15);
  overflow-y: auto;
}
.sidebar-logo {
  padding: 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.15);
  text-align: center;
}
.sidebar-logo img { width: 60px; height: 60px; border-radius: 50%; object-fit: cover; }
.sidebar-logo h2 { color: white; font-size: 1rem; margin-top: 8px; font-weight: 700; }
.sidebar-logo p { color: rgba(255,255,255,0.7); font-size: 0.7rem; }
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; color: rgba(255,255,255,0.8);
  cursor: pointer; transition: all 0.2s;
  border-radius: 0; font-size: 0.88rem;
}
.nav-item:hover { background: rgba(255,255,255,0.12); color: white; }
.nav-item.active { background: rgba(255,255,255,0.2); color: white; font-weight: 600; border-right: 3px solid var(--accent); }
.nav-item i { width: 18px; text-align: center; font-size: 0.95rem; }
.nav-section-title {
  color: rgba(255,255,255,0.4); font-size: 0.68rem;
  text-transform: uppercase; letter-spacing: 1px;
  padding: 14px 16px 4px; font-weight: 700;
}
.sidebar-footer { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,0.15); }
.user-info { color: rgba(255,255,255,0.9); font-size: 0.82rem; }
.user-info strong { display: block; font-size: 0.88rem; }
.user-role-badge {
  display: inline-block; background: var(--accent); color: white;
  font-size: 0.65rem; padding: 2px 8px; border-radius: 10px;
  margin-top: 4px; font-weight: 600;
}
.logout-btn {
  width: 100%; margin-top: 8px; padding: 8px;
  background: rgba(231,76,60,0.2); color: #ff8a80;
  border: 1px solid rgba(231,76,60,0.3); border-radius: 8px;
  cursor: pointer; font-size: 0.82rem; transition: all 0.2s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.logout-btn:hover { background: rgba(231,76,60,0.4); }

/* ── Main Layout ── */
.layout { display: flex; min-height: 100vh; }
.main-content { margin-right: var(--sidebar-width); flex: 1; padding: 24px; min-height: 100vh; }

/* ── Cards ── */
.card {
  background: var(--card-bg); border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07); padding: 20px;
  border: 1px solid var(--border);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding-bottom: 12px;
  border-bottom: 2px solid var(--bg);
}
.card-title { font-size: 1.05rem; font-weight: 700; color: var(--primary); display: flex; align-items: center; gap: 8px; }

/* ── Stats Grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: white; border-radius: 12px; padding: 18px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06); border: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
}
.stat-icon {
  width: 46px; height: 46px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; flex-shrink: 0;
}
.stat-value { font-size: 1.6rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-label { font-size: 0.75rem; color: var(--text-light); margin-top: 2px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border-radius: 8px; cursor: pointer;
  font-size: 0.85rem; font-weight: 600; border: none;
  transition: all 0.2s; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #219a52; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c0392b; }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #d68910; }
.btn-secondary { background: #95a5a6; color: white; }
.btn-secondary:hover { background: #7f8c8d; }
.btn-outline { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: white; }
.btn-sm { padding: 5px 12px; font-size: 0.78rem; }
.btn-lg { padding: 12px 28px; font-size: 0.95rem; }
.btn-icon { padding: 7px 10px; }

/* ── Tables ── */
.table-container { overflow-x: auto; border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
thead th {
  background: var(--primary); color: white; padding: 10px 14px;
  text-align: right; font-weight: 600; font-size: 0.8rem;
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid #f0f2f5; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 10px 14px; vertical-align: middle; }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Status Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px; font-size: 0.73rem; font-weight: 700;
}
.badge-draft { background: #e8f4f8; color: #2874a6; }
.badge-submitted { background: #d5f5e3; color: #1e8449; }
.badge-under_review { background: #fef9e7; color: #b7950b; }
.badge-accepted { background: #d5f5e3; color: #1e8449; }
.badge-rejected { background: #fadbd8; color: #c0392b; }
.badge-returned { background: #fdebd0; color: #ca6f1e; }
.badge-active { background: #d5f5e3; color: #1e8449; }
.badge-closed { background: #eaecee; color: #626567; }
.badge-pending { background: #fef9e7; color: #b7950b; }
.badge-approved { background: #d5f5e3; color: #1e8449; }
.badge-ai { background: #e8daef; color: #7d3c98; }
.badge-manual { background: #d6eaf8; color: #1a5276; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 0.83rem; font-weight: 600;
  color: var(--text); margin-bottom: 5px;
}
.form-label .required { color: var(--danger); margin-right: 2px; }
.form-control {
  width: 100%; padding: 9px 12px; border: 2px solid var(--border);
  border-radius: 8px; font-size: 0.88rem; color: var(--text);
  background: white; transition: border-color 0.2s;
  font-family: inherit;
}
.form-control:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(26,82,118,0.1); }
.form-control.error { border-color: var(--danger); }
.form-hint { font-size: 0.75rem; color: var(--text-light); margin-top: 3px; }
.form-error { font-size: 0.75rem; color: var(--danger); margin-top: 3px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236c757d' d='M6 8L0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 12px center; padding-left: 32px; }

/* ── Modals ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  z-index: 999; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-box {
  background: white; border-radius: 16px;
  width: 100%; max-width: 680px; max-height: 90vh;
  overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: modalIn 0.25s ease;
}
.modal-box-lg { max-width: 900px; }
.modal-box-xl { max-width: 1100px; }
@keyframes modalIn { from { opacity:0; transform: scale(0.95) translateY(-10px); } to { opacity:1; transform: scale(1) translateY(0); } }
.modal-header {
  padding: 18px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: white; z-index: 1; border-radius: 16px 16px 0 0;
}
.modal-title { font-size: 1rem; font-weight: 700; color: var(--primary); display: flex; align-items: center; gap: 8px; }
.modal-close { width: 32px; height: 32px; border-radius: 50%; border: none; background: #f0f2f5; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 1rem; color: var(--text-light); transition: all 0.2s; }
.modal-close:hover { background: var(--danger); color: white; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Tabs ── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab-item {
  padding: 10px 18px; cursor: pointer; font-size: 0.85rem; font-weight: 600;
  color: var(--text-light); border-bottom: 3px solid transparent;
  margin-bottom: -2px; white-space: nowrap; transition: all 0.2s;
}
.tab-item:hover { color: var(--primary); }
.tab-item.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Score Grid (Evaluation Sheet) ── */
.eval-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.eval-criterion {
  background: #f8fafc; border-radius: 10px; padding: 14px;
  border: 2px solid var(--border); transition: border-color 0.2s;
}
.eval-criterion:hover { border-color: var(--primary-light); }
.eval-criterion-title { font-size: 0.82rem; font-weight: 700; color: var(--primary); margin-bottom: 6px; }
.eval-criterion-subtitle { font-size: 0.73rem; color: var(--text-light); margin-bottom: 10px; }
.score-selector { display: flex; gap: 6px; flex-wrap: wrap; }
.score-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--border);
  background: white; cursor: pointer; font-weight: 700; font-size: 0.88rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s; color: var(--text);
}
.score-btn:hover { border-color: var(--primary); color: var(--primary); }
.score-btn.selected { background: var(--primary); border-color: var(--primary); color: white; }
.score-btn.score-5.selected { background: var(--success); border-color: var(--success); }
.score-btn.score-4.selected { background: #2ecc71; border-color: #2ecc71; }
.score-btn.score-3.selected { background: var(--warning); border-color: var(--warning); }
.score-btn.score-2.selected { background: #e67e22; border-color: #e67e22; }
.score-btn.score-1.selected { background: var(--danger); border-color: var(--danger); }
.total-score-display {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white; border-radius: 12px; padding: 20px; text-align: center;
}
.total-score-num { font-size: 3rem; font-weight: 800; line-height: 1; }
.total-score-label { font-size: 0.85rem; opacity: 0.85; margin-top: 4px; }
.endorse-btn {
  width: 100%; padding: 14px; border-radius: 10px; border: none; cursor: pointer;
  font-size: 1rem; font-weight: 700; transition: all 0.2s; margin-top: 14px;
}
.endorse-yes { background: var(--success); color: white; }
.endorse-no { background: #e0e0e0; color: var(--text-light); }

/* ── Document Upload ── */
.doc-upload-zone {
  border: 2px dashed var(--border); border-radius: 10px;
  padding: 24px; text-align: center; cursor: pointer;
  transition: all 0.2s; background: #fafbfc;
}
.doc-upload-zone:hover, .doc-upload-zone.dragover {
  border-color: var(--primary); background: #eef4fb;
}
.doc-upload-zone i { font-size: 2rem; color: var(--primary-light); }
.doc-list { display: grid; gap: 10px; }
.doc-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: #f8fafc;
  border-radius: 8px; border: 1px solid var(--border);
}
.doc-icon { font-size: 1.5rem; width: 36px; text-align: center; }
.doc-info { flex: 1; min-width: 0; }
.doc-name { font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { font-size: 0.73rem; color: var(--text-light); }
.doc-actions { display: flex; gap: 6px; }

/* ── Alerts ── */
.alert {
  padding: 12px 16px; border-radius: 8px; font-size: 0.85rem;
  display: flex; align-items: center; gap: 10px; margin-bottom: 16px;
}
.alert-success { background: #d5f5e3; color: #1e8449; border: 1px solid #a9dfbf; }
.alert-danger { background: #fadbd8; color: #c0392b; border: 1px solid #f1948a; }
.alert-warning { background: #fef9e7; color: #b7950b; border: 1px solid #f8c471; }
.alert-info { background: #d6eaf8; color: #1a5276; border: 1px solid #85c1e9; }

/* ── Login Page ── */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 50%, var(--secondary) 100%);
}
.login-card {
  background: white; border-radius: 20px; padding: 40px;
  width: 100%; max-width: 440px; box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { color: var(--primary); font-size: 1.8rem; font-weight: 800; }
.login-logo p { color: var(--text-light); font-size: 0.85rem; }

/* ── Empty States ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-light); }
.empty-state i { font-size: 3rem; margin-bottom: 12px; opacity: 0.5; display: block; }
.empty-state h3 { font-size: 1.1rem; color: var(--text); margin-bottom: 6px; }

/* ── Loading ── */
.spinner { display: inline-block; width: 20px; height: 20px; border: 3px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: white; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.8); z-index: 9999; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; }
.loading-spinner-lg { width: 48px; height: 48px; border: 5px solid var(--border); border-radius: 50%; border-top-color: var(--primary); animation: spin 0.9s linear infinite; }

/* ── Pagination ── */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.page-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: white; cursor: pointer; font-size: 0.85rem; transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Progress Bar ── */
.progress-bar { height: 8px; background: #e9ecef; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.progress-blue { background: var(--primary); }
.progress-green { background: var(--success); }
.progress-orange { background: var(--warning); }
.progress-red { background: var(--danger); }

/* ── Search Bar ── */
.search-bar { position: relative; }
.search-bar input { padding-right: 36px; }
.search-bar i { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-light); font-size: 0.9rem; }

/* ── Notifications ── */
.notif-item { display: flex; gap: 12px; padding: 12px; border-radius: 8px; cursor: pointer; transition: background 0.2s; }
.notif-item:hover { background: #f8fafc; }
.notif-item.unread { background: #eef4fb; }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-top: 5px; flex-shrink: 0; }

/* ── Section headers ── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-title { font-size: 1.4rem; font-weight: 800; color: var(--primary); display: flex; align-items: center; gap: 10px; }
.page-subtitle { font-size: 0.82rem; color: var(--text-light); margin-top: 2px; }

/* ── Two-column layout ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── Mobile ── */
@media(max-width: 900px) {
  .sidebar { position: fixed; right: -100%; transition: right 0.3s; width: 260px; }
  .sidebar.open { right: 0; }
  .main-content { margin-right: 0; padding: 16px; }
  .eval-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .mobile-menu-btn { display: flex !important; }
}

/* ── Top bar (mobile) ── */
.topbar { display: none; background: var(--primary); color: white; padding: 12px 16px; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 99; }
.mobile-menu-btn { display: none; background: none; border: none; color: white; font-size: 1.3rem; cursor: pointer; }
@media(max-width: 900px) {
  .topbar { display: flex; }
  .main-content { padding-top: 0; }
}

/* ── Tooltip ── */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 6px); right: 50%; transform: translateX(50%);
  background: #2c3e50; color: white; padding: 5px 10px; border-radius: 6px;
  font-size: 0.73rem; white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity 0.2s; z-index: 100;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ── Application form steps ── */
.form-steps { display: flex; gap: 0; overflow-x: auto; margin-bottom: 24px; border-radius: 10px; overflow: hidden; }
.form-step {
  flex: 1; padding: 10px 8px; text-align: center;
  background: #e9ecef; color: var(--text-light);
  font-size: 0.73rem; font-weight: 600; cursor: pointer;
  transition: all 0.2s; min-width: 80px; border-left: 1px solid white;
}
.form-step.active { background: var(--primary); color: white; }
.form-step.done { background: var(--success); color: white; }
.form-step-num { font-size: 1rem; font-weight: 800; display: block; }

/* ── Misc ── */
.divider { border: none; border-top: 2px solid var(--border); margin: 20px 0; }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--text-light); }
.fw-bold { font-weight: 700; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 20px; }
.mt-3 { margin-top: 12px; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.hidden { display: none !important; }
