/* ===== CSS VARIABLES — night (default) ===== */
.app-inner {
  --gold:      #C9A850;
  --t1:        rgba(255,255,255,0.90);
  --t2:        rgba(255,255,255,0.65);
  --t3:        rgba(255,255,255,0.50);
  --t4:        rgba(255,255,255,0.35);
  --t5:        rgba(255,255,255,0.25);
  --glass:     rgba(255,255,255,0.055);
  --glass-mid: rgba(255,255,255,0.07);
  --glass-lo:  rgba(255,255,255,0.04);
  --bd1:       rgba(255,255,255,0.11);
  --bd2:       rgba(255,255,255,0.07);
}

/* ===== CSS VARIABLES — day mode ===== */
body[data-theme="day"] .app-inner {
  --gold:      #7a5c00;
  --t1:        rgba(0,0,0,0.85);
  --t2:        rgba(0,0,0,0.68);
  --t3:        rgba(0,0,0,0.52);
  --t4:        rgba(0,0,0,0.40);
  --t5:        rgba(0,0,0,0.28);
  --glass:     rgba(255,255,255,0.62);
  --glass-mid: rgba(255,255,255,0.50);
  --glass-lo:  rgba(255,255,255,0.30);
  --bd1:       rgba(0,0,0,0.11);
  --bd2:       rgba(0,0,0,0.07);
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* NIGHT mode body (default) */
body {
  background: #070F18;
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  font-family: Georgia, serif;
  transition: background .3s;
}
/* DAY mode body — fixes the black outside area */
body[data-theme="day"] {
  background: #d8d0c0;
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(201,168,80,0.2); border-radius: 4px; }

#root { width: 100%; max-width: 1160px; }

/* ===== APP SHELL ===== */
.app {
  min-height: calc(100vh - 40px);
}
.app-inner {
  display: flex;
  min-height: calc(100vh - 40px);
  background: linear-gradient(145deg, #08131E 0%, #091D16 60%, #0C1F10 100%);
  border-radius: 22px;
  overflow: hidden;
  position: relative;
  border: 1px solid rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.85);
  transition: background .3s, color .3s;
  transform-origin: top left;
}

/* ===== DAY MODE — app-inner ===== */
body[data-theme="day"] .app-inner {
  background: linear-gradient(145deg, #f5f0e6 0%, #edf4e8 60%, #e4eed8 100%);
  border-color: rgba(0,0,0,0.08);
  color: rgba(0,0,0,0.82);
}
body[data-theme="day"] .geo { opacity: .1; filter: invert(1) sepia(1); }

/* ===== GEOMETRIC BACKGROUND ===== */
.geo { position: absolute; inset: 0; pointer-events: none; opacity: .4; }

/* ===== SIDEBAR ===== */
.side {
  position: relative;
  z-index: 20;
  width: 72px;
  flex-shrink: 0;
  background: rgba(255,255,255,0.03);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border-right: 1px solid rgba(255,255,255,0.07);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 4px;
  transition: background .3s, border-color .3s;
}
body[data-theme="day"] .side {
  background: rgba(255,255,255,0.45);
  border-right-color: rgba(0,0,0,0.08);
}

.logo { color: #C9A850; font-size: 10px; letter-spacing: 3px; margin-bottom: 12px; text-align: center; }
.logo-ar { font-size: 22px; color: #C9A850; margin-bottom: 3px; display: block; }
body[data-theme="day"] .logo,
body[data-theme="day"] .logo-ar { color: #7a5c00; }

.divider { width: 30px; height: 1px; background: rgba(201,168,80,0.2); margin-bottom: 8px; }
body[data-theme="day"] .divider { background: rgba(120,90,0,0.2); }

.nav {
  width: 52px; height: 48px; border-radius: 13px;
  border: 1px solid transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; background: transparent; color: rgba(255,255,255,0.3); transition: all .25s;
}
.nav.on  { background: rgba(201,168,80,0.1); border-color: rgba(201,168,80,0.28); color: #C9A850; }
.nav:hover:not(.on) { background: rgba(255,255,255,0.05); color: rgba(255,255,255,0.65); }
.nav .ic { font-size: 16px; line-height: 1; }
.nav .lb { font-size: 7px; letter-spacing: .6px; text-transform: uppercase; }
body[data-theme="day"] .nav { color: rgba(0,0,0,0.35); }
body[data-theme="day"] .nav.on { background: rgba(201,168,80,0.15); border-color: rgba(150,110,0,0.4); color: #7a5c00; }
body[data-theme="day"] .nav:hover:not(.on) { background: rgba(0,0,0,0.05); color: rgba(0,0,0,0.6); }

/* ── Side controls ── */
.side-controls { display: flex; flex-direction: column; align-items: center; gap: 6px; padding-bottom: 8px; }
.ctrl-btn {
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.13);
  background: transparent; color: rgba(255,255,255,0.45);
  cursor: pointer; font-size: 13px; font-family: Georgia, serif;
  display: flex; align-items: center; justify-content: center;
  transition: all .2s; letter-spacing: -.5px;
}
.ctrl-btn:hover:not(.disabled) { background: rgba(255,255,255,0.07); color: rgba(255,255,255,0.8); }
.ctrl-btn.disabled { opacity: .25; cursor: default; }
.ctrl-btn.theme-btn { font-size: 17px; border-color: rgba(201,168,80,0.25); color: rgba(201,168,80,0.6); }
.ctrl-btn.theme-btn:hover { background: rgba(201,168,80,0.1); color: #C9A850; }
body[data-theme="day"] .ctrl-btn { border-color: rgba(0,0,0,0.12); color: rgba(0,0,0,0.45); }
body[data-theme="day"] .ctrl-btn:hover:not(.disabled) { background: rgba(0,0,0,0.06); color: rgba(0,0,0,0.7); }
body[data-theme="day"] .ctrl-btn.theme-btn { border-color: rgba(120,90,0,0.3); color: #7a5c00; }

/* ===== MAIN CONTENT ===== */
.main { position: relative; z-index: 10; flex: 1; overflow-y: auto; padding: 22px; }

.hdr { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid rgba(255,255,255,0.06); }
body[data-theme="day"] .hdr { border-bottom-color: rgba(0,0,0,0.08); }

.hdr h1 { font-size: 18px; font-weight: 400; color: rgba(255,255,255,0.93); margin: 0; display: inline; }
body[data-theme="day"] .hdr h1 { color: rgba(0,0,0,0.82); }

.hdr-ar { font-size: 16px; color: #C9A850; direction: rtl; margin-left: 12px; }
body[data-theme="day"] .hdr-ar { color: #7a5c00; }

.hdr-sub { font-size: 10.5px; color: rgba(255,255,255,0.35); margin: 6px 0 10px; }
body[data-theme="day"] .hdr-sub { color: rgba(0,0,0,0.42); }

.madhab-legend { display: flex; gap: 14px; flex-wrap: wrap; }

/* ===== GLASS PANEL ===== */
.glass {
  background: rgba(255,255,255,0.055);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 16px;
}
.glass-gold { border-color: rgba(201,168,80,0.28) !important; }
body[data-theme="day"] .glass { background: rgba(255,255,255,0.6); border-color: rgba(0,0,0,0.1); }
body[data-theme="day"] .glass-gold { border-color: rgba(150,110,0,0.3) !important; }

/* ===== TOPIC LIST ===== */
.topic-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 13px; cursor: pointer; transition: background .15s;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.topic-row:last-child { border-bottom: none; }
.topic-row:hover { background: rgba(255,255,255,0.03); }
body[data-theme="day"] .topic-row { border-bottom-color: rgba(0,0,0,0.06); }
body[data-theme="day"] .topic-row:hover { background: rgba(0,0,0,0.03); }

/* ===== CATEGORY PILLS ===== */
.cats-wrap { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.cat-pill {
  padding: 5px 12px; border-radius: 20px; font-size: 9.5px; cursor: pointer;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04); color: rgba(255,255,255,0.5); transition: all .15s;
  font-family: Georgia, serif;
}
.cat-pill.on { background: rgba(201,168,80,0.12); border-color: rgba(201,168,80,0.35); color: #C9A850; }
body[data-theme="day"] .cat-pill { background: rgba(255,255,255,0.55); border-color: rgba(0,0,0,0.12); color: rgba(0,0,0,0.5); }
body[data-theme="day"] .cat-pill.on { background: rgba(201,168,80,0.18); border-color: rgba(150,110,0,0.4); color: #7a5c00; }

/* ===== ARABIC RULING ===== */
.ar-ruling {
  font-family: Georgia, serif; font-size: 12.5px; line-height: 2;
  color: rgba(201,168,80,0.88); direction: rtl; text-align: right;
  padding: 9px 11px; background: rgba(201,168,80,0.05);
  border-radius: 8px; margin-bottom: 8px; border-right: 2px solid rgba(201,168,80,0.25);
}
body[data-theme="day"] .ar-ruling { background: rgba(201,168,80,0.1); border-right-color: rgba(150,110,0,0.35); color: #7a5c00; }

.en-ruling { font-size: 11.5px; line-height: 1.85; color: rgba(255,255,255,0.62); font-family: Georgia, serif; }
body[data-theme="day"] .en-ruling { color: rgba(0,0,0,0.65); }

/* ===== LANG TOGGLE ===== */
.lang-btn {
  font-size: 8px; padding: 2px 7px; border-radius: 9px;
  border-width: 1px; border-style: solid; background: transparent;
  cursor: pointer; opacity: .7; transition: opacity .15s; font-family: Georgia, serif;
}
.lang-btn:hover { opacity: 1; }
body[data-theme="day"] .lang-btn { color: rgba(0,0,0,0.45) !important; }

/* ===== MADHAB CARD text ===== */
body[data-theme="day"] .madhab-card-name { color: inherit; }

/* ===== AI CHAT ===== */
.ai-area {
  width: 100%; padding: 10px 14px;
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 11px; font-size: 13px; color: rgba(255,255,255,0.88);
  resize: none; font-family: Georgia, serif;
}
.ai-area:focus { outline: none; border-color: rgba(201,168,80,0.38); }
.ai-area::placeholder { color: rgba(255,255,255,0.28); }
body[data-theme="day"] .ai-area { background: rgba(255,255,255,0.7); border-color: rgba(0,0,0,0.12); color: rgba(0,0,0,0.85); }
body[data-theme="day"] .ai-area::placeholder { color: rgba(0,0,0,0.3); }

.send {
  padding: 10px 18px; background: rgba(201,168,80,0.13);
  border: 1px solid rgba(201,168,80,0.32); border-radius: 11px;
  color: #C9A850; cursor: pointer; font-size: 12px; transition: all .15s;
  white-space: nowrap; font-family: Georgia, serif;
}
.send:hover { background: rgba(201,168,80,0.22); }
.send:disabled { opacity: .35; cursor: default; }
body[data-theme="day"] .send { background: rgba(201,168,80,0.18); border-color: rgba(150,110,0,0.4); color: #7a5c00; }
body[data-theme="day"] .send:hover { background: rgba(201,168,80,0.3); }

.msg-user { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.msg-user-bubble {
  background: rgba(201,168,80,0.1); border: 1px solid rgba(201,168,80,0.2);
  border-radius: 12px; padding: 8px 13px; max-width: 82%;
  font-size: 12.5px; color: rgba(255,255,255,0.85); line-height: 1.6; font-family: Georgia, serif;
}
body[data-theme="day"] .msg-user-bubble { background: rgba(201,168,80,0.12); border-color: rgba(150,110,0,0.2); color: rgba(0,0,0,0.8); }

.msg-ai { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 10px; }
.ai-avatar {
  width: 26px; height: 26px; border-radius: 8px;
  background: rgba(201,168,80,0.08); border: 1px solid rgba(201,168,80,0.18);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #C9A850; flex-shrink: 0;
}
body[data-theme="day"] .ai-avatar { background: rgba(201,168,80,0.15); border-color: rgba(150,110,0,0.3); color: #7a5c00; }
.msg-ai p { margin: 0 0 5px; font-size: 12.5px; line-height: 1.85; color: rgba(255,255,255,0.78); font-family: Georgia, serif; }
body[data-theme="day"] .msg-ai p { color: rgba(0,0,0,0.72); }

/* ===== SUGGESTION BUTTONS ===== */
.sbtn {
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px; cursor: pointer; color: rgba(255,255,255,0.5); transition: all .15s;
  font-family: Georgia, serif;
}
.sbtn:hover { background: rgba(255,255,255,0.09); color: rgba(255,255,255,0.75); }
body[data-theme="day"] .sbtn { background: rgba(255,255,255,0.55); border-color: rgba(0,0,0,0.1); color: rgba(0,0,0,0.5); }
body[data-theme="day"] .sbtn:hover { background: rgba(255,255,255,0.85); color: rgba(0,0,0,0.7); }

/* ===== BACK BUTTON ===== */
.back {
  color: #C9A850; background: none; border: none; cursor: pointer;
  font-size: 12px; display: flex; align-items: center; gap: 5px;
  margin-bottom: 14px; padding: 0; font-family: Georgia, serif;
}
body[data-theme="day"] .back { color: #7a5c00; }

/* ===== SEARCH ===== */
.srch {
  width: 100%; padding: 11px 15px;
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px; font-size: 13px; color: rgba(255,255,255,0.88); font-family: Georgia, serif;
}
.srch:focus { outline: none; border-color: rgba(201,168,80,0.38); }
.srch::placeholder { color: rgba(255,255,255,0.28); }
body[data-theme="day"] .srch { background: rgba(255,255,255,0.7); border-color: rgba(0,0,0,0.12); color: rgba(0,0,0,0.85); }
body[data-theme="day"] .srch::placeholder { color: rgba(0,0,0,0.3); }

/* ===== EXPAND PANEL ===== */
.expand-panel { padding: 10px 13px 14px; background: rgba(255,255,255,0.018); border-bottom: 1px solid rgba(255,255,255,0.04); }
body[data-theme="day"] .expand-panel { background: rgba(0,0,0,0.02); border-bottom-color: rgba(0,0,0,0.06); }

/* ===== COMPARE ===== */
.compare-layout { display: grid; grid-template-columns: 200px 1fr; gap: 14px; min-height: 540px; }
.compare-topic-list { padding: 8px; overflow-y: auto; max-height: 680px; }
.compare-topic-item {
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
  margin-bottom: 1px; transition: all .15s;
  border-left: 2px solid transparent;
}
.compare-topic-item.sel { background: rgba(201,168,80,0.07); border-left-color: #C9A850; }
.compare-topic-item:hover:not(.sel) { background: rgba(255,255,255,0.03); }
body[data-theme="day"] .compare-topic-item.sel { background: rgba(201,168,80,0.12); border-left-color: #8a6a00; }
body[data-theme="day"] .compare-topic-item:hover:not(.sel) { background: rgba(0,0,0,0.03); }

/* ===== TEXT HELPERS ===== */
.topic-ar { font-family: Georgia,serif; font-size: 15px; color: #C9A850; direction: rtl; }
body[data-theme="day"] .topic-ar { color: #7a5c00; }
.topic-tr { font-size: 9.5px; color: rgba(255,255,255,0.3); font-style: italic; letter-spacing: .3px; }
body[data-theme="day"] .topic-tr { color: rgba(0,0,0,0.35); }
.text-gold { color: #C9A850; }
body[data-theme="day"] .text-gold { color: #7a5c00; }
.text-muted { color: rgba(255,255,255,0.38); }
body[data-theme="day"] .text-muted { color: rgba(0,0,0,0.4); }
.text-secondary { color: rgba(255,255,255,0.55); }
body[data-theme="day"] .text-secondary { color: rgba(0,0,0,0.55); }

/* ===== SCHOLAR ===== */
.scholar-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.scholar-detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.scholar-meta-cell { padding: 7px 9px; background: rgba(255,255,255,0.04); border-radius: 8px; }
body[data-theme="day"] .scholar-meta-cell { background: rgba(0,0,0,0.04); }

/* ===== STAT PILL ===== */
.stat-pill { font-size: 9.5px; padding: 3px 10px; border-radius: 20px; background: rgba(255,255,255,0.05); color: rgba(255,255,255,0.38); flex-shrink: 0; }
body[data-theme="day"] .stat-pill { background: rgba(0,0,0,0.05); color: rgba(0,0,0,0.4); }

/* ===== ANIMATIONS ===== */
@keyframes fadein { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:translateY(0)} }
.fadein { animation: fadein .3s ease; }

/* Ruling grid */
.ruling-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
