/* Sonaa HR Documents - design system
   Uses CSS logical properties throughout so the same stylesheet serves both
   [dir="rtl"] (Arabic) and [dir="ltr"] (English) without a second file. */

:root {
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-border: #e4e8ef;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-primary: #2f6fed;
  --color-primary-dark: #1f4fc7;
  --color-primary-soft: #eaf1ff;
  --color-success: #16a34a;
  --color-success-soft: #e9f9ee;
  --color-warning: #b45309;
  --color-warning-soft: #fef3e0;
  --color-danger: #dc2626;
  --color-danger-soft: #fdecec;
  --color-muted-soft: #eef0f4;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --font: "Segoe UI", "Tahoma", system-ui, -apple-system, sans-serif;
}

/* Base size for every icon() svg - without this, an <svg> with only a viewBox (no
   width/height) renders at the browser's default replaced-element size (300x150px),
   which is what was blowing up buttons/topbar/cards across the whole UI. The more
   specific .sidebar-link .icon / .empty-state .icon / etc. rules below still win. */
.icon { width: 16px; height: 16px; flex-shrink: 0; display: inline-block; vertical-align: middle; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.55;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
img { max-width: 100%; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: #111827;
  color: #d1d5db;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  z-index: 40;
  transition: transform 0.2s ease;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar-brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--color-primary); }
.sidebar-nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.sidebar-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b7280;
  padding: 14px 12px 6px;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: #d1d5db;
  font-size: 13.5px;
  margin-bottom: 2px;
}
.sidebar-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.sidebar-link.active { background: var(--color-primary); color: #fff; }
.sidebar-link .icon { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-link .badge-count {
  margin-inline-start: auto;
  background: var(--color-danger);
  color: #fff;
  font-size: 11px;
  border-radius: 999px;
  padding: 1px 7px;
}

.main-area { flex: 1; margin-inline-start: var(--sidebar-width); display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-search { flex: 1; max-width: 460px; position: relative; }
.topbar-search input {
  width: 100%;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  font-size: 13.5px;
}
.topbar-search input:focus { outline: 2px solid var(--color-primary-soft); border-color: var(--color-primary); }
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-start: 0;
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 360px;
  overflow-y: auto;
  display: none;
  z-index: 50;
}
.search-results.open { display: block; }
.search-result-item { display: block; padding: 10px 14px; border-bottom: 1px solid var(--color-border); }
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--color-bg); }
.search-result-item .name { font-weight: 600; }
.search-result-item .meta { font-size: 12px; color: var(--color-text-muted); }

.topbar-actions { display: flex; align-items: center; gap: 14px; margin-inline-start: auto; }
.icon-btn {
  position: relative;
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  cursor: pointer;
}
.icon-btn .dot-badge {
  position: absolute; top: 4px; inset-inline-end: 4px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--color-danger);
}
.profile-menu { position: relative; }
.profile-trigger { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.profile-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--color-primary-soft); color: var(--color-primary-dark);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.dropdown {
  position: absolute; top: calc(100% + 8px); inset-inline-end: 0;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  min-width: 200px; display: none; overflow: hidden; z-index: 50;
}
.dropdown.open { display: block; }
.dropdown a, .dropdown button {
  display: block; width: 100%; text-align: start; padding: 10px 14px;
  border: none; background: none; font-size: 13.5px; cursor: pointer; color: var(--color-text);
}
.dropdown a:hover, .dropdown button:hover { background: var(--color-bg); }

.page-content { padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.page-subtitle { color: var(--color-text-muted); font-size: 13px; margin: 0; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 13.5px; font-weight: 600; cursor: pointer; background: var(--color-muted-soft); color: var(--color-text);
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.btn-outline { background: transparent; border-color: var(--color-border); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- Cards / grid ---------- */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow-sm); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 16px 18px; }
.stat-card .label { color: var(--color-text-muted); font-size: 12.5px; margin-bottom: 6px; }
.stat-card .value { font-size: 24px; font-weight: 800; }
.stat-card .hint { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }
.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
@media (max-width: 980px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- Tables ---------- */
.table-wrap { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: start; padding: 12px 14px; background: var(--color-bg); color: var(--color-text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
.data-table td { padding: 12px 14px; border-top: 1px solid var(--color-border); vertical-align: middle; }
.data-table tr:hover td { background: #fafbfd; }
.table-scroll { overflow-x: auto; }
.avatar-sm { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--color-muted-soft); }
.cell-strong { font-weight: 600; }
.cell-muted { color: var(--color-text-muted); font-size: 12.5px; }

/* ---------- Status badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge svg { width: 13px; height: 13px; }
.badge-valid { background: var(--color-success-soft); color: var(--color-success); }
.badge-expiring { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-expired { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-missing { background: var(--color-muted-soft); color: var(--color-text-muted); }
.badge-neutral { background: var(--color-primary-soft); color: var(--color-primary-dark); }

/* progress bar for completion % */
.progress { height: 8px; border-radius: 999px; background: var(--color-muted-soft); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--color-primary); }
.progress.good > span { background: var(--color-success); }
.progress.warn > span { background: var(--color-warning); }
.progress.bad > span { background: var(--color-danger); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 12.5px; font-weight: 600; color: var(--color-text-muted); }
.form-field .req { color: var(--color-danger); }
input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], input[type="tel"], input[type="search"], select, textarea {
  padding: 9px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  font-size: 13.5px; background: var(--color-surface); color: var(--color-text); width: 100%; font-family: inherit;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--color-primary-soft); border-color: var(--color-primary); }
.field-error { color: var(--color-danger); font-size: 12px; }
.form-section-title { font-size: 14px; font-weight: 700; margin: 18px 0 10px; padding-top: 14px; border-top: 1px solid var(--color-border); }
.form-section-title:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }

/* ---------- Wizard ---------- */
.wizard-steps { display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.wizard-step { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; background: var(--color-muted-soft); font-size: 12.5px; font-weight: 600; color: var(--color-text-muted); }
.wizard-step.active { background: var(--color-primary); color: #fff; }
.wizard-step.done { background: var(--color-success-soft); color: var(--color-success); }
.wizard-step .num { width: 20px; height: 20px; border-radius: 50%; background: rgba(255,255,255,0.3); display: flex; align-items: center; justify-content: center; font-size: 11px; }

/* ---------- Employee profile ---------- */
.profile-header { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.profile-header .avatar-lg { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; background: var(--color-muted-soft); flex-shrink: 0; }
.profile-header h1 { margin: 0 0 4px; font-size: 20px; }
.profile-meta { display: flex; flex-wrap: wrap; gap: 10px; color: var(--color-text-muted); font-size: 13px; }
.profile-meta span { display: inline-flex; align-items: center; gap: 5px; }

.completion-box { display: flex; align-items: center; gap: 16px; margin: 18px 0; }
.completion-ring { display: flex; flex-direction: column; }
.completion-ring .pct { font-size: 26px; font-weight: 800; }
.completion-ring .sub { font-size: 12.5px; color: var(--color-text-muted); }
.completion-track { flex: 1; }

.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 16px; }
.doc-card { border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 14px; background: var(--color-surface); }
.doc-card .doc-title { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13.5px; margin-bottom: 6px; }
.doc-card .doc-title .icon { color: var(--color-primary); }
.doc-card .doc-meta { font-size: 12px; color: var(--color-text-muted); margin-bottom: 10px; }
.doc-card .doc-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Filters bar ---------- */
.filters-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; background: var(--color-surface); border: 1px solid var(--color-border); padding: 14px; border-radius: var(--radius-lg); }
.filters-bar .form-field { min-width: 160px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 14px; font-size: 12.5px; color: var(--color-text-muted); }
.pagination .pages { display: flex; gap: 4px; }
.pagination a, .pagination span.current { padding: 6px 11px; border-radius: var(--radius-sm); border: 1px solid var(--color-border); }
.pagination span.current { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ---------- Modal / drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(17, 24, 39, 0.45); z-index: 100; display: none; }
.overlay.open { display: block; }
.modal { position: fixed; top: 50%; inset-inline-start: 50%; transform: translate(-50%, -50%); background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); width: 92%; max-width: 520px; max-height: 88vh; overflow-y: auto; z-index: 101; display: none; }
[dir="rtl"] .modal { transform: translate(50%, -50%); }
.modal.open { display: block; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--color-border); }
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 18px; }
.modal-footer { padding: 14px 18px; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 10px; }
.drawer { position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: 420px; max-width: 92vw; background: var(--color-surface); box-shadow: var(--shadow-md); z-index: 101; transform: translateX(100%); transition: transform 0.2s ease; display: flex; flex-direction: column; }
[dir="rtl"] .drawer { transform: translateX(-100%); }
.drawer.open { transform: translateX(0); }
.drawer-body { padding: 18px; overflow-y: auto; flex: 1; }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; bottom: 20px; inset-inline-end: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { background: #111827; color: #fff; padding: 12px 16px; border-radius: var(--radius-md); font-size: 13px; box-shadow: var(--shadow-md); min-width: 220px; }
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }

/* ---------- Empty / skeleton / error states ---------- */
.empty-state { text-align: center; padding: 50px 20px; color: var(--color-text-muted); }
.empty-state .icon { width: 46px; height: 46px; margin: 0 auto 12px; opacity: 0.5; }
.skeleton { background: linear-gradient(90deg, #eef0f4 25%, #f6f7f9 37%, #eef0f4 63%); background-size: 400% 100%; animation: skeleton-loading 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.error-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.error-box { text-align: center; max-width: 380px; }

/* ---------- Needs attention list ---------- */
.attention-list { list-style: none; margin: 0; padding: 0; }
.attention-list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--color-border); font-size: 13px; }
.attention-list li:last-child { border-bottom: none; }
.attention-list .icon { width: 16px; height: 16px; flex-shrink: 0; color: var(--color-warning); }

/* ---------- Dropzone ---------- */
.dropzone { border: 2px dashed var(--color-border); border-radius: var(--radius-md); padding: 26px; text-align: center; cursor: pointer; background: var(--color-bg); }
.dropzone.dragover { border-color: var(--color-primary); background: var(--color-primary-soft); }
.dropzone .icon { width: 30px; height: 30px; margin: 0 auto 8px; color: var(--color-text-muted); }
.upload-progress { height: 6px; background: var(--color-muted-soft); border-radius: 999px; overflow: hidden; margin-top: 8px; display: none; }
.upload-progress > span { display: block; height: 100%; width: 0; background: var(--color-primary); transition: width 0.15s ease; }

/* ---------- Viewer ---------- */
.viewer-toolbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--color-border); }
.viewer-body { flex: 1; overflow: auto; background: #0f172a; display: flex; align-items: center; justify-content: center; }
.viewer-body img { max-height: 82vh; }
.viewer-body iframe { width: 100%; height: 82vh; border: none; background: #fff; }

/* ---------- Utility ---------- */
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.text-muted { color: var(--color-text-muted); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.flex { display: flex; } .items-center { align-items: center; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.hidden { display: none !important; }
.sidebar-toggle { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .sidebar { transform: translateX(-100%); }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-inline-start: 0; }
  .sidebar-toggle { display: flex; }
}
@media (max-width: 640px) {
  .page-content { padding: 14px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-search { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .filters-bar .form-field { min-width: 130px; flex: 1; }
  .profile-header { flex-direction: column; align-items: flex-start; }
}
