:root{
  --bg: #0b0f17;
  --panel: #121826;
  --card: #ffffff;
  --muted: rgba(255,255,255,0.65);
  --text: #e8eefc;
  --shadow: 0 12px 30px rgba(0,0,0,0.35);
  --radius-lg: 18px;
  --radius-md: 14px;
}

* { box-sizing: border-box; }
body{
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background: radial-gradient(1200px 600px at 30% 0%, #1b2440 0%, var(--bg) 55%);
  color: var(--text);
}
.top-bar{
  position: fixed;
  top: 16px;
  left: 16px;
  display: flex;
  gap: 10px;
  z-index: 300;
}

.top-bar button{
  background: rgba(255,255,255,0.06);
  color: #e5e7eb;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 14px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 0.15s ease;

}
#historyBtn{
  background : transparent;
  border: none;
  padding: 6px;
  font-size: 18px;
  line-height: 1;
  color: #e5e7eb;
}

.top-bar button:hover{
  background: rgba(255,255,255,0.12);
}

#historyBtn:hover{
  background: rgba(255,255,255,0.08);
  border-radius: 8px;
}

.chat-history{
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100%;
  background: #0f172a;
  color: white;
  padding: 16px;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  z-index: 200;
}

.chat-history.show{
  transform: translateX(0);
}

.chat-history ul{
  list-style: none;
  padding: 0;
  margin: 0;
}

.chat-history li{
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.chat-history li:hover{
  background: rgba(255,255,255,0.08);
}
.chat-history.show ~ .top-bar #historyBtn{
  display: none;
}
.page.dimmed{
  filter: brightness(0.7);
}

#newBtn{
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  color: #e5e7eb;
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
}

#newBtn:hover{
  background: rgba(255,255,255,0.12);
}

.page{
  padding: 28px 16px 60px;
  display: flex;
  justify-content: center;
}

.container{
  width: 100%;
  max-width: 920px;
  padding: 16px; 
  margin: 0 auto; 
}

.input-card{
  position: relative;
  background: #f3f4f6;
  color: #111827;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: visible;
}

.input-textarea{
  width: 100%;
  border: none;
  outline: none;
  resize: vertical;
  min-height: 140px;
  padding: 18px 92px 18px 18px; 
  font-size: 16px;
  line-height: 1.4;
  background: transparent;
}

.input-actions{
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  gap: 8px;
}

.input-actions .icon-btn{
  position: static;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-size: 18px;
  background: #111827;
  color: white;
  display: grid;
  place-items: center;
}

.input-actions .icon-btn:hover{
  filter: brightness(1.05);
}

.api-key-btn{
  width: 36px;
  height: 36px;
  opacity: 0.9;
}

.api-key-btn:hover{
  opacity: 1;
}

.divider{
  height: 1px;
  background: rgba(255,255,255,0.12);
  margin: 22px 0;
}

/* sections */
.section{ margin-top: 18px; }

.section-title{
  margin: 0 0 12px 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

/* option card */
.option-card{
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-md);
  align-items: stretch;
  padding: 14px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.25);
}

.option-top{
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.badge{
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: rgba(245, 158, 11, 0.22);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.icon-btn.ghost{
  position: static;
  background: transparent;
  color: rgba(255,255,255,0.85);
  border: 1px solid rgba(255,255,255,0.18);
}
.icon-btn.ghost:hover{ background: rgba(255,255,255,0.08); }

.option-content{
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  padding: 14px;
  white-space: pre-wrap;
  line-height: 1.45;
  min-height: 88px;
}

.changes-list{
  margin: 0;
  padding-left: 20px;
  color: rgba(255,255,255,0.9);
}

.muted{ color: rgba(255,255,255,0.65); }

.status{
  margin-top: 14px;
  font-size: 14px;
  color: rgba(255,255,255,0.7);
}


.text-input{
  width: 100%;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(2,6,23,0.85);
  color: #fff;
  outline: none;
}

.primary-btn{
  border: none;
  cursor: pointer;
  border-radius: 12px;
  padding: 12px 14px;
  background: rgba(148,163,184,0.25);
  color: #e5e7eb;
  font-weight: 700;
}
.primary-btn:hover{ filter: brightness(1.08); }
.primary-btn.full{ width: 100%; }

.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.65);
  z-index: 10000;
  font-size: 18px;
  cursor: pointer;
}
.close-btn:hover { color: white; }

.api-key-popover{
  position: absolute;
  bottom: calc(100% -20px);
  right: 0; 
  left:0;

  width: auto;
  background:  #0f172a;
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.55);
  z-index: 999;
}

.api-key-popover.hidden {
  display: none;
}
.popover-title{
  font-size: 15px;
  font-weight: 800;
  margin: 0 0 6px 0;
  padding-right: 26px;
}

.popover-current{
  margin-bottom: 10px;
  font-size: 13px;
}

.popover-actions{
  margin-top: 10px;
}

.quota-overlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 14px 14px;
  z-index: 9999;
  pointer-events: auto;
}

.quota-toast{
  width: 100%;
  max-width: 640px;
  background: #ffffff;
  color: #111827;
  border-radius: 18px;
  padding: 22px 22px 18px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.45);
  position: relative;
  pointer-events: auto;
}

.quota-toast .close-btn{
  color: rgba(17,24,39,0.55);
}
.quota-toast .close-btn:hover{
  color: rgba(17,24,39,0.9);
}

.quota-toast h2{
  margin: 0 0 10px 0;
  font-size: 28px;
  letter-spacing: 0.2px;
}

.quota-toast .muted{
  color: rgba(17,24,39,0.7);
  margin: 0 0 14px 0;
  line-height: 1.4;
}

.quota-label{
  margin: 8px 0 10px 0;
  font-size: 16px;
}

.quota-link{
  color: #2563eb;
  text-decoration: none;
  font-weight: 700;
}
.quota-link:hover{ text-decoration: underline; }

.quota-input-row{
  display: flex;
  gap: 12px;
  align-items: center;
}

.quota-input-row .sparkle{
  font-size: 22px;
  width: 26px;
  text-align: center;
  color: rgba(37,99,235,0.9);
}

.quota-input-row .text-input{
  flex: 1;
  background: #ffffff;
  color: #111827;
  border: 1px solid rgba(17,24,39,0.15);
}

.quota-input-row .primary-btn{
  background: rgba(17,24,39,0.18);
  color: #111827;
  white-space: nowrap;
  padding: 12px 18px;
}

.quota-current{
  margin-top: 10px;
  font-size: 13px;
}

/* responsive tweaks */
@media (max-width: 600px){
  .section-title{ font-size: 18px; }
  .input-textarea{ padding-right: 92px; }
  .quota-toast h2{ font-size: 24px; }
  .quota-input-row{ flex-direction: column; align-items: stretch; }
  .quota-input-row .sparkle{ width: auto; }
}
.hidden {
  display: none !important;
}
.popover-current,
.quota-current {
  word-break: break-all;
  font-family: monospace;
}


/* MODES */
.modes{
  display: flex;
  align-items: center;
  gap: 10px; 
  margin: 12px 0; 
  padding: 10px 12px; 
  border-radius: 14px;
  background: linear-gradient(180deg, #1f1937, #111827);
  border: 1px solid rgba(255,255,255,0.06);
}

.modes-label{
  font-size: 14px;
  color: #e5e7eb;
  margin-right: 6px;
}

.mode-btn{
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.12);
  background: #1f2937;
  color: #facc15;
  opacity: 0.6;
  transition: all 0.2s ease;
}

.mode-btn:hover{
  opacity: 0.85;
}

.mode-btn.active{
  background: linear-gradient(180deg, #fbbf24, #f59e0b);
  color: #111827;
  border-color: #fbbf24;
  opacity: 1;
  font-weight: 600;
  box-shadow: 0 0 0 2px rgba(251,191,36,0.25);
}

@media (max-width: 600px){

  .page{
    display: block !important;
    padding: 0 0 60px !important;
  }
  .container{
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 12px !important;
  }

  .modes{
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;

    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;

    overflow: visible !important;
    padding: 10px !important;
  }

  .modes-label{
    grid-column: 1 / -1 !important; 
    margin: 0 0 6px 0 !important;
  }

  .mode-btn{
    width: 100% !important;
    min-width: 0 !important; 
    white-space: nowrap !important;
    text-align: center !important;
    padding: 8px 12px !important;
  }

  .option-content{
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    text-align: left !important;
  }
  .option-content,
  .option-content *{
    text-align: left !important;
  }

  .option-content .muted{
    white-space: normal !important;
    opacity: 0.7 !important;
  }

  #refinedText,
  #refinedText *{
    text-align: left !important;
  }
}
#refinedText{
  display: block !important;
  text-align: left !important;
  white-space: normal !important;

  justify-content: flex-start !important;
  align-items: flex-start !important;
  place-items: unset !important;
  place-content: unset !important;
}

#refinedText::before,
#refinedText::after{
  content: none !important;
}

#refinedText span,
#refinedText div,
#refinedText p{
  display: inline !important;
  float: none !important;
  margin: 0 !important;
}
