/* Extracted from latest.html (lines 12-548) */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #000000; --bg2: #0a0a0a; --bg3: #111111;
  --border: #222222; --text: #e5e7eb; --text2: #94a3b8;
  --accent: #00ff00; --accent-dim: #00cc00; --danger: #ff0000;
  --user-msg: #0a1a0a; --ai-msg: #0a0a0a;
}
html, body { max-width: 100vw; overflow-x: hidden; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; max-width: 100%; }

.app-container { display: flex; flex: 1; overflow: hidden; height: calc(100vh - 57px); }

.header { background: var(--bg2); border-bottom: 1px solid var(--border); padding: 12px 20px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; position: sticky; top: 0; z-index: 50; isolation: isolate; }
.header-brand { color: var(--accent); font-weight: bold; font-size: 1.1em; text-decoration: none; }
.header-brand:hover { color: var(--accent-dim); }
.header-actions { display: flex; gap: 8px; align-items: center; }

.dropdown-menu {
  display: none;
  position: fixed;
  top: 60px;
  right: 20px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 180px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 9999;
  margin-top: 4px;
}
.dropdown-menu.show { display: block; }
.dropdown-menu a {
  display: block;
  padding: 10px 14px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9em;
  border-bottom: 1px solid var(--border);
}
.dropdown-menu a:hover { background: var(--bg3); color: var(--accent); }
.dropdown-menu a:last-child { border-bottom: none; }
.dropdown-section {
  padding: 8px 14px;
  font-size: 0.75em;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 1px;
  background: var(--bg3);
}

.btn { padding: 8px 14px; border-radius: 8px; border: none; cursor: pointer; font-size: 0.9em; transition: all 0.2s; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--accent); color: #000; font-weight: bold; }
.btn-primary:hover { background: var(--accent-dim); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 0.8em; }

.hamburger { background: none; border: none; color: var(--text); font-size: 1.4em; cursor: pointer; padding: 4px 8px; }

.sidebar { width: 280px; background: var(--bg2); border-right: 1px solid var(--border); padding: 16px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; flex-shrink: 0; }
@media (max-width: 700px) { 
  .sidebar { display: none; position: fixed; top: 56px; left: 0; bottom: 0; z-index: 100; width: 100%; } 
  .sidebar.open { display: flex; }
  .modal-content { 
    width: 95vw !important; 
    max-width: 95vw !important; 
    max-height: 85vh !important;
    margin: 10px !important;
    border-radius: 12px !important;
  }
  .modal-header { padding: 12px 16px !important; }
  .modal-body { padding: 16px !important; }
  .modal-footer { 
    padding: 12px 16px !important;
    flex-wrap: wrap !important;
  }
  .btn, .hamburger, .modal-close, .module-item, .module-action-btn {
    min-height: 44px !important;
    min-width: 44px !important;
  }
  .header-brand { font-size: 1em !important; }
  .message { font-size: 0.95em !important; padding: 12px 14px !important; }
  .input-area textarea { font-size: 16px !important; }
  .input-area { padding: 12px 16px !important; }
  .chat-container { padding: 12px !important; }
  .settings-row { flex-direction: column !important; align-items: stretch !important; }
  .settings-row label { min-width: auto !important; margin-bottom: 4px !important; }
  .msg-copy { 
    display: flex !important;
    opacity: 0.7 !important;
  }
  .message:hover .msg-copy { opacity: 1 !important; }
  .msg-copy:active { transform: scale(0.95); }
  .module-item { padding: 12px 16px !important; }
  .module-actions { 
    display: flex !important; 
    position: static !important;
    margin-top: 8px !important;
  }
  .preview-toolbar {
    margin-left: 0 !important;
    gap: 4px !important;
    order: 2 !important;
  }
  .preview-toolbar button {
    padding: 8px !important;
    min-width: 44px !important;
    min-height: 44px !important;
  }
  .preview-view-toggle { order: 1 !important; margin-right: 0 !important; }
  .preview-view-toggle button {
    padding: 10px 12px !important;
    font-size: 0.8em !important;
  }
  .preview-modal {
    width: 95vw !important;
    max-width: 95vw !important;
    height: 85vh !important;
    max-height: 85vh !important;
  }
  .raw-code-preview { font-size: 11px !important; padding: 12px !important; }
}

@media (max-width: 480px) {
  .modal-content {
    width: 100vw !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    height: 100vh !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }
  #editHtmlModal .modal-content {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
  }
  #editHtmlModal #htmlEditor {
    height: calc(100vh - 180px) !important;
    min-height: 200px !important;
  }
  .header-actions { gap: 4px !important; }
  .header-actions select { max-width: 80px !important; }
  .hamburger { padding: 8px 12px !important; }
}

@media (min-width: 701px) and (max-width: 1024px) {
  .sidebar { width: 240px !important; }
  .modal-content { max-width: 600px !important; }
}

@media (hover: none) and (pointer: coarse) {
  .btn:hover, .module-item:hover, .hamburger:hover {
    transform: none !important;
    background: inherit !important;
  }
  .module-actions { display: flex !important; opacity: 0.7 !important; }
  .msg-copy { opacity: 0.5 !important; }
}

.sidebar h3 { color: var(--accent); font-size: 0.85em; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
.module-list { display: flex; flex-direction: column; gap: 6px; }
.module-item { padding: 10px 12px; background: var(--bg3); border-radius: 8px; cursor: pointer; transition: all 0.2s; border: 1px solid transparent; position: relative; }
.module-item:hover { border-color: var(--accent); }
.module-item.active { border-color: var(--accent); background: rgba(0,255,136,0.1); }
.module-name { font-weight: 600; font-size: 0.95em; }
.module-desc { font-size: 0.75em; color: var(--text2); margin-top: 4px; }
.module-actions { position: absolute; top: 2px; right: 4px; display: none; gap: 2px; z-index: 10; }
.module-item:hover .module-actions { display: flex; }
.module-action-btn { background: var(--bg2); border: 1px solid var(--border); color: var(--text2); padding: 2px 4px; border-radius: 3px; cursor: pointer; font-size: 0.65em; }
.module-action-btn:hover { color: var(--accent); border-color: var(--accent); }
.module-action-btn.delete:hover { color: var(--danger); border-color: var(--danger); }

.add-module-btn { border: 1px dashed var(--border); background: transparent; color: var(--text2); justify-content: center; }
.add-module-btn:hover { border-color: var(--accent); color: var(--accent); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.chat-container { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; width: 100%; max-width: 100%; scroll-behavior: smooth; padding-bottom: 80px; }

.message { max-width: 100%; width: 100%; padding: 14px 18px; border-radius: 16px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; color: var(--text); }
.message.user { align-self: flex-end; background: var(--user-msg); border-bottom-right-radius: 4px; }
.message.ai { align-self: flex-start; background: var(--ai-msg); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.message .role { font-size: 0.7em; color: var(--text2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 1px; display: flex; justify-content: space-between; align-items: center; }
.message.user .role { color: var(--accent); }
.message.ai .role { color: var(--accent); }
.message.selected { 
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  background: rgba(0, 255, 136, 0.1) !important;
}
.msg-copy { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 0.9em; padding: 2px 6px; border-radius: 4px; opacity: 0; transition: opacity 0.2s; }
.message:hover .msg-copy { opacity: 1; }
.msg-copy:hover { color: var(--accent); background: rgba(0,255,136,0.1); }
.message a { color: var(--accent); text-decoration: underline; }
.message code { background: var(--bg3); padding: 2px 6px; border-radius: 4px; font-family: Monaco, Menlo, monospace; font-size: 0.9em; color: var(--text); }
.message pre { background: var(--bg3); padding: 12px; border-radius: 8px; overflow-x: auto; margin: 10px 0; }
.message pre code { background: none; padding: 0; color: var(--text); }
.msg-content iframe { width: 100%; border: none; background: transparent; min-height: 120px; display: block; flex: 1; }
.msg-content-iframe { padding: 0; margin: 0; }

.input-area { background: var(--bg2); border-top: 1px solid var(--border); padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; position: sticky; bottom: 0; z-index: 40; }
.input-area textarea { width: 100%; padding: 12px 16px; background: var(--bg3); border: 1px solid var(--border); border-radius: 12px; color: var(--text); font-size: 1em; outline: none; resize: none; font-family: inherit; }
.input-area textarea:focus { border-color: var(--accent); }
.input-area textarea::placeholder { color: var(--text2); }
.input-area .btn-row { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }

.attachment-preview { display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 0; }
.attachment-preview img { max-width: 150px; max-height: 100px; border-radius: 8px; border: 1px solid var(--border); }
.attachment-file { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg3); border-radius: 8px; font-size: 0.85em; }
.attachment-file .icon { font-size: 1.2em; }
.attachment-preview.url-preview { justify-content: flex-start; }
.url-preview-card { display: flex; flex-direction: column; gap: 4px; max-width: 200px; }
.url-preview-card img { width: 100%; height: auto; border-radius: 8px; }
.url-preview-card .url-title { font-size: 0.75em; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.typing { color: var(--text2); font-style: italic; padding: 10px; }

.model-select { padding: 6px 8px; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 0.75em; cursor: pointer; max-width: 140px; }
.model-select:focus { border-color: var(--accent); outline: none; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 200; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal.open { display: flex; }
.modal-content { background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { color: var(--accent); font-size: 1.1em; }
.modal-close { background: none; border: none; color: var(--text2); font-size: 1.5em; cursor: pointer; }
.modal-close:hover { color: var(--danger); }
.modal-body { padding: 20px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 0.9em; color: var(--text2); }
.form-group input, .form-group textarea { width: 100%; padding: 10px 14px; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 0.95em; }
.form-group textarea { min-height: 120px; resize: vertical; font-family: inherit; }
.form-group input:focus, .form-group textarea:focus { border-color: var(--accent); outline: none; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

.preview-modal {
  max-width: 100vw;
  max-height: 100vh;
  width: 100%;
  height: 100%;
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.preview-modal .modal-header {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.preview-toolbar {
  display: flex;
  gap: 8px;
  margin-left: auto;
}
.preview-toolbar button {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  min-height: 32px;
  min-width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1em;
  transition: all 0.2s;
}
.preview-toolbar button:hover { background: var(--accent); color: #000; }
.preview-view-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg3);
  border-radius: 6px;
  padding: 2px;
}
.preview-view-toggle button {
  background: transparent;
  border: none;
  color: var(--text2);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85em;
  font-weight: 500;
  transition: all 0.2s;
}
.preview-view-toggle button.active { background: var(--accent); color: #000; }
.preview-view-toggle button:hover:not(.active) { color: var(--text); }
.preview-body {
  flex: 1;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.preview-view {
  flex: 1;
  min-height: 0;
  display: none;
  overflow: auto;
}
.preview-view.active {
  display: flex;
  flex-direction: column;
}
#renderedView { background: #000; flex: 1; min-height: 0; }
#previewFrame { width: 100%; height: 100%; flex: 1; border: none; border-radius: 0; background: #000; }

.raw-code-preview {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 16px;
  background: #1a1a22;
  color: #e5e7eb;
  border: none;
  border-radius: 0 0 16px 16px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.help-panel { background: var(--bg3); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.help-panel h4 { color: var(--accent); margin-bottom: 10px; font-size: 0.95em; }
.help-panel p { font-size: 0.85em; color: var(--text2); line-height: 1.5; }
.help-commands { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.help-cmd { background: var(--bg); padding: 4px 10px; border-radius: 6px; font-size: 0.8em; color: var(--accent); font-family: monospace; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--bg2); border: 1px solid var(--accent); padding: 12px 20px; border-radius: 8px; z-index: 300; animation: slideIn 0.3s; }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.loading-spinner.small { width: 16px; height: 16px; }
.loading-spinner.large { width: 32px; height: 32px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: 8px;
}
.loading-message {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9em;
}
.btn-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}
.btn-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.message-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--ai-msg);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  max-width: 200px;
}
.message-loading .dots { display: flex; gap: 4px; }
.message-loading .dot {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}
.message-loading .dot:nth-child(1) { animation-delay: -0.32s; }
.message-loading .dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

.settings-row { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.settings-row label { min-width: 80px; color: var(--text2); font-size: 0.9em; }
.settings-row input { flex: 1; }

.logs-panel { background: var(--bg3); border-radius: 12px; padding: 16px; max-height: 300px; overflow-y: auto; }
.memory-section { background: var(--bg3); border-radius: 12px; padding: 12px; max-height: 300px; overflow-y: auto; margin-top: 8px; }
.memory-item { padding: 8px; border-radius: 8px; background: var(--bg); margin-bottom: 6px; border: 1px solid var(--border); font-size: 0.85em; word-break: break-word; }
.memory-item-role { font-size: 0.75em; color: var(--accent); margin-bottom: 2px; font-weight: bold; }
.memory-item-text { margin-bottom: 4px; }
.memory-item-actions { display: flex; gap: 4px; }
.memory-item-actions button { padding: 2px 6px; font-size: 0.75em; cursor: pointer; border-radius: 4px; border: none; background: var(--bg3); color: var(--text2); }
.memory-item-actions button:hover { color: var(--accent); }
.memory-empty { font-size: 0.85em; color: var(--text2); padding: 8px; text-align: center; }
.msg-memory-btn { padding: 2px 6px; font-size: 0.75em; cursor: pointer; border-radius: 4px; border: 1px solid var(--border); background: transparent; color: var(--text2); margin-left: 4px; }
.msg-memory-btn:hover { color: var(--accent); border-color: var(--accent); }
.msg-memory-btn.remembered { color: var(--accent); border-color: var(--accent); }
.log-entry { font-size: 0.8em; padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; }
.log-entry:last-child { border-bottom: none; }
.log-time { color: var(--text2); min-width: 70px; }
.log-action { min-width: 60px; }
.log-detail { flex: 1; color: var(--text); word-break: break-all; }

.theme-select { padding: 6px 8px; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 0.75em; cursor: pointer; max-width: 100px; }
.theme-select:focus { border-color: var(--accent); outline: none; }
