/* ==========================================================================
   Grafeeky Panel — نظام تصميم موحد (راجع UI-DESIGN-SYSTEM.md)
   ========================================================================== */

:root{
  --bg: #f3f5f9;
  --card: #ffffff;
  --card-alt: #f6f7fb;
  --border: #e5e9f2;
  --text: #1a2130;
  --muted: #6b7385;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef0ff;
  --success: #12b76a;
  --success-soft: #e6f9f0;
  --danger: #f04438;
  --danger-soft: #feeceb;
  --warning: #f79009;
  --warning-soft: #fef3e2;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
}

[data-theme="dark"]{
  --bg: #10131a; --card: #171b26; --card-alt: #1d2230; --border: #262c3b;
  --text: #e7ebf5; --muted: #8b94a8; --primary: #6a63f0; --primary-dark: #7d77f3;
  --primary-soft: #232048; --success: #2dd087; --success-soft: #113228;
  --danger: #f36b61; --danger-soft: #351a1c; --warning: #f7a83e; --warning-soft: #362610;
}

*{ box-sizing: border-box; }

html{ -webkit-text-size-adjust: 100%; }

body{
  margin: 0;
  font-family: 'Cairo', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .15s ease, color .15s ease;
}

a{ color: inherit; text-decoration: none; }

button, input, select, textarea{ font-family: inherit; }

::selection{ background: var(--primary-soft); color: var(--primary-dark); }

/* --------------------------------------------------------------------
   Layout: Topbar + Sidebar
   -------------------------------------------------------------------- */

.app-shell{ height: 100vh; display: flex; overflow: hidden; }

.app-main-col{ flex: 1; min-width: 0; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.topbar{
  flex-shrink: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  height: 64px; padding: 0 20px;
  background: var(--card); border-bottom: 1px solid var(--border);
}

.topbar .brand{ display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.topbar .brand img{ height: 28px; }
.topbar .spacer{ flex: 1; }
.topbar .controls{ display: flex; align-items: center; gap: 10px; }

.topbar-balance{
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 10px;
  background: var(--primary-soft); color: var(--primary);
  font-weight: 800; font-size: 14.5px; text-decoration: none;
}
.topbar-balance:hover{ background: var(--primary); color: #fff; }

.menu-toggle{
  display: none;
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card-alt); color: var(--text); align-items: center; justify-content: center;
  cursor: pointer;
}

.sidebar{
  width: 260px; flex-shrink: 0;
  background: var(--card); border-inline-end: 1px solid var(--border);
  padding: 20px 14px; height: 100vh;
  display: flex; flex-direction: column;
  overflow-y: auto;
}

.sidebar-brand{
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none;
  padding: 0 12px 18px; margin-bottom: 10px; border-bottom: 1px solid var(--border);
}
.sidebar-brand img{ height: 28px; max-width: 100%; }

.sidebar-backdrop{ display: none; }

.sidebar nav{ display: flex; flex-direction: column; gap: 4px; flex: 1; min-height: 0; }

.side-link{
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; color: var(--muted); font-weight: 600; font-size: 14.5px;
}
.side-link svg{ width: 19px; height: 19px; flex-shrink: 0; }
.side-link:hover{ background: var(--card-alt); color: var(--text); }
.side-link.active{ background: var(--primary-soft); color: var(--primary); }

.side-logout-form{ margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.side-link.side-logout{
  width: 100%; border: none; background: none; cursor: pointer; color: var(--danger);
  font-family: inherit; text-align: start;
}
.side-link.side-logout:hover{ background: var(--danger-soft); color: var(--danger); }

.role-pill{
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
}

.main{ flex: 1; min-width: 0; padding: 24px; overflow-y: auto; }

@media (max-width: 960px){
  .menu-toggle{ display: inline-flex; }
  .app-shell{ height: auto; min-height: 100vh; overflow: visible; }
  .app-main-col{ height: auto; overflow: visible; }
  .main{ overflow-y: visible; }
  .sidebar{
    position: fixed; inset-inline-start: 0; top: 0; bottom: 0; z-index: 60;
    transform: translateX(100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  [dir="rtl"] .sidebar{ transform: translateX(100%); }
  [dir="ltr"] .sidebar{ transform: translateX(-100%); }
  .sidebar.open{ transform: translateX(0); }
  .sidebar-backdrop.open{
    display: block; position: fixed; inset: 0; z-index: 50;
    background: rgba(15, 18, 26, .5);
  }
  .main{ padding: 16px; }
}

/* --------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------- */

.card{
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card + .card{ margin-top: 16px; }

.card-header{ display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title{ font-size: 16px; font-weight: 700; margin: 0; }

/* Stat row */
.stat-row{ display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 16px; }

.stat-box{
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; display: flex; align-items: center; gap: 12px;
}
.stat-box .icon{
  width: 42px; height: 42px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--primary); flex-shrink: 0;
}
.stat-box .value{ font-size: 20px; font-weight: 800; line-height: 1.2; }
.stat-box .label{ font-size: 12.5px; color: var(--muted); }
a.stat-box{ transition: box-shadow .15s ease, transform .15s ease; }
a.stat-box:hover{ box-shadow: 0 6px 18px rgba(0,0,0,.08); transform: translateY(-1px); }

/* --------------------------------------------------------------------
   Segmented tabs (professional pill-style switcher)
   -------------------------------------------------------------------- */

.seg-tabs{
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--card-alt); border: 1px solid var(--border); border-radius: 12px;
  padding: 4px; flex-wrap: wrap;
}
.seg-tabs .seg-tab{
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 9px;
  font-weight: 700; font-size: 13.5px; color: var(--muted);
  text-decoration: none; white-space: nowrap;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.seg-tabs .seg-tab:hover{ color: var(--text); }
.seg-tabs .seg-tab.active{
  background: var(--card); color: var(--primary);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.seg-tabs .seg-tab .role-pill{ background: var(--danger); }
.seg-tabs.seg-tabs-sm .seg-tab{ padding: 6px 13px; font-size: 12.5px; }

/* --------------------------------------------------------------------
   Buttons & forms
   -------------------------------------------------------------------- */

.btn{
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 700; font-size: 14px; cursor: pointer; transition: all .15s ease;
}
.btn-primary{ background: var(--primary); color: #fff; }
.btn-primary:hover{ background: var(--primary-dark); }
.btn-outline{ background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover{ background: var(--card-alt); }
.btn-danger{ background: var(--danger); color: #fff; }
.btn-success{ background: var(--success); color: #fff; }
.btn-sm{ padding: 6px 12px; font-size: 13px; }
.btn:disabled{ opacity: .55; cursor: not-allowed; }

/* Pagination */
.pg-nav{ display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; }
.pg-pages{ display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pg-btn{
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 36px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  font-weight: 600; font-size: 13.5px; text-decoration: none; transition: all .15s ease;
}
.pg-btn:hover{ background: var(--card-alt); }
.pg-btn.pg-active{ background: var(--primary); border-color: var(--primary); color: #fff; cursor: default; }
.pg-btn.pg-disabled{ opacity: .45; cursor: not-allowed; }
.pg-dots{ padding: 0 4px; color: var(--muted); font-size: 13.5px; }

.form-group{ margin-bottom: 16px; }
.form-label{ display: block; font-size: 13.5px; font-weight: 700; margin-bottom: 6px; }
.form-control{
  width: 100%; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14.5px;
}
.form-control:focus{ outline: none; border-color: var(--primary); background: var(--card); }
.form-hint{ font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-error{ font-size: 12px; color: var(--danger); margin-top: 4px; }

/* Badges */
.badge{ display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-success{ background: var(--success-soft); color: var(--success); }
.badge-danger{ background: var(--danger-soft); color: var(--danger); }
.badge-warning{ background: var(--warning-soft); color: var(--warning); }
.badge-muted{ background: var(--card-alt); color: var(--muted); }

/* --------------------------------------------------------------------
   Tables → cards on mobile
   -------------------------------------------------------------------- */

.table-wrap{ overflow-x: auto; }
table.data-table{ width: 100%; border-collapse: collapse; font-size: 14px; }
table.data-table th{ text-align: start; padding: 12px; color: var(--muted); font-size: 12.5px; font-weight: 700; border-bottom: 1px solid var(--border); }
table.data-table td{ padding: 12px; border-bottom: 1px solid var(--border); }
table.data-table tbody tr.row-alt{ background: var(--card-alt); }
table.data-table tr.row-group{ border-inline-start: 3px solid var(--primary); }

.mobile-cards{ display: none; }

@media (max-width: 720px){
  table.data-table{ display: none; }
  .mobile-cards{ display: block; }
}

.mc-item{
  display: block; padding: 12px 4px; border-bottom: 1px solid var(--border);
}
.mc-item:last-child{ border-bottom: none; }
.mc-top{ display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.mc-name{ margin-top: 4px; font-size: 14px; }
.mc-details{ display: flex; gap: 14px; margin-top: 8px; overflow-x: auto; }
.mc-detail{ display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.mc-detail .l{ font-size: 11px; color: var(--muted); }
.mc-detail .v{ font-size: 13px; font-weight: 700; }

/* --------------------------------------------------------------------
   Custom select (icon + text)
   -------------------------------------------------------------------- */

.custom-select{ position: relative; }
.custom-select-trigger{
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 14px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--bg); cursor: pointer;
}
.custom-select-trigger img{ width: 20px; height: 20px; border-radius: 4px; }
.custom-select-panel{
  display: none; position: absolute; z-index: 30; top: calc(100% + 6px); inset-inline: 0;
  max-height: 280px; overflow-y: auto; background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
}
.custom-select-panel.open{ display: block; }
.custom-select-option{ display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; }
.custom-select-option:hover{ background: var(--card-alt); }
.custom-select-option img{ width: 20px; height: 20px; border-radius: 4px; }

/* --------------------------------------------------------------------
   Floating action button
   -------------------------------------------------------------------- */

.fab{
  position: fixed; bottom: 22px; inset-inline-end: 22px; z-index: 200;
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--success); color: #fff; box-shadow: var(--shadow);
}

/* --------------------------------------------------------------------
   Theme toggle
   -------------------------------------------------------------------- */

.theme-toggle{
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card-alt); color: var(--text); display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

/* --------------------------------------------------------------------
   Utility
   -------------------------------------------------------------------- */

.text-muted{ color: var(--muted); }
.text-success{ color: var(--success); }
.text-danger{ color: var(--danger); }
.text-warning{ color: var(--warning); }

/* --------------------------------------------------------------------
   Auth screens (login / register / password reset)
   -------------------------------------------------------------------- */

.auth-shell{ height: 100vh; display: flex; overflow: hidden; }

.auth-brand-panel{
  flex: 1.05; min-width: 0; min-height: 0; background: var(--primary-soft);
  display: flex; flex-direction: column; justify-content: center; gap: clamp(24px, 6vh, 56px);
  padding: 40px 64px; overflow: hidden;
}
.auth-brand-inner{ max-width: 480px; }
.auth-brand-title{ font-size: 30px; font-weight: 800; margin: 0 0 14px; color: var(--text); line-height: 1.35; }
.auth-brand-subtitle{ font-size: 15px; color: var(--muted); line-height: 1.7; margin: 0; }

.auth-marquee{ display: flex; flex-direction: column; gap: 14px; flex-shrink: 0; direction: ltr; }
.auth-marquee-row{ overflow: hidden; }
.auth-marquee-track{
  display: flex; gap: 12px; width: max-content; direction: ltr;
  animation: auth-marquee-scroll 42s linear infinite;
}
.auth-marquee-track.auth-marquee-reverse{ animation-name: auth-marquee-scroll-reverse; animation-duration: 50s; }
@keyframes auth-marquee-scroll{ from{ transform: translateX(0); } to{ transform: translateX(-50%); } }
@keyframes auth-marquee-scroll-reverse{ from{ transform: translateX(-50%); } to{ transform: translateX(0); } }

.auth-marquee-chip{
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
  padding: 9px 16px; border-radius: 999px; background: #ffffff; border: 1.5px solid rgba(79, 70, 229, .18);
  box-shadow: 0 6px 16px rgba(30, 27, 75, .14); font-size: 13px; font-weight: 700; color: var(--text); white-space: nowrap;
}
.auth-marquee-chip img{ width: 20px; height: 20px; border-radius: 6px; object-fit: cover; }
.auth-marquee-badge{
  width: 20px; height: 20px; border-radius: 6px; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 10.5px; font-weight: 800;
}

.auth-form-panel{
  flex: 1; min-width: 0; position: relative; overflow-y: auto;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: flex; align-items: center; justify-content: center; padding: 40px;
}
.auth-locale-toggle{
  position: fixed; top: 20px; inset-inline-end: 24px; z-index: 20;
  color: var(--text); text-decoration: none; font-weight: 800; font-size: 12.5px;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px;
  box-shadow: 0 4px 12px rgba(20,20,40,.08);
}
.auth-locale-toggle:hover{ background: var(--card-alt); }

.auth-footer{ color: rgba(255,255,255,.6); font-size: 12px; text-align: center; margin: 28px 0 0; }
.auth-footer-links{ display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; margin-top: 28px; }
.auth-footer-links a{ color: rgba(255,255,255,.75); font-size: 12.5px; font-weight: 600; }
.auth-footer-links a:hover{ color: #fff; }

.auth-form-card{ width: 100%; max-width: 400px; }
.auth-form-card h2{ color: #fff; font-size: 24px; text-align: start; margin: 0 0 6px; }
.auth-form-card .auth-form-hint{ color: rgba(255,255,255,.75); font-size: 14px; margin: 0 0 28px; }

.auth-form-card .form-label{ display: none; }
.auth-form-card .form-group{ margin-bottom: 14px; }
.auth-form-card .form-control{
  background: #fff; border: none; border-radius: 999px; color: #1a1a2e;
  padding: 13px 20px; font-size: 14.5px;
}
.auth-form-card .form-control:focus{ box-shadow: 0 0 0 3px rgba(255,255,255,.35); }
.auth-form-card .form-error{ color: #ffd7d7; font-size: 12.5px; margin-top: 6px; padding: 0 6px; }

.auth-form-card label,
.auth-form-card .text-muted{ color: rgba(255,255,255,.85) !important; }
.auth-form-card a{ color: #fff; }

.auth-form-card .btn-primary{ background: #14131f; color: #fff; border-radius: 999px; padding: 13px 18px; }
.auth-form-card .btn-primary:hover{ background: #060610; }
.auth-form-card .btn-outline{
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.4); color: #fff; border-radius: 999px;
}
.auth-form-card .btn-outline:hover{ background: rgba(255,255,255,.18); }
.auth-form-card .badge-success{ background: rgba(255,255,255,.15); color: #fff; }

@media (max-width: 900px){
  .auth-shell{ height: auto; min-height: 100vh; flex-direction: column; overflow: visible; }
  .auth-brand-panel{
    flex: none; gap: 22px; padding: 28px 24px; justify-content: flex-start; text-align: center;
  }
  .auth-brand-inner{ max-width: none; }
  .auth-brand-title{ font-size: 21px; }
  .auth-brand-subtitle{ display: none; }
  .auth-marquee-row:last-child{ display: none; }

  .auth-form-panel{ flex: none; padding: 32px 24px 40px; overflow-y: visible; }
}

/* --------------------------------------------------------------------
   Legal / content pages (privacy, terms, FAQ) + shared site footer
   -------------------------------------------------------------------- */

.legal-page{ min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }

.legal-header{
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 28px; border-bottom: 1px solid var(--border); background: var(--card);
}
.legal-brand{ display: flex; align-items: center; font-weight: 800; font-size: 18px; color: var(--text); text-decoration: none; }

.legal-content{ flex: 1; padding: 40px 20px; display: flex; justify-content: center; }
.legal-card{ width: 100%; max-width: 760px; }
.legal-title{ font-size: 24px; font-weight: 800; margin: 0 0 20px; }
.legal-card h2{ font-size: 17px; font-weight: 800; margin: 28px 0 10px; }
.legal-card p, .legal-card li{ font-size: 14.5px; line-height: 1.9; color: var(--text); }
.legal-card ul{ padding-inline-start: 22px; margin: 0 0 14px; }
.legal-card p{ margin: 0 0 14px; }

.site-footer{ padding: 28px 20px; text-align: center; border-top: 1px solid var(--border); background: var(--card); }
.site-footer-links{ display: flex; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap; margin-bottom: 10px; }
.site-footer-links a{ color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: none; }
.site-footer-links a:hover{ color: var(--primary); }
.site-footer-copy{ color: var(--muted); font-size: 12px; margin: 0; }

/* --------------------------------------------------------------------
   Modal (popup dialog)
   -------------------------------------------------------------------- */

.modal-backdrop{
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 18, 26, .5);
  align-items: center; justify-content: center; padding: 20px;
}
.modal-backdrop.open{ display: flex; }
.modal-box{
  position: relative; width: 100%; max-width: 420px;
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  padding: 24px;
}
.modal-close{
  position: absolute; top: 16px; inset-inline-end: 16px;
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--card-alt); color: var(--muted); display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 16px; line-height: 1;
}
.modal-close:hover{ background: var(--border); color: var(--text); }
.modal-title{ font-size: 17px; font-weight: 800; margin: 0 0 20px; padding-inline-end: 30px; }
.modal-footer{ display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.input-group{ display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.input-group-prefix{
  display: flex; align-items: center; padding: 0 14px; background: var(--card-alt);
  color: var(--muted); font-weight: 700; font-size: 13.5px; border-inline-end: 1px solid var(--border);
  white-space: nowrap;
}
.input-group .form-control{ border: none; border-radius: 0; }
.input-group .form-control:focus{ box-shadow: none; }
