/* IA Desk — hoja de estilo. Workspace oscuro, enfocado. */
:root {
  --bg:         #0e1013;
  --bg-elev:    #16191e;
  --bg-elev-2:  #1d2128;
  --line:       #262b33;
  --text:       #e7eaef;
  --text-dim:   #949cab;
  --text-faint: #667081;
  --accent:     #6ea8fe;
  --accent-2:   #8b7bff;
  --accent-soft:#1a2740;
  --danger:     #f2626b;
  --radius:     14px;
  --radius-sm:  9px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}

/* ---------- Auth ---------- */
.auth-body {
  display: grid; place-items: center; min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 80% -10%, #182238 0%, transparent 55%),
    radial-gradient(900px 500px at 0% 110%, #1c1830 0%, transparent 50%),
    var(--bg);
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 36px 32px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.6);
}
.auth-brand { display: flex; align-items: center; gap: 9px; margin-bottom: 26px; }
.brand-mark {
  color: var(--accent);
  font-size: 18px;
  filter: drop-shadow(0 0 8px rgba(110,168,254,.5));
}
.brand-name { font-weight: 650; letter-spacing: -.01em; }
.auth-title { font-size: 22px; margin: 0 0 6px; letter-spacing: -.02em; }
.auth-sub { color: var(--text-dim); margin: 0 0 24px; font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 15px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.auth-form input {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 11px 13px; font-size: 15px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.auth-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn-primary {
  margin-top: 6px;
  background: linear-gradient(180deg, var(--accent), #4f8cf0);
  color: #08111f; border: none; border-radius: var(--radius-sm);
  padding: 12px; font-size: 15px; font-weight: 650; cursor: pointer;
  transition: filter .15s, transform .05s;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:active { transform: translateY(1px); }
.auth-switch { text-align: center; margin: 22px 0 0; color: var(--text-dim); font-size: 14px; }
.auth-switch a { color: var(--accent); text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.auth-error {
  background: rgba(242,98,107,.1); border: 1px solid rgba(242,98,107,.35);
  color: #ffb3b8; border-radius: var(--radius-sm); padding: 10px 13px;
  font-size: 14px; margin-bottom: 18px;
}

/* ---------- Layout app ---------- */
.app-body { overflow: hidden; }
.layout { display: grid; grid-template-columns: 280px 1fr; height: 100vh; }

/* Sidebar */
.sidebar {
  background: var(--bg-elev); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-top { padding: 16px 14px 10px; }
.brand { display: flex; align-items: center; gap: 9px; padding: 4px 6px 14px; }
.btn-new {
  width: 100%; text-align: left;
  background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 13px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px;
  transition: background .15s, border-color .15s;
}
.btn-new:hover { background: #232833; border-color: #33404f; }

.sidebar-scroll { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.side-section { padding: 4px 8px 8px; }
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 8px 6px; font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-faint);
}
.side-add {
  background: none; border: 1px solid var(--line); color: var(--text-dim);
  width: 22px; height: 22px; border-radius: 6px; cursor: pointer; font-size: 15px; line-height: 1;
}
.side-add:hover { color: var(--text); border-color: #33404f; }
.project-list { display: flex; flex-direction: column; gap: 2px; }
.project-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-dim); font-size: 14px; border: 1px solid transparent;
}
.project-item:hover { background: var(--bg-elev-2); color: var(--text); }
.project-item.active { background: var(--accent-soft); color: var(--text); border-color: #2b3f63; }
.project-item .p-ico { color: var(--accent); font-size: 12px; }
.project-item .p-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.conv-list { overflow-y: visible; padding: 0 0 6px; display: flex; flex-direction: column; gap: 2px; }
.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer;
  color: var(--text-dim); font-size: 14px; border: 1px solid transparent;
  position: relative;
}
.conv-item:hover { background: var(--bg-elev-2); color: var(--text); }
.conv-item.active { background: var(--accent-soft); color: var(--text); border-color: #2b3f63; }
.conv-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-menu-btn {
  opacity: 0; background: none; border: none; color: var(--text-faint);
  cursor: pointer; font-size: 16px; padding: 0 2px; border-radius: 6px;
}
.conv-item:hover .conv-menu-btn, .conv-item.active .conv-menu-btn { opacity: 1; }
.conv-menu-btn:hover { color: var(--text); }

.sidebar-bottom {
  border-top: 1px solid var(--line); padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.user-chip { display: flex; align-items: center; gap: 9px; min-width: 0; }
.avatar {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #08111f; display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.user-name { font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-logout {
  background: none; border: 1px solid var(--line); color: var(--text-dim);
  padding: 6px 11px; border-radius: 8px; cursor: pointer; font-size: 13px; flex-shrink: 0;
}
.btn-logout:hover { color: var(--text); border-color: #33404f; }

/* Main */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.main-header {
  height: 52px; border-bottom: 1px solid var(--line); flex-shrink: 0;
  display: flex; align-items: center; gap: 12px; padding: 0 18px;
  background: rgba(14,16,19,.7); backdrop-filter: blur(8px);
}
.main-title { font-weight: 600; letter-spacing: -.01em; }
.btn-icon { background: none; border: none; color: var(--text-dim); font-size: 19px; cursor: pointer; }
.menu-toggle { display: none; }

.messages { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.msg-wrap { max-width: 760px; margin: 0 auto; padding: 26px 22px; display: flex; flex-direction: column; gap: 22px; }

.empty-state {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--text-dim); gap: 6px; padding: 20px;
}
.empty-mark { font-size: 34px; color: var(--accent); filter: drop-shadow(0 0 14px rgba(110,168,254,.4)); margin-bottom: 8px; }
.empty-state h2 { color: var(--text); margin: 0; font-size: 22px; letter-spacing: -.02em; }
.empty-state p { margin: 0; max-width: 360px; }

.msg { display: flex; gap: 14px; align-items: flex-start; }
.msg-avatar {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0; margin-top: 2px;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.msg.user .msg-avatar { background: var(--bg-elev-2); color: var(--text-dim); border: 1px solid var(--line); }
.msg.assistant .msg-avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #08111f; }
.msg-role { font-size: 12px; color: var(--text-faint); margin-bottom: 3px; font-weight: 600; letter-spacing: .02em; }
.msg-body { min-width: 0; flex: 1; }
.msg-content { color: var(--text); word-wrap: break-word; }
.msg-content p { margin: 0 0 11px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content h1, .msg-content h2, .msg-content h3 { margin: 16px 0 8px; line-height: 1.3; }
.msg-content ul, .msg-content ol { margin: 8px 0 11px; padding-left: 22px; }
.msg-content li { margin: 3px 0; }
.msg-content code {
  background: var(--bg-elev-2); border: 1px solid var(--line); border-radius: 5px;
  padding: 1px 5px; font-family: var(--mono); font-size: .88em;
}
.msg-content pre {
  background: #0a0c0f; border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 15px; overflow-x: auto; margin: 11px 0;
}
.msg-content pre code { background: none; border: none; padding: 0; font-size: 13px; }
.msg-content a { color: var(--accent); }
.cursor { display: inline-block; width: 8px; height: 15px; background: var(--accent); margin-left: 1px; border-radius: 2px; vertical-align: text-bottom; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Breadcrumb */
.breadcrumb { color: var(--accent); font-size: 13px; cursor: pointer; }
.breadcrumb:hover { text-decoration: underline; }

/* Vista de proyecto */
.project-view { flex: 1; overflow-y: auto; }
.project-inner { max-width: 820px; margin: 0 auto; padding: 26px 24px 60px; display: flex; flex-direction: column; gap: 26px; }
.project-hero { display: flex; align-items: center; gap: 14px; }
.project-name-input {
  flex: 1; background: none; border: none; border-bottom: 1px solid transparent; color: var(--text);
  font-size: 26px; font-weight: 700; letter-spacing: -.02em; padding: 4px 2px; outline: none;
}
.project-name-input:focus { border-bottom-color: var(--line); }
.btn-danger-ghost {
  background: none; border: 1px solid rgba(242,98,107,.35); color: var(--danger);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; flex-shrink: 0;
}
.btn-danger-ghost:hover { background: rgba(242,98,107,.1); }

.project-block { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.block-label { font-size: 14px; font-weight: 650; color: var(--text); }
.block-label-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.block-hint { font-size: 12px; color: var(--text-faint); margin: 4px 0 12px; }
.project-instr {
  width: 100%; background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 12px; font-family: var(--font); font-size: 14px;
  line-height: 1.5; resize: vertical; outline: none;
}
.project-instr:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.block-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.btn-primary.sm { padding: 8px 16px; font-size: 13px; }
.save-note { font-size: 13px; color: #57d191; }

.project-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.btn-upload {
  background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--text-dim);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.btn-upload:hover { color: var(--text); border-color: #33404f; }
.file-list, .proj-conv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file-item, .proj-conv-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 13px;
}
.file-item .f-name, .proj-conv-item .c-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.file-item .f-meta { color: var(--text-faint); font-size: 12px; flex-shrink: 0; }
.file-item a.f-dl { color: var(--accent); text-decoration: none; flex-shrink: 0; }
.file-item a.f-dl:hover { text-decoration: underline; }
.file-item .f-del, .proj-conv-item .c-del { background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 15px; flex-shrink: 0; }
.file-item .f-del:hover, .proj-conv-item .c-del:hover { color: var(--danger); }
.proj-conv-item { cursor: pointer; }
.proj-conv-item:hover { border-color: #33404f; }
.proj-conv-item .c-ico { color: var(--accent); font-size: 12px; }
.list-empty { color: var(--text-faint); font-size: 13px; padding: 6px 2px; }
.file-item.uploading { opacity: .6; }

/* Botón guardar respuesta como archivo (dentro de proyecto) */
.msg-tools { margin-top: 8px; display: flex; gap: 10px; }
.msg-save-btn {
  background: none; border: 1px solid var(--line); color: var(--text-dim);
  padding: 4px 10px; border-radius: 7px; cursor: pointer; font-size: 12px;
}
.msg-save-btn:hover { color: var(--text); border-color: #33404f; }

/* Cowork */
.cowork-list { display: flex; flex-direction: column; gap: 2px; }
.cowork-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-dim); font-size: 14px; border: 1px solid transparent;
}
.cowork-item:hover { background: var(--bg-elev-2); color: var(--text); }
.cowork-item.active { background: var(--accent-soft); color: var(--text); border-color: #2b3f63; }
.cowork-item .cw-ico { color: var(--accent); font-size: 12px; }
.cowork-item .cw-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cowork-view { flex: 1; display: flex; min-height: 0; }
.cowork-files {
  width: 300px; flex-shrink: 0; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; background: var(--bg-elev);
}
.cw-files-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px; }
.cw-files-title { font-weight: 650; font-size: 14px; }
.cw-files-actions { display: flex; gap: 4px; }
.cw-icon-btn {
  background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--text-dim);
  padding: 5px 9px; border-radius: 8px; cursor: pointer; font-size: 12px;
}
.cw-icon-btn:hover { color: var(--text); border-color: #33404f; }
.cw-breadcrumb { padding: 0 14px 8px; font-size: 12px; color: var(--text-faint); word-break: break-all; }
.cw-breadcrumb a { color: var(--accent); cursor: pointer; }
.cw-file-list { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 2px; }
.cw-row {
  display: flex; align-items: center; gap: 9px; padding: 8px 9px; border-radius: var(--radius-sm);
  font-size: 13px; cursor: default; border: 1px solid transparent;
}
.cw-row:hover { background: var(--bg-elev-2); }
.cw-row .cw-r-ico { flex-shrink: 0; }
.cw-row .cw-r-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.cw-row.dir .cw-r-name { cursor: pointer; color: var(--accent); }
.cw-row .cw-r-size { color: var(--text-faint); font-size: 11px; flex-shrink: 0; }
.cw-row .cw-r-act { background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 13px; padding: 0 2px; flex-shrink: 0; }
.cw-row .cw-r-act:hover { color: var(--text); }
.cw-row .cw-r-act.del:hover { color: var(--danger); }
.cw-hint { padding: 8px 14px; font-size: 11px; color: var(--text-faint); border-top: 1px solid var(--line); margin: 0; }
.cw-empty { color: var(--text-faint); font-size: 13px; padding: 10px 6px; }

.cowork-chat { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.cowork-chat .messages { flex: 1; }

/* Actividad de herramientas (tool use) */
.tool-activity { display: flex; flex-direction: column; gap: 5px; margin: 2px 0 4px; }
.tool-line {
  display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--text-dim);
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 8px; padding: 7px 11px;
}
.tool-line .tool-spin {
  width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; flex-shrink: 0;
}
.tool-line.done .tool-spin { border: 2px solid transparent; border-top-color: transparent; }
.tool-line.done::before { content: '✓'; color: #57d191; font-weight: 700; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .cowork-files { width: 220px; }
}

/* Composer */
.composer { border-top: 1px solid var(--line); padding: 14px 22px 10px; flex-shrink: 0; background: var(--bg); }
.composer form { max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 8px 8px 14px; transition: border-color .15s; }
.composer form:focus-within { border-color: #33404f; }
#input {
  flex: 1; resize: none; border: none; outline: none; background: none; color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.5; max-height: 200px; padding: 6px 0;
}
.btn-send {
  width: 36px; height: 36px; flex-shrink: 0; border: none; border-radius: 9px; cursor: pointer;
  background: linear-gradient(180deg, var(--accent), #4f8cf0); color: #08111f; font-size: 18px; font-weight: 700;
  display: grid; place-items: center; transition: filter .15s, opacity .15s;
}
.btn-send:hover { filter: brightness(1.08); }
.btn-send:disabled { opacity: .4; cursor: default; }
.composer-hint { text-align: center; color: var(--text-faint); font-size: 12px; margin: 8px 0 2px; }

/* Menú contextual de conversación */
.ctx-menu {
  position: fixed; z-index: 50; background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 5px; min-width: 150px; box-shadow: 0 20px 50px -12px rgba(0,0,0,.7);
}
.ctx-menu button {
  display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text);
  padding: 8px 11px; border-radius: 7px; cursor: pointer; font-size: 14px;
}
.ctx-menu button:hover { background: var(--bg-elev); }
.ctx-menu button.danger { color: var(--danger); }

/* Responsive */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40;
    transform: translateX(-100%); transition: transform .22s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 60px rgba(0,0,0,.6); }
  .menu-toggle { display: block; }
  .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 39; }
  .project-columns { grid-template-columns: 1fr; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a303a; border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #38404d; background-clip: padding-box; }
