/* ============================================================
   IT Business Manager v3 — Stylesheet
   ============================================================ */

/* ── Variables ── */
:root {
  --bg:        #0d1117;
  --bg2:       #161b22;
  --bg3:       #21262d;
  --bg4:       #2d333b;
  --border:    #30363d;
  --border2:   #21262d;
  --text:      #e6edf3;
  --text2:     #b1bac4;
  --text3:     #8b949e;
  --blue-l:    #388bfd;
  --blue-bg:   #0d2340;
  --green-l:   #3fb950;
  --green-bg:  #0a2b0f;
  --red-l:     #f85149;
  --red-bg:    #2d0c0c;
  --red:       #da3633;
  --amber-l:   #d29922;
  --amber-bg:  #2d1f00;
  --purple-l:  #a371f7;
  --purple-bg: #1e1038;
  --teal-l:    #39d0cc;
  --teal-bg:   #0a2320;
  --font:      'Tajawal', sans-serif;
  --mono:      'IBM Plex Mono', monospace;
  --radius:    8px;
  --radius-lg: 12px;
  --sidebar-w: 220px;
  --header-h:  56px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: var(--font); background: var(--bg); color: var(--text);
       direction: rtl; min-height: 100vh; overflow-x: hidden; }
a { color: var(--blue-l); text-decoration: none; }
button { cursor: pointer; font-family: var(--font); }
input, select, textarea { font-family: var(--font); }
::selection { background: var(--blue-bg); color: var(--blue-l); }

/* ── Loading Screen ── */
.db-loading-screen {
  position: fixed; inset: 0; background: var(--bg); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
.db-loading-inner { text-align: center; }
.db-load-logo  { height: 64px; max-width: 280px; object-fit: contain; margin-bottom: 12px; }
.db-load-title { font-size: 20px; font-weight: 800; margin-bottom: 6px; }
.db-load-txt   { font-size: 13px; color: var(--text3); margin-bottom: 20px; }
.db-load-bar   { width: 200px; height: 3px; background: var(--bg3);
                 border-radius: 2px; margin: 0 auto; overflow: hidden; }
.db-load-fill  { height: 100%; width: 40%; background: var(--blue-l);
                 border-radius: 2px; animation: loadPulse 1.2s ease-in-out infinite; }
@keyframes loadPulse { 0%,100%{transform:translateX(-100%)} 50%{transform:translateX(250%)} }
.db-err { background: var(--red-bg); border: 1px solid var(--red);
          border-radius: var(--radius-lg); padding: 20px 24px;
          font-size: 13px; color: var(--red-l); line-height: 1.7;
          max-width: 460px; text-align: right; }
.db-err code { background: var(--bg3); padding: 2px 6px; border-radius: 4px;
               font-family: var(--mono); font-size: 12px; }

/* ── Login ── */
.login-wrap { position: fixed; inset: 0; background: var(--bg);
              display: flex; align-items: center; justify-content: center;
              z-index: 100; }
.login-box  { background: var(--bg2); border: 1px solid var(--border);
              border-radius: 16px; padding: 36px 32px; width: 360px;
              text-align: center; }
.login-logo  { height: 56px; max-width: 260px; object-fit: contain; margin-bottom: 10px; }
.login-title { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.login-sub   { font-size: 13px; color: var(--text3); margin-bottom: 24px; }
.login-err   { background: var(--red-bg); color: var(--red-l); border-radius: var(--radius);
               padding: 9px 14px; font-size: 13px; margin-bottom: 12px; text-align: right; }
.login-hint  { font-size: 11px; color: var(--text3); margin-top: 14px;
               font-family: var(--mono); }

/* ── App Layout ── */
.app-wrap { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Header ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-h);
  background: var(--bg2); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  z-index: 200;
}
.tb-logo { display: flex; align-items: center; white-space: nowrap; }
.tb-logo img { height: 34px; width: auto; object-fit: contain; }
.tb-right { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.u-info  { display: flex; flex-direction: column; align-items: flex-end; }
.u-name  { font-size: 13px; font-weight: 600; }
.u-role  { font-size: 10px; padding: 1px 7px; border-radius: 10px; font-weight: 700; }
.u-role.admin   { background: var(--purple-bg); color: var(--purple-l); }
.u-role.manager { background: var(--blue-bg);   color: var(--blue-l); }
.u-role.staff   { background: var(--bg3);        color: var(--text3); }

/* ── Search ── */
.search-wrap { position: relative; flex: 1; max-width: 340px; }
.search-input {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 7px 14px 7px 36px; border-radius: 20px;
  font-size: 13px; font-family: var(--font); outline: none; transition: .2s;
}
.search-input:focus { border-color: var(--blue-l); background: var(--bg4); }
.search-icon { position: absolute; right: 12px; top: 50%;
               transform: translateY(-50%); color: var(--text3);
               font-size: 14px; pointer-events: none; }
.search-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0; left: 0;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); z-index: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,.5); display: none;
  max-height: 360px; overflow-y: auto;
}
.search-dropdown.open { display: block; }
.search-group { padding: 8px 12px 4px; font-size: 10px; font-weight: 700;
                color: var(--text3); text-transform: uppercase; letter-spacing: .06em; }
.search-item  { display: flex; align-items: center; gap: 10px;
                padding: 9px 14px; cursor: pointer; transition: .15s; font-size: 13px; }
.search-item:hover { background: var(--bg3); }
.search-item .si-icon { font-size: 16px; width: 24px; text-align: center; }
.search-item .si-main { font-weight: 600; color: var(--text); }
.search-item .si-sub  { font-size: 11px; color: var(--text3); margin-top: 1px; }
.search-empty { padding: 20px; text-align: center; color: var(--text3); font-size: 13px; }

/* ── Sidebar ── */
.sidebar {
  position: fixed; top: var(--header-h); right: 0; bottom: 0;
  width: var(--sidebar-w); background: var(--bg2);
  border-left: 1px solid var(--border); overflow-y: auto;
  padding: 12px 0; z-index: 100;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }
.nav-sec  { font-size: 10px; font-weight: 700; color: var(--text3);
            text-transform: uppercase; letter-spacing: .06em;
            padding: 14px 16px 4px; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 9px 16px;
            font-size: 13px; cursor: pointer; transition: .15s; color: var(--text2);
            border-right: 3px solid transparent; position: relative; }
.nav-item:hover  { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--bg3); color: var(--blue-l);
                   border-right-color: var(--blue-l); }
.ni { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.nav-badge { background: var(--red-l); color: #fff; font-size: 10px;
             font-weight: 700; padding: 1px 6px; border-radius: 10px;
             margin-right: auto; }

/* ── Main Content ── */
.main-content {
  margin-top: var(--header-h); margin-left: 0;
  margin-right: var(--sidebar-w); padding: 20px;
  min-height: calc(100vh - var(--header-h)); flex: 1;
}

/* ── Pages ── */
.page { display: none; }
.page.active { display: block; }

/* ── Page Header ── */
.ph { display: flex; align-items: flex-start; justify-content: space-between;
      margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.pt { font-size: 20px; font-weight: 800; }
.ps { font-size: 13px; color: var(--text3); margin-top: 3px; }

/* ── KPIs ── */
.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr);
            gap: 16px; margin-bottom: 20px; }
.kpi { background: var(--bg2); border: 1px solid var(--border);
       border-radius: var(--radius-lg); padding: 16px 18px; }
.kpi-lbl { font-size: 11px; color: var(--text3); margin-bottom: 6px; font-weight: 600; text-transform: uppercase; }
.kpi-val { font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.kpi-sub { font-size: 11px; color: var(--text3); }
.kpi-val.blue   { color: var(--blue-l); }
.kpi-val.green  { color: var(--green-l); }
.kpi-val.red    { color: var(--red-l); }
.kpi-val.amber  { color: var(--amber-l); }
.kpi-val.purple { color: var(--purple-l); }
.kpi-val.teal   { color: var(--teal-l); }

/* ── Cards ── */
.card { background: var(--bg2); border: 1px solid var(--border);
        border-radius: var(--radius-lg); margin-bottom: 20px; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between;
             padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 14px; font-weight: 700; }
.card-body  { padding: 16px 18px; }

/* ── Tables ── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl thead tr { background: var(--bg3); }
.tbl th { padding: 10px 14px; text-align: right; font-size: 11px;
          font-weight: 700; color: var(--text3); text-transform: uppercase;
          letter-spacing: .04em; white-space: nowrap; }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border2);
          color: var(--text2); vertical-align: middle; }
.tbl tr:hover td { background: var(--bg3); }
.tbl tr:last-child td { border-bottom: none; }

/* ── Forms ── */
.fg   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.fl   { display: flex; flex-direction: column; gap: 5px; }
.fl.full { grid-column: 1/-1; }
.flb  { font-size: 12px; font-weight: 600; color: var(--text2); }
.fi   {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 9px 12px; border-radius: var(--radius);
  font-size: 13px; font-family: var(--font); outline: none; width: 100%;
  transition: border-color .15s;
}
.fi:focus { border-color: var(--blue-l); }
.fi::placeholder { color: var(--text3); }
textarea.fi { resize: vertical; min-height: 80px; }
select.fi   { appearance: none; cursor: pointer; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius); border: none;
  font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: var(--font); transition: .15s; white-space: nowrap;
}
.btn-pr { background: var(--blue-l);  color: #fff; }
.btn-pr:hover { background: #58a6ff; }
.btn-gh { background: var(--bg3); border: 1px solid var(--border);
          color: var(--text2); }
.btn-gh:hover { background: var(--bg4); color: var(--text); }
.btn-dn { background: var(--red-bg); border: 1px solid var(--red);
          color: var(--red-l); }
.btn-dn:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-grp { display: flex; gap: 8px; flex-wrap: wrap; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Icon Buttons ── */
.ic-btn { background: transparent; border: none; font-size: 15px;
          padding: 4px 6px; border-radius: 6px; transition: .15s; }
.ic-btn:hover { background: var(--bg3); }
.ic-btn.red { background: var(--red-bg); border: 1px solid rgba(218,54,51,.35); }
.ic-btn.red:hover { background: var(--red); border-color: var(--red); }

/* ── Badges ── */
.badge { font-size: 11px; font-weight: 700; padding: 2px 9px;
         border-radius: 20px; display: inline-block; }
.badge.active  { background: var(--blue-bg);   color: var(--blue-l); }
.badge.done    { background: var(--green-bg);   color: var(--green-l); }
.badge.late    { background: var(--red-bg);     color: var(--red-l); }
.badge.paused  { background: var(--bg3);        color: var(--text3); }
.badge.pending { background: var(--amber-bg);   color: var(--amber-l); }
.badge.info    { background: var(--purple-bg);  color: var(--purple-l); }

/* ── Filter Tabs ── */
.ftabs { display: flex; gap: 4px; margin-bottom: 16px;
         background: var(--bg3); border-radius: var(--radius-lg);
         padding: 5px; width: fit-content; flex-wrap: wrap; }
.ftab  { padding: 7px 14px; border-radius: 8px; font-size: 12px; font-weight: 600;
         border: none; background: transparent; color: var(--text3);
         cursor: pointer; transition: .15s; }
.ftab:hover { color: var(--text); }
.ftab.on    { background: var(--bg2); color: var(--text);
              box-shadow: 0 1px 4px rgba(0,0,0,.3); }

/* ── Modals ── */
.mbg { position: fixed; inset: 0; background: rgba(0,0,0,.7);
       z-index: 400; display: none; align-items: center; justify-content: center;
       padding: 20px; }
.mbg.open { display: flex; }
.modal { background: var(--bg2); border: 1px solid var(--border);
         border-radius: var(--radius-lg); width: 100%; max-width: 560px;
         max-height: 90vh; overflow-y: auto; }
.modal-lg { max-width: 800px; }
.mh { display: flex; align-items: center; justify-content: space-between;
      padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0;
      background: var(--bg2); z-index: 1; }
.mt { font-size: 15px; font-weight: 700; }
.mc { background: var(--bg3); border: 1px solid var(--border); color: var(--text2);
      width: 28px; height: 28px; border-radius: 6px; font-size: 13px;
      display: flex; align-items: center; justify-content: center; }
.mc:hover { background: var(--red-bg); color: var(--red-l); }
.mb { padding: 20px; }
.mf { display: flex; gap: 10px; justify-content: flex-end;
      padding: 14px 20px; border-top: 1px solid var(--border); }

/* ── Alerts ── */
.al { display: flex; align-items: flex-start; gap: 12px; padding: 12px;
      border-radius: var(--radius); margin-bottom: 8px; cursor: pointer; transition: .15s; }
.al:hover { opacity: .85; }
.al.danger { background: var(--red-bg);   border: 1px solid rgba(218,54,51,.3); }
.al.warn   { background: var(--amber-bg); border: 1px solid rgba(210,153,34,.3); }
.al.info   { background: var(--blue-bg);  border: 1px solid rgba(56,139,253,.3); }
.al-icon   { font-size: 20px; flex-shrink: 0; margin-top: 2px; }
.al-title  { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.al-desc   { font-size: 12px; color: var(--text3); }

/* ── Progress Bars ── */
.prog { height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; }
.pf   { height: 100%; border-radius: 3px; transition: width .5s; }
.pf.green  { background: var(--green-l); }
.pf.blue   { background: var(--blue-l); }
.pf.amber  { background: var(--amber-l); }
.pf.red    { background: var(--red-l); }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; gap: 6px;
              justify-content: center; padding: 14px 0; flex-wrap: wrap; }
.pg-btn { min-width: 34px; height: 34px; border-radius: 6px;
          border: 1px solid var(--border); background: var(--bg3);
          color: var(--text2); font-size: 13px; cursor: pointer;
          display: flex; align-items: center; justify-content: center; transition: .15s; }
.pg-btn:hover  { background: var(--bg4); color: var(--text); }
.pg-btn.active { background: var(--blue-l); color: #fff;
                 border-color: var(--blue-l); font-weight: 700; }
.pg-btn:disabled { opacity: .4; cursor: not-allowed; }
.pg-info { font-size: 12px; color: var(--text3); padding: 0 6px; }

/* ── Charts ── */
.chart-row   { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.chart-label { width: 120px; font-size: 12px; color: var(--text2);
               text-align: right; white-space: nowrap;
               overflow: hidden; text-overflow: ellipsis; }
.chart-bar   { height: 20px; border-radius: 4px; background: var(--blue-l);
               transition: width .5s; min-width: 2px; }
.chart-val   { width: 80px; font-size: 12px; font-weight: 700; }

/* ── Invoices ── */
.inv-number { font-family: var(--mono); font-size: 12px;
              color: var(--blue-l); font-weight: 700; }
.inv-type-invoice   { background: var(--blue-bg);   color: var(--blue-l);
                      border-radius: 20px; padding: 2px 10px; font-size: 11px; font-weight: 700; }
.inv-type-quotation { background: var(--purple-bg); color: var(--purple-l);
                      border-radius: 20px; padding: 2px 10px; font-size: 11px; font-weight: 700; }
.inv-st-draft     { background: var(--bg3);        color: var(--text3); }
.inv-st-sent      { background: var(--blue-bg);    color: var(--blue-l); }
.inv-st-approved  { background: var(--purple-bg);  color: var(--purple-l); }
.inv-st-paid      { background: var(--green-bg);   color: var(--green-l); }
.inv-st-cancelled { background: var(--red-bg);     color: var(--red-l); }
.inv-item-row input {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font-size: 13px;
  color: var(--text); font-family: var(--font); width: 100%; outline: none;
}
.inv-item-row input:focus { border-color: var(--blue-l); }
.inv-totals-box { width: 280px; background: var(--bg3); border: 1px solid var(--border);
                  border-radius: var(--radius); padding: 14px 16px; }
.inv-totals-row { display: flex; justify-content: space-between;
                  padding: 7px 0; font-size: 13px; border-bottom: 1px solid var(--border2); }
.inv-totals-row:last-child { border-bottom: none; font-size: 15px; font-weight: 700; padding-top: 10px; }

/* ── Inventory ── */
.inv-stock-low  { color: var(--red-l); font-weight: 700; }
.inv-stock-ok   { color: var(--green-l); }
.inv-cat-badge  { background: var(--purple-bg); color: var(--purple-l);
                  border-radius: 12px; padding: 2px 9px; font-size: 11px; }

/* ── Activity Log ── */
.act-row  { display: flex; align-items: center; gap: 12px; padding: 10px 0;
            border-bottom: 1px solid var(--border2); }
.act-icon { width: 32px; height: 32px; border-radius: 50%;
            display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.act-icon.add  { background: var(--green-bg); }
.act-icon.edit { background: var(--blue-bg); }
.act-icon.del  { background: var(--red-bg); }
.act-time { font-size: 11px; color: var(--text3); margin-right: auto; white-space: nowrap; }

/* ── Backup ── */
.backup-card { background: var(--bg3); border: 2px solid var(--border);
               border-radius: var(--radius-lg); padding: 28px;
               text-align: center; cursor: pointer; transition: .2s; }
.backup-card:hover { border-color: var(--blue-l); background: var(--bg4); }
.backup-card .bc-icon  { font-size: 44px; margin-bottom: 10px; }
.backup-card .bc-title { font-size: 15px; font-weight: 700; margin-bottom: 5px; }
.backup-card .bc-sub   { font-size: 12px; color: var(--text3); line-height: 1.6; }

/* ── Toast ── */
.toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
         opacity: 0; transition: all .3s; z-index: 9000; padding: 11px 22px;
         border-radius: 24px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok  { background: var(--green-bg); color: var(--green-l); border: 1px solid var(--green-l); }
.toast.err { background: var(--red-bg);   color: var(--red-l);   border: 1px solid var(--red); }
.toast.inf { background: var(--blue-bg);  color: var(--blue-l);  border: 1px solid var(--blue-l); }

/* ── Print ── */
#inv-print-area { display: none; }
@media print {
  body > * { display: none !important; }
  #inv-print-area { display: block !important; position: static !important;
                    padding: 32px; font-family: var(--font); color: #000; direction: rtl; }
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .fg       { grid-template-columns: 1fr; }
  .sidebar  { width: 56px; }
  .sidebar .nav-sec, .sidebar .nav-item span:not(.ni) { display: none; }
  .main-content { margin-right: 56px; }
}
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .main-content { padding: 12px; }
}

/* ── v4 additions to style.css ── */
.inv-st-partial   { background: var(--amber-bg);  color: var(--amber-l);  border-radius: 20px; padding: 2px 9px; font-size: 11px; font-weight: 700; }
.badge-new        { background: var(--bg3);        color: var(--text2);   }
.badge-surveying  { background: var(--blue-bg);    color: var(--blue-l);  }
.badge-quoted     { background: var(--purple-bg);  color: var(--purple-l);}
.badge-awaiting_approval { background: var(--amber-bg); color: var(--amber-l); }
.badge-approved   { background: var(--green-bg);   color: var(--green-l); }
.badge-converted  { background: var(--teal-bg);    color: var(--teal-l);  }
.badge-rejected   { background: var(--red-bg);     color: var(--red-l);   }
.badge-active     { background: var(--blue-bg);    color: var(--blue-l);  }
.badge-expiring   { background: var(--amber-bg);   color: var(--amber-l); }
.badge-expired    { background: var(--red-bg);     color: var(--red-l);   }
.badge-cancelled  { background: var(--bg3);        color: var(--text3);   }
.badge-open       { background: var(--blue-bg);    color: var(--blue-l);  }
.badge-in_progress{ background: var(--amber-bg);   color: var(--amber-l); }
.badge-resolved   { background: var(--green-bg);   color: var(--green-l); }
.badge-closed     { background: var(--bg3);        color: var(--text3);   }
.badge-scheduled  { background: var(--blue-bg);    color: var(--blue-l);  }
.badge-completed  { background: var(--green-bg);   color: var(--green-l); }
.kpi-val.red      { color: var(--red-l); }
