/* =========================================================
   كلاننا — dark, mobile-first, RTL
   ========================================================= */

:root {
  --bg: #0b0f14;
  --surface: #141a22;
  --surface-2: #1b232d;
  --surface-3: #222c38;
  --border: #26303c;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #f5a623;
  --accent-dim: #7a5410;
  --green: #3fb950;
  --red: #f85149;
  --blue: #58a6ff;
  --radius: 14px;
  --radius-sm: 10px;
  --tab-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Noto Naskh Arabic", "Noto Sans Arabic", Tahoma, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  overscroll-behavior-y: contain;
}

body { min-height: 100dvh; }

#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- boot ---------- */
.boot {
  position: fixed; inset: 0; display: grid; place-content: center;
  justify-items: center; gap: 14px; color: var(--muted); background: var(--bg);
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--surface-3); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- topbar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: calc(10px + var(--safe-t)) 16px 10px;
  background: rgba(11, 15, 20, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand-mark { color: var(--accent); font-size: 18px; }

.icon-btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  width: 38px; height: 38px; border-radius: 10px; font-size: 16px; cursor: pointer;
}
.icon-btn:active { background: var(--surface-3); }

/* ---------- menu ---------- */
.menu {
  position: absolute; top: calc(58px + var(--safe-t)); left: 12px; z-index: 40;
  min-width: 210px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px; box-shadow: 0 18px 40px rgba(0,0,0,.55);
}
.menu-user { padding: 8px 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; display: flex; flex-direction: column; gap: 4px; }
.menu-item {
  display: block; width: 100%; text-align: right; background: none; border: 0;
  color: var(--text); padding: 11px 10px; border-radius: 8px; font-size: 14px; cursor: pointer;
  font-family: inherit;
}
.menu-item:active { background: var(--surface-3); }
.menu-item.danger { color: var(--red); }

/* ---------- main ---------- */
#view {
  flex: 1; padding: 16px 14px calc(var(--tab-h) + var(--safe-b) + 24px);
  max-width: 780px; width: 100%; margin: 0 auto;
}

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 22px 0 10px; color: var(--text); }
h3 { font-size: 14px; margin: 0 0 8px; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.card.tight { padding: 12px; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.stat .k { color: var(--muted); font-size: 12px; display: block; margin-bottom: 2px; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .v.gold { color: var(--accent); }
.stat .v.green { color: var(--green); }
.stat .v.red { color: var(--red); }

/* ---------- rows ---------- */
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }
.row-main { min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { color: var(--muted); font-size: 12px; }
.row-end { text-align: left; flex-shrink: 0; font-variant-numeric: tabular-nums; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; background: var(--surface-3); color: var(--muted);
  white-space: nowrap;
}
.badge.win, .badge.in { background: rgba(63,185,80,.15); color: var(--green); }
.badge.loss, .badge.out { background: rgba(248,81,73,.15); color: var(--red); }
.badge.draw { background: rgba(139,152,165,.15); color: var(--muted); }
.badge.gold { background: rgba(245,166,35,.15); color: var(--accent); }
.badge.live { background: rgba(88,166,255,.15); color: var(--blue); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit; width: 100%;
}
.btn:active { background: var(--surface-3); }
.btn.primary { background: var(--accent); color: #1a1200; border-color: var(--accent); }
.btn.primary:active { background: #d98f14; }
.btn.danger { color: var(--red); border-color: rgba(248,81,73,.35); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; }
.btn.sm { width: auto; padding: 7px 12px; font-size: 13px; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
input, select, textarea {
  width: 100%; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; font-size: 15px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent); }
textarea { min-height: 130px; resize: vertical; font-family: ui-monospace, monospace; font-size: 12px; direction: ltr; text-align: left; }

/* ---------- tabs / filters ---------- */
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 7px 14px; border-radius: 999px; font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  cursor: pointer; font-family: inherit;
}
.chip[aria-pressed="true"] { background: var(--accent); color: #1a1200; border-color: var(--accent); font-weight: 700; }

/* ---------- bottom nav ---------- */
#tabbar {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(20, 26, 34, .96); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}
.tab {
  background: none; border: 0; color: var(--muted); font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 2px; font-size: 10.5px; cursor: pointer; height: var(--tab-h);
}
.tab .ico { font-size: 18px; line-height: 1; }
.tab[aria-current="page"] { color: var(--accent); }

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 34px 12px; font-size: 14px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, monospace; direction: ltr; unicode-bidi: embed; }
.num { font-variant-numeric: tabular-nums; }
.sep { height: 1px; background: var(--border); margin: 14px 0; }

.toast {
  position: fixed; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); right: 50%;
  transform: translateX(50%); z-index: 60;
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  padding: 11px 18px; border-radius: 999px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: 90vw;
}
.toast.err { border-color: rgba(248,81,73,.5); color: #ffb4ae; }

.skeleton { background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; height: 14px; margin: 8px 0; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- login ---------- */
.login-wrap { display: flex; flex-direction: column; justify-content: center; min-height: 100dvh; padding: 24px; max-width: 420px; margin: 0 auto; }
.login-logo { text-align: center; font-size: 44px; margin-bottom: 6px; }
.login-title { text-align: center; font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 26px; }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: right; color: var(--muted); font-weight: 600; font-size: 11.5px; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.table td { padding: 9px 6px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: left; }

/* ---------- war detail ---------- */
.side-title { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 8px; }
.attack-line { font-size: 12.5px; color: var(--muted); padding: 3px 0; }
.attack-line .fresh { color: var(--green); }
.attack-line .cleanup { color: var(--accent); }

@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  #tabbar { grid-template-columns: repeat(5, minmax(0, 120px)); justify-content: center; }
}


[hidden] { display: none !important; }


/* Language toggle + LTR menu */
.top-actions { display: flex; align-items: center; gap: 8px; }
.lang-btn {
  background: rgba(255,255,255,.08);
  color: #f0f6fc;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}
.lang-btn:hover { background: rgba(255,255,255,.16); }
.login-lang { position: fixed; top: 16px; inset-inline-end: 16px; z-index: 999; }
html[dir="ltr"] .menu { left: auto; right: 12px; }
