/* Shared site header. Single source of truth for every page.
   Physical layout (independent of text direction):
   back button LEFT | logo/title CENTER | user menu RIGHT. */
:root {
  --header-bg: rgba(52, 52, 52, 0.95);
  --header-border: #454545;
  --header-foreground: #fafafa;
  --header-primary: #0891b2;
  --header-primary-strong: #0e7490;
  --header-muted: #454545;
  --header-muted-foreground: #b5b5b5;
  --header-destructive: #dc2626;
  --header-radius: 12px;
  --header-page-gutter: 24px;
  --header-height: 64px;
}

.header {
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
  border-bottom: 1px solid var(--header-border);
  background-color: var(--header-bg);
  backdrop-filter: blur(8px);
  font-family: "Vazirmatn", "IRANSans", system-ui, sans-serif;
  line-height: 1.6;
  box-sizing: border-box;
}
.header *, .header *::before, .header *::after { box-sizing: border-box; }

.header-content {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: 8px;
  height: var(--header-height);
  padding: 0 var(--header-page-gutter);
  direction: ltr; /* fixes physical left/center/right slots */
}
.header-content > * { direction: rtl; }

/* ---- back (left) ---- */
.header .back-button {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--header-primary);
  color: var(--header-foreground);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: background-color .12s, transform .08s;
}
.header .back-button:hover { background-color: var(--header-primary-strong); transform: translateY(-1px); }
.header .back-button .icon { width: 16px; height: 16px; flex-shrink: 0; color: var(--header-foreground); }
.header .back-button .back-label { color: inherit; }

/* ---- logo (center) ---- */
.header .logo-section {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.header .logo-section:hover .logo-icon { opacity: .9; }
.header .logo-icon {
  display: flex;
  height: 32px;
  width: 32px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border-radius: var(--header-radius);
  background-color: var(--header-primary);
}
.header .logo-icon .icon { height: 16px; width: 16px; color: var(--header-foreground); }
.header .logo-text {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--header-foreground);
}

/* ---- user (right) ---- */
.header .user-dropdown {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  position: relative;
}
.header .user-button {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: var(--header-radius);
  cursor: pointer;
  transition: background-color .2s;
  color: var(--header-foreground);
  font-family: inherit;
}
.header .user-button:hover { background-color: var(--header-muted); }
.header .user-name { font-size: 14px; font-weight: 500; color: var(--header-foreground); }
.header .avatar {
  height: 32px;
  width: 32px;
  border-radius: 50%;
  background-color: var(--header-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.header .avatar-image { width: 100%; height: 100%; object-fit: cover; }
.header .avatar-icon { height: 16px; width: 16px; color: var(--header-muted-foreground); }

.header .dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  left: auto;
  width: 192px;
  max-width: calc(100vw - 24px);
  background-color: rgb(46, 46, 46);
  border: 1px solid var(--header-border);
  border-radius: var(--header-radius);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, .1);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all .2s;
  z-index: 100;
}
.header .dropdown-menu.show { opacity: 1; visibility: visible; transform: translateY(0); }
.header .dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--header-foreground);
  transition: background-color .2s;
}
.header .dropdown-item:hover { background-color: var(--header-muted); }
.header .dropdown-item.logout { color: var(--header-destructive); }
.header .dropdown-item.logout:hover { background-color: rgba(220, 38, 38, .1); }
.header .dropdown-icon { height: 16px; width: 16px; }

/* ---- mobile: logo/title hidden, back left, user right ---- */
@media (max-width: 640px) {
  :root { --header-page-gutter: 12px; --header-height: 56px; }
  .header .logo-section { display: none; }
  .header .back-button { padding: 8px 10px; font-size: 13px; }
  .header .user-button { gap: 8px; padding: 6px 8px; }
  .header .user-name { font-size: 12px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .header .avatar { height: 28px; width: 28px; }
}
@media (max-width: 360px) {
  .header .user-name { max-width: 70px; }
}

/* anonymous pages (login/OTP/...): logo-only bar, keep logo visible on mobile */
.header.header-anon .logo-section { display: flex; }
@media (max-width: 640px) {
  .header.header-anon .logo-text { font-size: 15px; }
  .header.header-anon .logo-icon { height: 28px; width: 28px; border-radius: 8px; }
}
.header .back-button.login-link { grid-column: 3; grid-row: 1; justify-self: end; }

/* ---- Standalone page shell ----
   For pages whose <body> centers a card: add class "with-header" to <body>
   and wrap the old body content in <div class="header-page-center">. */
body.with-header { display: block !important; padding: 0 !important; height: auto !important; min-height: 100vh; }
.header-page-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  min-height: calc(100vh - var(--header-height));
}
@media (max-width: 640px) {
  .header-page-center { padding: 12px; min-height: calc(100vh - var(--header-height)); }
}
