:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e8eaef;
  --muted: #8b92a3;
  --accent: #5865f2;
  --accent-2: #7983f5;
  --good: #3ba55d;
  --warn: #f0b232;
  --bad: #ed4245;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h2 { font-size: 22px; }
h3 { font-size: 16px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 40px 32px; max-width: 400px; width: 100%;
}
.login-card h1 { text-align: center; }
.logo {
  width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 16px;
  background: var(--accent); display: grid; place-items: center; font-size: 30px; font-weight: 700;
}

/* layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex-shrink: 0; background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.brand img, .me img { width: 40px; height: 40px; border-radius: 50%; background: var(--panel-2); }
.brand div { display: flex; flex-direction: column; }
.brand span { font-size: 12px; }
nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
nav button {
  background: none; border: 0; color: var(--muted); text-align: right; padding: 10px 12px;
  border-radius: 8px; font: inherit; cursor: pointer;
}
nav button:hover { background: var(--panel-2); color: var(--text); }
nav button.active { background: var(--accent); color: #fff; }
.me { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.me img { width: 32px; height: 32px; }
.me span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { flex: 1; padding: 24px; min-width: 0; max-width: 1200px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; }

/* cards */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
}
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.cards .card { margin: 0; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { font-size: 30px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 12px; min-height: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* chart */
.chart { direction: ltr; display: flex; align-items: flex-end; gap: 4px; height: 200px; padding-top: 20px; }
.bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; position: relative; }
.bar { width: 100%; max-width: 28px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; transition: background .15s; }
.bar-wrap:hover .bar { background: var(--accent-2); }
.bar-wrap .tip {
  position: absolute; bottom: 100%; background: var(--panel-2); border: 1px solid var(--border);
  padding: 4px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap; display: none; z-index: 2;
}
.bar-wrap:hover .tip { display: block; }
.bar-label { font-size: 10px; color: var(--muted); margin-top: 4px; height: 14px; }

/* lists */
.list-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row img { width: 28px; height: 28px; border-radius: 50%; background: var(--panel-2); }
.list-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.meter div { height: 100%; background: var(--accent); }
.meter.full div { background: var(--bad); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: right; padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
.user { display: inline-flex; align-items: center; gap: 6px; }
.user img { width: 22px; height: 22px; border-radius: 50%; background: var(--panel-2); }
.badge { padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--panel-2); }
.badge.good { background: rgba(59,165,93,.18); color: #6fd58f; }
.badge.bad { background: rgba(237,66,69,.18); color: #f47b7d; }
.badge.warn { background: rgba(240,178,50,.18); color: #f5c95e; }

/* payments */
.payments { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.payments .card { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.payments pre {
  background: var(--panel-2); padding: 10px; border-radius: 8px; margin: 0; white-space: pre-wrap;
  word-break: break-word; font-family: inherit; font-size: 13px; max-height: 140px; overflow: auto;
}
.limit-box { background: var(--panel-2); border-radius: 8px; padding: 10px; }

/* forms */
.form { display: flex; flex-direction: column; gap: 6px; }
label { font-size: 13px; color: var(--muted); margin-top: 8px; }
input, textarea, select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 11px; font: inherit; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.row input { width: auto; flex: 1; min-width: 100px; }

.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer;
  text-decoration: none; display: inline-block; color: var(--text); background: var(--panel-2);
}
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: rgba(237,66,69,.15); color: #f47b7d; border-color: rgba(237,66,69,.3); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.big { padding: 12px 20px; margin-top: 12px; }
.btn.sm { padding: 5px 10px; font-size: 13px; }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; width: min(520px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0,0,0,.6); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2);
  border: 1px solid var(--border); padding: 10px 18px; border-radius: 10px; z-index: 10;
}
.toast.bad { border-color: var(--bad); }

@media (max-width: 800px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; border-left: 0; border-bottom: 1px solid var(--border); }
  nav { flex-direction: row; overflow-x: auto; }
  nav button { white-space: nowrap; }
  .me { display: none; }
  main { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .payments { grid-template-columns: 1fr; }
}
