:root { --gap: 12px; --border: #e5e7eb; --bg: #fafafa; --hdr: #111827; --row-h: 28px; --chat-row-h: 20px; --accent: #4f46e5; }
* { box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif; margin: 0; background: var(--bg); color: #111; display: flex; flex-direction: column; min-height: 100vh; overflow: hidden; }
header { padding: 12px 16px; border-bottom: 1px solid var(--border); background: #fff; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { font-size: 18px; margin: 0; color: var(--hdr); display: inline-flex; align-items: center; gap: 8px; }
/* App title icon */
.app-title { display: inline-flex; align-items: center; gap: 8px; }
.app-title .app-icon { width: 1em; height: 1em; display: inline-block; fill: #0b3d91; }
main { padding: 12px; flex: 1; min-height: 0; overflow: hidden; }
.app-layout { display: grid; grid-template-columns: 1fr var(--drawer-w, 0px); gap: var(--gap); align-items: stretch; height: 100%; }
.report-area { border: 1px solid var(--border); border-radius: 6px; background: #fff; display: flex; flex-direction: column; min-height: 0; }
.report-area iframe { flex: 1; border: none; width: 100%; min-height: 0; }
.report-placeholder { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 32px; background: #f9fafb; }
.placeholder-card { max-width: 520px; width: 100%; border: 1px dashed #d1d5db; border-radius: 12px; padding: 24px 28px; background: #fff; box-shadow: 0 10px 30px rgba(15,23,42,0.08); display: flex; flex-direction: column; gap: 16px; text-align: left; color: #1f2937; }
.placeholder-title { margin: 0; font-size: 20px; font-weight: 700; color: #111827; }
.placeholder-body { margin: 0; font-size: 15px; line-height: 1.6; color: #4b5563; }
.placeholder-steps { margin: 0; padding-left: 20px; font-size: 15px; line-height: 1.6; color: #374151; display: flex; flex-direction: column; gap: 8px; }
.placeholder-steps li { margin-left: 4px; }
.placeholder-examples { display: flex; flex-direction: column; gap: 8px; padding: 16px; border-radius: 10px; background: #f3f4f6; }
.placeholder-examples-title { font-weight: 600; color: #1f2937; }
.placeholder-examples-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; color: #374151; }
.placeholder-examples-list li { list-style: disc; }
.assistant-panel { border: 1px solid var(--border); border-radius: 6px; background: #fff; display: flex; flex-direction: column; min-height: 0; }
.assistant-header { padding: 8px 10px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.assistant-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.assistant-actions { margin-left: auto; display: inline-flex; gap: 6px; }
.assistant-panel { position: relative; }
.assistant-resizer { position: absolute; left: -8px; top: 0; bottom: 0; width: 16px; cursor: ew-resize; background: transparent; z-index: 5; touch-action: none; }
/* Hide border and resizer completely when panel is closed */
.assistant-panel[aria-hidden="true"] { display: none !important; border: none; pointer-events: none; overflow: hidden; }
.assistant-panel[aria-hidden="true"] .assistant-resizer { display: none !important; }

/* Improve dragging UX: prevent text selection and iframe capture during resize */
.resizing, .resizing * { user-select: none !important; -webkit-user-select: none !important; cursor: ew-resize !important; }
.resizing iframe { pointer-events: none; }
.assistant-fab { position: fixed; right: 16px; bottom: 16px; z-index: 64; display: inline-flex; align-items: center; gap: 8px; background: #111827; color: #fff; border: none; border-radius: 999px; padding: 10px 14px; box-shadow: 0 8px 20px rgba(0,0,0,.25); cursor: pointer; }
.assistant-fab .icon { width: 18px; height: 18px; }
.fab-label { font-weight: 600; }
.lang-switch { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.auth-actions { display: inline-flex; align-items: center; gap: 8px; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; }
.user-menu { position: relative; }
#user-popover { right: 0; }
.menu-popover hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; }
.menu-popover .menu-label { padding: 6px 10px; color: #6b7280; }
.user-chip #user-initials { display: inline-flex; width: 24px; height: 24px; border-radius: 999px; background: #111827; color: #fff; align-items: center; justify-content: center; font-weight: 700; }
.visually-hidden { position: absolute !important; height: 1px; width: 1px; overflow: hidden; clip: rect(1px, 1px, 1px, 1px); white-space: nowrap; }
.accordion details { border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: 6px 10px; }
.columns { display: grid; grid-template-columns: minmax(30%, 35%) auto minmax(0, 1fr); gap: var(--gap); align-items: stretch; }
.dataset-editor { height: calc(var(--row-h) * 20); min-height: calc(var(--row-h) * 20); max-height: calc(var(--row-h) * 20); overflow: hidden; }
.panel { border: 1px solid var(--border); border-radius: 6px; padding: 6px; background: #fff; display: flex; flex-direction: column; }
.panel { height: 100%; min-height: 0; }
.dataset-editor > .panel { min-height: 0; }
.panel-header { font-weight: 600; padding: 0 6px; border-bottom: 1px solid var(--border); margin-bottom: 6px; height: 28px; display: flex; align-items: center; }
.header-flex { display: flex; align-items: center; gap: 6px; }
.header-flex .btn-icon { width: 24px; height: 24px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.header-flex .btn-icon .icon { width: 18px; height: 18px; }
/* Ensure hidden always wins over header flex button display */
.btn-icon.hidden { display: none !important; }
.breadcrumbs { color: #6b7280; font-weight: 400; margin-left: auto; }
.breadcrumbs .sep { margin: 0 6px; color: #9ca3af; }
.breadcrumbs a { color: #2563eb; cursor: pointer; text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }
.list { list-style: none; padding: 0; margin: 0; overflow: auto; flex: 1; }
.list li { padding: 0 8px; border-bottom: 1px dashed var(--border); cursor: pointer; height: var(--row-h); line-height: var(--row-h); white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.list li.active { background: #eef2ff; }
.list li .row { display: grid; grid-template-columns: 18px 1fr 18px; align-items: center; gap: 6px; }
.icon-16 { width: 16px; height: 16px; display: inline-block; color: #6b7280; }
.icon-ok { color: #16a34a; }
.icon-wait { color: #9ca3af; }
.panel.fixed10 .list { max-height: none; }
.controls { display: flex; align-items: center; justify-content: center; }
.controls.vertical { flex-direction: column; gap: 8px; }
button { padding: 6px 10px; cursor: pointer; }
.btn-icon { display: inline-flex; align-items: center; gap: 6px; }
.btn-icon .icon { width: 18px; height: 18px; display: inline-block; }
.controls.vertical .btn-icon { width: 40px; height: 40px; padding: 0; align-items: center; justify-content: center; }
.controls.vertical .btn-icon .icon { width: 22px; height: 22px; }

.bottom { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.chat, .report { display: flex; flex-direction: column; }
.assistant-panel .chat { flex: 1; min-height: 0; overflow: hidden; }
.chat-log { flex: 1; overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; max-height: none; }
.chat-hint { padding: 6px 10px; color: #6b7280; font-size: 12px; border-top: 1px dashed var(--border); }
.msg { padding: 8px 10px; border-radius: 10px; max-width: 75%; line-height: var(--chat-row-h); }
.msg.user { align-self: flex-end; background: #dcfce7; }
.msg.assistant { align-self: flex-start; background: #e0e7ff; }
/* Thinking indicator */
.msg.assistant.thinking { background: #f3f4f6; color: #6b7280; }
.typing-dots { display: inline-flex; align-items: center; gap: 4px; height: 10px; }
.typing-dots .dot { width: 6px; height: 6px; border-radius: 50%; background: #9ca3af; opacity: .3; animation: dotPulse 1.2s infinite ease-in-out; }
.typing-dots .dot:nth-child(2) { animation-delay: .15s; }
.typing-dots .dot:nth-child(3) { animation-delay: .3s; }
@keyframes dotPulse { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }
.chat-input { display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px; padding: 8px; border-top: 1px solid var(--border); position: relative; }
.chat-input .btn-icon { width: 40px; height: 40px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.chat-input .btn-icon .icon { width: 22px; height: 22px; }
textarea { width: 100%; }
#chat-text { resize: none; overflow-y: hidden; }
iframe { flex: 1; border: none; }

/* Modal */
.hidden { display: none; }
.blocker-overlay { position: fixed; inset: 64px 12px 12px 12px; background: rgba(255,255,255,.85); backdrop-filter: blur(2px); z-index: 40; display: flex; align-items: center; justify-content: center; border: 1px dashed var(--border); border-radius: 8px; }
.blocker-overlay.hidden { display: none !important; }
.blocker-inner { text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.blocker-text { color: #374151; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
/* Ensure conflict resolution dialog always stacks above other modals */
#modal-overlay { z-index: 80; }
#modal-confirm-remove-overlay { z-index: 90; }
.modal-overlay.hidden { display: none !important; }
.modal { background: #fff; border: 1px solid var(--border); border-radius: 10px; width: 440px; max-width: 100%; box-shadow: 0 10px 30px rgba(0,0,0,.15); overflow: hidden; }
.modal.modal-large { width: 960px; max-width: 95vw; }
.modal.modal-medium { width: 640px; max-width: 95vw; }

/* AppsHub modal: fixed body height = 12 rows; Browser scrolls inside */
#modal-editor-overlay-appshub .modal-body { height: calc(var(--row-h) * 12); min-height: calc(var(--row-h) * 12); max-height: calc(var(--row-h) * 12); overflow: hidden; }
#dataset-editor-core-chat { height: 100%; display: flex; flex-direction: column; }
.modal-header { font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 12px 14px; }
.form-row { display: grid; grid-template-columns: 120px 1fr; align-items: center; gap: 10px; margin: 8px 0; }
.form-error { color: #b91c1c; font-size: 12px; }
.modal-actions { padding: 10px 14px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.btn { padding: 6px 12px; border: 1px solid var(--border); background: #fff; border-radius: 6px; cursor: pointer; }
.btn.primary { background: #4f46e5; border-color: #4f46e5; color: #fff; }
.btn.subtle { color: #374151; }
.btn[disabled], .btn:disabled { opacity: 0.55; cursor: not-allowed; pointer-events: none; }
.btn.primary[disabled], .btn.primary:disabled { background: #c7d2fe; border-color: #c7d2fe; color: #fff; opacity: 1; }
.conflicts { margin: 6px 0 0 0; padding-left: 18px; max-height: 160px; overflow: auto; }
.conflicts li { line-height: 22px; }

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #111827; color: #fff; padding: 10px 12px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); opacity: .95; }

/* Dataset panel layout */
.dataset-layout { display: grid; grid-template-columns: 30% 70%; gap: 8px; align-items: stretch; height: 100%; }
.dataset-layout > .list, .dataset-layout > .props { min-height: 0; }
.props { overflow: auto; }
/* Dataset file list: allow horizontal scroll for long names */
.dataset-layout > .list { overflow-x: auto; }
.dataset-layout > .list li { overflow: visible; text-overflow: initial; white-space: nowrap; }
.dataset-layout .props { border: 1px solid var(--border); border-radius: 6px; padding: 0; background: #fff; display: flex; flex-direction: column; }
.dataset-layout .props .panel-header { margin: 0; }
.props-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.props-table td { border-bottom: 1px dashed var(--border); padding: 6px 8px; vertical-align: top; }
.props-table td.prop-name { width: 40%; font-weight: 600; color: #374151; }
.props-table td.prop-val { width: 60%; color: #111; word-break: break-word; }
/* File meta modal: fixed body height ~20 rows with inner scroll */
#modal-meta-overlay .props-scroll { height: calc(var(--row-h) * 20); min-height: calc(var(--row-h) * 20); max-height: calc(var(--row-h) * 20); overflow: auto; }

/* Chat Files Panel */
.chat-files-panel { display: flex; flex-direction: row; flex-wrap: nowrap; gap: 8px; padding: 6px 10px; border-top: 1px dashed var(--border); border-bottom: 1px dashed var(--border); overflow-x: auto; white-space: nowrap; }
.chat-files-panel.hidden { display: none; }
.file-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 999px; background: #fff; color: #111; white-space: nowrap; flex: 0 0 auto; }
.file-pill .icon-16 { width: 14px; height: 14px; }
.file-pill .pill-remove { width: 16px; height: 16px; display: inline-flex; align-items: center; justify-content: center; color: #6b7280; cursor: pointer; }
.file-pill .pill-remove:hover { color: #ef4444; }

/* Chat add-file popover menu */
.menu-popover { position: absolute; min-width: 220px; background: #fff; color: #111; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.15); padding: 6px; z-index: 70; }
.menu-popover .menu-item { display: block; width: 100%; text-align: left; background: transparent; border: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu-popover .menu-item:hover { background: #f3f4f6; }

@media (max-width: 1024px) {
  .app-layout { grid-template-columns: 1fr var(--drawer-w, 0px); }
}
