/* ذكاء الهجدة — تصميم Grok Dark Gold */

:root {
  --bg: #0c0b10;
  --bg-2: #14131a;
  --bg-3: #1b1a22;
  --gold: #c9a46a;
  --gold-dim: #9a7a45;
  --cream: #f3efe6;
  --muted: #9b958a;
  --line: rgba(201, 164, 106, 0.16);
  --danger: #c45c5c;
  --ok: #3d9a6a;
  --font: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --sidebar-w: 280px;
  --top-h: 56px;
  --composer-min: 52px;
  --radius: 14px;
  --radius-pill: 999px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  font-variant-numeric: lining-nums;
  background: var(--bg);
  color: var(--cream);
  -webkit-font-smoothing: antialiased;
}

body.chat-app {
  overflow: hidden;
}

.skip-link {
  position: absolute;
  top: -100px;
  right: 1rem;
  z-index: 10000;
  background: var(--gold);
  color: #1a140c;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  font-weight: 700;
  text-decoration: none;
}
.skip-link:focus { top: 1rem; }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
  height: 100vh;
}

/* ===== Sidebar (RTL: يمين) ===== */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-inline-start: 1px solid var(--line);
  min-height: 0;
}

.sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--cream);
  min-width: 0;
}

.sidebar__mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--gold);
}

.sidebar__brand strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.2;
}

.sidebar__brand small {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
}

.sidebar__toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--cream);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
}

.btn-new {
  margin: 0.75rem 1rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  width: calc(100% - 2rem);
  padding: 0.65rem 1rem;
  border-radius: var(--radius);
  border: 1px dashed var(--line);
  background: rgba(201, 164, 106, 0.06);
  color: var(--cream);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.btn-new:hover {
  border-color: var(--gold-dim);
  background: rgba(201, 164, 106, 0.12);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.35rem 0.65rem 0.75rem;
  list-style: none;
  margin: 0;
}

.chat-list__empty {
  padding: 1.25rem 0.75rem;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  line-height: 1.6;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.25rem;
}

.chat-item__btn {
  flex: 1;
  min-width: 0;
  text-align: start;
  padding: 0.55rem 0.75rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--cream);
  font-family: inherit;
  font-size: 0.84rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s, border-color 0.12s;
}
.chat-item__btn:hover {
  background: var(--bg-3);
}
.chat-item.is-active .chat-item__btn {
  background: rgba(201, 164, 106, 0.1);
  border-color: var(--line);
}

.chat-item__del {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s;
}
.chat-item:hover .chat-item__del,
.chat-item__del:focus-visible { opacity: 1; }
.chat-item__del:hover { color: var(--danger); }

.sidebar__foot {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar__foot a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.78rem;
  padding: 0.35rem 0;
}
.sidebar__foot a:hover { color: var(--gold); }

.model-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  background: var(--bg-3);
}
.model-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}
.model-pill.is-ok .dot { background: var(--ok); }
.model-pill.is-bad .dot { background: var(--danger); }

/* ===== Main ===== */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(ellipse 70% 45% at 50% -15%, rgba(201, 164, 106, 0.07), transparent 55%),
    var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  height: var(--top-h);
  padding: 0 1rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.topbar__menu {
  display: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--cream);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
}

.topbar__title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-bar {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mode-btn {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
}
.mode-btn:hover { color: var(--cream); border-color: var(--gold-dim); }
.mode-btn.is-active {
  color: #1a140c;
  background: var(--gold);
  border-color: var(--gold);
}

/* ===== Thread ===== */
.thread-wrap {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.thread {
  max-width: 780px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2rem;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1rem 4rem;
  gap: 0.35rem;
}

.hero__kicker {
  margin: 0;
  font-size: 0.88rem;
  color: var(--gold);
  letter-spacing: 0.02em;
}

.hero__title {
  margin: 0;
  font-size: clamp(2.4rem, 8vw, 3.6rem);
  font-weight: 700;
  color: var(--cream);
  line-height: 1.15;
}

.hero__sub {
  margin: 0.75rem 0 0;
  max-width: 28rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.7;
}

.hero__cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.65rem;
  width: 100%;
  max-width: 540px;
  margin-top: 2rem;
}

.hero-card {
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-2);
  text-align: start;
}
.hero-card strong {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}
.hero-card span {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.5;
}

.msg {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  animation: fadeUp 0.25s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg__avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid var(--line);
}
.msg--user .msg__avatar {
  background: var(--bg-3);
  color: var(--gold);
}
.msg--assistant .msg__avatar {
  background: rgba(201, 164, 106, 0.12);
  color: var(--gold);
}

.msg__body { flex: 1; min-width: 0; }

.msg__role {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.msg__text {
  font-size: 0.95rem;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg__text.is-streaming::after {
  content: '▍';
  animation: blink 0.9s step-end infinite;
  color: var(--gold);
}
@keyframes blink { 50% { opacity: 0; } }

.msg__attach {
  margin-top: 0.5rem;
  max-width: 280px;
  border-radius: 10px;
  border: 1px solid var(--line);
  overflow: hidden;
}
.msg__attach img {
  display: block;
  width: 100%;
  height: auto;
}
.msg__attach-name {
  padding: 0.35rem 0.5rem;
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--bg-3);
}

.msg--error .msg__text { color: var(--danger); }

/* ===== Composer ===== */
.composer-dock {
  flex-shrink: 0;
  padding: 0 1rem 1rem;
  background: linear-gradient(transparent, var(--bg) 28%);
}

.composer {
  max-width: 780px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  background: var(--bg-2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.composer__attach-preview {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--muted);
}
.composer__attach-preview.is-visible { display: flex; }

.composer__attach-preview button {
  margin-inline-start: auto;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
}

.composer__row {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
  padding: 0.5rem 0.65rem;
}

.composer__tools {
  display: flex;
  gap: 0.15rem;
  flex-shrink: 0;
}

.tool-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color 0.12s, background 0.12s;
}
.tool-btn:hover { color: var(--cream); background: var(--bg-3); }
.tool-btn.is-recording { color: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.composer__input {
  flex: 1;
  min-width: 0;
  min-height: var(--composer-min);
  max-height: 160px;
  resize: none;
  border: none;
  background: transparent;
  color: var(--cream);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  padding: 0.65rem 0.25rem;
}
.composer__input::placeholder { color: var(--muted); }
.composer__input:focus { outline: none; }

.composer__send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: var(--gold);
  color: #1a140c;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: opacity 0.12s, transform 0.12s;
}
.composer__send:hover { transform: scale(1.04); }
.composer__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.composer__hint {
  padding: 0 0.85rem 0.55rem;
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
}

.hidden-input { display: none; }

/* ===== Mobile ===== */
@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(var(--sidebar-w), 88vw);
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.22s ease;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.45);
  }
  [dir="rtl"] .sidebar {
    inset: 0 0 0 auto;
    transform: translateX(-100%);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 199;
  }
  .sidebar-backdrop.is-visible { display: block; }

  .topbar__menu,
  .sidebar__toggle { display: grid; place-items: center; }

  .mode-bar { display: none; }
  .mode-bar.is-mobile-open {
    display: flex;
    position: absolute;
    top: var(--top-h);
    left: 0;
    right: 0;
    padding: 0.5rem 1rem;
    background: var(--bg-2);
    border-bottom: 1px solid var(--line);
    z-index: 10;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
