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

:root {
  --primary: #006a62;
  --on-primary: #fff;
  --primary-c: #c5ede6;
  --on-primary-c: #00201d;
  --bg: #f5fafb;
  --surface: #ffffff;
  --surface-2: #eaf2f2;
  --surface-3: #dce6e6;
  --text: #171d1d;
  --text-2: #56605f;
  --outline: #c1cac9;
  --danger: #ba1a1a;
  --good: #146c2e;
  --good-c: #d4f5d9;
  --warn: #7a5900;
  --warn-c: #ffefc6;
  --shadow: 0 1px 3px rgba(0, 40, 40, .08), 0 4px 14px rgba(0, 40, 40, .06);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --primary: #5fd9c9;
  --on-primary: #003732;
  --primary-c: #00504a;
  --on-primary-c: #a7f3e8;
  --bg: #0f1414;
  --surface: #171d1d;
  --surface-2: #1f2626;
  --surface-3: #2a3232;
  --text: #dee4e3;
  --text-2: #a3adac;
  --outline: #3f4948;
  --danger: #ffb4ab;
  --good: #8ddc9c;
  --good-c: #10391b;
  --warn: #f3c34a;
  --warn-c: #3d2e00;
  --shadow: 0 1px 3px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Cairo, system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; padding: 0; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }

.ic { width: 24px; height: 24px; fill: currentColor; flex: none; }
.ic.sm { width: 18px; height: 18px; }
[dir="rtl"] .back .ic, [dir="rtl"] .chev { transform: scaleX(-1); }
[dir="ltr"] .flip-ltr { transform: scaleX(-1); }

/* App bar */
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  padding: calc(6px + var(--safe-t)) 8px 6px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; flex: 1; padding-inline-start: 8px; }
.brand h1 { font-size: 20px; }
.brand-ic { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); }
.brand-ic .ic { width: 22px; height: 22px; }
#hdr-title { flex: 1; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none; color: var(--text-2); }
.icon-btn:active { background: var(--surface-3); }
.icon-btn.sm { width: 34px; height: 34px; }
.appbar .icon-btn { color: var(--text); }

main#view { padding: 4px 16px calc(110px + var(--safe-b)); max-width: 760px; margin: 0 auto; }

/* Home */
.hero { padding: 4px 4px 8px; }
.hero p { margin: 0 0 10px; color: var(--text-2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.chip.good { background: var(--good-c); color: var(--good); }
.chip.warn { background: var(--warn-c); color: var(--warn); }
.chip.neutral { background: var(--surface-3); }
.section { font-size: 14px; color: var(--text-2); margin: 18px 6px 8px; }
.tools { display: grid; gap: 10px; }
@media (min-width: 600px) { .tools { grid-template-columns: 1fr 1fr; } }
.tool {
  display: flex; align-items: center; gap: 14px; padding: 14px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .12s;
}
.tool:active { transform: scale(.98); }
.tool-ic { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; flex: none; }
.tool-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tool-txt b { font-size: 16px; }
.tool-txt small { color: var(--text-2); font-size: 13px; }
.chev { color: var(--text-2); opacity: .6; }
.c1 { background: #d9f2ec; color: #00695c; }
.c2 { background: #e3ecff; color: #2a59c7; }
.c3 { background: #fde6d8; color: #b4480b; }
.c4 { background: #fde1e3; color: #b3261e; }
.c5 { background: #eee2ff; color: #6a3fc1; }
.c6 { background: #fff1c7; color: #8a6100; }
.c7 { background: #dcf3fb; color: #00688a; }
[data-theme="dark"] .c1 { background: #0e3b35; color: #7fe3d1; }
[data-theme="dark"] .c2 { background: #1b2c55; color: #a9c2ff; }
[data-theme="dark"] .c3 { background: #4a2610; color: #ffb68e; }
[data-theme="dark"] .c4 { background: #4d1a1a; color: #ffb3ad; }
[data-theme="dark"] .c5 { background: #331f57; color: #d3bbff; }
[data-theme="dark"] .c6 { background: #3e3000; color: #f3cd5a; }
[data-theme="dark"] .c7 { background: #0b3a4a; color: #8ad8f5; }

.banner { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin: 8px 0 0; border-radius: 14px; background: var(--primary-c); color: var(--on-primary-c); font-size: 13.5px; }
.banner span { flex: 1; }
.banner .icon-btn { color: inherit; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.btn.sm { height: 36px; padding: 0 12px; font-size: 13.5px; gap: 5px; }
.btn.filled { background: var(--primary); color: var(--on-primary); }
.btn.tonal { background: var(--primary-c); color: var(--on-primary-c); }
.btn.outlined { border: 1px solid var(--outline); color: var(--primary); }
.btn.text { color: var(--primary); }
.btn:active { filter: brightness(.92); }
.btn:disabled { opacity: .45; }
.btn.big { width: 100%; height: 54px; font-size: 16.5px; }

.bottom-bar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 9;
  padding: 10px 16px calc(10px + var(--safe-b));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  display: flex; gap: 10px; justify-content: center;
}
.bottom-bar .btn { max-width: 728px; box-shadow: 0 4px 16px rgba(0, 80, 70, .25); }

/* Cards & form */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin: 12px 0; }
.field { margin-bottom: 14px; }
.field > label { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.field output { color: var(--primary); font-weight: 700; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.input { width: 100%; height: 44px; border-radius: 12px; border: 1px solid var(--outline); background: var(--surface-2); padding: 0 12px; outline: none; }
.input:focus { border-color: var(--primary); }
select.input { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23889' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E"); background-size: 22px; background-repeat: no-repeat; background-position: left 8px center; padding-inline-end: 34px; }
[dir="ltr"] select.input { background-position: right 8px center; }
input[type=number].input { max-width: 110px; text-align: center; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--text-2); font-size: 13.5px; }
.center { text-align: center; }
.quick { gap: 6px; }
.btnchip { cursor: pointer; padding: 6px 12px; font-size: 13px; }
.btnchip:active { background: var(--primary-c); }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; min-height: 38px; border-radius: 10px; font-size: 13.5px; font-weight: 700; color: var(--text-2); padding: 2px 6px; line-height: 1.25; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
[data-theme="dark"] .seg button[aria-checked="true"] { background: var(--surface-3); }

.range { width: 100%; accent-color: var(--primary); height: 28px; }

.switch { display: flex; align-items: center; gap: 12px; min-height: 44px; font-weight: 700; font-size: 14px; cursor: pointer; }
.switch span { flex: 1; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { width: 46px; height: 28px; border-radius: 99px; background: var(--surface-3); position: relative; transition: background .15s; flex: none; }
.switch i::after { content: ''; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--text-2); transition: all .15s; }
.switch input:checked + i { background: var(--primary); }
.switch input:checked + i::after { background: var(--on-primary); left: 22px; }
[dir="rtl"] .switch i::after { left: 22px; }
[dir="rtl"] .switch input:checked + i::after { left: 4px; }

.note { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--text-2); margin: 8px 0 0; }
.note .ic { margin-top: 2px; }
.note.warn { color: var(--warn); background: var(--warn-c); padding: 10px 12px; border-radius: 12px; font-size: 13.5px; }
.hint { display: flex; gap: 6px; align-items: center; color: var(--text-2); font-size: 13px; margin: 4px 4px 8px; }

.radio-card { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1.5px solid var(--outline); border-radius: 14px; margin-bottom: 8px; cursor: pointer; }
.radio-card:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary-c) 45%, transparent); }
.radio-card input { accent-color: var(--primary); width: 20px; height: 20px; margin: 0; }
.radio-card b { display: block; }
.radio-card small { color: var(--text-2); font-size: 12.5px; }

/* Dropzone */
.dropzone {
  width: 100%; margin: 14px 0 4px; padding: 34px 16px; border-radius: 22px;
  border: 2px dashed var(--outline); background: var(--surface);
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
}
.dropzone:active { background: var(--surface-2); }
.dz-ic { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; background: var(--primary-c); color: var(--on-primary-c); margin-bottom: 6px; }
.dz-ic .ic { width: 32px; height: 32px; }
.dropzone b { font-size: 17px; }
.dropzone small { color: var(--text-2); }

/* Lists */
.list-head { display: flex; align-items: center; gap: 4px; margin: 12px 4px 6px; font-weight: 700; }
.list-head > span { flex: 1; }
.list-head small { color: var(--text-2); font-weight: 400; }
.img-list, .out-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.img-list li, .out-list li, .file-card {
  display: flex; align-items: center; gap: 10px; padding: 8px; padding-inline-end: 4px;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
}
.out-list li { box-shadow: none; background: var(--surface-2); }
.img-list b, .out-list b, .file-card b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.img-list small, .out-list small, .file-card small { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; color: var(--text-2); font-size: 12.5px; }
.img-list small.res { color: var(--text); }
.img-list small.res b { display: inline; }
.thumb { width: 64px; height: 64px; border-radius: 12px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; flex: none; color: var(--text-2); }
.thumb.sm { width: 48px; height: 48px; border-radius: 10px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.drag { color: var(--text-2); padding: 8px 2px; cursor: grab; touch-action: none; }
.file-card { margin-top: 10px; padding: 10px; }
.file-ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.file-ic.pdf { background: #fde1e3; color: #b3261e; }
.file-ic.img { background: #e3ecff; color: #2a59c7; }
[data-theme="dark"] .file-ic.pdf { background: #4d1a1a; color: #ffb3ad; }
[data-theme="dark"] .file-ic.img { background: #1b2c55; color: #a9c2ff; }

.summary .row { margin-top: 12px; justify-content: center; }
.summary .row .btn { flex: 1; }
.savings { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; text-align: center; padding: 6px 0; }
.savings small { display: block; color: var(--text-2); font-size: 12px; }
.savings b { font-size: 19px; }
.savings .chip { font-size: 15px; padding: 4px 12px; }
.savings .arrow { color: var(--text-2); }
.savings.neutral b { color: var(--text-2); }

/* Page grid */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-top: 10px; }
.pg { position: relative; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: block; text-align: center; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.pg-img { aspect-ratio: 3 / 4; display: grid; place-items: center; overflow: hidden; border-radius: 6px; background: var(--surface-2); }
.pg-img img { max-width: 100%; max-height: 100%; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
.pg-img img.ready, .pg-img img[src] { opacity: 1; }
.pg-n { display: block; font-size: 12px; font-weight: 700; color: var(--text-2); margin-top: 2px; }
.pg-x { position: absolute; top: -6px; inset-inline-end: -6px; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; box-shadow: var(--shadow); }
.pg-check { position: absolute; top: 10px; inset-inline-start: 10px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: rgba(0, 0, 0, .25); display: none; place-items: center; color: transparent; }
.selecting .pg-check { display: grid; }
.selecting .pg[aria-pressed="true"] { outline: 2.5px solid var(--primary); }
.selecting .pg[aria-pressed="true"] .pg-check { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.selecting .pg[aria-pressed="false"] .pg-img { opacity: .55; }
.org .pg-tools { display: flex; justify-content: space-around; margin-top: 2px; }
.org .pg-tools button { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: var(--text-2); }
.org .pg-tools button:active { background: var(--surface-3); }
.org .pg-tools .danger { color: var(--danger); }
.pg.deleted .pg-img { opacity: .25; }
.pg.deleted .pg-n { text-decoration: line-through; }
.pg.deleted .danger { color: var(--primary); }
.ghost { opacity: .35; }
.chosen { box-shadow: 0 8px 24px rgba(0, 0, 0, .25); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 0; }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); opacity: 0; transition: opacity .2s; }
.sheet-panel {
  position: absolute; inset-inline: 0; bottom: 0; max-height: 92vh; overflow: auto;
  background: var(--surface); border-radius: 24px 24px 0 0;
  padding: 6px 16px calc(16px + var(--safe-b));
  transform: translateY(100%); transition: transform .22s ease-out;
  max-width: 760px; margin: 0 auto;
}
.sheet.full .sheet-panel { height: 92vh; display: flex; flex-direction: column; }
.sheet.full #sheet-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.sheet.open .sheet-scrim { opacity: 1; }
.sheet.open .sheet-panel { transform: none; }
.sheet-grab { width: 36px; height: 4px; border-radius: 4px; background: var(--outline); margin: 4px auto 8px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sheet-head h2 { flex: 1; font-size: 18px; }
.ok-ic { color: var(--good); }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }

/* Compare */
.cmp { position: relative; flex: 1; min-height: 240px; border-radius: 14px; overflow: hidden; background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface-3) 0 50%) 0 0 / 20px 20px; touch-action: none; }
.cmp img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.cmp-line { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; box-shadow: 0 0 6px rgba(0, 0, 0, .5); transform: translateX(-1px); pointer-events: none; }
.cmp-line span { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 38px; height: 38px; border-radius: 50%; background: #fff; color: #333; display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0, 0, 0, .35); }
.cmp-tag { position: absolute; top: 10px; padding: 2px 10px; border-radius: 99px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 12px; font-weight: 700; }
.cmp-tag.l { left: 10px; } .cmp-tag.r { right: 10px; }

/* Busy */
.busy { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .45); display: grid; place-items: center; padding: 24px; }
.busy-card { background: var(--surface); border-radius: 22px; padding: 22px; width: min(320px, 100%); display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.busy-card small { color: var(--text-2); min-height: 1.4em; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spinner, .spin { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--primary-c); border-top-color: var(--primary); animation: spin 0.9s linear infinite; }
.spin { width: 22px; height: 22px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.bar { width: 100%; height: 6px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--primary); width: 0; transition: width .2s; }
.bar.indet i { width: 35% !important; animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { from { transform: translateX(-120%); } to { transform: translateX(320%); } }
[dir="rtl"] .bar i { margin-inline-start: 0; }

.toast {
  position: fixed; bottom: calc(86px + var(--safe-b)); left: 50%; transform: translate(-50%, 20px);
  background: #2b3131; color: #eef3f2; padding: 10px 18px; border-radius: 14px; z-index: 70;
  max-width: calc(100% - 32px); font-size: 14px; opacity: 0; transition: all .2s; box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
