:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273549;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --danger: #f87171;
  --success: #4ade80;
  --warn: #fbbf24;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

.screen { min-height: 100vh; }

/* شاشة الدخول */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { font-size: 1.2rem; margin: 0 0 8px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }

input, select, textarea {
  background: #0b1322;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: inherit;
}
textarea { min-height: 70px; resize: vertical; }

button {
  background: var(--accent);
  color: #06202f;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}
button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.small { padding: 6px 10px; font-size: 0.8rem; }
button.danger { background: var(--danger); color: #2b0b0b; }
button:disabled { opacity: 0.6; cursor: not-allowed; }

.error-text { color: var(--danger); font-size: 0.85rem; min-height: 1em; }
.result-text { font-size: 0.85rem; min-height: 1em; white-space: pre-wrap; }

/* التطبيق الرئيسي */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.1rem; margin: 0; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 12px 16px;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

main { padding: 24px; max-width: 1100px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.cards { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 24px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  min-width: 140px;
}
.card .value { font-size: 1.6rem; font-weight: 700; }
.card .label { color: var(--muted); font-size: 0.8rem; }

.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input[type="search"] { flex: 1; min-width: 200px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
th { color: var(--muted); font-weight: 600; background: var(--panel-2); }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--panel-2); }

.badge { padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; }
.badge.active { background: rgba(74,222,128,.15); color: var(--success); }
.badge.unused { background: rgba(148,163,184,.15); color: var(--muted); }
.badge.suspended { background: rgba(248,113,113,.15); color: var(--danger); }

.pagination { display: flex; gap: 8px; margin-top: 12px; justify-content: center; }

.form-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.form-card label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 50;
}
.modal-content {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px; max-width: 640px; width: 100%; position: relative;
}
.close-btn { position: absolute; top: 12px; left: 12px; background: transparent; color: var(--muted); border: none; }

.action-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 0.88rem; margin-bottom: 16px; }
.kv .k { color: var(--muted); }

.events-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.events-list li { font-size: 0.8rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; color: var(--muted); }
.events-list li b { color: var(--text); }
