:root{
  --bg:#e8f2ff;
  --glass-bg: rgba(255, 255, 255, 0.35);
  --glass-border: rgba(255,255,255,0.6);
  --text:#0b2b4f;
  --muted:#4b6b8a;
  --primary:#2a84ff;
  --primary-weak:#d6e6ff;
  --ring: rgba(42,132,255,0.35);
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial;
  color: var(--text);
  background: linear-gradient(160deg, #f7fbff 0%, #eaf1ff 50%, #dfeaff 100%);
  overflow-x:hidden;
}

/* Liquid glass background waves */
.app-bg::before, .app-bg::after{
  content:"";
  position: fixed; inset: -20% -10% auto auto;
  width: 50vmax; height: 50vmax;
  background: radial-gradient(closest-side, rgba(153,198,255,0.45), transparent 70%);
  filter: blur(40px);
  z-index: 0;
}
.app-bg::after{
  inset: auto auto -25% -10%;
  background: radial-gradient(closest-side, rgba(196,230,255,0.55), transparent 70%);
}

.glass{
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: 0 10px 30px rgba(13,49,119,0.08);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-radius: 18px;
}

.app-header{
  position: relative; z-index: 2;
  margin: 16px;
  padding: 10px 12px;
  display:flex; align-items:center; justify-content:space-between;
}

.brand{ display:flex; align-items:center; gap:10px; font-weight:700; }
.logo-dot{ width:14px; height:14px; border-radius:999px; background: var(--primary); box-shadow: 0 0 20px var(--primary); }

.actions{ display:flex; gap:8px; }

.layout{
  position: relative; z-index: 1;
  display:grid;
  grid-template-columns: 260px minmax(0,1fr) 360px;
  grid-template-rows: 1fr;
  gap: 16px;
  height: calc(100vh - 88px);
  padding: 0 16px 16px 16px;
}

.sidebar, .editor-wrap, .chat-panel{
  overflow: hidden;
}

.sidebar{
  padding: 12px;
  display:flex; flex-direction:column;
}
.sidebar-header{ padding: 6px 6px 10px; }
.file-list{
  list-style:none; padding:0; margin:0; overflow:auto; flex:1;
}
.file-item{
  display:flex; align-items:center; gap:8px;
  padding: 8px 10px; margin: 6px; border-radius: 10px;
  cursor: pointer;
}
.file-item:hover{ background: var(--primary-weak); }
.file-item.active{ background: #fff; border:1px solid var(--primary-weak); }

.editor-wrap{
  display:flex; flex-direction:column;
  padding: 12px;
}
.editor-toolbar{
  display:flex; align-items:center; gap:12px; padding: 6px; margin-bottom: 10px;
}
.file-info{ font-weight:600; }
.editor-actions{ display:flex; gap:8px; flex:1; align-items:center; }
.input{
  flex:1;
  padding:10px 12px; border-radius: 12px; border:1px solid var(--glass-border);
  background: rgba(255,255,255,0.8); color: var(--text);
  outline: none;
}
.input:focus{ border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }

.editor{
  flex:1; min-height: 240px; overflow-x:hidden; border-radius: 14px; border:1px solid var(--glass-border);
  background: rgba(255,255,255,0.9);
}
.cm-editor { height: 100%; }

.diff-panel{
  margin-top: 10px; padding: 8px; border-radius: 14px;
}
.diff-panel.hidden{ display:none; }
.diff-header{ display:flex; align-items:center; gap:10px; }
.diff-header .grow{ flex:1; }
.diff-content{
  display:grid; grid-template-columns: 1fr 1fr; gap:10px;
  margin-top: 8px; max-height: 220px; overflow:auto;
}
.diff-title{ font-size:12px; color: var(--muted); margin-bottom:4px; }
pre{ margin:0; padding:10px; background: rgba(255,255,255,0.7); border: 1px dashed var(--glass-border); border-radius: 10px; white-space: pre-wrap; }

.chat-panel{
  display:flex; flex-direction:column; padding: 12px;
}
.chat-header{ padding: 6px; }
.chat-log{
  flex:1; overflow:auto; display:flex; flex-direction:column; gap:10px; padding: 6px;
}
.msg{
  max-width: 85%;
  padding: 10px 12px; border-radius: 14px; border:1px solid var(--glass-border); background: rgba(255,255,255,0.85);
}
.msg.user{ align-self:flex-end; background:#ffffff; }
.msg.ai{ align-self:flex-start; }
.chat-input{ display:flex; gap:8px; }
.chat-input textarea{
  flex:1; min-height: 54px; max-height: 30vh; resize: vertical;
  padding:10px 12px; border-radius: 12px; border:1px solid var(--glass-border);
  background: rgba(255,255,255,0.9);
}
.btn{
  padding:10px 12px; border-radius: 12px; border:1px solid var(--glass-border);
  background: rgba(255,255,255,0.9); cursor:pointer; font-weight:600;
}
.btn:hover{ border-color: var(--primary); }
.btn.primary{ background: linear-gradient(180deg, #eaf3ff, #d8e9ff); border-color: #cfe3ff; }
.btn.primary:active{ transform: translateY(1px); }

/* Modal */
.modal{ position: fixed; inset:0; display:flex; align-items:center; justify-content:center; background: rgba(8,26,54,0.25); z-index: 10; }
.modal.hidden{ display:none; }
.modal-card{ width: min(760px, 92vw); padding: 14px; }
.modal-header{ display:flex; align-items:center; justify-content:space-between; margin-bottom: 8px; }
.settings-grid{ display:grid; gap:10px; grid-template-columns: 1fr 1fr; }
.settings-grid .field{ display:flex; flex-direction:column; gap:6px; }
.switch{ display:flex; align-items:center; gap:10px; }

/* Responsive */
@media (max-width: 1100px){
  .layout{ grid-template-columns: 210px minmax(0,1fr) 320px; }
}
@media (max-width: 900px){
  .layout{ grid-template-columns: 1fr; grid-template-rows: auto auto auto; height: auto; overflow:auto; }
  .sidebar, .editor-wrap, .chat-panel{ height:auto; }
}
.api-list{
  margin: 12px 0;
  display:flex; flex-direction:column; gap:10px;
}
.api-item{
  padding: 10px; border-radius:12px;
  background: rgba(255,255,255,0.7);
  display:flex; align-items:center; justify-content:space-between;
}
.api-item span{ font-weight:600; }
.api-item button{ margin-left:8px; }

.add-api{ margin-top: 12px; padding:10px; border-radius:12px; }
.add-api h4{ margin:0 0 6px; }

/* Dark Theme */
body.dark {
  --bg:#1e1e1e;
  --glass-bg: rgba(50, 50, 50, 0.6);
  --glass-border: rgba(80,80,80,0.8);
  --text:#f1f1f1;
  --muted:#c0c0c0;
  --primary:#4da3ff;
  --primary-weak:#333;
  --ring: rgba(77,163,255,0.35);
  background: var(--bg);
  color: var(--text);
}

/* Responsive Layout */
@media (max-width: 768px) {
  .container {
    flex-direction: column;
  }
  .chat, .editor {
    width: 100% !important;
    height: auto !important;
  }
}


/* Switch (liquid glass style) */
.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px) saturate(160%);
  -webkit-backdrop-filter: blur(10px) saturate(160%);
  border-radius: 999px;
  transition: all 0.3s ease;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px; width: 20px;
  left: 4px; bottom: 4px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--primary);
  transition: transform 0.3s ease;
}

.switch input:checked + .slider {
  background: var(--primary-weak);
}

.switch input:checked + .slider:before {
  transform: translateX(24px);
}

.switch-label {
  margin-left: 10px;
  font-weight: 600;
  color: var(--text);
}


/* Smooth transition for theme change */
body, .glass, .switch-label {
  transition: background 0.4s ease, color 0.4s ease, backdrop-filter 0.4s ease;
}

body.theme-transition {
  transition: background 0.4s ease, color 0.4s ease;
}
