/* ==========================================================================
   AX Book — design system
   --------------------------------------------------------------------------
   Direction: "Majlis" — a warm ink-plum ground with a saffron-gold accent.
   Not cream+serif+terracotta, not near-black+neon, not a purple gradient hero.
   Gold and deep jewel tones read naturally for an Arabic/Pakistani audience
   without leaning on any single cliché. Two purpose-built Arabic/Latin
   faces (Changa for display, Cairo for body) so a bdi()-wrapped Arabic name
   sitting next to a Latin @handle actually looks designed, not tolerated.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Changa:wght@500;600;700;800&family=Cairo:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ---------- tokens: light (base) ---------- */
:root{
  --bg:            #f5f0f4;
  --bg-elevated:   #ffffff;
  --surface:       #ffffff;
  --surface-hover: #f1e7ef;
  --border:        #e1d0df;
  --text:          #241a2b;
  --text-muted:    #6d5d75;
  --text-faint:    #9c8ba4;

  --accent:        #a8630f;
  --accent-hover:  #c17716;
  --accent-text:   #ffffff;

  --success:       #1f8f5f;
  --warning:       #9c6b00;
  --danger:        #c23a4b;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --font-display: 'Changa', 'Segoe UI', Tahoma, Geneva, sans-serif;
  --font-body:    'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --shadow-sm: 0 1px 2px rgba(36,26,43,.09), 0 1px 1px rgba(36,26,43,.05);
  --shadow-md: 0 10px 28px rgba(36,26,43,.12), 0 2px 8px rgba(36,26,43,.06);

  color-scheme: light;
}

/* ---------- tokens: system dark (only when no explicit choice) ---------- */
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:            #19121e;
    --bg-elevated:   #201725;
    --surface:       #241a2b;
    --surface-hover: #2d2135;
    --border:        #3a2c43;
    --text:          #f3e9f4;
    --text-muted:    #b6a3bf;
    --text-faint:    #7c6a86;

    --accent:        #f5a83c;
    --accent-hover:  #ffbf66;
    --accent-text:   #221722;

    --success:       #4fd393;
    --warning:       #e0a940;
    --danger:        #f2687a;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 14px 32px rgba(0,0,0,.5), 0 2px 8px rgba(0,0,0,.35);

    color-scheme: dark;
  }
}

/* ---------- tokens: explicit toggle wins both directions ---------- */
:root[data-theme="dark"]{
  --bg:            #19121e;
  --bg-elevated:   #201725;
  --surface:       #241a2b;
  --surface-hover: #2d2135;
  --border:        #3a2c43;
  --text:          #f3e9f4;
  --text-muted:    #b6a3bf;
  --text-faint:    #7c6a86;

  --accent:        #f5a83c;
  --accent-hover:  #ffbf66;
  --accent-text:   #221722;

  --success:       #4fd393;
  --warning:       #e0a940;
  --danger:        #f2687a;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 14px 32px rgba(0,0,0,.5), 0 2px 8px rgba(0,0,0,.35);

  color-scheme: dark;
}
:root[data-theme="light"]{
  --bg:            #f5f0f4;
  --bg-elevated:   #ffffff;
  --surface:       #ffffff;
  --surface-hover: #f1e7ef;
  --border:        #e1d0df;
  --text:          #241a2b;
  --text-muted:    #6d5d75;
  --text-faint:    #9c8ba4;

  --accent:        #a8630f;
  --accent-hover:  #c17716;
  --accent-text:   #ffffff;

  --success:       #1f8f5f;
  --warning:       #9c6b00;
  --danger:        #c23a4b;

  --shadow-sm: 0 1px 2px rgba(36,26,43,.09), 0 1px 1px rgba(36,26,43,.05);
  --shadow-md: 0 10px 28px rgba(36,26,43,.12), 0 2px 8px rgba(36,26,43,.06);

  color-scheme: light;
}

/* ==========================================================================
   base
   ========================================================================== */
*{ box-sizing: border-box; }
html{ background: var(--bg); }
body{
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a{ color: var(--accent); text-decoration: none; }
a:hover{ text-decoration: underline; }
button{ font: inherit; color: inherit; }
::selection{ background: color-mix(in srgb, var(--accent) 35%, transparent); }
.hide{ display: none !important; }

:focus-visible{
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::-webkit-scrollbar{ width: 10px; height: 10px; }
::-webkit-scrollbar-track{ background: transparent; }
::-webkit-scrollbar-thumb{ background: var(--border); border-radius: 99px; border: 2px solid transparent; background-clip: padding-box; }

/* ==========================================================================
   utility layout primitives
   ========================================================================== */
.row{ display: flex; align-items: center; gap: var(--space-2); }
.stack{ display: flex; flex-direction: column; gap: var(--space-3); }
.divider{ border: none; border-top: 1px solid var(--border); margin: var(--space-4) 0; }
.grow{ flex: 1; }

.grid-media{
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: var(--space-2);
}

/* ==========================================================================
   header / shell
   ========================================================================== */
header{
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--space-4);
  padding: 10px 20px;
}
.brand{
  font-family: var(--font-display);
  font-weight: 700; font-size: 21px; letter-spacing: .2px;
  color: var(--accent);
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap;
}

.search{ width: 280px; max-width: 40vw; }

/* ==========================================================================
   buttons
   ========================================================================== */
.btn{
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 9px 20px;
  font-weight: 700; font-size: 14px;
  cursor: pointer;
  background: var(--surface-hover);
  color: var(--text);
  transition: transform .12s ease, background-color .15s ease, border-color .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.btn:hover{ background: var(--border); }
.btn:active{ transform: scale(.96); }
.btn:disabled{ opacity: .5; cursor: default; transform: none; }
.btn-sm{ padding: 6px 14px; font-size: 13px; }

.btn-primary{
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover{ background: var(--accent-hover); }

.btn-ghost{
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover{ background: var(--surface-hover); color: var(--text); border-color: var(--accent); }

.btn-danger{
  background: transparent;
  border-color: var(--border);
  color: var(--danger);
}
.btn-danger:hover{ background: color-mix(in srgb, var(--danger) 12%, transparent); border-color: var(--danger); }

.btn-icon{
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; padding: 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-hover);
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease, transform .12s ease;
}
.btn-icon:hover{ border-color: var(--accent); color: var(--accent); }
.btn-icon:active{ transform: scale(.94); }

/* ==========================================================================
   surfaces / cards
   ========================================================================== */
.surface{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-sm);
  animation: card-in .28s ease both;
}
@keyframes card-in{
  from{ opacity: 0; transform: translateY(6px); }
  to{ opacity: 1; transform: translateY(0); }
}

.pill{
  display: inline-flex; align-items: center;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 11px;
  font-size: 12px;
  color: var(--text-muted);
}
.pill-accent{ color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.badge{
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--danger); color: #fff;
  border-radius: 999px; font-size: 11px; font-weight: 700; line-height: 1;
}
.badge-float{ position: absolute; top: -5px; right: -5px; }

/* ==========================================================================
   avatar
   ========================================================================== */
.avatar, .av{
  width: 40px; height: 40px; flex: none;
  border-radius: 50%;
  background: linear-gradient(155deg, var(--surface-hover), var(--surface));
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; color: var(--accent);
  overflow: hidden;
}
.avatar img, .av img{ width: 100%; height: 100%; object-fit: cover; }
.avatar-sm, .av.sm{ width: 30px; height: 30px; font-size: 12px; }
.avatar-lg, .av.lg{ width: 80px; height: 80px; font-size: 28px; border-width: 2px; }

/* ==========================================================================
   tabs
   ========================================================================== */
.tab-bar, .tabs{
  display: flex; gap: 6px; margin-bottom: var(--space-4);
  overflow-x: auto;
}
.tab{
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  font-size: 13.5px; font-weight: 600;
  white-space: nowrap;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.tab:hover{ border-color: var(--accent); color: var(--text); }
.tab.on{ background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* ==========================================================================
   inputs
   ========================================================================== */
.input, .textarea, .select,
input[type=text], input[type=search], input[type=password], input[type=email],
textarea, select{
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.textarea, textarea{ resize: vertical; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus,
input:focus, textarea:focus, select:focus{
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.input::placeholder, .textarea::placeholder, textarea::placeholder, input::placeholder{
  color: var(--text-faint);
}
input[type=checkbox]{ accent-color: var(--accent); width: 15px; height: 15px; }

/* ==========================================================================
   empty state / skeleton
   ========================================================================== */
.empty-state{
  text-align: center;
  padding: var(--space-6) var(--space-4);
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  font-size: 14px;
}

.skeleton{
  position: relative;
  overflow: hidden;
  background: var(--surface-hover);
  border-radius: var(--radius-sm);
}
.skeleton::after{
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 8%, transparent), transparent);
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
@keyframes skeleton-shimmer{
  0%{ transform: translateX(-100%); }
  100%{ transform: translateX(100%); }
}
.skeleton-card{ height: 96px; border-radius: var(--radius-lg); margin-bottom: var(--space-3); }
.skeleton-line{ height: 12px; border-radius: 6px; margin: 6px 0; }
.skeleton-line.w60{ width: 60%; }
.skeleton-line.w40{ width: 40%; }

/* ==========================================================================
   modal
   ========================================================================== */
.modal-backdrop, .pickwrap, .lightbox{
  position: fixed; inset: 0; z-index: 70;
  background: color-mix(in srgb, #000 70%, transparent);
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
  animation: fade-in .15s ease both;
}
.lightbox{ cursor: zoom-out; background: color-mix(in srgb, #000 90%, transparent); }
.lightbox img{ max-width: 94vw; max-height: 94vh; border-radius: var(--radius-md); }

.modal, .pick{
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: min(720px, 100%);
  max-height: 86vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: var(--shadow-md);
  animation: modal-in .2s cubic-bezier(.2,.8,.3,1) both;
}
@keyframes fade-in{ from{ opacity: 0 } to{ opacity: 1 } }
@keyframes modal-in{ from{ opacity: 0; transform: translateY(10px) scale(.98); } to{ opacity: 1; transform: translateY(0) scale(1); } }

.pick .ph{ display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.pick .ph b{ font-family: var(--font-display); font-size: 15px; }
.pick .pg{ padding: var(--space-3); overflow: auto; }
.pick .pi{ position: relative; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); cursor: pointer; background: var(--surface-hover); transition: transform .12s ease; }
.pick .pi:hover{ border-color: var(--accent); transform: scale(1.02); }
.pick .pi img{ width: 100%; height: 100%; object-fit: cover; display: block; }
.pick .pi .cap{ position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 6px; font-size: 10.5px; background: color-mix(in srgb, #000 60%, transparent); color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick .pf{ padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pick .note{ padding: var(--space-6) var(--space-4); text-align: center; color: var(--text-muted); font-size: 13.5px; line-height: 1.6; }

/* ==========================================================================
   app shell layout
   ========================================================================== */
.wrap{
  max-width: 1180px; margin: 0 auto;
  display: grid; grid-template-columns: 224px 1fr; gap: var(--space-5);
  padding: var(--space-5) 18px 90px;
}
nav.side{
  display: flex; flex-direction: column; gap: 2px;
  align-self: start; position: sticky; top: 76px;
}
.navitem{
  background: none; border: 1px solid transparent;
  color: var(--text-muted);
  text-align: left;
  padding: 10px 13px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14.5px; font-weight: 600;
  display: flex; align-items: center; gap: 10px;
  transition: background-color .15s ease, color .15s ease;
}
.navitem:hover{ background: var(--surface-hover); color: var(--text); }
.navitem.on{ background: var(--surface); border-color: var(--border); color: var(--accent); box-shadow: var(--shadow-sm); }
.navitem .nav-icon{ font-size: 17px; line-height: 1; }
.navitem .n, .navitem .badge{ margin-left: auto; }

@media (max-width: 860px){
  .wrap{ grid-template-columns: 1fr; padding-bottom: 84px; }
  nav.side{
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 30;
    flex-direction: row; justify-content: space-around; gap: 0;
    background: color-mix(in srgb, var(--bg-elevated) 96%, transparent);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .navitem{
    flex-direction: column; gap: 2px; flex: 1;
    padding: 6px 2px; border-radius: var(--radius-sm); font-size: 10.5px;
  }
  .navitem .nav-icon{ font-size: 20px; }
  .navitem.on{ box-shadow: none; }
  .chat .threads.busy{ display: none; }
}

/* ==========================================================================
   post card
   ========================================================================== */
.post{ display: flex; gap: var(--space-3); }
.pbody{ flex: 1; min-width: 0; }
.name{ font-family: var(--font-display); font-weight: 700; color: var(--text); }
.handle{ color: var(--text-muted); font-size: 13px; font-family: var(--font-mono); }
.ptext{ white-space: pre-wrap; word-wrap: break-word; margin: 6px 0 0; }
.pimg{
  margin-top: var(--space-3); border-radius: var(--radius-md); border: 1px solid var(--border);
  max-height: 440px; max-width: 100%; display: block; cursor: zoom-in;
  transition: opacity .15s ease;
}
.pimg:hover{ opacity: .94; }
.acts{ display: flex; gap: 2px; margin-top: var(--space-3); flex-wrap: wrap; }
.act{
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 6px 10px; border-radius: 999px; font-size: 13px;
  transition: background-color .15s ease, color .15s ease;
}
.act:hover{ background: var(--surface-hover); color: var(--text); }
.act.on{ color: var(--danger); }
.quoted{
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 10px 13px; margin-top: var(--space-3); background: var(--bg);
}
.pin{ color: var(--warning); font-size: 12px; font-weight: 700; }

/* ==========================================================================
   chat
   ========================================================================== */
.chat{
  display: grid; grid-template-columns: 260px 1fr; gap: 0; height: 72vh;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden; box-shadow: var(--shadow-sm);
}
.threads{ border-right: 1px solid var(--border); overflow-y: auto; }
.thread{
  padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
  display: flex; gap: 9px; align-items: center;
  transition: background-color .15s ease;
}
.thread:hover{ background: var(--surface-hover); }
.thread.on{ background: var(--surface-hover); }
.msgs{ display: flex; flex-direction: column; height: 100%; }
.mlist{ flex: 1; overflow-y: auto; padding: var(--space-4); display: flex; flex-direction: column; gap: 8px; }
.bubble{
  max-width: 76%; padding: 9px 13px; border-radius: 16px 16px 16px 4px;
  background: var(--bg); border: 1px solid var(--border);
  align-self: flex-start; white-space: pre-wrap; word-wrap: break-word;
}
.bubble.me{
  align-self: flex-end; border-radius: 16px 16px 4px 16px;
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
.bubble .t{ display: block; font-size: 11px; color: var(--text-faint); margin-top: 3px; font-family: var(--font-mono); }
.mform{ display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.mform input{ flex: 1; }

/* ==========================================================================
   toast
   ========================================================================== */
.toast{
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 18px; z-index: 90; box-shadow: var(--shadow-md);
  font-size: 14px; font-weight: 600;
  animation: toast-in .22s cubic-bezier(.2,.8,.3,1) both;
}
@keyframes toast-in{
  from{ opacity: 0; transform: translate(-50%, 14px); }
  to{ opacity: 1; transform: translate(-50%, 0); }
}

/* ==========================================================================
   gate
   ========================================================================== */
.gate{ max-width: 460px; margin: 16vh auto; text-align: center; }

/* ==========================================================================
   tables (admin)
   ========================================================================== */
table{ width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td{ text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th{ color: var(--text-muted); font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; }

/* ==========================================================================
   misc utility classes referenced from the page
   ========================================================================== */
.muted{ color: var(--text-muted); font-size: 13.5px; }

/* ==========================================================================
   reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
