:root {
  --bg: #0b1020;
  --bg-soft: #121a31;
  --surface: #161f3a;
  --surface-2: #1d284a;
  --line: #26325a;
  --text: #e8edfb;
  --muted: #8f9dc4;
  --accent: #5b7cfa;
  --accent-soft: rgba(91, 124, 250, 0.16);
  --ok: #2fbf87;
  --warn: #e5a13a;
  --danger: #f0616d;
  --radius: 14px;
  --shadow: 0 18px 40px rgba(3, 7, 20, 0.45);
}

* {
  box-sizing: border-box;
}

/* Class-level `display` rules would otherwise beat the UA style for [hidden]. */
[hidden] {
  display: none !important;
}

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

body {
  font-family: Vazirmatn, "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1b2750 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
}

code {
  font-family: "SF Mono", Consolas, monospace;
  direction: ltr;
  unicode-bidi: embed;
  font-size: 12px;
}

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

/* ------------------------------------------------------------- login -- */

.login-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card h1 {
  margin: 18px 0 4px;
  font-size: 22px;
}

.login-card p {
  margin: 0 0 22px;
}

.login-card .field {
  text-align: right;
}

.login-mark,
.brand-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-inline: auto;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), #8f6bfb);
  font-weight: 700;
  letter-spacing: 1px;
  font-size: 16px;
  color: #fff;
}

/* --------------------------------------------------------------- app -- */

.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100%;
}

/* Grid items default to min-width:auto, which lets the wide tables inside
   stretch the whole page instead of scrolling within their own container. */
.app > * {
  min-width: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 18px;
  background: rgba(11, 16, 32, 0.72);
  border-inline-end: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  margin: 0;
  border-radius: 14px;
  font-size: 13px;
}

.brand strong {
  display: block;
  font-size: 15px;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-align: start;
  transition: background 0.15s, color 0.15s;
}

.nav-item .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
}

.nav-item:hover {
  background: var(--surface);
  color: var(--text);
}

.nav-item.is-active {
  background: var(--accent-soft);
  color: #cfd9ff;
}

.nav-item.is-active .dot {
  opacity: 1;
  background: var(--accent);
}

.content {
  padding: 28px 32px 60px;
  /* Wide enough for the users table to fit without sideways scrolling, while
     still stopping the text pages from running edge to edge on a big monitor. */
  max-width: 1560px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-head h2 {
  margin: 0;
  font-size: 21px;
}

.head-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.tab {
  display: none;
}

.tab.is-active {
  display: block;
  animation: fade 0.22s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ------------------------------------------------------------ cards -- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}

.card.no-pad {
  padding: 0;
  overflow: hidden;
}

.card h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.stat b {
  display: block;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.3;
}

.stat span {
  color: var(--muted);
  font-size: 12.5px;
}

.stat.ok b {
  color: var(--ok);
}
.stat.warn b {
  color: var(--warn);
}
.stat.accent b {
  color: #93aaff;
}

.kv {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  flex-wrap: wrap;
}

.kv span {
  color: var(--muted);
  font-size: 12.5px;
}

.kv code {
  flex: 1;
  min-width: 180px;
  word-break: break-all;
}

/* ------------------------------------------------ client of a sub link -- */

/* A lettermark rather than the real logo: the panel stays offline-safe and we
   are not shipping other people's trademarks. Colour carries the recognition. */
.cli {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 9px 11px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.cli .mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #fff;
  background: var(--c, #5b6478);
  box-shadow: 0 3px 10px -4px var(--c, #5b6478);
}

.cli .who {
  flex: 1;
  min-width: 0;
}

.cli .who b {
  display: block;
  font-size: 13px;
  font-weight: 600;
}

.cli .who span {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.cli .when {
  text-align: left;
  direction: ltr;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

/* ----------------------------------------------------------- tables -- */

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th,
td {
  padding: 13px 12px;
  text-align: start;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12.5px;
  background: rgba(11, 16, 32, 0.4);
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: rgba(91, 124, 250, 0.05);
}

.meter {
  margin-top: 5px;
  height: 5px;
  min-width: 90px;
  border-radius: 3px;
  background: var(--bg-soft);
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.meter .ok {
  background: var(--ok);
}
.meter .warn {
  background: var(--warn);
}
.meter .danger {
  background: var(--danger);
}

td .sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

td .uri {
  display: block;
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  /* Six buttons on one line were what pushed the table past the screen. */
  flex-wrap: wrap;
}

.empty {
  padding: 40px;
  text-align: center;
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.badge.ok {
  background: rgba(47, 191, 135, 0.14);
  color: var(--ok);
}
.badge.off {
  background: rgba(143, 157, 196, 0.14);
  color: var(--muted);
}
.badge.danger {
  background: rgba(240, 97, 109, 0.14);
  color: var(--danger);
}

/* --------------------------------------------------------- controls -- */

.btn {
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: filter 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn:hover {
  filter: brightness(1.12);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

.btn.danger {
  background: rgba(240, 97, 109, 0.14);
  color: var(--danger);
}

.btn.tiny {
  padding: 5px 11px;
  font-size: 12.5px;
  background: var(--surface-2);
  color: var(--text);
}

.btn.block {
  width: 100%;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field > span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12.5px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="date"],
textarea,
select {
  width: 100%;
  padding: 10px 13px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea {
  resize: vertical;
  direction: ltr;
  text-align: start;
}

textarea[name="announcement"] {
  direction: rtl;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search {
  width: 200px;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  cursor: pointer;
}

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

/* ------------------------------------------------- country picker -- */

.country-picker {
  position: relative;
  margin-bottom: 14px;
}

.country-list {
  position: absolute;
  z-index: 5;
  inset-inline: 0;
  top: calc(100% + 4px);
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.country-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.country-item:hover {
  background: var(--accent-soft);
}

.country-item span {
  font-size: 16px;
  line-height: 1;
}

.country-item small {
  margin-inline-start: auto;
  color: var(--muted);
  font-size: 11.5px;
}

.form-error {
  margin-bottom: 12px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(240, 97, 109, 0.12);
  color: var(--danger);
  font-size: 13px;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  margin: -8px 0 14px;
}

/* ------------------------------------------------------------ modal -- */

.modal-root {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 20, 0.66);
  backdrop-filter: blur(3px);
}

.modal {
  position: relative;
  width: min(520px, 100%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  animation: pop 0.18s ease;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}

/* ----------------------------------------------------------- toasts -- */

.toasts {
  position: fixed;
  bottom: 20px;
  inset-inline-start: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
}

.toast {
  padding: 11px 16px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: slide 0.2s ease;
  max-width: 340px;
}

.toast.ok {
  border-color: rgba(47, 191, 135, 0.5);
}
.toast.err {
  border-color: rgba(240, 97, 109, 0.5);
}

@keyframes slide {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

/* ------------------------------------------------------- responsive -- */

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    overflow-x: auto;
    padding: 12px 16px;
    border-inline-end: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand small,
  .sidebar #logoutBtn {
    display: none;
  }

  .nav {
    flex-direction: row;
  }

  .content {
    padding: 20px 16px 48px;
  }

  .search {
    width: 140px;
  }
}
