/* مِرسال — هوية مستقلة: أخضر هادئ، وخط IBM Plex Sans Arabic */

:root,
:root[data-theme='light'] {
  --accent: #1f7a5c;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ea;
  --bg: #f4f6f5;
  --panel: #ffffff;
  --panel-2: #eef2f0;
  --ink: #18221e;
  --ink-2: #3c4a44;
  --mute: #6b7a73;
  --line: #dde5e1;
  --ok: #1f7a5c;
  --warn: #a06312;
  --bad: #b23a2e;
  --shadow: 0 1px 2px rgba(16, 32, 26, 0.05), 0 8px 24px rgba(16, 32, 26, 0.06);
  color-scheme: light;
}

:root[data-theme='dark'] {
  --accent: #3fb68b;
  --accent-ink: #08130f;
  --accent-soft: #14322a;
  --bg: #0d1412;
  --panel: #141d1a;
  --panel-2: #1b2622;
  --ink: #e5eeea;
  --ink-2: #c1cec8;
  --mute: #8a9a93;
  --line: #24312c;
  --ok: #4cc497;
  --warn: #e0a656;
  --bad: #ec7f72;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
}

.boot {
  padding: 3rem;
  text-align: center;
  color: var(--mute);
}

/* ── الغلاف ─────────────────────────────────────────────── */

.layout {
  min-height: 100svh;
}

.side {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-inline-end: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.1rem 1.1rem 1rem;
  font-weight: 700;
  font-size: 1.15rem;
}

.brand img {
  width: 30px;
  height: 30px;
}

.brand small {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--mute);
}

.nav {
  display: grid;
  gap: 0.15rem;
  padding: 0.4rem 0.6rem;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 42px;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  color: var(--ink-2);
  font-weight: 600;
  text-decoration: none;
}

.nav a:hover {
  background: var(--panel-2);
}

.nav a.on {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav svg,
.tabbar svg,
.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.side-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.9rem 1rem;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
  color: var(--mute);
}

.main {
  min-width: 0;
  padding: 1.5rem clamp(1rem, 3vw, 2.25rem) 6rem;
  max-width: 920px;
}

.topbar {
  display: none;
}

.tabbar {
  display: none;
}

@media (min-width: 900px) {
  .layout {
    display: flex;
  }
  .side {
    position: sticky;
    top: 0;
    width: 240px;
    height: 100svh;
    flex-shrink: 0;
  }
  .main {
    flex: 1;
  }
}

@media (max-width: 899.98px) {
  .side {
    display: none;
  }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 1rem;
    padding-top: calc(0.65rem + env(safe-area-inset-top));
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
    font-weight: 700;
  }
  .topbar img {
    width: 26px;
    height: 26px;
  }
  .topbar .grow {
    flex: 1;
  }
  .main {
    padding-bottom: calc(6rem + env(safe-area-inset-bottom));
  }
  .tabbar {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(var(--tabs, 4), 1fr);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel);
    border-top: 1px solid var(--line);
  }
  .tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    padding: 0.5rem 0 0.45rem;
    color: var(--mute);
    font-size: 0.72rem;
    font-weight: 600;
    text-decoration: none;
  }
  .tabbar a.on {
    color: var(--accent);
  }
}

/* ── العناصر ───────────────────────────────────────────── */

h1 {
  margin: 0 0 0.25rem;
  font-size: 1.55rem;
  line-height: 1.3;
}

.lead {
  margin: 0 0 1.25rem;
  color: var(--mute);
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1.1rem 1.15rem;
}

.card + .card,
.stack > * + * {
  margin-top: 1rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.row .grow {
  flex: 1;
  min-width: 0;
}

.field {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.9rem;
}

.field > span {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-2);
}

.field em {
  font-style: normal;
  font-size: 0.8rem;
  color: var(--mute);
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.8rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.textarea {
  min-height: 140px;
  resize: vertical;
  line-height: 1.7;
}

.input:focus-visible,
.textarea:focus-visible,
.select:focus-visible,
.btn:focus-visible,
.chip:focus-visible,
.nav a:focus-visible,
.tabbar a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.ltr {
  direction: ltr;
  text-align: right;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
}

.btn:hover {
  background: var(--panel-2);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.primary:hover {
  filter: brightness(1.06);
}

.btn.danger {
  color: var(--bad);
}

.btn.small {
  min-height: 34px;
  padding: 0.25rem 0.7rem;
  font-size: 0.85rem;
}

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--mute);
  cursor: pointer;
  font-weight: 600;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 36px;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  cursor: pointer;
  font-size: 0.9rem;
}

.chip.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.pill {
  display: inline-block;
  padding: 0.1rem 0.6rem;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--ink-2);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.pill.ok {
  background: var(--accent-soft);
  color: var(--ok);
}

.pill.warn {
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  color: var(--warn);
}

.pill.bad {
  background: color-mix(in srgb, var(--bad) 13%, transparent);
  color: var(--bad);
}

.note {
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--ink-2);
  font-size: 0.9rem;
}

.note.warn {
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  color: var(--warn);
}

.note.bad {
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  color: var(--bad);
}

.note.ok {
  background: var(--accent-soft);
  color: var(--ok);
}

.mute {
  color: var(--mute);
}

.small {
  font-size: 0.85rem;
}

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--mute);
}

.list {
  display: grid;
  gap: 0;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
}

.list-item:first-child {
  border-top: 0;
}

a.list-item:hover .title {
  color: var(--accent);
}

.list-item .title {
  font-weight: 600;
}

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  display: flex;
}

.progress i {
  display: block;
  height: 100%;
}

.progress .p-ok {
  background: var(--ok);
}

.progress .p-bad {
  background: var(--bad);
}

.preview {
  white-space: pre-wrap;
  padding: 0.8rem 1rem;
  border-radius: 12px 12px 4px 12px;
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
  border: 1px solid var(--line);
  max-width: 420px;
}

.qr {
  display: block;
  width: min(300px, 100%);
  aspect-ratio: 1;
  margin: 0.5rem auto;
  border-radius: 12px;
  background: #fff;
  padding: 6px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}

.stat {
  padding: 0.8rem 0.9rem;
  border-radius: 12px;
  background: var(--panel-2);
}

.stat b {
  display: block;
  font-size: 1.4rem;
  line-height: 1.2;
}

.stat span {
  color: var(--mute);
  font-size: 0.82rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 0.55rem 0.4rem;
  border-top: 1px solid var(--line);
  text-align: start;
  vertical-align: middle;
}

th {
  color: var(--mute);
  font-weight: 600;
  font-size: 0.82rem;
  border-top: 0;
}

.table-wrap {
  overflow-x: auto;
}

.checks {
  display: grid;
  gap: 0.35rem;
}

.checks label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.checks input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.toast {
  position: fixed;
  inset-inline: 1rem;
  bottom: calc(5.5rem + env(safe-area-inset-bottom));
  z-index: 50;
  margin: 0 auto;
  max-width: 420px;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  box-shadow: var(--shadow);
  text-align: center;
}

.login {
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding: 1.5rem;
}

.login .card {
  width: min(400px, 100%);
}

.login .brand {
  justify-content: center;
  padding: 0 0 1rem;
}

.file-pick {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.file-pick input[type='file'] {
  max-width: 100%;
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
