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

:root {
  --bg:         #0f1117;
  --bg2:        #161b27;
  --bg3:        #1e2535;
  --border:     #2a3245;
  --text:       #e2e8f0;
  --text-muted: #8892a4;
  --primary:    #6366f1;
  --primary-h:  #4f52e0;
  --success:    #22c55e;
  --danger:     #ef4444;
  --warning:    #f59e0b;
  --info:       #38bdf8;
  --radius:     10px;
  --sidebar-w:  230px;
  --transition: .2s ease;
}

html, body { height: 100%; }
body { background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, sans-serif;
       font-size: 14px; min-height: 100vh; display: flex; margin: 0; }

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-h); }

/* ─── Sidebar ─────────────────────────────────────────────────────── */
.sidebar { width: var(--sidebar-w); background: var(--bg2); border-right: 1px solid var(--border);
           display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh;
           z-index: 100; transition: transform var(--transition); }
.sidebar-header { display: flex; align-items: center; gap: .6rem; padding: 1.2rem 1rem;
                  border-bottom: 1px solid var(--border); }
.logo-icon { font-size: 1.5rem; }
.logo-text { font-size: 1.1rem; font-weight: 700; color: var(--primary); }
.nav-links { flex: 1; padding: .8rem 0; overflow-y: auto; }
.nav-link { display: flex; align-items: center; gap: .7rem; padding: .6rem 1rem;
            color: var(--text-muted); transition: background var(--transition), color var(--transition);
            border-radius: var(--radius); margin: 2px .5rem; }
.nav-link:hover, .nav-link.active { background: var(--bg3); color: var(--text); }
.nav-link.active { border-left: 3px solid var(--primary); }
.sidebar-footer { padding: .8rem; border-top: 1px solid var(--border); display: flex; align-items: center; gap: .5rem; }
.user-info { display: flex; align-items: center; gap: .6rem; flex: 1; overflow: hidden; }
.user-avatar { width: 32px; height: 32px; background: var(--primary); border-radius: 50%;
               display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex-shrink: 0; }
.user-name { font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .72rem; color: var(--text-muted); }
.logout-btn { color: var(--text-muted); font-size: 1.2rem; padding: .3rem; border-radius: 6px; transition: color var(--transition); }
.logout-btn:hover { color: var(--danger); }

/* ─── Main Layout ─────────────────────────────────────────────────── */
.main-wrap { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: .75rem 1.5rem;
          background: var(--bg2); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.page-title { font-size: 1rem; font-weight: 600; flex: 1; }
.menu-toggle { display: none; background: none; border: none; color: var(--text); font-size: 1.3rem; cursor: pointer; }
.content { padding: 1.5rem; flex: 1; }

/* ─── Lang Toggle ─────────────────────────────────────────────────── */
.lang-toggle {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .3rem .75rem; border-radius: 20px; font-size: .78rem; font-weight: 600;
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  cursor: pointer; transition: background .2s, border-color .2s; white-space: nowrap;
  font-family: 'Segoe UI', system-ui, sans-serif;
}
.lang-toggle:hover { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ─── RTL Support ─────────────────────────────────────────────────── */
[dir="rtl"] body { font-family: 'Segoe UI', 'Tahoma', system-ui, sans-serif; }
[dir="rtl"] .sidebar { left: auto; right: 0; border-right: none; border-left: 1px solid var(--border); }
[dir="rtl"] .main-wrap { margin-left: 0; margin-right: var(--sidebar-w); }
[dir="rtl"] .nav-link { flex-direction: row-reverse; }
[dir="rtl"] .nav-link.active { border-left: none; border-right: 3px solid var(--primary); }
[dir="rtl"] .topbar { flex-direction: row-reverse; }
[dir="rtl"] .sidebar-header { flex-direction: row-reverse; }
[dir="rtl"] .sidebar-footer { flex-direction: row-reverse; }
[dir="rtl"] .user-info { flex-direction: row-reverse; }
[dir="rtl"] .section-header { flex-direction: row-reverse; }
[dir="rtl"] .kpi-card { direction: rtl; text-align: right; }
[dir="rtl"] table { direction: rtl; }
[dir="rtl"] th, [dir="rtl"] td { text-align: right; }
[dir="rtl"] .form-grid { direction: rtl; }
[dir="rtl"] .form-group { text-align: right; }
[dir="rtl"] .form-control { text-align: right; direction: rtl; }
[dir="rtl"] .check-item { flex-direction: row-reverse; }
[dir="rtl"] .checklist-grid { direction: rtl; }
[dir="rtl"] .section-header .flex { flex-direction: row-reverse; }
[dir="rtl"] .flex:not(.topbar .flex):not(.form-group) { flex-direction: row-reverse; }
[dir="rtl"] .chart-title { text-align: right; }
[dir="rtl"] .form-section-title { text-align: right; }
[dir="rtl"] .section-title { text-align: right; }
[dir="rtl"] .kpi-label, [dir="rtl"] .kpi-sub { text-align: right; }
[dir="rtl"] .photo-caption { text-align: right; }
[dir="rtl"] .text-muted { text-align: right; }

/* Keep topbar flex always left-to-right internally but reversed for RTL */
[dir="rtl"] .topbar .page-title { text-align: right; }
[dir="rtl"] .login-box { direction: rtl; }
[dir="rtl"] .login-logo { direction: ltr; } /* keep logo centered */
[dir="rtl"] .login-box .form-group label { text-align: right; }

@media (max-width: 768px) {
  [dir="rtl"] .sidebar { transform: translateX(100%); left: auto; right: 0; }
  [dir="rtl"] .sidebar.open { transform: translateX(0); }
  [dir="rtl"] .main-wrap { margin-right: 0; }
}

/* ─── Login ───────────────────────────────────────────────────────── */
.login-box { background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
             padding: 2.5rem 2rem; width: 380px; max-width: 95vw; }
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo .icon { font-size: 2.5rem; }
.login-logo h2 { font-size: 1.3rem; margin-top: .4rem; }
.login-logo p  { font-size: .8rem; color: var(--text-muted); }

/* ─── Flash ───────────────────────────────────────────────────────── */
.flash { padding: .5rem 1rem; border-radius: var(--radius); font-size: .85rem; transition: opacity 1s; }
.flash-success { background: rgba(34,197,94,.15); border: 1px solid var(--success); color: var(--success); }
.flash-error   { background: rgba(239,68,68,.15);  border: 1px solid var(--danger);  color: var(--danger); }
.flash-info    { background: rgba(56,189,248,.15);  border: 1px solid var(--info);    color: var(--info); }

/* ─── Cards / KPI ─────────────────────────────────────────────────── */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; display: flex; flex-direction: column; gap: .4rem; }
.kpi-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.kpi-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.kpi-sub   { font-size: .75rem; color: var(--text-muted); }
.kpi-pass   { color: var(--success); }
.kpi-fail   { color: var(--danger); }
.kpi-review { color: var(--warning); }
.kpi-total  { color: var(--info); }

/* ─── Charts ──────────────────────────────────────────────────────── */
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px,1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.chart-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; }
.chart-title { font-size: .85rem; font-weight: 600; margin-bottom: 1rem; color: var(--text-muted); text-transform: uppercase; }

/* ─── Tables ──────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .7rem 1rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--bg3); font-size: .75rem; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
tr:hover td { background: rgba(255,255,255,.02); }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section-title  { font-size: 1rem; font-weight: 600; }

/* ─── Badges ──────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: .2rem .6rem; border-radius: 20px; font-size: .72rem; font-weight: 600; }
.badge-pass      { background: rgba(34,197,94,.15);   color: var(--success); border: 1px solid var(--success); }
.badge-fail      { background: rgba(239,68,68,.15);   color: var(--danger);  border: 1px solid var(--danger); }
.badge-review    { background: rgba(245,158,11,.15);  color: var(--warning); border: 1px solid var(--warning); }
.badge-na        { background: rgba(136,146,164,.15); color: var(--text-muted); border: 1px solid var(--border); }
.badge-draft     { background: rgba(136,146,164,.15); color: var(--text-muted); border: 1px solid var(--border); }
.badge-submitted { background: rgba(56,189,248,.15);  color: var(--info);    border: 1px solid var(--info); }

/* ─── Buttons ─────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1rem; border-radius: 8px;
       font-size: .85rem; font-weight: 500; cursor: pointer; border: none; transition: opacity var(--transition); }
.btn:hover { opacity: .88; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg3); }
.btn-sm { padding: .3rem .7rem; font-size: .78rem; }

/* ─── Forms ───────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-group label { font-size: .8rem; color: var(--text-muted); font-weight: 500; }
.form-control { background: var(--bg3); border: 1px solid var(--border); color: var(--text);
                padding: .55rem .8rem; border-radius: 8px; font-size: .88rem; width: 100%; transition: border-color var(--transition); }
.form-control:focus { outline: none; border-color: var(--primary); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-section { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; margin-bottom: 1rem; }
.form-section-title { font-size: .85rem; font-weight: 600; color: var(--primary); margin-bottom: 1rem; text-transform: uppercase; letter-spacing: .5px; }

/* ─── Checklist ───────────────────────────────────────────────────── */
.checklist-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px,1fr)); gap: .6rem; }
.check-item { display: flex; align-items: center; justify-content: space-between; background: var(--bg3);
              border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; gap: .5rem; }
.check-name { font-size: .82rem; flex: 1; }
.check-select { background: var(--bg); border: 1px solid var(--border); color: var(--text);
                padding: .25rem .5rem; border-radius: 6px; font-size: .78rem; }

/* ─── Photos ──────────────────────────────────────────────────────── */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px,1fr)); gap: .6rem; }
.photo-thumb { border-radius: 8px; overflow: hidden; border: 1px solid var(--border); aspect-ratio: 1; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-caption { font-size: .7rem; color: var(--text-muted); padding: .3rem .4rem; background: var(--bg3); }

/* ─── Misc ────────────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }
.flex { display: flex; } .items-center { align-items: center; } .gap-2 { gap: .5rem; } .gap-4 { gap: 1rem; }
.justify-between { justify-content: space-between; }

/* ─── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .menu-toggle { display: block; }
  .kpi-grid { grid-template-columns: repeat(2,1fr); }
}
