@font-face {
  font-family: "IRANSans";
  src: url("/fonts/IRANSans.woff2") format("woff2");
  font-display: swap;
}

:root {
  --color-primary: #1455d9;
  --color-primary-strong: #0f46ba;
  --color-bg: #f7f8fa;
  --color-surface: #ffffff;
  --color-surface-muted: #f2f4f7;
  --color-border: #e5e8ee;
  --color-text: #17191f;
  --color-text-muted: #68707f;
  --color-success: #167a4c;
  --color-warning: #9c6415;
  --color-danger: #ba2d35;
  --color-info: #2466c2;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --shadow-subtle: 0 8px 24px rgba(19, 28, 45, .045);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --container: 1180px;
  --mobile-nav-height: 68px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--color-text);
  background: var(--color-bg);
  font-family: "IRANSans", Tahoma, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.8;
}
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }

.app-shell { min-height: 100vh; }
.container {
  width: min(calc(100% - 28px), var(--container));
  margin-inline: auto;
}
.page {
  padding-block: 22px calc(var(--mobile-nav-height) + 28px);
}
.page-title {
  margin: 0;
  font-size: 21px;
  line-height: 1.5;
  font-weight: 800;
  letter-spacing: -.2px;
}
.page-subtitle {
  margin: 5px 0 0;
  color: var(--color-text-muted);
  font-size: 13px;
}
.section-title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 800;
}

.surface {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-subtle);
}
.card { padding: 18px; }
.stack { display: grid; gap: 14px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(247, 248, 250, .96);
  border-bottom: 1px solid var(--color-border);
  backdrop-filter: blur(8px);
}
.topbar-inner {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: var(--color-primary);
  color: #fff;
}
.brand-mark svg { width: 20px; height: 20px; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 8px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 700;
  transition: .16s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--color-primary-strong);
}
.btn-secondary {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-danger {
  background: #fff4f4;
  border-color: #f0c9cc;
  color: var(--color-danger);
}
.btn-sm {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 12px;
}

.field {
  display: grid;
  gap: 7px;
}
.label {
  font-size: 12px;
  font-weight: 700;
  color: #383e49;
}
.input, .select, .textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--color-border);
  border-radius: 13px;
  background: #fff;
  color: var(--color-text);
  outline: 0;
  padding: 10px 12px;
  font-size: 16px;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: #8aacef;
  box-shadow: 0 0 0 3px rgba(20, 85, 217, .08);
}
.help {
  font-size: 12px;
  color: var(--color-text-muted);
}
.error-text {
  color: var(--color-danger);
  font-size: 12px;
}

.alert {
  padding: 12px 14px;
  border-radius: 13px;
  border: 1px solid var(--color-border);
  background: #fff;
  margin-bottom: 14px;
}
.alert-success {
  color: var(--color-success);
  border-color: #c8e6d6;
  background: #f5fbf8;
}
.alert-danger {
  color: var(--color-danger);
  border-color: #f1c9cc;
  background: #fff7f7;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  background: var(--color-surface-muted);
  color: #48505d;
}
.badge-success {
  background: #edf8f2;
  color: var(--color-success);
}
.badge-warning {
  background: #fff7e8;
  color: var(--color-warning);
}
.badge-danger {
  background: #fff0f1;
  color: var(--color-danger);
}
.badge-info {
  background: #eef5ff;
  color: var(--color-info);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #fff;
}
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}
.table th, .table td {
  padding: 12px 14px;
  border-bottom: 1px solid #edf0f4;
  text-align: right;
  white-space: nowrap;
}
.table th {
  background: #fafbfc;
  color: #596171;
  font-size: 12px;
  font-weight: 800;
}
.table tr:last-child td { border-bottom: 0; }

.stat { padding: 16px; }
.stat-label {
  color: var(--color-text-muted);
  font-size: 12px;
}
.stat-value {
  margin-top: 4px;
  font-weight: 900;
  font-size: 20px;
  line-height: 1.4;
}

.bottom-nav {
  position: fixed;
  z-index: 40;
  left: 10px;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  min-height: var(--mobile-nav-height);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: stretch;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 18px;
  box-shadow: 0 12px 36px rgba(22, 31, 48, .08);
  overflow: hidden;
}
.nav-item {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  color: #707786;
  font-size: 10px;
  font-weight: 700;
}
.nav-item svg {
  width: 20px;
  height: 20px;
}
.nav-item.active {
  color: var(--color-primary);
  background: #f7f9fe;
}
.sidebar { display: none; }
.desktop-shell { display: block; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: min(100%, 430px);
  padding: 24px;
}
.auth-head { margin-bottom: 22px; }
.auth-head h1 {
  font-size: 21px;
  margin: 0 0 7px;
}
.auth-head p {
  color: var(--color-text-muted);
  margin: 0;
  font-size: 13px;
}
.auth-form {
  display: grid;
  gap: 14px;
}

.skeleton {
  position: relative;
  overflow: hidden;
  background: #eceff3;
  border-radius: 10px;
  min-height: 14px;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background:
    linear-gradient(
      90deg,
      transparent,
      rgba(255,255,255,.55),
      transparent
    );
  animation: skeleton 1.4s infinite;
}
@keyframes skeleton {
  100% { transform: translateX(100%); }
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.empty {
  padding: 26px;
  text-align: center;
  color: var(--color-text-muted);
}

@media (min-width: 900px) {
  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .bottom-nav { display: none; }
  .page { padding-bottom: 36px; }
  .desktop-shell {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    min-height: calc(100vh - 63px);
  }
  .sidebar {
    display: block;
    border-left: 1px solid var(--color-border);
    background: #fff;
    padding: 18px 12px;
    position: sticky;
    top: 63px;
    height: calc(100vh - 63px);
  }
  .sidebar-nav {
    display: grid;
    gap: 5px;
  }
  .sidebar .nav-item {
    display: flex;
    justify-content: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 13px;
  }
  .sidebar .nav-item.active {
    background: #f2f6ff;
  }
}

/* Phase 2 shared components */
.page-head,
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.page-head { margin-bottom: 18px; }
.section-gap { margin-top: 14px; }
.grow { flex: 1 1 auto; }
.align-end { align-self: end; }
.cell-sub {
  margin-top: 2px;
  color: var(--color-text-muted);
  font-size: 11px;
}
.badge-list,
.inline-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.inline-checks { gap: 14px; min-height: 46px; }
.inline-checks label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.filter-bar,
.form-grid,
.form-row,
.test-row {
  display: grid;
  gap: 12px;
}
.filter-actions {
  display: flex;
  gap: 8px;
  align-items: end;
  flex-wrap: wrap;
}
.form-section {
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}
.check-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.check-card {
  min-height: 58px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 12px;
  border: 1px solid var(--color-border);
  border-radius: 13px;
  background: #fff;
  cursor: pointer;
}
.check-card input { margin-top: 5px; }
.check-card span { display: grid; gap: 1px; }
.check-card small {
  color: var(--color-text-muted);
  direction: ltr;
  text-align: left;
}
.permission-groups { display: grid; gap: 14px; }
.permission-group {
  padding: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #fbfcfd;
}
.permission-group h3 {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--color-text-muted);
  text-transform: uppercase;
}
.detail-list { display: grid; gap: 0; }
.detail-list > div {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #edf0f4;
}
.detail-list > div:last-child { border-bottom: 0; }
.detail-list > div > span { color: var(--color-text-muted); font-size: 12px; }
.template-box {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}
.notification-card {
  padding: 14px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.notification-card p { margin: 6px 0 0; color: #404653; }
.notification-card.is-unread { border-color: #bed0f8; }
.notification-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-primary);
  margin-top: 7px;
  flex: 0 0 auto;
}
.notification-card:not(.is-unread) .notification-dot { background: #c7cbd3; }
.code-box {
  margin: 0;
  max-height: 420px;
  overflow: auto;
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f8f9fb;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 12px;
  font: 12px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.pager {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.pager-link {
  min-width: 62px;
  min-height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--color-border);
  border-radius: 11px;
  background: #fff;
  font-size: 12px;
  font-weight: 700;
}
.pager-link.disabled { opacity: .45; cursor: default; }
.pager-meta { color: var(--color-text-muted); font-size: 12px; }
.text-danger { color: var(--color-danger); }

@media (max-width: 899px) {
  .bottom-nav {
    grid-auto-columns: minmax(72px, 1fr);
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }
  .bottom-nav::-webkit-scrollbar { display: none; }
  .page-head > .inline-actions { width: 100%; }
  .page-head > .inline-actions .btn { flex: 1; }
}

@media (min-width: 700px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar { grid-template-columns: minmax(230px, 2fr) minmax(150px, 1fr) minmax(150px, 1fr) auto; align-items: end; }
  .check-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-row, .test-row { grid-template-columns: minmax(180px, 1fr) minmax(260px, 2fr) auto; align-items: end; }
}

.dashboard-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) {
  .dashboard-stats { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
