/* ===== CORE VARIABLES & RESET ===== */
*{box-sizing:border-box; transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;}
html,body{height:100%; overflow:hidden;}

:root{
  --bg:#f8fafc;
  --panel:#ffffff;
  --border:#e2e8f0;
  --text:#1e293b;
  --muted:#64748b;
  --accent:#2563eb;
  --accent-soft:rgba(37, 99, 235, 0.05);
  --danger:#ef4444;
  --radius:12px;
}
[data-theme="dark"]{
  --bg:#0f172a;
  --panel:#1e293b;
  --border:#334155;
  --text:#f1f5f9;
  --muted:#94a3b8;
  --accent:#38bdf8;
  --accent-soft:rgba(56, 189, 248, 0.1);
}

body{
  margin:0;
  font-family:'Poppins',system-ui, sans-serif;
  background:var(--bg);
  color:var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ===== HEADER ===== */
header{
  position:fixed;
  top:0;left:0;right:0;
  height:56px;
  background:var(--panel);
  border-bottom:1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 20px;
  z-index:1000;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
header .left { display: flex; align-items: center; gap: 12px; }
header strong{font-size:14px; font-weight:600; color: var(--accent);}
header .right {
  display: flex;
  gap: 8px;
  align-items: center;
  /* Enable horizontal sliding */
  overflow-x: auto; 
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  padding: 5px;
  /* Hide scrollbars for a clean look */
  scrollbar-width: none; 
  -ms-overflow-style: none;
}

header .right::-webkit-scrollbar {
  display: none;
}

/* Force buttons to stay their full size */
header .right button {
  flex-shrink: 0;
}
button{
  background:var(--panel);
  border:1px solid var(--border);
  color:var(--text);
  padding:7px 16px;
  border-radius:10px;
  font-family:inherit;
  font-size:13px;
  font-weight: 500;
  cursor:pointer;
}
button.primary{ background:var(--accent); color:#fff; border-color:var(--accent); }
button:hover{ border-color: var(--accent); background: var(--accent-soft); }
button.primary:hover{ opacity: 0.9; background: var(--accent); color: #fff; }

/* ===== MAIN LAYOUT ===== */
main{
  position:absolute;
  top:56px; bottom:0; left:0; right:0;
  display:grid;
  grid-template-columns:240px 1fr 300px;
}

/* ===== SIDEBAR ===== */
aside#tree{
  background:var(--panel);
  border-right:1px solid var(--border);
  padding:12px;
  overflow-y:auto;
}



/* ===== EDITOR SECTION (FIXED) ===== */
section#editor-container {
  display:flex;
  flex-direction:column;
  height:100%;
  min-height: 0;
  overflow:hidden;
  border-right:1px solid var(--border);
  background: var(--panel);
}
#editor { flex: 1; width: 100%; min-height: 0; }
iframe{ border:0; background:#fff; width:100%; flex-shrink: 0; }

.splitter{
  height:12px;
  background:var(--bg);
  cursor:row-resize;
  display:flex; align-items:center; justify-content:center;
  position:relative; z-index: 10;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.split-handle{
  width:24px; height:24px;
  border-radius:50%;
  background:var(--panel);
  border:1px solid var(--border);
  cursor:pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  position: absolute;
  z-index: 11;
}

/* ===== AI PANEL ===== */
#ai-panel { background: var(--panel); display: flex; flex-direction: column; height: 100%; }
.ai-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between;
}
.dot-status { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }
#ai-chat-history { flex: 1; padding: 15px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.ai-message { padding: 12px 16px; border-radius: 12px; font-size: 13px; line-height: 1.5; max-width: 90%; }
.ai-message.system { background: var(--bg); align-self: flex-start; border: 1px solid var(--border); }
.ai-message.user { background: var(--accent); color: #fff; align-self: flex-end; }

.ai-input-area { padding: 15px; border-top: 1px solid var(--border); }
#aiInput {
  width: 100%; height: 80px; padding: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-family: inherit; font-size: 13px; resize: none; margin-bottom: 8px;
}

/* ===== GORGEOUS MODALS ===== */
.modal{
  position:fixed; inset:0;
  background:rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  display:none; align-items:center; justify-content:center;
  z-index:2000;
}
.modal-box{
  background:var(--panel); 
  width:400px; 
  border-radius:16px; 
  padding:28px;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
  max-height: 85vh;
  display: flex; flex-direction: column;
}
.modal-box h3{ margin:0 0 8px; font-size:18px; font-weight: 600; }
.modal-box p{ margin:0 0 20px; font-size:14px; color:var(--muted); }

/* SCROLLABLE PROJECT LIST */
.scroll-area {
  flex: 1; overflow-y: auto; 
  margin-bottom: 20px;
  padding-right: 8px;
}
.scroll-area::-webkit-scrollbar { width: 6px; }
.scroll-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.project-row {
  display:flex; justify-content:space-between; align-items:center;
  padding:14px 16px; margin-bottom:8px; border-radius:12px;
  background:var(--bg); border: 1px solid transparent;
}
.project-row:hover {
  background: var(--panel);
  border-color: var(--accent);
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}
.project-row span:first-child { font-weight: 500; font-size: 14px; }

.project-actions { display:flex; gap:12px; font-size:12px; }
.project-actions span { cursor: pointer; color: var(--muted); font-weight: 500; }
.project-actions span:hover { color: var(--accent); }
.danger:hover { color: var(--danger) !important; }

/* INPUTS & SEGMENTS */
.modal-box input, .modal-box select {
  width:100%; padding:12px; border-radius:10px;
  border: 1px solid var(--border); background:var(--bg);
  color:var(--text); margin-bottom:12px; font-family: inherit;
}
.modal-box input:focus { border-color: var(--accent); outline: none; }

.segment { 
  display:flex; gap:6px; margin-bottom:16px; 
  background: var(--bg); padding: 4px; border-radius: 10px;
}
.segment button { 
  flex:1; border: none; padding: 8px; border-radius: 8px; 
  background: transparent; color: var(--muted); font-weight: 600;
}
.segment button.active { 
  background: var(--panel); color: var(--accent); 
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.actions { display:flex; justify-content:flex-end; gap:10px; }

/* ===== MOBILE ===== */
@media(max-width:1100px){
  main { grid-template-columns: 240px 1fr; }
  #ai-panel { display: none; }
}
@media(max-width:900px){
  #mobilePageBtn { display: inline-block !important; }
  main { grid-template-columns: 1fr; }
  aside#tree {
    display: none; position: fixed; top: 56px; left: 0; bottom: 0;
    width: 260px; z-index: 1500; box-shadow: 5px 0 15px rgba(0,0,0,0.1);
  }
  body.sidebar-open aside#tree { display: block; }
}

#ai-panel { 
  background: var(--panel); 
  display: flex; 
  flex-direction: column; 
  height: 100%; 
  overflow: hidden; /* Prevents the panel itself from growing */
}

#ai-chat-history { 
  flex: 1; /* This area takes all available space */
  overflow-y: auto; /* It scrolls internally */
  padding: 15px; 
  display: flex; 
  flex-direction: column; 
  gap: 12px; 
}

.ai-input-area { 
  padding: 15px; 
  background: var(--panel); 
  border-top: 1px solid var(--border); 
  flex-shrink: 0; /* Prevents the input box from being squashed or pushed away */
}

/* Update in your style.css */
.actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap; /* Allows buttons to wrap on small screens */
}






/* ===== FILE TREE ROWS & COLORED DOTS ===== */
.row {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  margin-bottom: 2px;
  color: var(--text);
}

.row:hover {
  background: var(--accent-soft);
}

/* Ensure dots have size and are visible */
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0; /* Prevents dot from squashing */
  display: inline-block;
}
.dot {
  transition: none !important;
}

/* Specific Tonal Colors */
.dot-html { background: #3b82f6 !important; box-shadow: 0 0 4px rgba(59, 130, 246, 0.5); }
.dot-css  { background: #8b5cf6 !important; box-shadow: 0 0 4px rgba(139, 92, 246, 0.5); }
.dot-js   { background: #f59e0b !important; box-shadow: 0 0 4px rgba(245, 158, 11, 0.5); }
.dot-other{ background: #9ca3af !important; }


/* Restored Folder Shadow & Styling */
.folder {
  font-weight: 600;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 2px 4px rgba(0,0,0,0.06); /* The restored shadow */
  margin-top: 4px;
  margin-bottom: 4px;
  color: var(--muted);
}

.folder:hover {
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.row.active {
  border: 2px solid var(--accent, #027AFF);
  border-radius: 8px;
  background: rgba(2, 122, 255, 0.06);
}
@media (max-width: 600px) {
  header .left {
    max-width: 120px; /* Limits the title width */
  }
  header strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
  }
}
.ai-hidden {
  display: none !important;
}

/* Ensure the editor expands when AI is hidden on desktop */
/* This ensures that when AI is hidden, the center section expands to fill everything */
body:has(.ai-hidden) main {
  grid-template-columns: 240px 1fr 0px;
}

@media (max-width: 1100px) {
  /* On mobile/tablet, hide the gap entirely and let the editor grow */
  body:has(.ai-hidden) main {
    display: flex;
    flex-direction: column;
  }
  
  body:has(.ai-hidden) #editor-container {
    flex: 1;
    height: 100%;
  }
}
