:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --text: #0f1b24;
  --muted: #64717d;
  --line: #e3e8ec;
  --line2: #eef1f4;
  --pri: #0f766e;
  --pri-d: #0b5c56;
  --pri-l: #e6f4f1;
  --danger: #c2410c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'Cairo', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  font-size: 15px; line-height: 1.6;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--pri); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.35; }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 17px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 700; color: #33414d; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---------- الهيدر ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 24px; background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; color: var(--text); }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--pri); color: #fff; font-weight: 900; font-size: 15px; letter-spacing: -.5px;
}
.brand-mark.big { width: 64px; height: 64px; font-size: 28px; border-radius: 18px; margin: 0 auto 12px; }
.topnav { display: flex; gap: 18px; align-items: center; }
.topnav a { color: #33414d; font-weight: 600; }
.muted-link { color: var(--muted) !important; }

.container { max-width: 1060px; margin: 0 auto; padding: 24px 16px 60px; }
.container.wide { max-width: 1600px; }

/* ---------- عناصر عامة ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card.flat { box-shadow: none; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  font-weight: 700; cursor: pointer; transition: .15s; white-space: nowrap; color: #26333e;
}
.btn:hover { border-color: #c9d2d9; background: #fafbfc; }
.btn.primary { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.primary:hover { background: var(--pri-d); }
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; color: var(--danger); border-color: #f3d3c4; }
.btn.danger-ghost:hover { background: #fff6f2; }
.btn.sm { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn.lg { padding: 12px 26px; font-size: 16px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after { content: ''; position: absolute; width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.5); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: 13px; font-weight: 700; color: #45525e; }
.field.sm { margin-bottom: 10px; }
.field.sm > span { font-size: 12px; }
input[type=text], input[type=search], input[type=number], input[type=password], select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; outline: none; transition: .15s;
}
input:focus, select:focus { border-color: var(--pri); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12); }
.field.sm input, .field.sm select { padding: 7px 10px; font-size: 14px; }
.req { color: var(--danger); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; margin: 6px 0; }
.check.sm { font-size: 13px; margin: 3px 0; }
.check input { accent-color: var(--pri); width: 16px; height: 16px; }

.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line2); text-align: center; white-space: nowrap; }
.tbl thead th { background: #f7f9fa; font-weight: 700; color: #45525e; font-size: 13px; position: sticky; top: 0; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.table-scroll .tbl tr:last-child td { border-bottom: 0; }

.empty { padding: 30px; text-align: center; color: var(--muted); }
.empty.big { padding: 60px 20px; background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty .btn { margin-top: 12px; }
.alert { background: #fff4ed; color: var(--danger); border: 1px solid #fbd5c0; padding: 8px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }
.badge { display: inline-block; min-width: 22px; padding: 0 8px; border-radius: 999px; background: var(--pri-l); color: var(--pri); font-size: 12px; font-weight: 800; line-height: 22px; text-align: center; }

/* ---------- التوست ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #16222c; color: #fff; padding: 11px 20px; border-radius: 12px; font-weight: 600; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2); transition: .25s; z-index: 100; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: #0f766e; }
.toast.err { background: #b42318; }

/* ---------- تسجيل الدخول ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: #fff; padding: 32px 26px; border-radius: 20px; border: 1px solid var(--line); box-shadow: var(--shadow); text-align: center; }
.login-card h1 { font-size: 22px; }
.login-card input { margin: 16px 0 12px; text-align: center; }

/* ---------- الصفحة الرئيسية ---------- */
.hero { margin: 8px 0 20px; }
.hero p { margin: 6px 0 0; max-width: 620px; }
.upload-card { padding: 16px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 44px 20px; border: 2px dashed #c8d4db; border-radius: 12px; cursor: pointer; transition: .15s;
  color: var(--pri); background: #fbfdfd; text-align: center;
}
.dropzone strong { color: var(--text); font-size: 16px; }
.dropzone:hover, .dropzone.over { border-color: var(--pri); background: var(--pri-l); }
.map-step { padding: 4px; }
.map-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.file-pill { font-weight: 800; font-size: 16px; word-break: break-all; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mapping { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; }
.mapping summary { cursor: pointer; font-weight: 700; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 14px; }
.preview-wrap { margin-bottom: 16px; }
.preview-wrap .muted { margin-bottom: 6px; }
.actions-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.search-sm { max-width: 220px; padding: 7px 12px !important; }

.uploads-list { display: flex; flex-direction: column; gap: 8px; }
.upload-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line2); border-radius: 12px; transition: .15s; }
.upload-row:hover { border-color: #cfe3df; background: #fbfdfd; }
.upload-main { display: flex; align-items: center; gap: 12px; color: inherit; min-width: 0; flex: 1; }
.upload-main > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.upload-title { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-icon { flex: none; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--pri-l); color: var(--pri); font-weight: 900; }
.upload-actions { display: flex; gap: 6px; flex: none; }

@media (max-width: 700px) {
  .topbar { padding: 10px 16px; }
  h1 { font-size: 22px; }
  .grid-2 { grid-template-columns: 1fr; }
  .upload-row { flex-direction: column; align-items: stretch; }
  .upload-actions { justify-content: flex-end; }
  .card { padding: 14px; }
}
