:root {
  --bg: #10131a;
  --surface: #1b2230;
  --surface-2: #242d3d;
  --primary: #45c7e8;
  --accent: #f3b64b;
  --success: #54d39a;
  --text: #f2f6fb;
  --muted: #a9b5c6;
  --error: #f06c75;
  --danger: #d94d57;
  --border: #334054;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
  --radius: 0.5rem;
  --spacing: 1rem;
  --transition: 180ms ease;
  --font: Tahoma, Arial, sans-serif;

  --secondary: var(--surface-2);
  --bg-color: var(--bg);
  --secondary-color: var(--surface-2);
  --text-color: var(--text);
  --primary-color: var(--primary);
  --muted-color: var(--muted);
}

*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  font-family: var(--font);
  line-height: 1.7;
  text-rendering: optimizeLegibility;
}

::selection {
  background: rgba(69, 199, 232, 0.35);
}

a {
  color: inherit;
}

header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(27, 34, 48, 0.96);
  padding: 0.8rem 1.5rem;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(12px);
}

.logo {
  color: var(--primary);
  font-size: 1.25rem;
  font-weight: 700;
  white-space: nowrap;
}

.menu-toggle {
  display: none;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 1.25rem;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}

.menu-toggle:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

nav a,
.user-info a {
  text-decoration: none;
}

nav a {
  position: relative;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.45rem 0.65rem;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}

nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  transform: translateY(-1px);
}

nav a.is-active {
  background: rgba(69, 199, 232, 0.13);
  color: var(--primary);
}

.user-info {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

main {
  width: min(1100px, calc(100% - 2rem));
  margin: 2rem auto 4rem;
  animation: pageEnter 360ms ease both;
}

footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  padding: 1.5rem;
  text-align: center;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.55rem 1rem;
  text-align: center;
  text-decoration: none;
  transition: background var(--transition), box-shadow var(--transition), color var(--transition), transform var(--transition);
}

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

.btn-secondary {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

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

.btn-primary:hover,
.btn-secondary:hover,
.btn-danger:hover {
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.24);
  transform: translateY(-1px);
}

.btn-primary:active,
.btn-secondary:active,
.btn-danger:active {
  transform: translateY(0);
}

.flash-list {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.flash {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.8rem 1rem;
  animation: slideDown 240ms ease both;
}

.flash-success {
  border-color: rgba(84, 211, 154, 0.5);
  color: var(--success);
}

.flash-error {
  border-color: rgba(240, 108, 117, 0.5);
  color: var(--error);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2rem;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(69, 199, 232, 0.16), rgba(243, 182, 75, 0.12)),
    var(--surface);
  box-shadow: var(--shadow);
  padding: clamp(1.5rem, 4vw, 3rem);
}

.hero-content {
  max-width: 680px;
}

.hero-content h1 {
  margin-bottom: 1rem;
  color: var(--text);
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1.25;
}

.hero-content p,
.page-heading p,
.login-container p {
  color: var(--muted);
}

.hero-illustration img {
  display: block;
  width: min(220px, 30vw);
  height: auto;
  filter: drop-shadow(0 18px 28px rgba(0, 0, 0, 0.32));
  animation: floatSoft 4.5s ease-in-out infinite;
}

.login-container,
.no-access,
.admin-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: clamp(1.25rem, 3vw, 2rem);
}

.login-container {
  max-width: 520px;
  margin: 4rem auto;
  text-align: center;
}

.login-container h1,
.login-container h2,
.no-access h2,
.page-heading h1 {
  color: var(--primary);
  margin-bottom: 0.8rem;
}

.login-container .btn-primary {
  margin-top: 1.25rem;
}

.no-access-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.access-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 1rem;
  align-items: end;
  margin: 1.5rem 0;
}

.access-form label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.access-form input,
.table-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: 0.75rem;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.table-input {
  min-width: 10rem;
  font-size: 0.95rem;
  padding: 0.55rem 0.7rem;
}

.table-input[readonly] {
  border-color: rgba(84, 211, 154, 0.35);
  background: rgba(84, 211, 154, 0.07);
  color: var(--muted);
  cursor: not-allowed;
}

.identity-status {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem 0.55rem;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.identity-bound {
  border-color: rgba(84, 211, 154, 0.45);
  background: rgba(84, 211, 154, 0.1);
  color: var(--success);
  direction: ltr;
}

.identity-pending {
  border-color: rgba(243, 182, 75, 0.45);
  background: rgba(243, 182, 75, 0.09);
  color: var(--accent);
}

.access-form input:focus,
.table-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(69, 199, 232, 0.16);
  outline: none;
}

.access-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.access-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: rgba(16, 19, 26, 0.35);
}

.access-table th,
.access-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem;
  text-align: right;
  vertical-align: middle;
}

.access-table th {
  position: sticky;
  top: 0;
  background: rgba(36, 45, 61, 0.92);
  color: var(--muted);
  font-size: 0.9rem;
}

.access-table tr {
  transition: background var(--transition);
}

.access-table tbody tr:hover {
  background: rgba(69, 199, 232, 0.06);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.inline-form {
  display: inline;
}

.hidden-form-row {
  display: none;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.rules-accordion {
  width: 100%;
  max-width: 900px;
}

.rule-card {
  border: 1px solid var(--border);
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.rule-card:hover {
  border-color: rgba(69, 199, 232, 0.38);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.22);
  transform: translateY(-1px);
}

.rule-card.open {
  border-color: rgba(69, 199, 232, 0.55);
}

.rule-toggle {
  min-height: 3.35rem;
}

.rule-toggle span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
}

.rule-content {
  overflow-wrap: anywhere;
}

.reveal {
  opacity: 0;
  transform: translateY(14px);
}

.reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 420ms ease, transform 420ms ease;
}

code,
pre {
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pageEnter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes floatSoft {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@media (max-width: 900px) {
  header {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.7rem;
    padding: 0.75rem 1rem;
  }

  .logo {
    min-width: 0;
    overflow: hidden;
    font-size: 1.05rem;
    text-overflow: ellipsis;
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    justify-self: end;
  }

  nav,
  .user-info {
    grid-column: 1 / -1;
    max-height: 32rem;
    opacity: 1;
    overflow: hidden;
    transition: max-height 260ms ease, opacity 220ms ease, padding 220ms ease;
  }

  body.nav-closed nav,
  body.nav-closed .user-info {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
  }

  nav {
    align-items: stretch;
    flex-direction: column;
  }

  nav a,
  .user-info a,
  .user-info span {
    width: 100%;
  }

  nav a {
    padding: 0.65rem 0.75rem;
  }

  .user-info {
    align-items: stretch;
    flex-direction: column;
    justify-content: stretch;
  }

  main {
    width: min(100% - 1rem, 1100px);
    margin-top: 1rem;
  }

  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
    gap: 1.25rem;
  }

  .hero-content h1 {
    font-size: 1.75rem;
  }

  .hero-illustration img {
    width: 150px;
  }

  .access-form {
    grid-template-columns: 1fr;
  }

  .no-access-actions,
  .row-actions {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 720px) {
  .login-container {
    margin: 1.5rem auto;
  }

  .access-table-wrap {
    overflow: visible;
    border: 0;
  }

  .access-table {
    min-width: 0;
    background: transparent;
  }

  .access-table,
  .access-table thead,
  .access-table tbody,
  .access-table tr,
  .access-table td {
    display: block;
    width: 100%;
  }

  .access-table thead {
    display: none;
  }

  .access-table tr {
    margin-bottom: 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(16, 19, 26, 0.42);
    overflow: hidden;
  }

  .access-table td {
    display: grid;
    grid-template-columns: 8.5rem minmax(0, 1fr);
    gap: 0.75rem;
    align-items: center;
    border-bottom: 1px solid var(--border);
  }

  .access-table td:last-child {
    border-bottom: 0;
  }

  .access-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
  }

  .empty-cell {
    display: block !important;
  }

  .empty-cell::before {
    display: none;
  }

  .rule-toggle {
    font-size: 0.98rem !important;
    line-height: 1.6;
  }

  .rule-content table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

@media (max-width: 460px) {
  header {
    padding: 0.7rem;
  }

  main {
    width: min(100% - 0.75rem, 1100px);
  }

  .hero,
  .login-container,
  .no-access,
  .admin-panel {
    padding: 1rem;
  }

  .access-table td {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }

  .btn-primary,
  .btn-secondary,
  .btn-danger {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }

  .reveal {
    opacity: 1;
    transform: none;
  }
}
