/* =========================
   HS Minimal Glass UI (full-screen, no app corners)
   ========================= */

/* --- Design tokens --- */
:root{
  --bg: #0f1012;
  --surface: rgba(255,255,255,0.06);
  --surface-strong: rgba(255,255,255,0.10);
  --glass: rgba(22,24,28,0.55);
  --glass-strong: rgba(22,24,28,0.68);
  --text: #e8edf2;
  --muted: #b7c2cf;
  --brand: #4fc3f7;
  --brand-weak: rgba(79,195,247,.28);
  --ring: rgba(79,195,247,.22);
  --border: rgba(255,255,255,.10);
  --shadow-1: 0 10px 24px rgba(0,0,0,.28);
  --shadow-2: 0 18px 40px rgba(0,0,0,.34);
  --radius-xl: 0; /* <- kill big corners globally */
}

/* --- Base --- */
html, body { height: 100%; }
* { box-sizing: border-box; }
body{
  margin:0;
  font-family: 'Ubuntu', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  display:flex; align-items:center; justify-content:center;
}

/* ===== Optional Video Background ===== */
#bg-video{
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; z-index: -2;
  filter: saturate(1.05) contrast(1.02) brightness(0.95);
}
.bg-vignette{
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(140% 100% at 50% 0%, rgba(0,0,0,.22) 0 60%, transparent 60%),
    linear-gradient(180deg, rgba(0,0,0,.40), rgba(0,0,0,.60));
}

/* --- App container (FULL SCREEN, NO CORNERS) --- */
#container{
  display:flex;
  width: 100%;
  height: 100dvh;
  border-radius: 0;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.05);
  -webkit-backdrop-filter: blur(14px) saturate(1.05);
  border: none;
  box-shadow: none;
  overflow: hidden;
}

/* --- Sidebar --- */
#sidebar{
  width: 20%;
  background: linear-gradient(180deg, rgba(20,22,24,.72), rgba(20,22,24,.58));
  border-right: 1px solid var(--border);
  padding: 20px;
  display:flex; flex-direction:column; align-items:center;
}
#sidebar .sidebar-logo{ width: 110px; height: 54px; margin-bottom: 16px; object-fit: contain; }
.rtra-badge{
  margin-top:auto; padding: 8px 12px; border: 1px solid var(--brand-weak);
  color: var(--brand); border-radius: 999px; font-size: .85rem; display:flex; gap:8px; align-items:center; opacity:.95;
}
.rtra-badge .dot{ width:8px; height:8px; background:var(--brand); border-radius:50%; box-shadow: 0 0 6px var(--brand); }

/* --- Main content --- */
#main-content{
  width: 80%;
  padding: 20px;
  display:flex; flex-direction:column; align-items:center; justify-content:flex-start;
  height:100%; min-height:0;
}

/* Greeting */
#greeting{ text-align:center; margin: 4px 0 6px; }
#greeting .logo{ max-width: 280px; height:auto; margin-bottom: 8px; }
#greeting h1{ font-size: 1.7rem; margin: 6px 0 0; color: var(--text); }
#greeting p{ font-size: 1rem; color: var(--muted); margin: 2px 0 6px; }

/* Greeting fade/collapse */
.fade-out{ animation: hsFadeOut .35s ease forwards; }
@keyframes hsFadeOut{ to{ opacity:0; transform: translateY(-6px);} }
.collapsed{ height:0 !important; margin:0 !important; padding:0 !important; overflow:hidden !important; }
.hidden{ display:none !important; }

/* Quick buttons */
#predefined-questions{
  display:flex; justify-content:center; gap:8px; margin: 4px 0 6px; width:100%;
}
.question{
  background: transparent;
  color: var(--brand);
  padding:8px 14px; border-radius: 999px;
  border: 1.2px solid var(--brand-weak);
  font-size:.95rem; cursor:pointer;
  transition: border-color .15s ease, background .15s ease, transform .12s ease;
}
.question:hover{ border-color: var(--brand); background: rgba(79,195,247,.08); transform: translateY(-1px); }

/* Status line */
#status{
  width:100%; max-width:740px; min-height:22px; margin: 4px 0;
  font-size:.9rem; color:#9bd8ff; opacity:.95; text-align:center;
}
#status.thinking{ animation: pulseText 1.4s ease-in-out infinite; }
#status.thinking::before{ content:"Thinking…"; margin-right:10px; }
@keyframes pulseText{ 0%{opacity:.4} 50%{opacity:1} 100%{opacity:.4} }

/* Chat stream */
#chat-container{
  flex:1 1 auto; min-height:0;
  width:100%; max-width:740px; align-self:center;
  display:flex; flex-direction:column; gap:10px; align-items:flex-start;
  overflow-y:auto; padding: 8px 0;
  scrollbar-width: thin; scrollbar-color: var(--brand) transparent;
}
#chat-container::-webkit-scrollbar{ width:8px; }
#chat-container::-webkit-scrollbar-thumb{ background: var(--brand); border-radius:10px; }
#chat-container::-webkit-scrollbar-track{ background: transparent; }

/* Messages */
.message{
  padding: 10px 14px;
  border-radius: 14px;
  max-width: 92%;
  line-height: 1.45;
  font-size: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 6px 14px rgba(0,0,0,.22);
  animation: fadeInUp .28s ease both;
}
.message.user{
  align-self:flex-end;
  background: rgba(79,195,247,.14);
  color: var(--text);
  border: 1px solid var(--brand-weak);
}
.message.ai{ align-self:flex-start; }
@keyframes fadeInUp{ from{opacity:0; transform:translateY(6px)} to{opacity:1; transform:none} }

/* Sources (optional) */
#sources{
  display:flex; gap:8px; flex-wrap:wrap; align-items:center; justify-content:center;
  width:100%; max-width:740px; margin: 4px 0 6px;
}
.source-chip{
  font-size:.8rem; padding: 6px 10px; border-radius:999px;
  border: 1px solid var(--brand-weak);
  color:#cfefff; background: rgba(79,195,247,.10);
  text-decoration:none; cursor:pointer;
}
.source-chip:hover{ background: rgba(79,195,247,.18); }

/* ===== Input Bar ===== */
#input-bar{
  --focus-outline: 0 0 0 2px var(--ring);
  display:flex; align-items:center; gap:8px;
  width:100%; max-width:820px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--glass-strong);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  margin-top: 10px;
  transition: box-shadow .2s ease, border-color .2s ease, background .2s ease;
  isolation: isolate; /* keep overlays above keyboards */
}
#input-bar:focus-within{
  border-color: var(--brand-weak);
  box-shadow: var(--shadow-2), var(--focus-outline);
  background: rgba(22,24,28,0.74);
}

/* === Mode Switch (Search / Conversation / Math) === */
.mode-switch{
  position: relative;
  display: inline-flex;
  align-items: center;
  z-index: 10; /* float above input */
  isolation: isolate;
}

/* Current button (pill) */
.mode-current{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--brand-weak);           /* light blue contour */
  background: rgba(79,195,247,.08);               /* very light blue fill */
  color: #cfefff;                                  /* soft ice text */
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255,255,255,.05) inset;
  transition: transform .12s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.mode-current:hover{
  background: rgba(79,195,247,.12);
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--ring);
}
.mode-current:active{ transform: translateY(0.5px); }
.mode-current:focus{ outline: none; box-shadow: 0 0 0 2px var(--ring); }

.mode-current .mode-dot{
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--brand);                       /* blue status dot */
  box-shadow: 0 0 6px var(--brand);
}
.mode-current .mode-label{
  font-size: .95rem; letter-spacing: .1px; white-space: nowrap;
}
.mode-current .mode-chev{
  opacity: .85;
}

/* Dropdown menu (OPENS UPWARDS) */
.mode-menu{
  position: absolute;
  top: auto;
  bottom: calc(100% + 8px);   /* open up */
  left: 0;
  min-width: 220px;
  background: var(--glass-strong);
  backdrop-filter: blur(14px) saturate(1.05);
  -webkit-backdrop-filter: blur(14px) saturate(1.05);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-2);
  border-radius: 12px;
  padding: 6px;
  margin: 0;
  list-style: none;
  display: none;              /* toggled by :focus-within / :hover */
  z-index: 999;
  transform-origin: bottom left;
}

/* Open behavior (no JS needed for now) */
.mode-switch:focus-within .mode-menu,
.mode-switch:hover .mode-menu{
  display: block;
}

/* Options */
.mode-option{
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px;
  border-radius: 10px;
  font-size: .95rem;
  color: var(--text);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: background .12s ease, border-color .12s ease, transform .08s ease;
}
.mode-option .mode-dot{
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--brand);
  box-shadow: 0 0 6px var(--brand);
}
.mode-option[aria-selected="true"]{
  background: rgba(79,195,247,.10);
  border-color: var(--brand-weak);
}
.mode-option:hover{
  background: rgba(79,195,247,.14);
  border-color: var(--brand);
}

/* Arrow attaches to the bottom edge when opening upwards */
.mode-menu::before{
  content:"";
  position:absolute;
  bottom: -7px; left: 12px;
  width:12px; height:12px;
  transform: rotate(45deg);
  background: var(--glass-strong);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

/* Text input */
#text-input{
  flex:1; border:none; outline:none; background:transparent;
  font-size: 1.04rem; color: var(--text);
  padding: 10px 10px; caret-color: #9bd8ff;
}
#text-input::placeholder{ color: rgba(230,240,255,.60); }

/* Math toggle + Send */
#math-toggle, #send-button{
  width: 40px; height: 40px; border-radius: 10px;
  display:inline-flex; align-items:center; justify-content:center;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  cursor: pointer;
  transition: transform .1s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
#math-toggle:hover, #send-button:hover{
  transform: translateY(-1px);
  background: rgba(255,255,255,.07);
  border-color: var(--brand-weak);
}
#math-toggle::before{ content:"∑"; font-size: 16px; font-weight:700; color:#cfefff; transform: translateY(-1px); }
#send-button{
  background-image: url("send-icon.png");
  background-repeat:no-repeat; background-position:center; background-size: 18px 18px;
}
#send-button:disabled{ opacity:.45; cursor: default; }

/* Graph */
.graph-canvas{
  width:100%; max-width:740px;
  height: clamp(240px, 42dvh, 420px);
  border-radius: 12px;
  background: rgba(10,12,14,.85);
  border: 1px solid var(--border);
  box-shadow: 0 6px 18px rgba(0,0,0,.28) inset;
  margin: 6px 0 4px;
}

/* Footer */
#footer{ display:flex; justify-content:center; gap:18px; margin-top: 14px; }
#footer a{ color:#e7e7e7; text-decoration:none; font-size:.9rem; }
#footer a:hover{ color:#ffffff; text-decoration:underline; }
#footer a:visited{ color:#e7e7e7; }

/* ===== Math Keyboard ===== */
#hs-math-kb{
  position: fixed; z-index: 9999; left: 50%; top: 18%;
  transform: translateX(-50%);
  width: min(820px, calc(100% - 16px));
  background: rgba(20,22,24,.82);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 12px; box-shadow: var(--shadow-2);
  display: none; user-select: none;
}
#hs-math-kb.visible{ display:block; }
#hs-math-kb.dragging{ cursor: grabbing; }

.kb-header{
  display:flex; align-items:center; justify-content:space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  cursor: grab; border-top-left-radius:12px; border-top-right-radius:12px;
}
.kb-title{ font-weight:700; color:#cfefff; }
.kb-controls{ display:flex; gap:6px; }
.kb-ctrl{
  width:28px; height:28px; border-radius:999px;
  border:1px solid var(--border); background: rgba(255,255,255,.06);
  color:#e6f0ff; cursor:pointer;
}
.kb-ctrl.kb-min::before{ content:"–"; font-size: 16px; position:relative; top:-2px; }
.kb-ctrl.kb-close::before{ content:"×"; font-size:16px; }

.kb-rows{ padding: 10px; }
.kb-row{ display:flex; gap:8px; margin: 6px 6px; flex-wrap: wrap; }
.kb-key{
  padding: 10px 12px; border-radius: 10px; font-size: .95rem;
  background: rgba(255,255,255,.06); color:#eaf3ff; border: 1px solid var(--border);
  cursor:pointer; transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.kb-key:hover{ transform: translateY(-1px); background: rgba(255,255,255,.10); border-color: var(--brand-weak); }
.kb-key.wide{ padding: 10px 18px; }
.kb-key.accent{ border-color: var(--brand-weak); box-shadow: 0 0 0 2px rgba(79,195,247,.10) inset; }
.kb-key.danger{ border-color: rgba(255,99,132,.30); }
.kb-key.func{ border-style: dashed; }

.kb-minbar{ display:none; padding:8px 10px; border-top: 1px solid var(--border); }
.kb-key.mini{ padding: 6px 10px; font-size: .9rem; }
#hs-math-kb.minimized .kb-rows{ display:none; }
#hs-math-kb.minimized .kb-minbar{ display:flex; gap:8px; flex-wrap:wrap; }

/* ===== Mobile ===== */
@media (max-width: 768px){
  #container{
    flex-direction: column;
    width: 100%;
    height: 100dvh;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }
  #sidebar{ display:none; }
  #main-content{ width:100%; height:100%; padding: 12px 10px 10px; }
  #greeting .logo{ width: 72%; height:auto; }
  .question{ font-size:.95rem; padding:8px 12px; margin-bottom: 6px; }
  #status{ max-width:100%; margin: 4px 0; }
  #chat-container{ max-width:100%; padding: 6px 0 6px; }
  #input-bar{ max-width:100%; padding: 10px 12px; }
  #math-toggle, #send-button{ width: 38px; height: 38px; border-radius: 10px; }
  #text-input{ font-size: 1rem; }
  .message{ max-width: 92%; }

  /* Mode menu mobile spacing */
  .mode-menu{ min-width: 200px; }
}

/* Solid fallback for browsers without blur support */
@supports not ((backdrop-filter: blur(10px)) or (-webkit-backdrop-filter: blur(10px))){
  #container, #input-bar, #hs-math-kb, .mode-menu{ background: #1f2328; }
}
