/* =========================================================================
   EXACT DESIGN TOKENS FROM bahth-reserarcher-desktop-apple.figcraft
   Page 366 (Light Mode) + Page 1181 (Dark Mode)
   ========================================================================= */
:root,
[data-theme="light"] {
  --bg: #FFFFFF;
  --sidebar-bg: #F7F7F8;
  --card-bg: #FFFFFF;
  --card-selected: #F5F5F7;
  --surface-soft: #F2F2F5;
  --surface-pill: #EFEFF4;
  --border: #E5E5EA;
  --border-soft: #ECECEF;
  --ink: #1D1D1F;
  --ink-2: #48484A;
  --ink-3: #6E6E73;
  --muted: #86868B;
  --muted-2: #8E8E93;
  --blue: #0071E3;
  --blue-tint: #E8F1FD;
  --emerald: #008F6B;
  --emerald-bright: #00C896;
  --emerald-tint: #E2F9F1;
  --purple: #A594F9;
  --purple-tint: #F1EEFF;
  --amber: #D97706;
  --amber-tint: #FEF3C7;
  --red: #D70015;
  --red-tint: #FFEBF0;
  --dark-card: #161619;
  --dark-card-ink: #FFFFFF;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] {
  --bg: #111113;
  --sidebar-bg: #161619;
  --card-bg: #18181C;
  --card-selected: #1D1D23;
  --surface-soft: #25252D;
  --surface-pill: #26262C;
  --border: #25252C;
  --border-soft: #23232A;
  --ink: #F5F5F7;
  --ink-2: #D1D1D6;
  --ink-3: #98989F;
  --muted: #98989F;
  --muted-2: #8E8E93;
  --blue: #58A6FF;
  --blue-tint: #132B47;
  --emerald: #34D399;
  --emerald-bright: #34D399;
  --emerald-tint: #103328;
  --purple: #A594F9;
  --purple-tint: #25213E;
  --amber: #FBBF24;
  --amber-tint: #332710;
  --red: #FF6978;
  --red-tint: #3A181E;
  --dark-card: #1D1D23;
  --dark-card-ink: #F5F5F7;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.45);
}

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

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'IBM Plex Sans Arabic', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.mono { font-family: 'Consolas', ui-monospace, SFMono-Regular, monospace; direction: ltr; unicode-bidi: embed; }
.ltr { direction: ltr; unicode-bidi: embed; }

/* =========================================================================
   APPLE WORKSPACE SHELL (280px Right Sidebar + Fluid Main Canvas)
   ========================================================================= */
.workspace {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
}

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.brand-id {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-id img {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  object-fit: contain;
}

.brand-name { font-size: 15px; font-weight: 800; color: var(--ink); line-height: 1.15; }
.brand-sub { font-size: 11px; color: var(--muted); }

.theme-btn {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.search-box {
  position: relative;
  margin-bottom: 14px;
}

.search-box input {
  width: 100%;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px 8px 44px;
  color: var(--ink);
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
}

.search-box input:focus { border-color: var(--blue); }
.search-kbd {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-family: 'Consolas', monospace;
  font-size: 10.5px;
  color: var(--muted);
  background: var(--surface-pill);
  padding: 2px 6px;
  border-radius: 6px;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 16px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: right;
  transition: background 0.14s ease, color 0.14s ease;
}

.nav-item:hover { background: var(--surface-soft); color: var(--ink); }
.nav-item.active {
  background: var(--blue-tint);
  color: var(--blue);
  font-weight: 700;
}

.nav-count {
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 99px;
  background: var(--surface-pill);
  color: var(--ink-3);
  font-family: 'Consolas', monospace;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-item.active .nav-count {
  background: var(--blue);
  color: #FFFFFF;
}

.nav-count.alert { background: var(--red-tint); color: var(--red); }

.sidebar-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  padding: 4px 10px 6px;
}

.folder-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sync-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--emerald-tint);
  color: var(--emerald);
  font-size: 11.5px;
  font-weight: 700;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emerald-bright);
  box-shadow: 0 0 0 3px rgba(0, 200, 150, 0.22);
}

/* Main Area */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 56px;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 30;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.breadcrumb .current { color: var(--ink); font-weight: 800; }
.breadcrumb button {
  background: transparent; border: none; color: var(--muted); font: inherit; cursor: pointer;
}
.breadcrumb button:hover { color: var(--blue); }

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

.meta-pill {
  padding: 5px 12px;
  border-radius: 99px;
  background: var(--surface-soft);
  color: var(--ink-3);
  font-size: 11.5px;
  font-weight: 600;
}

.content {
  padding: 24px 28px 40px;
  max-width: 1220px;
  width: 100%;
}

/* Headings & Filters */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.h1 {
  font-family: 'Tajawal', sans-serif;
  font-size: 24px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.015em;
}

.h2 {
  font-family: 'Tajawal', sans-serif;
  font-size: 18px;
  font-weight: 800;
  color: var(--ink);
}

.sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.filter-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.fpill {
  padding: 6px 13px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--ink-3);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.fpill.active {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

/* =========================================================================
   APPLE 3D COLORED FOLDER CARDS (EXACTLY MATCHING FIGCRAFT SCREEN 01 & 05)
   ========================================================================= */
.folder-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.folder-grid.three { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 1080px) {
  .folder-grid { grid-template-columns: repeat(2, 1fr); }
  .folder-grid.three { grid-template-columns: 1fr; }
}

.folder-card {
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: 18px;
  padding: 18px 16px 16px;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
  text-align: center;
  box-shadow: var(--shadow);
}

.folder-card:hover { transform: translateY(-2px); border-color: var(--blue); }
.folder-card.selected {
  background: var(--card-selected);
  border-color: var(--blue);
}

.folder-icon-wrap {
  position: relative;
  width: 112px;
  height: 82px;
  margin: 0 auto 14px;
}

.folder-back {
  position: absolute;
  top: 0;
  right: 6px;
  width: 46px;
  height: 18px;
  border-radius: 8px 8px 0 0;
}

.folder-body {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 70px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  font-weight: 800;
  font-size: 13px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.folder-purple .folder-back { background: #7C6CE0; }
.folder-purple .folder-body { background: linear-gradient(160deg, #B7A7FF 0%, #7C6CE0 100%); }

.folder-blue .folder-back { background: #005BBF; }
.folder-blue .folder-body { background: linear-gradient(160deg, #5AC8FA 0%, #0071E3 100%); }

.folder-gold .folder-back { background: #D97706; }
.folder-gold .folder-body { background: linear-gradient(160deg, #FCD34D 0%, #F59E0B 100%); color: #451A03; }

.folder-red .folder-back { background: #C41E3A; }
.folder-red .folder-body { background: linear-gradient(160deg, #FF6B81 0%, #E11D48 100%); }

.folder-title { font-size: 14px; font-weight: 800; color: var(--ink); }
.folder-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* =========================================================================
   CARDS, TABLES, BADGES, BUTTONS
   ========================================================================= */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.dark-panel {
  background: var(--dark-card);
  color: var(--dark-card-ink);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 20px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: right;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--card-selected); }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--blue-tint);
  color: var(--blue);
  font-weight: 800;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-blue { background: var(--blue-tint); color: var(--blue); }
.badge-emerald { background: var(--emerald-tint); color: var(--emerald); }
.badge-purple { background: var(--purple-tint); color: var(--purple); }
.badge-amber { background: var(--amber-tint); color: var(--amber); }
.badge-red { background: var(--red-tint); color: var(--red); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.14s ease, transform 0.12s ease;
  text-decoration: none;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-blue { background: #0071E3; color: #FFFFFF; }
.btn-emerald { background: #00C896; color: #052E22; }
.btn-dark { background: var(--ink); color: var(--bg); }
.btn-outline { background: var(--card-bg); color: var(--ink); border-color: var(--border); }
.btn-soft-red { background: var(--red-tint); color: var(--red); }
.btn-soft-blue { background: var(--blue-tint); color: var(--blue); }
.btn-soft-emerald { background: var(--emerald-tint); color: var(--emerald); }
.btn-block { width: 100%; padding: 11px 16px; font-size: 13.5px; }

/* Two-Column Workspace Layouts (Screens 02 & 03) */
.split-detail {
  display: grid;
  grid-template-columns: 1.35fr 0.95fr;
  gap: 18px;
  align-items: start;
}

@media (max-width: 1040px) {
  .split-detail { grid-template-columns: 1fr; }
}

.step-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.step-pill-box {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
}

.step-pill-box.done { background: var(--emerald-tint); color: var(--emerald); }
.step-pill-box.active { background: var(--blue-tint); color: var(--blue); }

.upload-slot {
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.upload-slot.word { background: var(--blue-tint); border-color: rgba(0, 113, 227, 0.28); }
.upload-slot.pdf { background: var(--red-tint); border-color: rgba(215, 0, 21, 0.26); }

.file-icon-box {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #FFFFFF;
  flex-shrink: 0;
}

.file-icon-box.w { background: #0071E3; font-size: 16px; }
.file-icon-box.p { background: #D70015; font-size: 11px; }

.qr-preview-box {
  width: 200px;
  height: 200px;
  margin: 14px auto;
  background: #FFFFFF;
  border-radius: 16px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.qr-preview-box img, .qr-preview-box svg { width: 100%; height: 100%; object-fit: contain; }

/* Partner Cards (Screen 04) */
.partner-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

@media (max-width: 1100px) { .partner-grid { grid-template-columns: repeat(2, 1fr); } }

.partner-card {
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.partner-card.selected {
  background: var(--dark-card);
  color: #FFFFFF;
  border-color: var(--emerald-bright);
}

.partner-card.selected .sub { color: #A1A1A6; }

/* Inputs */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 5px; }
.input, .textarea, .select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.input:focus, .textarea:focus { border-color: var(--blue); }
.textarea { min-height: 70px; resize: vertical; }

/* Auth Gate */
.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--sidebar-bg);
}

.auth-box {
  width: 100%;
  max-width: 440px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px 26px;
  box-shadow: var(--shadow-lg);
}

.seg-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-soft);
  border-radius: 11px;
  padding: 3px;
  margin: 14px 0 16px;
}

.seg-tab {
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 9px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}

.seg-tab.active {
  background: var(--card-bg);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Modal & Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
}

.toast-root {
  position: fixed;
  top: 16px;
  left: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}

.toast {
  background: #1D1D1F;
  color: #FFFFFF;
  padding: 11px 15px;
  border-radius: 12px;
  font-size: 12.5px;
  font-weight: 600;
  border-right: 4px solid #00C896;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.25);
}

.toast.error { border-right-color: #FF4A5A; }
.toast.info { border-right-color: #58A6FF; }

.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack-8 { display: flex; flex-direction: column; gap: 8px; }
