/* OpenMontage Design System — Apple/ChatGPT neutral style */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Tokens ── */
:root {
  --bg: #FFFFFF;
  --bg-secondary: #F7F7F8;
  --bg-tertiary: #ECECEC;
  --border: #E5E5E5;
  --border-strong: #D1D1D1;

  --text-primary: #171717;
  --text-secondary: #6B6B6B;
  --text-tertiary: #9CA3AF;

  --accent: #10A37F;
  --accent-hover: #0D8C6D;

  --success: #10A37F;
  --danger: #EF4444;
  --warning: #F59E0B;

  --hover: #F7F7F8;
  --active: #ECECEC;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.1);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --sidebar-width: 260px;
}

[data-theme="dark"] {
  --bg: #171717;
  --bg-secondary: #212121;
  --bg-tertiary: #2A2A2A;
  --border: #3A3A3A;
  --border-strong: #4A4A4A;
  --text-primary: #ECECEC;
  --text-secondary: #A0A0A0;
  --text-tertiary: #6B6B6B;
  --hover: #2A2A2A;
  --active: #333333;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.2);
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,.25);
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Layout ── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
}

.sidebar-logo svg { width: 24px; height: 24px; }
.sidebar-logo span { font-size: 16px; font-weight: 600; color: var(--text-primary); }

.btn-new-project {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
}

.btn-new-project:hover { background: var(--hover); }
.btn-new-project svg { width: 16px; height: 16px; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-section {
  margin-bottom: 8px;
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 12px 4px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font);
}

.sidebar-item:hover { background: var(--hover); }
.sidebar-item.active { background: var(--active); font-weight: 500; }
.sidebar-item svg { width: 16px; height: 16px; color: var(--text-secondary); flex-shrink: 0; }

.sidebar-item-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--text-primary);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.sidebar-user-name { font-size: 14px; font-weight: 500; }

/* ── Main Area ── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Header ── */
.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.main-header-title {
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Content ── */
.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  font-family: var(--font);
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--text-primary);
  color: var(--bg);
}

.btn-primary:hover { opacity: 0.85; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.btn-ghost:hover { background: var(--hover); }

.btn-danger {
  background: white;
  border: 1px solid var(--danger);
  color: var(--danger);
}

.btn-danger:hover { background: #FEF2F2; }

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover { background: var(--accent-hover); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }

.btn-icon {
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover { background: var(--hover); color: var(--text-primary); }
.btn-icon svg { width: 18px; height: 18px; }

/* ── Input ── */
.input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg);
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
}

.input:focus { border-color: var(--border-strong); box-shadow: 0 0 0 2px rgba(0,0,0,.05); }
.input::placeholder { color: var(--text-tertiary); }

textarea.input {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

.field { margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

/* ── Auth Screen ── */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.auth-logo svg { width: 32px; height: 32px; }
.auth-logo span { font-size: 22px; font-weight: 700; color: var(--text-primary); }

.auth-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
  display: none;
}

/* ── Status Pills ── */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-draft { background: var(--bg-tertiary); color: var(--text-secondary); }
.status-draft .status-dot { background: var(--text-tertiary); }

.status-processing { background: #EFF6FF; color: #2563EB; }
.status-processing .status-dot { background: #2563EB; animation: pulse 1.5s infinite; }

.status-done { background: #ECFDF5; color: var(--success); }
.status-done .status-dot { background: var(--success); }

.status-failed { background: #FEF2F2; color: var(--danger); }
.status-failed .status-dot { background: var(--danger); }

/* ── Project Cards ── */
.projects-list {
  padding: 16px 24px;
}

.project-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}

.project-card:hover { background: var(--hover); }
.project-card.active { background: var(--active); }

.project-card-info { flex: 1; min-width: 0; }

.project-card-name {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-card-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}


/* ── Chat Layout ── */

.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  min-height: 0;
}

.chat-messages {
  max-width: 768px;
  margin: 0 auto;
}

.chat-input-area {
  flex-shrink: 0;
  padding: 12px 24px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.chat-input-wrap {
  max-width: 768px;
  margin: 0 auto;
  position: relative;
}

/* File preview - horizontal scroll, fixed height */
#chat-file-preview {
  max-width: 768px;
  margin: 0 auto;
  max-height: 100px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding-bottom: 6px;
}

.chat-file-chip {
  transition: transform 0.15s;
}
.chat-file-chip:active {
  transform: scale(0.95);
}

@media (max-width: 768px) {
  .chat-input-area { padding: 8px 12px 14px; }
  #chat-file-preview { max-height: 80px; padding: 0 4px 6px; }
  .chat-file-chip { width: 52px !important; height: 52px !important; }
  .chat-container { padding: 16px 12px; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  #chat-file-preview { max-height: 90px; }
}

/* ── Chat (original) ── */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.chat-messages {
  max-width: 768px;
  margin: 0 auto;
}

.chat-message {
  display: flex;
  gap: 16px;
  padding: 24px 0;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
}

.chat-message-user .chat-avatar { background: var(--text-primary); color: var(--bg); }
.chat-message-assistant .chat-avatar { background: var(--accent); color: white; }

.chat-content {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-primary);
}

.chat-content p { margin-bottom: 8px; }
.chat-content p:last-child { margin-bottom: 0; }

/* ── Tool Calls ── */
.tool-call {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 8px 0;
  overflow: hidden;
}

.tool-call-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.tool-call-header:hover { background: var(--hover); }

.tool-call-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.tool-call-check {
  color: var(--success);
}

.tool-call-body {
  display: none;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

.tool-call.open .tool-call-body { display: block; }

/* ── File Card ── */
.file-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 8px 0;
}

.file-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.file-card-icon svg { width: 20px; height: 20px; color: var(--text-secondary); }

.file-card-info { flex: 1; min-width: 0; }
.file-card-name { font-size: 14px; font-weight: 500; }
.file-card-meta { font-size: 12px; color: var(--text-tertiary); }

.file-card-actions { display: flex; gap: 6px; }

/* ── Video Player ── */
.video-player {
  border-radius: var(--radius);
  overflow: hidden;
  margin: 8px 0;
  background: #000;
}

.video-player video {
  width: 100%;
  max-height: 400px;
  display: block;
}

/* ── Chat Input ── */
.chat-input-area {
  padding: 16px 24px 24px;
  background: var(--bg);
}

.chat-input-wrap {
  max-width: 768px;
  margin: 0 auto;
  position: relative;
}

.chat-input {
  width: 100%;
  padding: 12px 50px 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg);
  outline: none;
  resize: none;
  min-height: 44px;
  max-height: 200px;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.chat-input:focus { border-color: var(--border-strong); }

.chat-send-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--text-primary);
  color: var(--bg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}

.chat-send-btn:hover { opacity: 0.85; }
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-send-btn svg { width: 16px; height: 16px; }

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  color: var(--text-tertiary);
}

.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state p { font-size: 14px; margin-bottom: 16px; }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-body { padding: 24px; }

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Upload Zone ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 16px;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(16,163,127,.05);
}

.upload-zone svg { width: 40px; height: 40px; color: var(--text-tertiary); margin-bottom: 8px; }
.upload-zone p { color: var(--text-secondary); font-size: 14px; }
.upload-zone .sub { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }

/* ── File List ── */
.file-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  margin-bottom: 6px;
  font-size: 13px;
}

.file-list-item .name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list-item .size { color: var(--text-tertiary); font-size: 12px; }
.file-list-item .remove {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
}

.file-list-item .remove:hover { color: var(--danger); background: #FEF2F2; }

/* ── Materials / Results Grid ── */
.content-page {
  padding: 24px;
  max-width: 960px;
  overflow-y: auto;
  flex: 1;
  margin: 0 auto;
}

.content-page h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
}

.result-card {
  display: flex;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
}

.result-thumb {
  width: 160px;
  height: 90px;
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.result-thumb video { width: 100%; height: 100%; object-fit: cover; }
.result-thumb svg { width: 32px; height: 32px; color: var(--text-tertiary); }

.result-info { flex: 1; }
.result-info h4 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.result-info p { font-size: 13px; color: var(--text-secondary); }

.result-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ── Settings ── */
.settings-section {
  margin-bottom: 32px;
}

.settings-section h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-child { border-bottom: none; }
.settings-label { font-size: 14px; color: var(--text-secondary); }
.settings-value { font-size: 14px; font-weight: 500; }

/* ── Animations ── */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    z-index: 200;
    transition: left 0.2s;
  }

  .sidebar.open { left: 0; }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.3);
    z-index: 199;
  }

  .sidebar.open ~ .sidebar-overlay { display: block; }

  .main-header { padding: 12px 16px; }
  .chat-container { padding: 16px; }
  .chat-input-area { padding: 12px 16px 16px; }

  .result-card { flex-direction: column; }
  .result-thumb { width: 100%; height: 120px; }
}

/* ── Rich Messages ── */
.chat-content h2,
.chat-content h3,
.chat-content h4 {
  color: var(--text-primary);
}

.chat-content ul,
.chat-content ol {
  margin: 8px 0;
  padding-left: 24px;
}

.chat-content li {
  margin: 4px 0;
  line-height: 1.6;
}

.chat-content blockquote {
  margin: 8px 0;
}

.chat-content hr {
  margin: 16px 0;
}

.chat-content a {
  color: var(--accent);
  text-decoration: underline;
}

.chat-content a:hover {
  opacity: 0.8;
}

.chat-content pre {
  margin: 8px 0;
}

.chat-content pre code {
  background: none;
  padding: 0;
  font-size: 13px;
}

/* ── Table dark mode fix ── */
[data-theme=dark] .chat-content table th {
  background: var(--bg-tertiary);
  border-color: var(--border);
  color: var(--text-primary);
}
[data-theme=dark] .chat-content table td {
  border-color: var(--border);
  color: var(--text-primary);
}
[data-theme=dark] .chat-content table {
  border-color: var(--border);
}

/* ── Chat input fix — file button position ── */
.chat-input {
  padding-left: 44px !important;
  padding-right: 50px !important;
}

#chat-file-btn {
  position: absolute;
  left: 4px;
  bottom: 4px;
  z-index: 1;
}

.chat-send-btn {
  right: 8px;
}

/* ── iOS / Touch fixes ── */
* {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.sidebar {
  -webkit-overflow-scrolling: touch;
}

.chat-container {
  -webkit-overflow-scrolling: touch;
}

/* Safe area for notch devices */
@supports (padding-top: env(safe-area-inset-top)) {
  .sidebar {
    padding-top: env(safe-area-inset-top);
  }
  .chat-input-area {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .main-header {
    padding-top: env(safe-area-inset-top);
  }
}

/* Prevent zoom on input focus */
input, textarea, select {
  font-size: 16px !important;
}

/* Video player iOS fix */
.video-player video {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}


  #chat-file-preview { max-height: 100px; padding: 0 4px 6px; }
  .chat-file-chip { width: 56px !important; height: 56px !important; }
}
@media (min-width: 769px) and (max-width: 1024px) {
  #chat-file-preview { max-height: 110px; }
}
