@font-face { font-family: Tajawal; font-weight: 400; font-display: swap; src: url(../fonts/tajawal-arabic-400-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Tajawal; font-weight: 400; font-display: swap; src: url(../fonts/tajawal-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-02FF, U+2000-206F; }
@font-face { font-family: Tajawal; font-weight: 700; font-display: swap; src: url(../fonts/tajawal-arabic-700-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Tajawal; font-weight: 700; font-display: swap; src: url(../fonts/tajawal-latin-700-normal.woff2) format("woff2"); unicode-range: U+0000-02FF, U+2000-206F; }

:root {
  --navy: #12355b; --navy-2: #1b4674; --accent: #d9822b; --primary: #1d67b0; --primary-d: #17528c;
  --bg: #f4f7fb; --card: #fff; --ink: #1c2940; --muted: #647082; --line: #dde3ec;
  --ok: #17794f; --ok-bg: #e6f4ee; --warn: #a8660f; --warn-bg: #fdf1e1; --bad: #bd2c2c; --bad-bg: #fbeaea; --info-bg: #e8f0fa;
  --radius: 10px; --shadow: 0 1px 3px rgba(18, 53, 91, .1);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.6 Tajawal, "Segoe UI", Tahoma, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 17px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 0 0 8px; }
.mono { font-family: Consolas, monospace; font-size: 12px; direction: ltr; unicode-bidi: embed; overflow-wrap: anywhere; display: inline-block; text-align: left; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; } .nowrap { white-space: nowrap; } .pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.grow { flex: 1; min-width: 0; }

/* Layout */
.shell { display: flex; min-height: 100%; }
.side { width: 240px; flex: none; background: var(--navy); color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 30; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand img { width: 34px; height: 34px; object-fit: contain; background: #fff; border-radius: 8px; padding: 2px; }
.nav { padding: 10px 0; flex: 1; overflow-y: auto; }
.nav a { display: block; color: #d9e4f1; padding: 9px 18px; border-inline-start: 3px solid transparent; }
.nav a:hover { background: var(--navy-2); text-decoration: none; }
.nav a.active { background: var(--navy-2); color: #fff; font-weight: 700; border-inline-start-color: var(--accent); }
.who { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; }
.who b { display: block; font-size: 14px; } .who .btn { width: 100%; margin-top: 8px; background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.who .btn:hover { background: rgba(255,255,255,.14); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 10px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.btn.menu-btn { display: none; margin-inline-end: auto; }
.content { padding: 22px 24px 40px; flex: 1; }
.head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.head .actions { margin-inline-start: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 10px; }

/* Components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.btn { font: inherit; font-weight: 500; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; display: inline-block; line-height: 1.4; }
.btn:hover { background: #f1f4f8; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; } .btn.primary:hover { background: var(--primary-d); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; } .btn.danger:hover { background: #a02424; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: block; margin-bottom: 12px; font-weight: 500; font-size: 14px; }
label.field > input, label.field > select, label.field > textarea { margin-top: 4px; }
input[type=text], input[type=tel], input[type=email], input[type=password], input[type=search], input[type=date], input[type=datetime-local], input[type=url], input[type=file], select, textarea {
  width: 100%; font: inherit; font-weight: 400; padding: 7px 10px; border: 1px solid #c7cfda; border-radius: 8px; background: #fff; color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }
.hint { font-size: 12.5px; color: var(--muted); font-weight: 400; margin-top: 3px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { font: inherit; background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--muted); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 700; background: #f8fafc; white-space: nowrap; }
tr.link { cursor: pointer; } tr.link:hover td { background: #f6f9fd; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 500; background: #eceff4; color: #46536a; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.bad { background: var(--bad-bg); color: var(--bad); } .badge.info { background: var(--info-bg); color: var(--primary-d); }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }
.alert { padding: 9px 13px; border-radius: 8px; margin-bottom: 12px; background: var(--info-bg); font-size: 14px; }
.alert.bad { background: var(--bad-bg); color: var(--bad); } .alert.ok { background: var(--ok-bg); color: var(--ok); } .alert.warn { background: var(--warn-bg); color: var(--warn); }
.pager { display: flex; align-items: center; gap: 10px; justify-content: center; margin-top: 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 14px; } .kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; } .row > * { flex: 1 1 150px; } .row > .btn { flex: 0 0 auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { background: var(--info-bg); border-radius: 99px; padding: 2px 6px 2px 10px; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; padding: 0 3px; }

/* Stats */
.section-title { font-weight: 700; margin: 18px 0 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 10px; }
.stat { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; color: inherit; box-shadow: var(--shadow); }
a.stat:hover { border-color: var(--primary); text-decoration: none; }
.stat b { display: block; font-size: 24px; color: var(--primary); line-height: 1.3; } .stat span { font-size: 13px; color: var(--muted); }
.stat.alert-num b { color: var(--bad); }

/* Modal & toast */
.overlay { position: fixed; inset: 0; background: rgba(18, 30, 50, .5); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 12px; overflow-y: auto; z-index: 100; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 480px; padding: 18px 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; margin-bottom: 12px; } .modal-head h2 { margin: 0; flex: 1; }
.x { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 14px; }
#toasts { position: fixed; bottom: 18px; left: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, 90vw); }
.toast { background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); } .toast.ok { background: var(--ok); }

/* Bell */
.bell { position: relative; }
.bell .dot { position: absolute; top: -6px; left: -6px; background: var(--bad); color: #fff; border-radius: 99px; font-size: 11px; min-width: 18px; padding: 0 4px; text-align: center; line-height: 18px; }
.notif-panel { position: absolute; top: 48px; left: 20px; width: min(380px, calc(100vw - 24px)); max-height: 70vh; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.2); z-index: 40; }
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: 9px 12px; border-bottom: 1px solid var(--line); font-weight: 700; }
.notif { display: block; padding: 9px 12px; border-bottom: 1px solid var(--line); color: inherit; font-size: 14px; } .notif:hover { background: #f6f9fd; text-decoration: none; }
.notif.unread { background: var(--info-bg); font-weight: 500; }

/* Auth */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, var(--navy), #24598f); }
.auth-card { background: #fff; border-radius: 14px; padding: 26px; width: 100%; max-width: 420px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.auth-card .logo { display: block; width: 62px; height: 62px; object-fit: contain; margin: 0 auto 8px; }
.auth-card h1 { text-align: center; font-size: 20px; margin-bottom: 4px; } .auth-card .sub { text-align: center; color: var(--muted); margin-bottom: 18px; font-size: 14px; }
.auth-card .btn.primary { width: 100%; padding: 9px; }
.qr { display: block; width: 190px; height: 190px; margin: 8px auto; }

/* Document workspace */
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-items: start; }
.viewer { background: #d9dfe8; border-radius: var(--radius); padding: 12px; max-height: calc(100vh - 150px); overflow: auto; }
.pdf-page { position: relative; margin: 0 auto 12px; background: #fff; box-shadow: 0 1px 6px rgba(0,0,0,.25); direction: ltr; }
.pdf-page canvas { display: block; width: 100%; height: 100%; }
.pdf-page.placing { cursor: crosshair; }
.box { position: absolute; border: 2px dashed var(--primary); background: rgba(29, 103, 176, .1); color: var(--primary-d); font-size: 12px; display: flex; align-items: center; justify-content: center; text-align: center; overflow: hidden; user-select: none; direction: rtl; touch-action: none; }
.box.edit { cursor: move; }
.box.mine { border: 2px solid var(--accent); background: rgba(217, 130, 43, .14); color: var(--warn); cursor: pointer; font-weight: 700; }
.box.pending { border-style: solid; border-color: #9aa6b6; background: rgba(120, 130, 150, .08); color: var(--muted); }
.box.signed { border: 2px solid var(--ok); background: rgba(23, 121, 79, .05); }
.box.signed img { max-width: 100%; max-height: 100%; object-fit: contain; }
.box.declined { border: 2px solid var(--bad); background: var(--bad-bg); color: var(--bad); }
.box .rm { position: absolute; top: 1px; left: 1px; background: var(--bad); color: #fff; border: 0; border-radius: 4px; cursor: pointer; font-size: 12px; line-height: 1; width: 17px; height: 17px; padding: 0; }
.box .grip { position: absolute; right: 0; bottom: 0; width: 13px; height: 13px; background: var(--primary); cursor: nwse-resize; border-radius: 3px 0 0 0; }
.box-list { list-style: none; padding: 0; margin: 0; font-size: 14px; } .box-list li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.sigpad { display: block; width: 100%; height: 170px; border: 1px dashed #9aa6b6; border-radius: 8px; background: #fff; touch-action: none; cursor: crosshair; }
.sig-preview { max-width: 220px; max-height: 90px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; display: block; }
.radio-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 10px; } .radio-row label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.check-list { max-height: 210px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; } .check-list label { display: flex; gap: 7px; padding: 3px 0; align-items: center; cursor: pointer; }

/* Reports */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.bars .bar-row { display: grid; grid-template-columns: 90px 1fr 34px; gap: 8px; align-items: center; margin-bottom: 7px; font-size: 13px; }
.bar-track { background: #edf0f5; height: 14px; border-radius: 4px; overflow: hidden; } .bar-fill { height: 100%; border-radius: 4px; background: var(--primary); min-width: 2px; }
.bar-fill.ok { background: var(--ok); } .bar-fill.warn { background: var(--accent); } .bar-fill.bad { background: var(--bad); } .bar-fill.gray { background: #93a0b2; }
.gauge { text-align: center; } .gauge b { font-size: 34px; color: var(--primary); display: block; }

@media (max-width: 900px) {
  .side { position: fixed; inset-block: 0; right: 0; transform: translateX(100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: -6px 0 26px rgba(0,0,0,.3); }
  .btn.menu-btn { display: inline-block; }
  .content { padding: 16px; } .topbar { padding: 8px 16px; }
  .doc-layout { grid-template-columns: minmax(0, 1fr); } .viewer { max-height: 70vh; }
}
@media print {
  .side, .topbar, .no-print, #toasts, .foot { display: none !important; }
  body, .content { background: #fff; padding: 0; } .card { box-shadow: none; break-inside: avoid; }
}
