:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #2a3f54;
  --muted: #73879c;
  --border: #e5e9ef;
  --primary: #1abb9c;
  --primary-strong: #159c83;
  --sidebar: #263a4f;
  --sidebar-dark: #1f3042;
  --danger: #d9534f;
  --warning-bg: #fff7d6;
  --danger-bg: #fff1f0;
  --success-bg: #e8f6ee;
  --shadow: 0 12px 28px rgba(42, 63, 84, 0.08);
}

@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

.public-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 52px;
}

.public-hero {
  position: relative;
  min-height: 220px;
  padding: 42px;
  overflow: hidden;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--sidebar), var(--sidebar-dark));
  color: #fff;
  box-shadow: var(--shadow);
}

.public-hero::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 5px;
  background: var(--primary);
}

.public-hero .eyebrow {
  color: var(--primary);
}

.public-hero-content {
  display: flex;
  align-items: center;
  gap: 24px;
}

.public-hero-logo {
  width: 92px;
  height: auto;
  flex: 0 0 auto;
  filter: brightness(0) invert(1);
}

.public-hero h1 {
  max-width: 720px;
  color: #fff;
  font-size: 34px;
}

.public-search-card {
  width: min(1040px, calc(100% - 34px));
  margin: -72px auto 0;
  z-index: 2;
}

.search-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.search-card-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 5px 12px;
  border: 1px solid rgba(26, 187, 156, 0.35);
  border-radius: 999px;
  background: rgba(26, 187, 156, 0.1);
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 800;
}

.search-panel,
.auth-panel,
.form-panel,
.filter-panel,
.table-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.search-panel {
  position: relative;
  padding: 28px;
  overflow: hidden;
}

.search-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  width: auto;
  height: 4px;
  background: var(--primary);
}

.brand-row,
.admin-header,
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  line-height: 1.4;
}

h1 {
  color: var(--text);
  font-size: 29px;
  font-weight: 700;
}

h2 {
  font-size: 19px;
}

.admin-link,
.secondary-button,
.ghost-button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.admin-link,
.primary-button,
.secondary-button,
.danger-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 16px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  box-shadow: 0 6px 14px rgba(26, 187, 156, 0.2);
}

.primary-button:hover {
  background: var(--primary-strong);
}

.danger-button {
  border: 1px solid var(--danger);
  background: var(--danger);
  color: #fff;
}

.small {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 14px;
}

.search-controls {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(220px, 1fr) auto;
  grid-template-areas:
    "search-label search-label search-label"
    "search-input search-input search-input"
    "department-label office-label ."
    "department-select office-select actions";
  gap: 10px 16px;
}

.search-controls label:nth-of-type(1) {
  grid-area: search-label;
}

.search-controls label:nth-of-type(2) {
  grid-area: department-label;
}

.search-controls label:nth-of-type(3) {
  grid-area: office-label;
}

.search-controls input {
  grid-area: search-input;
}

.search-controls select:nth-of-type(1) {
  grid-area: department-select;
}

.search-controls select:nth-of-type(2) {
  grid-area: office-select;
}

.search-actions {
  grid-area: actions;
  display: flex;
  align-items: end;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  padding: 9px 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 187, 156, 0.14);
}

label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.results-section {
  width: min(1040px, calc(100% - 34px));
  margin: 28px auto 0;
  overflow-x: auto;
}

.results-meta,
.empty-state {
  color: var(--muted);
}

.plain-list {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0 18px 0 0;
  color: var(--danger);
}

.results-meta.is-loading {
  color: var(--primary);
}

.results-table {
  min-width: 940px;
  margin-top: 16px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.result-row {
  display: grid;
  grid-template-columns: 82px minmax(220px, 1.4fr) minmax(210px, 1.25fr) minmax(190px, 1fr) 122px 92px;
  align-items: center;
  min-height: 76px;
  border-bottom: 1px solid var(--border);
}

.result-row:last-child {
  border-bottom: 0;
}

.result-row-head {
  min-height: 54px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.result-row-head > div,
.result-cell {
  min-width: 0;
  padding: 12px 14px;
}

.result-cell {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: break-word;
}

.result-name-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
}

.result-extension-cell strong {
  color: var(--primary-strong);
  font-size: 18px;
}

.result-action-cell {
  display: flex;
  justify-content: flex-start;
}

.result-photo-cell {
  display: flex;
  justify-content: center;
}

.person-avatar,
.admin-table-avatar,
.admin-photo-preview {
  display: block;
  object-fit: cover;
  background: #eef4f7;
  border: 1px solid var(--border);
}

.person-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
}

.admin-table-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
}

.admin-photo-preview {
  width: 92px;
  height: 92px;
  border-radius: 8px;
}

.head-icon {
  display: inline-grid;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  place-items: center;
  border-radius: 50%;
  background: rgba(26, 187, 156, 0.14);
  color: var(--primary-strong);
  font-size: 15px;
  line-height: 1;
}

.contact-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

.contact-details {
  display: grid;
  gap: 12px;
  margin: 16px 0 0;
}

.contact-details div {
  display: grid;
  gap: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f0f3f6;
}

.contact-details dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.contact-details dd {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  min-width: 0;
  word-break: normal;
  overflow-wrap: break-word;
  text-align: right;
}

.contact-extension-row {
  display: grid;
  grid-template-columns: minmax(112px, max-content) minmax(82px, max-content);
  gap: 8px;
  align-items: stretch;
  justify-content: start;
  margin-bottom: 2px;
}

.extension-badge {
  align-self: start;
  min-width: 92px;
  padding: 10px 12px;
  border-radius: 6px;
  background: rgba(26, 187, 156, 0.12);
  color: var(--primary-strong);
  text-align: center;
}

.extension-badge span,
.extension-badge strong {
  display: block;
}

.extension-badge span {
  font-size: 12px;
}

.extension-badge strong {
  font-size: 25px;
  line-height: 1.3;
}

.copy-extension-button {
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--primary-strong);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.copy-extension-button:hover {
  border-color: var(--primary);
}

.public-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: min(1040px, calc(100% - 34px));
  min-height: 74px;
  margin: 28px auto 0;
  padding: 18px 24px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--sidebar), var(--sidebar-dark));
  color: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.public-footer a {
  color: #fff;
  font-weight: 800;
}

.public-footer span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 14px;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
  padding: 28px;
}

.form-stack {
  display: grid;
  gap: 16px;
  margin-top: 22px;
}

.form-panel .form-stack {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.form-panel .form-actions {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 6px;
}

.select-search-input {
  min-height: 38px;
}

.photo-upload-row {
  display: flex;
  gap: 14px;
  align-items: center;
}

.photo-upload-controls {
  display: grid;
  gap: 10px;
  align-items: start;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
}

.checkbox-field input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--primary);
}

.field-error {
  color: var(--danger);
  font-size: 13px;
}

.admin-shell {
  display: flex;
  direction: ltr;
  min-height: 100vh;
}

.admin-sidebar {
  order: 2;
  display: flex;
  flex-direction: column;
  flex: 0 0 270px;
  width: 270px;
  min-height: 100vh;
  gap: 24px;
  padding: 24px;
  background: var(--sidebar);
  color: #fff;
  direction: rtl;
}

.admin-main {
  order: 1;
  flex: 1;
  min-width: 0;
  direction: rtl;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-logo {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
}

.sidebar-title {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.4;
}

.sidebar-brand span {
  color: rgba(255, 255, 255, 0.68);
  font-size: 12px;
}

.admin-sidebar nav {
  display: grid;
  gap: 8px;
}

.sidebar-footer {
  display: grid;
  gap: 4px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.64);
  font-size: 12px;
  line-height: 1.8;
}

.admin-sidebar nav a {
  position: relative;
  padding: 10px 14px;
  border-radius: 4px;
  color: #eef3ff;
}

.admin-sidebar nav a:hover,
.admin-sidebar nav a.active {
  background: var(--sidebar-dark);
}

.admin-sidebar nav a.active::before {
  content: "";
  position: absolute;
  inset: 8px 0 8px auto;
  width: 4px;
  border-radius: 4px 0 0 4px;
  background: var(--primary);
}

.admin-sidebar .ghost-button {
  width: 100%;
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
}

.admin-main {
  padding: 30px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin: 22px 0;
}

.stat-card {
  display: grid;
  gap: 8px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.stat-card span {
  color: var(--muted);
}

.stat-card strong {
  font-size: 34px;
}

.table-section,
.filter-panel,
.form-panel {
  margin-top: 22px;
  padding: 20px;
  overflow-x: auto;
}

.filter-panel {
  overflow: visible;
}

.admin-filter-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 220px 220px auto;
  gap: 14px;
  align-items: end;
}

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

.table-meta {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
}

.table-meta span {
  margin-right: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}

th {
  color: var(--muted);
  font-size: 14px;
  background: #f8fafc;
}

tbody tr:hover {
  background: #fbfcfd;
}

.actions-cell {
  display: flex;
  gap: 8px;
  align-items: center;
}

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

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

.pagination-status,
.pagination-disabled {
  color: var(--muted);
  font-size: 14px;
}

.pagination-disabled {
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  opacity: 0.6;
}

.flash-list {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.flash {
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.flash-success {
  background: var(--success-bg);
}

.flash-warning {
  background: var(--warning-bg);
}

.flash-danger {
  background: var(--danger-bg);
}

@media (max-width: 760px) {
  .brand-row,
  .admin-header,
  .section-title-row,
  .filter-actions,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search-controls {
    grid-template-columns: 1fr;
    grid-template-areas:
      "search-label"
      "search-input"
      "department-label"
      "department-select"
      "office-label"
      "office-select";
  }

  .search-controls label,
  .search-controls input,
  .search-controls select,
  .search-controls label:nth-of-type(1),
  .search-controls label:nth-of-type(2),
  .search-controls label:nth-of-type(3),
  .search-controls select:nth-of-type(1),
  .search-controls select:nth-of-type(2) {
    grid-column: 1;
  }

  .public-hero {
    min-height: 190px;
    padding: 28px 22px;
  }

  .public-hero-content {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  .public-hero-logo {
    width: 72px;
  }

  .public-hero h1 {
    font-size: 27px;
  }

  .public-search-card,
  .results-section {
    width: 100%;
  }

  .public-search-card {
    margin-top: -46px;
  }

  .search-card-header {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-shell {
    flex-direction: column;
  }

  .admin-sidebar {
    order: 1;
    width: 100%;
    min-height: auto;
    flex-basis: auto;
  }

  .admin-main {
    order: 2;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

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

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

  .pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .contact-card {
    min-height: 118px;
    padding: 15px;
  }

  .extension-badge {
    min-width: 92px;
  }

  .contact-extension-row {
    grid-template-columns: 1fr 1fr;
    justify-content: stretch;
  }
}
