/* ============================================================
   Kawan Melayu — ChatGPT-like layout (UI v3.6 Malaysia Light)
   - Desktop: lock page scroll; chat-stream is always the scroll container
   - Mobile behavior unchanged
   ============================================================ */

:root{
  /* Background (very white) */
  --bg0:#ffffff;
  --bg1:#fbfdff;

  /* Surfaces */
  --panel: rgba(255,255,255,0.94);
  --panel2: rgba(255,255,255,0.97);
  --border: rgba(0,50,160,0.16);

  /* Text */
  --text: rgba(15,23,42,0.96);
  --muted: rgba(71,85,105,0.92);

  /* Accents (Malaysia + batik) */
  --red:#CC0000;     /* Jalur Gemilang red */
  --blue:#0032A0;    /* Jalur Gemilang blue */
  --green:#2dd4bf;   /* seafoam (batik pastel feel) */
  --amber:#FFD100;   /* Jalur Gemilang yellow */
  --purple:#7c3aed;

  --shadow: 0 14px 46px rgba(2,6,23,0.10);
  --radius: 16px;
  --radius2: 12px;

  --sidebarW: 320px;
  --headerH: 64px;

  --font: Nunito, "Noto Sans TC", sans-serif;

  /* JS will set this based on .composer height */
  --composerPad: 0px;
}

*{box-sizing:border-box;}
html,body{height:100%; overflow:hidden;}
body{
  margin:0;
  font-family:var(--font);
  color:var(--text);
  background:
    radial-gradient(1100px 760px at 12% 0%, rgba(45,212,191,0.10), transparent 64%),
    radial-gradient(900px 680px at 92% 10%, rgba(0,50,160,0.08), transparent 66%),
    radial-gradient(860px 820px at 38% 96%, rgba(255,209,0,0.08), transparent 68%),
    radial-gradient(900px 700px at 86% 88%, rgba(204,0,0,0.05), transparent 72%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
}

a{color: rgba(0,50,160,0.92);}
a:hover{color: rgba(0,36,125,1);}

::-webkit-scrollbar{width:8px;}
::-webkit-scrollbar-thumb{background:rgba(0,50,160,0.18); border-radius:10px;}
::-webkit-scrollbar-thumb:hover{background:rgba(0,50,160,0.28);}

/* ===== Shell Grid ===== */
.app-shell{
  height:100dvh;
  overflow:hidden;
  display:grid;
  grid-template-columns: var(--sidebarW) minmax(0,1fr);
  grid-template-rows: var(--headerH) minmax(0,1fr);
}

.sidebar-collapsed{
  grid-template-columns: 0px minmax(0,1fr);
}

/* ===== Header ===== */
.cg-header{
  grid-column: 1 / -1;
  grid-row: 1;
  position: sticky;
  top:0;
  z-index: 1200;
  display:grid;
  grid-template-columns: 320px minmax(0, 1fr) 220px;
  align-items:center;
  gap:12px;
  padding: 10px 12px;
  height: var(--headerH);
  background: rgba(255,255,255,0.80);
  border-bottom:1px solid var(--border);
  backdrop-filter: blur(16px);
}

.hdr-left{ display:flex; align-items:center; gap:10px; min-width:0; }
.hdr-title{ display:flex; flex-direction:column; gap:2px; min-width:0; }
.brand-title{
  font-weight:900;
  letter-spacing:1px;
  color: rgba(0,50,160,0.96);
  text-transform: uppercase;
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}
.brand-sub{
  font-size:0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}

.hdr-center{ display:flex; gap:10px; overflow:auto; padding-bottom:2px; min-width:0; }
.hdr-right{ display:flex; justify-content:flex-end; gap:10px; }

/* Buttons */
.icon-btn{
  width:40px;
  height:40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.86);
  color: rgba(15,23,42,0.92);
  cursor:pointer;
  font-weight:900;
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
  box-shadow: 0 8px 18px rgba(2,6,23,0.07);
}
.icon-btn:hover{ transform: translateY(-1px); background: rgba(255,255,255,0.98); }

/* ===== Status chips ===== */
.chip{
  display:flex;
  align-items:center;
  gap:8px;
  padding:6px 10px;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.78);
  flex: 0 0 auto;
  box-shadow: 0 10px 20px rgba(2,6,23,0.05);
}
.chip-label{ font-weight:900; font-size:0.82rem; }
.chip-val{ font-weight:900; font-size:0.82rem; min-width: 24px; text-align:right; color: rgba(15,23,42,0.88); }
.chip-hp .chip-label{ color: rgba(204,0,0,0.86); }
.chip-en .chip-label{ color: rgba(0,50,160,0.90); }

.chip-bar{
  width: 92px;
  height: 8px;
  border-radius: 999px;
  overflow:hidden;
  background: rgba(2,6,23,0.08);
}
.chip-bar-fill{
  height:100%;
  width:0%;
  transition: width .7s cubic-bezier(0.34,1.56,0.64,1);
}
.chip-bar-fill.hp{ background: linear-gradient(90deg, rgba(204,0,0,1), rgba(251,113,133,1)); }
.chip-bar-fill.en{ background: linear-gradient(90deg, rgba(45,212,191,1), rgba(0,50,160,1)); }

.chip-meta{ gap:8px; }
.chip-pill{
  padding:3px 9px;
  border-radius:999px;
  font-weight:900;
  font-size:0.78rem;
  background: rgba(255,209,0,0.18);
  border:1px solid rgba(255,209,0,0.28);
  color: rgba(0,50,160,0.95);
  white-space: nowrap;
}
.chip-loc{
  background: rgba(45,212,191,0.12);
  border-color: rgba(45,212,191,0.20);
  color: rgba(15,23,42,0.92);
  max-width: 220px;
  overflow:hidden;
  text-overflow: ellipsis;
}

/* ===== Sidebar Overlay (mobile) ===== */
.panel-overlay{
  position: fixed;
  inset: 0;
  background: rgba(2,6,23,0.22);
  backdrop-filter: blur(6px);
  z-index: 1300;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
  display:none;
}

/* ===== Sidebar ===== */
.cg-sidebar{
  grid-column: 1;
  grid-row: 2;
  background: rgba(255,255,255,0.90);
  border-right: 1px solid var(--border);
  display:flex;
  flex-direction:column;
  min-width:0;
  overflow:hidden;
  box-shadow: 18px 0 42px rgba(2,6,23,0.07);
}

.sidebar-collapsed .cg-sidebar{
  display:none;
}

.sb-top{
  padding: 12px 12px 10px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  border-bottom: 1px solid var(--border);
}
.sb-brand{ display:flex; align-items:center; gap:10px; min-width:0; }
.sb-logo{
  width:34px;
  height:34px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-radius: 12px;
  background: rgba(0,50,160,0.08);
  border:1px solid var(--border);
  color: rgba(0,50,160,0.96);
}
.sb-name{ font-weight:900; color: rgba(15,23,42,0.92); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.sb-close{
  width:38px;
  height:38px;
  border-radius: 12px;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.92);
  color: rgba(15,23,42,0.92);
  cursor:pointer;
  font-size: 1.4rem;
  line-height: 1;
}
.sb-close:hover{ background: rgba(255,255,255,0.99); }

.sb-actions{
  padding: 12px;
  display:flex;
  flex-direction:column;
  gap:10px;
  border-bottom: 1px solid var(--border);
}
.sb-row{ display:flex; gap:10px; }
.sb-btn{
  flex:1;
  height:38px;
  border-radius: 12px;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.92);
  color: rgba(15,23,42,0.92);
  cursor:pointer;
  font-weight:900;
  padding: 0 12px;
  box-shadow: 0 10px 22px rgba(2,6,23,0.05);
  transition: transform .15s ease, background .15s ease;
}
.sb-btn:hover{ transform: translateY(-1px); background: rgba(255,255,255,0.99); }
.sb-btn-primary{
  background: linear-gradient(135deg, rgba(0,50,160,0.92), rgba(45,212,191,0.92));
  border-color: rgba(0,50,160,0.20);
  color: rgba(255,255,255,0.98);
}

.sb-settings{
  padding: 12px;
  border-bottom: 1px solid var(--border);
  overflow:auto;
  max-height: 440px;
  transition: max-height .24s ease, padding .24s ease;
}
.settings-collapsed .sb-settings{
  max-height: 0px;
  padding-top: 0;
  padding-bottom: 0;
  border-bottom: none;
  overflow:hidden;
}
.sb-section-title{
  font-weight: 900;
  color: rgba(15,23,42,0.92);
  margin-bottom: 10px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.sb-field{ display:flex; flex-direction:column; gap:8px; margin-bottom: 12px; }
.sb-label{ font-size:0.82rem; color: rgba(71,85,105,0.92); font-weight:900; }

.sb-settings input,
.sb-settings select{
  height:38px;
  border-radius: 12px;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.97);
  color: rgba(15,23,42,0.92);
  padding: 0 12px;
  outline:none;
  min-width:0;
  box-shadow: 0 10px 22px rgba(2,6,23,0.04);
}
.sb-settings input::placeholder{ color: rgba(100,116,139,0.75); }
.sb-settings select option{ background:#ffffff; color: rgba(15,23,42,0.92); }

.sb-opt{
  display:flex;
  flex-direction:column;
  gap:10px;
  margin-top: 8px;
}
.opt{
  display:flex;
  align-items:center;
  gap:8px;
  font-size: 0.86rem;
  color: rgba(15,23,42,0.88);
  user-select:none;
}
.opt input{ transform: translateY(1px); }

.sb-links{
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px dashed rgba(0,50,160,0.16);
}
.sb-link-row{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  font-weight:900;
}
.sb-link-row a{
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(0,50,160,0.14);
  background: rgba(255,255,255,0.88);
  text-decoration: none;
  color: rgba(0,50,160,0.92);
}
.sb-link-row a:hover{ background: rgba(255,255,255,0.99); }

.sb-vocab{
  padding: 12px;
  overflow:auto;
  flex: 1;
  min-height:0;
}

.badge{
  display:inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  border:1px solid rgba(255,209,0,0.28);
  background: rgba(255,209,0,0.16);
  color: rgba(0,50,160,0.95);
  font-weight: 900;
  font-size: 0.78rem;
}

.vocab-list{ margin-top: 10px; }
.vocab-item{
  background: rgba(255,255,255,0.98);
  color: rgba(15,23,42,0.92);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-left: 4px solid rgba(255,209,0,0.92);
  box-shadow: 0 12px 22px rgba(2,6,23,0.07);
  font-weight: 900;
  overflow-wrap:anywhere;
  animation: vocabPop .22s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes vocabPop{
  from{ transform: scale(0.92); opacity:0; }
  to{ transform: scale(1); opacity:1; }
}

.sb-foot{
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,0.74);
}
.sb-foot-hint{ color: rgba(71,85,105,0.92); font-size: 0.82rem; }

/* ===== Main ===== */
.cg-main{
  grid-column: 2;
  grid-row: 2;
  min-width:0;
  min-height:0;
  height:100%;
  overflow:hidden;
  display:flex;
  justify-content:center;
}

.chat-wrap{
  width: min(920px, 100%);
  height:100%;
  min-height: 0;
  overflow:hidden;
  display:flex;
  flex-direction:column;
  padding: 14px 14px 18px;
}

.chat-stream{
  flex: 1;
  min-height:0;
  overflow-x:hidden;
  overflow-y:auto;
  padding: 6px 2px calc(18px + var(--composerPad) + env(safe-area-inset-bottom, 0px));
  display:flex;
  flex-direction:column;
  gap: 12px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  overflow-anchor: none;
  scroll-padding-bottom: calc(18px + var(--composerPad) + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

/* Messages */
.mud-msg{
  border: 1px solid rgba(0,50,160,0.12);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: rgba(255,255,255,0.94);
  box-shadow: 0 12px 26px rgba(2,6,23,0.07);
  line-height: 1.75;
  overflow-wrap:anywhere;
  word-break: break-word;
  animation: fadeUp .18s ease;
}
@keyframes fadeUp{
  from{ opacity:0; transform: translateY(6px); }
  to{ opacity:1; transform: translateY(0); }
}
.mud-user{
  align-self: flex-end;
  max-width: 92%;
  background: linear-gradient(135deg, rgba(0,50,160,0.08), rgba(45,212,191,0.10));
  border-color: rgba(0,50,160,0.14);
}
.mud-ai{
  align-self: flex-start;
  max-width: 100%;
  background: rgba(255,255,255,0.97);
}
.mud-ai.mud-system{
  align-self: center;
  max-width: 100%;
  text-align:center;
  background: rgba(251,253,255,0.95);
  border-style: dashed;
  color: rgba(71,85,105,0.92);
  font-size: 0.92rem;
}

/* Markdown inside AI */
.mud-ai p{ margin: 0.45em 0; }
.mud-ai ul{ margin: 0.25em 0 0.35em 1.3em; }
.mud-ai li{ margin: 0.18em 0; }
.mud-ai strong{ color: rgba(0,50,160,0.96); }

/* Loading */
.mud-loading{
  color: rgba(71,85,105,0.85);
  font-size:0.9rem;
  text-align:center;
  margin: 6px 0;
  font-style: italic;
}
.loading-dots span{
  animation: dotBlink 1.4s ease-in-out infinite;
  opacity:0;
}
.loading-dots span:nth-child(1){ animation-delay: 0s; }
.loading-dots span:nth-child(2){ animation-delay: 0.2s; }
.loading-dots span:nth-child(3){ animation-delay: 0.4s; }
@keyframes dotBlink{
  0%,80%,100%{ opacity:0; }
  40%{ opacity:1; }
}

/* Composer */
.composer{
  position: sticky;
  bottom: 0;
  padding-top: 10px;
  background: linear-gradient(180deg, rgba(255,255,255,0), rgba(251,253,255,0.80) 30%, rgba(251,253,255,0.97));
  backdrop-filter: blur(10px);
}
.composer-inner{
  display:flex;
  gap:10px;
  padding: 10px;
  border: 1px solid rgba(0,50,160,0.14);
  border-radius: 18px;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 14px 34px rgba(2,6,23,0.07);
}
.composer-input{
  flex:1;
  min-width:0;
  height:44px;
  border-radius: 14px;
  border:1px solid rgba(0,50,160,0.14);
  background: rgba(255,255,255,0.99);
  color: rgba(15,23,42,0.92);
  padding: 0 14px;
  outline:none;
}
.composer-input:focus{
  border-color: rgba(45,212,191,0.42);
  box-shadow: 0 0 0 4px rgba(45,212,191,0.14);
}
.composer-input::placeholder{ color: rgba(100,116,139,0.75); }

.composer-send,
.composer-stop{
  height:44px;
  border-radius: 14px;
  border:1px solid rgba(0,50,160,0.14);
  cursor:pointer;
  font-weight:900;
  padding:0 14px;
  color: rgba(255,255,255,0.98);
  transition: transform .15s ease, filter .15s ease;
}
.composer-send{
  background: linear-gradient(135deg, rgba(0,50,160,0.92), rgba(45,212,191,0.92));
  border-color: rgba(0,50,160,0.18);
}
.composer-stop{
  background: linear-gradient(135deg, rgba(204,0,0,0.92), rgba(244,63,94,0.92));
  border-color: rgba(204,0,0,0.18);
}
.composer-send:hover:not(:disabled),
.composer-stop:hover:not(:disabled){ transform: translateY(-1px); filter: brightness(1.03); }
.composer-send:disabled,
.composer-stop:disabled{ opacity: .55; cursor:not-allowed; transform:none; filter:none; }

.composer-note{
  margin-top: 8px;
  padding: 0 4px 8px;
  color: rgba(71,85,105,0.88);
  font-size: 0.84rem;
}

/* ===== Help modal ===== */
.modal-overlay{
  position: fixed;
  inset: 0;
  background: rgba(2,6,23,0.44);
  backdrop-filter: blur(10px);
  display:none;
  justify-content:center;
  align-items:center;
  z-index: 2000;
  padding: 20px;
}
.modal-content{
  background: rgba(255,255,255,0.95);
  border: 1px solid rgba(0,50,160,0.14);
  border-radius: 22px;
  max-width: 680px;
  width: 100%;
  padding: 24px;
  box-shadow: 0 22px 70px rgba(2,6,23,0.16);
  animation: modalPop .22s cubic-bezier(0.34,1.56,0.64,1);
  max-height: min(86vh, 760px);
  overflow:auto;
}
@keyframes modalPop{
  from{ transform: scale(0.92); opacity:0; }
  to{ transform: scale(1); opacity:1; }
}
.modal-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  border-bottom: 1px solid rgba(0,50,160,0.12);
  padding-bottom: 10px;
  margin-bottom: 14px;
}
.modal-header h2{ margin:0; color: rgba(0,50,160,0.96); }
.close-btn{
  background: none;
  border:none;
  color: rgba(71,85,105,0.92);
  font-size: 2rem;
  cursor:pointer;
  line-height:1;
}
.close-btn:hover{ color: rgba(15,23,42,0.92); }
.info-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.info-card{
  background: rgba(240,249,255,0.78);
  border: 1px solid rgba(0,50,160,0.10);
  padding: 14px;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: rgba(15,23,42,0.90);
}
.info-card ol,
.info-card ul{
  margin: 0.35em 0 0.35em 1.25em;
  padding: 0;
}
.info-card li{ margin: 0.2em 0; }
.card-title{
  font-weight: 900;
  margin-bottom: 6px;
  color: rgba(0,50,160,0.96);
}
.green-card  { border-left: 4px solid rgba(45,212,191,0.92); background: rgba(45,212,191,0.10); }
.orange-card { border-left: 4px solid rgba(255,209,0,0.92); background: rgba(255,209,0,0.10); }
.blue-card   { border-left: 4px solid rgba(0,50,160,0.92); background: rgba(0,50,160,0.08); }
.purple-card { border-left: 4px solid rgba(167,139,250,0.92); background: rgba(167,139,250,0.10); }

.help-link-row{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  margin-top: 8px;
  margin-bottom: 8px;
  font-weight:900;
}
.help-link-row a{
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(0,50,160,0.14);
  background: rgba(255,255,255,0.88);
  text-decoration: none;
  color: rgba(0,50,160,0.92);
}
.help-link-row a:hover{ background: rgba(255,255,255,0.99); }

.inline-code{
  display:inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  border: 1px solid rgba(0,50,160,0.14);
  background: rgba(0,50,160,0.06);
  color: rgba(15,23,42,0.92);
  font-weight: 900;
}

/* ===== Responsive ===== */
@media (max-width: 1020px){
  .cg-header{
    grid-template-columns: 1fr;
    height: auto;
    padding: 10px 12px 12px;
    gap:10px;
  }
  .hdr-right{ justify-content:flex-start; }
  .hdr-center{ padding-bottom: 0; }
}

@media (max-width: 820px){
  /* Mobile: lock page scroll, let chat-stream be the scroll container */
  html, body{ height:100%; overflow:hidden; }

  .app-shell{
    height:100dvh;
    overflow:hidden;
    grid-template-columns: 0px minmax(0,1fr);
  }

  .cg-main{
    min-height:0;
    height:100%;
    overflow:hidden;
  }

  .chat-wrap{
    height:100%;
    flex:1;
    overflow:hidden;
  }

  .cg-sidebar{
    position: fixed;
    top:0;
    left:0;
    bottom:0;
    width: min(var(--sidebarW), 92vw);
    z-index: 1400;
    box-shadow: var(--shadow);
    transform: translateX(-102%);
    transition: transform .22s ease;
    display:flex;
  }
  .sidebar-open .cg-sidebar{
    transform: translateX(0);
  }
  .sidebar-open .panel-overlay{
    display:block;
    opacity: 1;
    pointer-events: auto;
    z-index: 1300;
  }
  .sidebar-collapsed .cg-sidebar{
    display:flex;
  }
}

/* small */
@media (max-width: 640px){
  /* Mobile: move Lv/Location + buttons to the top-right area (keep desktop unchanged) */
  .cg-header{
    grid-template-columns: 1fr auto auto;
    height: var(--headerH);
    padding: 8px 10px;
    gap: 8px;
  }

  .brand-sub{ display:none; }

  .hdr-center{
    grid-column: 2;
    justify-content:flex-end;
    overflow:hidden;
    padding-bottom:0;
  }

  .hdr-right{
    grid-column: 3;
    justify-content:flex-end;
  }

  /* Hide HP/EN chips, keep only Lv/Location */
  .chip-hp,
  .chip-en{ display:none; }

  .chip-bar{ width: 70px; }
  .info-grid{ grid-template-columns: 1fr; }
}
