:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #64748b;
  --line: #dbe2ea;
  --brand: #156f75;
  --brand-dark: #0f5258;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #067647;
}

* { box-sizing: border-box; }
html {
  max-width: 100%;
  overflow-x: hidden;
}
body {
  margin: 0;
  min-height: 100vh;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

a { color: inherit; text-decoration: none; }
button, .button, .admin-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--brand);
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
button:hover, .button:hover, .admin-button:hover { background: var(--brand-dark); }
button:focus-visible, .button:focus-visible, .admin-button:focus-visible {
  outline: 2px solid rgba(21, 111, 117, 0.28);
  outline-offset: 2px;
}
button:disabled, .button.disabled, .admin-button.disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
button.small, .button.small { min-height: 28px; padding: 0 10px; font-size: 12px; }
button.danger, .button.danger {
  background: var(--danger);
  border-color: var(--danger);
}
button.danger:hover, .button.danger:hover {
  background: #912018;
  border-color: #912018;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 100;
  width: 230px;
  padding: 18px 14px;
  background: #101828;
  color: #fff;
  overflow-y: auto;
}
.brand {
  padding: 10px 8px 20px;
  font-weight: 800;
  font-size: 18px;
}
.sidebar nav { display: grid; gap: 4px; }
.sidebar a {
  padding: 10px 12px;
  border-radius: 6px;
  color: #cbd5e1;
}
.sidebar a.active, .sidebar a:hover {
  background: #1d2939;
  color: #fff;
}
.mobile-header, .navigation-close, .navigation-backdrop { display: none; }

.profile-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  overflow: hidden;
  border: 2px solid var(--brand);
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
}
.profile-avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
a.profile-avatar:hover { border-color: var(--brand-dark); background: var(--brand-dark); }
a.profile-avatar:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
a.profile-avatar[aria-current="page"] { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--brand); }
.profile-avatar-large { width: 80px; height: 80px; flex-basis: 80px; font-size: 26px; }
.panel.profile-panel { max-width: 820px; }
.profile-form { display: grid; gap: 20px; }
.profile-picture-row { display: flex; align-items: center; gap: 16px; min-width: 0; }
.profile-picture-upload { flex: 1; min-width: 0; }
.profile-picture-upload > label { margin-bottom: 8px; }
.profile-picture-upload p { margin: 8px 0 0; line-height: 1.5; }
.form-grid.profile-details { grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; align-items: start; }
.profile-details input[readonly] { background: var(--bg); color: var(--muted); }
.profile-password { min-width: 0; margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 6px; }
.profile-password legend { padding: 0 6px; font-weight: 700; }
.profile-password p { margin: 0 0 16px; line-height: 1.5; }
.profile-form > button { justify-self: start; min-height: 40px; }
.profile-picture-upload:focus-within .admin-file-button { outline: 2px solid var(--brand); outline-offset: 2px; }
.profile-picture-upload:has(input:disabled) .admin-file-button { opacity: 0.6; cursor: not-allowed; }

.main {
  position: relative;
  z-index: 1;
  margin-left: 230px;
  width: calc(100% - 230px);
  max-width: calc(100vw - 230px);
  min-width: 0;
  padding: 24px;
  overflow-x: hidden;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.topbar h1 { margin: 0; font-size: 24px; }
.topbar > div:first-child > span { display: block; margin-top: 4px; color: var(--muted); }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.locale-form label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.locale-form select {
  min-height: 34px;
  min-width: 138px;
  padding: 7px 28px 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.locale-form select:hover { border-color: #b8c4d2; }
.locale-form select:focus {
  border-color: var(--brand);
  outline: 2px solid rgba(21, 111, 117, 0.16);
  outline-offset: 0;
}
.login-locale {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 2;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.stat-card { padding: 16px; }
.stat-card span { display: block; color: var(--muted); margin-bottom: 8px; }
.stat-card strong { font-size: 24px; }

.panel {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 16px;
  margin-bottom: 18px;
  overflow: auto;
  contain: layout paint;
}
.panel h2 { margin: 0 0 14px; font-size: 18px; }
.panel h3 { margin: 18px 0 10px; font-size: 15px; }
.grid-two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
table.wide {
  width: max-content;
  min-width: 100%;
  max-width: none;
}
th, td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}
td small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}
td input,
td select,
.filters input,
.filters select,
.form-grid input,
.form-grid select,
.login-card input,
.login-card select {
  width: 100%;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
td input:hover,
td select:hover,
.filters input:hover,
.filters select:hover,
.form-grid input:hover,
.form-grid select:hover,
.login-card input:hover,
.login-card select:hover {
  border-color: #b8c4d2;
}
td input:focus,
td select:focus,
.filters input:focus,
.filters select:focus,
.form-grid input:focus,
.form-grid select:focus,
.login-card input:focus,
.login-card select:focus {
  border-color: var(--brand);
  outline: 2px solid rgba(21, 111, 117, 0.16);
  outline-offset: 0;
}
.managed-field {
  display: grid;
  gap: 8px;
  width: 100%;
  min-width: 150px;
  max-width: 260px;
}
.form-grid .managed-field {
  max-width: none;
}
.managed-text-input {
  width: 100%;
  min-width: 0;
  min-height: 34px;
}
.admin-file-upload {
  display: grid;
  grid-template-columns: minmax(112px, auto) minmax(120px, 1fr);
  gap: 8px;
  align-items: center;
  width: 100%;
  min-width: 0;
  min-height: 34px;
}
.managed-field .custom-file-input,
td input.custom-file-input,
.form-grid input.custom-file-input,
.custom-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  opacity: 0;
  white-space: nowrap;
  border: 0;
  pointer-events: none;
}
.admin-file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--brand);
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.admin-file-button:hover { background: var(--brand-dark); }
.admin-file-name {
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
table.wide td,
table.wide th {
  max-width: 280px;
}
table.wide td {
  min-width: 92px;
}
table.wide td:has(.admin-file-upload),
table.wide td:has(.managed-field .custom-file-input) {
  min-width: 260px;
  max-width: 320px;
}

.switch-control {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  width: 42px;
  max-width: 42px;
  flex: 0 0 42px;
  min-height: 34px;
  isolation: isolate;
  vertical-align: middle;
}
.switch-control input {
  position: absolute;
  inset: 0;
  width: 1px !important;
  height: 1px !important;
  min-height: 0 !important;
  padding: 0 !important;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}
.switch-control .switch-track {
  position: relative;
  display: block;
  flex: 0 0 42px;
  width: 42px;
  min-width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #d0d5dd;
  border: 1px solid #b8c4d2;
  transition: background 0.16s ease, border-color 0.16s ease;
}
.switch-control .switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.18);
  transition: transform 0.16s ease;
}
.switch-control input:checked + .switch-track {
  background: var(--brand);
  border-color: var(--brand);
}
.switch-control input:checked + .switch-track::after {
  transform: translateX(18px);
}
.switch-control input:focus-visible + .switch-track {
  outline: 2px solid rgba(21, 111, 117, 0.28);
  outline-offset: 2px;
}

.field-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.help-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: 1px solid #b8c4d2;
  border-radius: 50%;
  color: var(--muted);
  background: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  cursor: help;
  text-transform: none;
}
.help-icon::after {
  content: attr(aria-label);
  display: none;
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: 240px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #101828;
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  text-transform: none;
  transform: translateX(-50%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  white-space: normal;
  box-shadow: 0 8px 18px rgba(16, 24, 40, 0.18);
}
.help-icon:hover::after,
.help-icon:focus-visible::after {
  display: block;
  opacity: 1;
  visibility: visible;
}

.filters, .form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}
.form-grid.compact { grid-template-columns: 1fr; }
label:not(.switch-control), .form-field { display: grid; gap: 6px; font-size: 12px; font-weight: 700; }
.inline-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-actions input { max-width: 220px; }
.permissions-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 8px;
}
.permissions-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
  color: var(--text);
}
.permissions-grid input { width: auto; min-height: auto; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #eef2f6;
  color: #344054;
}
.state-9 { background: #dcfae6; color: var(--ok); }
.state-0 { background: #fee4e2; color: var(--danger); }
.state-1 { background: #fef0c7; color: var(--warn); }
.state-2, .state-3 { background: #f2f4f7; color: #475467; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.tabs a {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
}
.tabs a.active {
  border-color: var(--brand);
  color: var(--brand);
  font-weight: 700;
}

.pager {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 18px;
}
.pager a {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
.muted { color: var(--muted); }
.text-preview {
  display: block;
  max-width: 360px;
  overflow-wrap: anywhere;
  line-height: 1.45;
}
.media-thumb {
  display: block;
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: #fff;
}
.alert {
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
}
.alert.danger { background: #fff1f3; color: var(--danger); border-color: #fecdd6; }
.alert.success { background: #ecfdf3; color: #027a48; border-color: #abefc6; }
.alert.warning { background: #fffaeb; color: #b54708; border-color: #fedf89; }

[dir="rtl"] body { direction: rtl; }
[dir="rtl"] .sidebar { inset: 0 0 0 auto; }
[dir="rtl"] .main {
  margin-left: 0;
  margin-right: 230px;
}
[dir="rtl"] th,
[dir="rtl"] td {
  text-align: right;
}
[dir="rtl"] .topbar-actions { justify-content: flex-start; }
[dir="rtl"] .login-locale {
  right: auto;
  left: 18px;
}
[dir="rtl"] .switch-control .switch-track::after {
  left: auto;
  right: 2px;
}
[dir="rtl"] .switch-control input:checked + .switch-track::after {
  transform: translateX(-18px);
}
[dir="rtl"] .help-icon::after {
  left: auto;
  right: 50%;
  transform: translateX(50%);
}

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  padding: 24px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
}
.login-card h1 { margin: 0 0 6px; font-size: 24px; }
.login-card code {
  display: block;
  padding: 10px;
  background: #f2f4f7;
  border-radius: 6px;
  overflow-wrap: anywhere;
}

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-two { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  /* Keep the sticky header attached to the page's scrolling viewport. */
  .admin-layout { overflow-x: clip; }
  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 60px;
    padding: 8px 16px;
    background: #101828;
    color: #fff;
    font-size: 18px;
    font-weight: 800;
  }
  .mobile-brand { flex: 1; min-width: 0; font-size: clamp(14px, 4vw, 18px); }
  .mobile-profile-avatar { margin-inline-start: auto; }
  .mobile-profile-avatar:focus-visible { outline-color: #fff; }
  .desktop-profile-avatar { display: none; }
  .profile-picture-row { align-items: flex-start; flex-wrap: wrap; }
  .profile-picture-upload { flex-basis: 100%; }
  .form-grid.profile-details { grid-template-columns: 1fr; }
  .navigation-toggle, .navigation-close {
    display: inline-flex;
    flex: 0 0 44px;
    width: 44px;
    min-height: 44px;
    padding: 0;
    border-color: #475467;
    background: transparent;
    color: #fff;
  }
  .navigation-toggle:hover, .navigation-close:hover { background: #1d2939; }
  .navigation-toggle:focus-visible, .navigation-close:focus-visible, .sidebar a:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
  }
  .navigation-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(16, 24, 40, 0.6);
  }
  .sidebar {
    z-index: 300;
    width: min(300px, calc(100% - 48px));
    height: 100vh;
    height: 100dvh;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    visibility: hidden;
    transform: translateX(-100%);
    overscroll-behavior-y: contain;
    overflow-wrap: anywhere;
  }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar.is-open, [dir="rtl"] .sidebar.is-open {
    visibility: visible;
    transform: translateX(0);
  }
  .sidebar-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
  }
  .sidebar-heading .brand { padding: 10px 8px; }
  html.navigation-open { overflow: hidden; }
  html.navigation-open body {
    position: fixed;
    top: var(--navigation-scroll-top);
    width: 100%;
    overflow: hidden;
  }
  .main {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
    padding: 16px;
  }
  .topbar { align-items: flex-start; flex-wrap: wrap; }
  .topbar > div { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
  .main :is([id], a, button, input, select, textarea) { scroll-margin-top: 76px; }
  .stats-grid, .filters, .form-grid { grid-template-columns: 1fr; }
  .permissions-grid { grid-template-columns: 1fr; }
  .admin-file-upload { grid-template-columns: 1fr; }
  .admin-file-button { width: 100%; }
  .topbar-actions { justify-content: flex-start; }
  .login-locale {
    position: static;
    width: min(420px, 100%);
  }
  [dir="rtl"] .main {
    margin-right: 0;
  }
}
