/* Phonebook — dark/light theme, RTL */
@font-face { font-family: Vazirmatn; src: url('../fonts/Vazirmatn-Regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: Vazirmatn; src: url('../fonts/Vazirmatn-Medium.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: Vazirmatn; src: url('../fonts/Vazirmatn-Bold.woff2') format('woff2'); font-weight: 700; font-display: swap; }

:root, html[data-theme="dark"] {
  --bg: #0b1220;
  --bg-soft: #111a2e;
  --surface: #152341;
  --surface-2: #1a2b4e;
  --border: rgba(255,255,255,0.09);
  --text: #e6ecf7;
  --text-dim: #94a3b8;
  --accent: #06b6d4;        /* cyan */
  --accent-2: #3b82f6;      /* blue */
  --accent-ink: #042631;
  --primary: #0ea5e9;        /* sky */
  --primary-ink: #04222e;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  color-scheme: dark;
}
html[data-theme="light"] {
  --bg: #f4f7fb;
  --bg-soft: #ffffff;
  --surface: #ffffff;
  --surface-2: #f1f5fb;
  --border: rgba(14, 30, 65, 0.09);
  --text: #0f172a;
  --text-dim: #64748b;
  --accent: #0891b2;
  --accent-2: #2563eb;
  --accent-ink: #ffffff;
  --primary: #0284c7;
  --primary-ink: #ffffff;
  --shadow: 0 10px 30px rgba(6, 28, 60, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: Vazirmatn, system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.container { max-width: 1180px; margin: 0 auto; padding: 0 18px; }

/* Header */
.app-header {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  border-bottom: 1px solid var(--border);
  padding: 18px 0;
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(8px);
}
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo { width: 48px; height: 48px; padding: 8px; background: var(--accent); border-radius: 14px; filter: drop-shadow(0 4px 10px rgba(6,182,212,.45)); }
.brand-text h1 { margin: 0; font-size: 20px; font-weight: 700; }
.brand-text p { margin: 2px 0 0; font-size: 13px; color: var(--text-dim); }
.header-actions { display: flex; gap: 10px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 18px; cursor: pointer;
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }

/* Main */
.main { padding: 24px 0 60px; display: flex; flex-direction: column; gap: 22px; }

.intro-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.9;
}

/* CTA row */
.cta-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.cta-card {
  display: flex; align-items: center; gap: 14px;
  padding: 18px; border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-align: right;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: transform .1s, box-shadow .15s, background .15s;
  box-shadow: var(--shadow);
}
.cta-card:hover { transform: translateY(-2px); background: var(--surface-2); }
.cta-icon {
  width: 56px; height: 56px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--surface-2);
  font-size: 26px;
}
.cta-primary .cta-icon { background: var(--accent); color: var(--accent-ink); }
.cta-bot .cta-icon { background: #0088cc; color: white; }
.cta-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cta-body strong { font-size: 16px; }
.cta-body small { color: var(--text-dim); font-size: 13px; line-height: 1.7; }

/* Search card */
.search-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 14px 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.search-wrap {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px; padding: 0 14px;
}
.search-icon { font-size: 18px; opacity: 0.7; }
.search-wrap input {
  border: 0; background: transparent; color: var(--text);
  font: inherit; padding: 14px 4px; outline: none; width: 100%;
}
.search-wrap input::-webkit-search-cancel-button,
.search-wrap input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.search-clear {
  border: 0; background: transparent; color: var(--text-dim);
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center;
}
.search-clear[hidden] { display: none !important; }
.search-clear:hover { background: var(--surface); color: var(--text); }

.dept-chips {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, transform .1s;
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit;
}
.chip:hover { background: var(--surface); }
.chip.is-active {
  background: var(--accent); color: var(--accent-ink); border-color: transparent;
  font-weight: 700;
}
.chip-count {
  background: rgba(0,0,0,0.25); padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700;
}
.chip.is-active .chip-count { background: rgba(255,255,255,0.3); }
html[data-theme="light"] .chip-count { background: rgba(0,0,0,0.08); }
html[data-theme="light"] .chip.is-active .chip-count { background: rgba(255,255,255,0.35); }

/* List */
.list-section { display: flex; flex-direction: column; gap: 14px; }
.list-meta {
  display: flex; justify-content: space-between; align-items: center;
  color: var(--text-dim); font-size: 13px;
  padding: 4px 2px;
}

.contact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.contact-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: flex; gap: 14px; align-items: flex-start;
  cursor: pointer;
  transition: transform .1s, background .15s, box-shadow .15s;
  box-shadow: var(--shadow);
}
.contact-card:hover { transform: translateY(-2px); background: var(--surface-2); }

.avatar {
  flex-shrink: 0;
  width: 56px; height: 56px;
  border-radius: 14px;
  background: var(--surface-2);
  display: grid; place-items: center;
  overflow: hidden;
  position: relative;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-fallback {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: white; font-weight: 700; font-size: 18px;
}

.contact-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.contact-name { font-weight: 700; font-size: 15px; line-height: 1.5; }
.contact-role { color: var(--text-dim); font-size: 13px; line-height: 1.6; }
.contact-chips { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.contact-chip {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  display: inline-flex; align-items: center; gap: 4px;
}
.contact-chip.has-phone { color: var(--success); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.contact-chip.has-tg    { color: #0088cc; border-color: color-mix(in srgb, #0088cc 45%, transparent); }
.contact-chip.has-rb    { color: #9333ea; border-color: color-mix(in srgb, #9333ea 45%, transparent); }

.chunk-sentinel { height: 40px; }
.empty-state {
  text-align: center; padding: 60px 20px;
  background: var(--surface); border-radius: 14px; border: 1px solid var(--border);
}
.empty-icon { font-size: 40px; margin-bottom: 10px; }
.empty-state h3 { margin: 0 0 6px; font-size: 16px; }
.empty-state p { margin: 0; color: var(--text-dim); font-size: 13px; }

/* Footer */
.app-footer {
  border-top: 1px solid var(--border);
  padding: 22px 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* Modal */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none !important; }
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  animation: fade .15s ease-out;
}
.modal-panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
  max-height: 90vh; overflow-y: auto;
  animation: pop .2s ease-out;
  width: 100%;
}
.modal-sm { max-width: 420px; }
.modal-md { max-width: 560px; }
.modal-lg { max-width: 720px; }
.modal-panel h2 { margin: 0 0 6px; font-size: 20px; }
.modal-sub { margin: 0 0 14px; color: var(--text-dim); font-size: 13px; }
.modal-close {
  position: absolute; top: 12px; left: 12px;
  width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: var(--surface-2); color: var(--text);
  font-size: 15px; cursor: pointer;
}
.modal-close:hover { background: var(--bg-soft); }
.success-icon { font-size: 40px; text-align: center; margin-bottom: 8px; }

/* Form */
.form { display: flex; flex-direction: column; gap: 14px; margin-top: 10px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); font-weight: 600; }
.form input, .form textarea, .form select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form input:focus, .form textarea:focus, .form select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.form textarea { resize: vertical; min-height: 80px; font-family: inherit; }
.divider { height: 1px; background: var(--border); margin: 4px 0; }
.hint { color: var(--text-dim); font-size: 12px; margin: 0; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

.btn-primary {
  background: var(--accent); color: var(--accent-ink);
  border: 0; padding: 12px 22px; border-radius: 10px;
  font: inherit; font-weight: 700; cursor: pointer;
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 85%, #000); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); padding: 10px 18px; border-radius: 10px;
  font: inherit; cursor: pointer;
}
.btn-secondary:hover { background: var(--bg-soft); }
.btn-danger {
  background: var(--danger); color: #fff;
  border: 0; padding: 10px 18px; border-radius: 10px;
  font: inherit; font-weight: 700; cursor: pointer;
}
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }
.btn-success {
  background: var(--success); color: #fff;
  border: 0; padding: 10px 18px; border-radius: 10px;
  font: inherit; font-weight: 700; cursor: pointer;
}
.btn-success:hover { background: color-mix(in srgb, var(--success) 85%, #000); }

/* Detail modal */
.detail-hero {
  display: flex; align-items: center; gap: 16px;
  padding-bottom: 16px; border-bottom: 1px solid var(--border); margin-bottom: 16px;
}
.detail-hero .avatar { width: 84px; height: 84px; border-radius: 18px; }
.detail-hero .avatar-fallback { font-size: 26px; }
.detail-hero h3 { margin: 0 0 4px; font-size: 19px; }
.detail-hero .detail-role { margin: 0; color: var(--text-dim); font-size: 14px; }
.detail-dept-chip {
  display: inline-flex; gap: 4px; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700;
  background: var(--surface-2); color: var(--text-dim);
  border: 1px solid var(--border);
  margin-top: 8px;
}

.detail-section-title { font-size: 13px; color: var(--text-dim); margin: 14px 0 8px; font-weight: 700; }

.detail-rows { display: flex; flex-direction: column; gap: 8px; }
.detail-row {
  display: grid; grid-template-columns: 30px 70px 1fr auto; align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
}
.detail-row .row-icon { font-size: 18px; text-align: center; }
.detail-row .row-label { color: var(--text-dim); font-size: 12px; font-weight: 600; }
.detail-row .row-value { color: var(--text); direction: ltr; text-align: left; word-break: break-word; min-width: 0; overflow-wrap: anywhere; }
.detail-row .row-value a { color: var(--accent); text-decoration: none; }
.detail-row .row-value a:hover { text-decoration: underline; }
.detail-row.is-rtl .row-value { direction: rtl; text-align: right; }
.copy-btn {
  border: 0; background: var(--surface); color: var(--text-dim);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
  font-size: 14px; display: grid; place-items: center;
}
.copy-btn:hover { background: var(--bg-soft); color: var(--text); }
.copy-btn.is-ok { color: var(--success); background: color-mix(in srgb, var(--success) 20%, transparent); }

.detail-desc {
  margin-top: 14px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px; line-height: 1.8;
}

/* Mobile */
@media (max-width: 720px) {
  .brand-text h1 { font-size: 17px; }
  .brand-text p { font-size: 12px; }
  .cta-row { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .contact-grid { grid-template-columns: 1fr; }
  .detail-row { grid-template-columns: 26px 1fr auto; }
  .detail-row .row-label { display: none; }
  .modal-panel { padding: 18px; }
  .modal-close { left: 8px; top: 8px; }
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* Admin-specific (shared with /admin/) */
.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 24px 18px 60px; }
.admin-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 22px;
  box-shadow: var(--shadow);
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.admin-header h2 { margin: 0 0 4px; font-size: 18px; }
.admin-header p { margin: 0; color: var(--text-dim); font-size: 13px; }
.admin-tabs {
  display: flex; flex-wrap: wrap; gap: 10px;
  border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 14px;
}
.admin-tab {
  padding: 10px 18px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
}
.admin-tab:hover { background: var(--bg-soft); }
.admin-tab.is-active {
  background: var(--accent); color: var(--accent-ink); border-color: transparent;
  font-weight: 700;
}
.admin-search {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 14px;
}
.admin-search .search-wrap { padding: 0 14px; }
.admin-search .result-count {
  color: var(--text-dim); font-size: 12px;
  text-align: end;
  padding: 0 4px;
  min-height: 14px;
}

.admin-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px; align-items: flex-start;
}
.admin-card .avatar { width: 48px; height: 48px; border-radius: 12px; }
.admin-card-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.admin-card-name { font-weight: 700; font-size: 15px; }
.admin-card-role { color: var(--text-dim); font-size: 13px; }
.admin-card-meta { color: var(--text-dim); font-size: 12px; display: flex; flex-wrap: wrap; gap: 10px; }
.admin-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-card-actions button { padding: 6px 12px; font-size: 12px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700;
}
.status-pill.pending { background: color-mix(in srgb, var(--warning) 20%, transparent); color: var(--warning); }
.status-pill.approved { background: color-mix(in srgb, var(--success) 20%, transparent); color: var(--success); }
.status-pill.rejected { background: color-mix(in srgb, var(--danger) 20%, transparent); color: var(--danger); }

@media (max-width: 640px) {
  .admin-card { grid-template-columns: 1fr; }
}
