/* ============================================================
   NSOffice.AI Excel Analyst - app styles
   Builds on tokens.css (brand + Apple UX + glass).
   ============================================================ */

/* The critical fix: the hidden attribute must beat component display rules
   like .dropzone{display:flex}. Without this, views stack on top of each other. */
[hidden] { display: none !important; }

html, body { height: 100%; }
body { background: var(--bg); overflow: hidden; }

/* ---------- App shell ---------- */
.app { display: flex; height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 268px; flex: 0 0 268px; height: 100vh;
  background: var(--bg-alt); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; z-index: 20;
}
.sidebar-top { padding: var(--space-md); display: flex; flex-direction: column; gap: var(--space-md);
  border-bottom: 1px solid var(--line); }
.side-logo { height: 20px; align-self: flex-start; opacity: 0.9; }
.new-chat-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 16px; border-radius: var(--radius-pill); border: none; cursor: pointer;
  background: var(--blue); color: #fff; font: var(--text-medium); font-weight: 700;
  transition: filter var(--t-fast), transform var(--t-fast);
}
.new-chat-btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
.new-chat-btn .material-symbols-rounded { font-size: 20px; }

.chat-list { flex: 1; overflow-y: auto; padding: var(--space-sm); display: flex; flex-direction: column; gap: 4px; }
.chat-list .empty { color: var(--slate); font: var(--text-caption); padding: var(--space-md); text-align: center; }
.chat-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--ink); transition: background var(--t-fast);
}
.chat-item:hover { background: rgba(154,167,188,0.14); }
.chat-item.active { background: var(--blue-soft); }
.chat-item .ci-icon { font-size: 18px; color: var(--slate); flex: 0 0 auto; }
.chat-item.active .ci-icon { color: var(--blue); }
.chat-item .ci-body { flex: 1; min-width: 0; }
.chat-item .ci-title { font: var(--text-caption); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .ci-sub { font-size: 11px; color: var(--slate); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .ci-del { opacity: 0; border: none; background: none; cursor: pointer; color: var(--slate);
  display: grid; place-items: center; border-radius: 8px; padding: 4px; }
.chat-item:hover .ci-del { opacity: 1; }
.chat-item .ci-del:hover { color: #C0392B; background: rgba(192,57,43,0.1); }
.chat-item .ci-del .material-symbols-rounded { font-size: 17px; }

.sidebar-foot { padding: var(--space-md); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.loaded-files { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.loaded-files .lf-empty { font: var(--text-caption); color: var(--slate); padding: 2px 2px 4px; }
.file-chip { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--bg); max-height: 60px; overflow: hidden;
  transition: max-height var(--t-fast), opacity var(--t-fast), transform var(--t-fast),
              padding var(--t-fast), margin var(--t-fast), border-width var(--t-fast); }
.file-chip.removing { max-height: 0; opacity: 0; transform: translateX(10px);
  padding-top: 0; padding-bottom: 0; border-width: 0; margin-top: -6px; }
.file-chip .fc-icon { font-size: 16px; color: var(--blue); flex: 0 0 auto; }
.file-chip .fc-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: var(--text-caption); font-weight: 700; color: var(--ink); }
.file-chip .fc-del { border: none; background: none; cursor: pointer; color: var(--slate);
  display: grid; place-items: center; border-radius: 6px; padding: 3px; flex: 0 0 auto; transition: all var(--t-fast); }
.file-chip .fc-del:hover { color: #C0392B; background: rgba(192,57,43,0.1); }
.file-chip .fc-del .material-symbols-rounded { font-size: 15px; }

/* dataset-removed badge */
.removed-badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px;
  border-radius: var(--radius-pill); background: rgba(192,57,43,0.1); color: #C0392B;
  font: var(--text-caption); font-weight: 700; }
.removed-badge .material-symbols-rounded { font-size: 16px; }

/* toast */
.toast-host { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; }
.toast { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: var(--radius-pill);
  background: var(--ink); color: #fff; font: var(--text-medium); font-weight: 600; box-shadow: var(--shadow-float);
  opacity: 0; transform: translateY(10px); transition: opacity var(--t-fast), transform var(--t-fast); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast .material-symbols-rounded { font-size: 18px; }
.toast.success .material-symbols-rounded { color: #5be49b; }
.toast.error { background: #C0392B; }

/* confirm modal */
.modal-host { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; }
.modal-scrim { position: absolute; inset: 0; background: rgba(11,14,20,0.4); backdrop-filter: blur(2px);
  animation: fadeIn var(--t-fast) both; }
.modal-card { position: relative; width: min(420px, calc(100% - 40px)); padding: var(--space-lg);
  border-radius: var(--radius-lg); text-align: center; animation: modalPop 0.2s var(--ease) both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalPop { from { opacity: 0; transform: scale(0.94) translateY(8px); } to { opacity: 1; transform: none; } }
.modal-icon { width: 48px; height: 48px; border-radius: 14px; margin: 0 auto var(--space-md);
  display: grid; place-items: center; background: rgba(192,57,43,0.1); color: #C0392B; }
.modal-icon .material-symbols-rounded { font-size: 26px; }
.modal-card h3 { font-size: 18px; margin-bottom: 6px; }
.modal-card p { font: var(--text-medium); color: var(--slate); margin-bottom: var(--space-lg); }
.modal-actions { display: flex; gap: var(--space-sm); justify-content: center; }
.modal-btn { padding: 10px 20px; border-radius: var(--radius-pill); font: var(--text-medium); font-weight: 700;
  cursor: pointer; border: 1px solid var(--line); transition: all var(--t-fast); }
.modal-btn.cancel { background: var(--bg); color: var(--ink); }
.modal-btn.cancel:hover { background: var(--bg-alt); }
.modal-btn.danger { background: #C0392B; color: #fff; border-color: #C0392B; }
.modal-btn.danger:hover { filter: brightness(1.1); }
.side-action {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg); cursor: pointer; color: var(--ink);
  font: var(--text-caption); font-weight: 600; transition: all var(--t-fast);
}
.side-action:hover { border-color: var(--blue); color: var(--blue); }
.side-action .material-symbols-rounded { font-size: 18px; }

/* ---------- Main / views ---------- */
.main { flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; overflow: hidden; }
.sidebar-toggle { display: none; }

/* ---------- Upload view ---------- */
.upload-view { position: relative; flex: 1; display: flex; align-items: center; justify-content: center;
  overflow: hidden; padding: var(--space-xl) var(--space-lg); background: var(--bg); }
.upload-view.hive-bg { }
.upload-inner { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: var(--space-md); max-width: 640px; }
.wordmark { height: 30px; opacity: 0.92; margin-bottom: 4px; }
.upload-inner h1 { font-size: clamp(34px, 5vw, 52px); }
.upload-inner .lede { font: var(--text-light); font-size: 17px; color: var(--slate); max-width: 560px; }

.dropzone {
  display: flex; align-items: center; gap: var(--space-md);
  width: min(560px, 100%); padding: var(--space-lg); cursor: pointer; text-align: left;
  margin-top: var(--space-sm); transition: transform var(--t-fast), box-shadow var(--t-med);
}
.dropzone:hover { transform: translateY(-2px); }
.dropzone.dragover { box-shadow: 0 24px 60px rgba(0,0,254,0.22), inset 0 0 0 2px var(--blue); }
.dropzone .dz-text { display: flex; flex-direction: column; gap: 2px; }
.dropzone .dz-text strong { font-weight: 700; color: var(--ink); }

/* progress / estimation bar */
.progress-wrap { width: min(560px, 100%); display: flex; flex-direction: column; gap: 8px;
  margin-top: var(--space-sm); }
.progress-head { display: flex; justify-content: space-between; font: var(--text-medium); color: var(--ink); }
.progress-head #progressPct { font-weight: 700; color: var(--blue); }
.progress-track { height: 10px; border-radius: var(--radius-pill); background: var(--blue-soft); overflow: hidden; }
.progress-bar { height: 100%; width: 0%; border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--blue), var(--blue-bright));
  transition: width 0.3s var(--ease); }
.progress-wrap #progressFile { color: var(--slate); text-align: left; }
.upload-error { color: #C0392B; font: var(--text-medium); max-width: 560px; }

/* ---------- Chat view ---------- */
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.topbar {
  display: flex; align-items: center; gap: var(--space-md); flex-wrap: wrap;
  padding: 12px var(--space-lg); border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.85); backdrop-filter: blur(10px); z-index: 5;
}
.ready-badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px;
  border-radius: var(--radius-pill); background: rgba(30,142,62,0.1); color: #1E8E3E;
  font: var(--text-caption); font-weight: 700; white-space: nowrap; }
.ready-badge .material-symbols-rounded { font-size: 17px; }
.dataset-chips { display: flex; flex-wrap: wrap; gap: var(--space-sm); flex: 1; overflow: hidden; }
.dchip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px;
  border-radius: var(--radius-pill); background: var(--bg-alt); font: var(--text-caption);
  color: var(--ink); white-space: nowrap; }
.dchip .material-symbols-rounded { font-size: 16px; color: var(--blue); }

/* thread */
.thread { flex: 1; overflow-y: auto; padding: var(--space-xl) var(--space-lg); }
.msg { max-width: 860px; margin: 0 auto var(--space-lg); display: flex; gap: var(--space-md); }
.msg.user { flex-direction: row-reverse; }
.msg .avatar { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 12px; display: grid; place-items: center; }
.msg.assistant .avatar { background: var(--lavender); color: var(--blue); }
.msg.user .avatar { background: var(--blue); color: #fff; }
.msg .avatar .material-symbols-rounded { font-size: 20px; }
.bubble { max-width: 100%; min-width: 0; }
.msg.user .bubble { background: var(--blue); color: #fff; padding: 12px 18px;
  border-radius: var(--radius-lg) var(--radius-lg) 6px var(--radius-lg); font: var(--text-medium); max-width: 560px; }
.msg.assistant .bubble { flex: 1; }

/* markdown */
.md { font: var(--text-body); color: var(--ink); }
.md > *:first-child { margin-top: 0; } .md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { margin: var(--space-md) 0 var(--space-sm); line-height: 1.25; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 16px; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md strong { font-weight: 700; }
.md code { background: var(--bg-alt); padding: 1px 6px; border-radius: 6px; font-size: 0.9em; }
.md pre { background: var(--ink-dark-surface); color: var(--text-on-dark); padding: 14px;
  border-radius: var(--radius-sm); overflow-x: auto; }
.md pre code { background: none; color: inherit; padding: 0; }
.md .table-wrap { overflow-x: auto; margin: 10px 0; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.md table { border-collapse: collapse; width: 100%; font: var(--text-caption); }
.md th, .md td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.md thead th { background: var(--bg-alt); font-weight: 700; color: var(--ink); }
.md tbody tr:last-child td { border-bottom: none; }
.md td:not(:first-child), .md th:not(:first-child) { text-align: right; }

/* viz cards */
.viz-card { border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow-card);
  padding: var(--space-lg); margin: var(--space-md) 0; background: var(--bg); }
.viz-card .viz-title { font: var(--text-heading); font-size: 16px; margin-bottom: var(--space-md); }
.viz-chart-wrap { position: relative; height: 320px; }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-md); margin: var(--space-md) 0; }
.kpi-tile { border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-md) var(--space-lg); background: var(--bg-alt); }
.kpi-tile .kpi-label { font: var(--text-caption); color: var(--slate); text-transform: uppercase; letter-spacing: 0.05em; }
.kpi-tile .kpi-value { font: 800 26px/1.1 var(--font); color: var(--ink); margin-top: 4px; }
.kpi-tile .kpi-unit { font-size: 14px; font-weight: 600; color: var(--slate); margin-left: 4px; }
.kpi-tile .kpi-delta { font: var(--text-caption); font-weight: 700; margin-top: 6px; display: inline-block; }
.kpi-delta.up { color: #1E8E3E; } .kpi-delta.down { color: #C0392B; } .kpi-delta.flat { color: var(--slate); }

/* trace */
.trace { margin-top: 10px; }
.trace summary { cursor: pointer; font: var(--text-caption); font-weight: 700; color: var(--slate);
  list-style: none; display: inline-flex; align-items: center; gap: 6px; user-select: none; }
.trace summary::-webkit-details-marker { display: none; }
.trace summary .material-symbols-rounded { font-size: 16px; transition: transform var(--t-fast); }
.trace[open] summary .material-symbols-rounded { transform: rotate(90deg); }
.trace-item { margin-top: 8px; padding: 10px 12px; background: var(--ink-dark-surface); border-radius: var(--radius-sm); }
.trace-item .trace-head { font: var(--text-caption); color: var(--blue-bright); font-weight: 700; margin-bottom: 4px; }
.trace-item pre { margin: 0; color: var(--text-on-dark); font-size: 12px; white-space: pre-wrap; word-break: break-word;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.trace-item .trace-meta { font-size: 11px; color: var(--text-on-dark-2); margin-top: 4px; }

/* HTML dashboard artifact (rendered live in a sandboxed iframe) */
.artifact { border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden;
  margin: var(--space-md) 0; box-shadow: var(--shadow-card); background: var(--bg); }
.artifact-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-md);
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--bg-alt); }
.artifact-title { font: var(--text-caption); font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 6px; }
.artifact-title .material-symbols-rounded { color: var(--blue); font-size: 18px; }
.artifact-actions { display: flex; gap: 8px; }
.artifact-btn { display: inline-flex; align-items: center; gap: 4px; padding: 5px 10px; border: 1px solid var(--line);
  background: var(--bg); border-radius: var(--radius-pill); font: var(--text-caption); font-weight: 600; color: var(--ink); cursor: pointer; }
.artifact-btn:hover { border-color: var(--blue); color: var(--blue); }
.artifact-btn .material-symbols-rounded { font-size: 16px; }
.artifact-frame { width: 100%; height: 760px; border: 0; display: block; background: #fff; }

/* chain-of-thought (live reasoning) panel */
.cot { margin-bottom: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-alt); overflow: hidden; }
.cot > summary { cursor: pointer; padding: 10px 14px; font: var(--text-caption); font-weight: 700; color: var(--ink);
  display: flex; align-items: center; gap: 8px; list-style: none; user-select: none; }
.cot > summary::-webkit-details-marker { display: none; }
.cot-check { font-size: 17px; color: #1E8E3E; }
.cot-spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--blue-soft);
  border-top-color: var(--blue); animation: spin 0.7s linear infinite; flex: 0 0 auto; }
.cot-body { padding: 0 14px 12px; display: flex; flex-direction: column; gap: 10px; max-height: 300px; overflow-y: auto; }
.cot-think { font: var(--text-caption); line-height: 1.5; color: var(--slate); white-space: pre-wrap; }
.cot-note.md { font-size: 12.5px; line-height: 1.55; color: var(--ink); }
.cot-note.md > *:first-child { margin-top: 0; }
.cot-note.md > *:last-child { margin-bottom: 0; }
.cot-tool { border-left: 2px solid var(--blue); padding-left: 10px; }
.cot-tool-head { font: var(--text-caption); font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cot-tool-head .material-symbols-rounded { font-size: 16px; color: var(--blue); }
.cot-run { font-weight: 600; color: var(--slate); }
.cot-run.ok { color: #1E8E3E; } .cot-run.err { color: #C0392B; }
.cot-tool pre { margin: 6px 0 0; background: var(--ink-dark-surface); color: var(--text-on-dark);
  padding: 8px 10px; border-radius: 8px; font-size: 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-word;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; }
/* Live-streamed answer preview: rendered as real Markdown (not raw text) so it
   matches the final formatted answer instead of "popping" into shape at the end. */
.cot-preview.md { font: var(--text-body); color: var(--ink); margin-bottom: 6px; }
.cot-preview.md > *:first-child { margin-top: 0; }
.cot-preview.md > *:last-child { margin-bottom: 0; }
.cot-preview.md::after {
  content: ''; display: inline-block; width: 8px; height: 15px; margin-left: 2px;
  background: var(--blue); vertical-align: text-bottom; animation: cotblink 0.9s step-start infinite;
}
@keyframes cotblink { 50% { opacity: 0; } }

/* typing */
.typing { display: inline-flex; gap: 5px; padding: 6px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--slate); animation: bounce 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: 0.15s; } .typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%,80%,100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }

/* composer */
.composer { border-top: 1px solid var(--line); padding: var(--space-md) var(--space-lg) var(--space-lg);
  background: var(--bg); }
.composer-inner { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-sm); }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.suggestion { padding: 7px 14px; border-radius: var(--radius-pill); border: 1px solid var(--line);
  background: var(--bg); font: var(--text-caption); font-weight: 600; color: var(--ink); cursor: pointer;
  transition: all var(--t-fast); white-space: nowrap; }
.suggestion:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); }
.decision-bar { width: 100%; }
.decision-bar .go:disabled { opacity: 0.5; cursor: not-allowed; transform: none; filter: none; }
.composer-hint { font: var(--text-caption); color: var(--slate); text-align: center; }

.scrim { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform var(--t-med); box-shadow: var(--shadow-float); }
  .app.nav-open .sidebar { transform: translateX(0); }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(11,14,20,0.35); z-index: 15; }
  .sidebar-toggle { display: grid; place-items: center; position: absolute; top: 10px; left: 10px; z-index: 6;
    width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; }
  .topbar { padding-left: 60px; }
  .thread { padding: var(--space-lg) var(--space-md); }
  .viz-chart-wrap { height: 260px; }
  .msg.user .bubble { max-width: 85%; }
}
