* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1e1e1e;
  --panel: #252526;
  --panel-2: #2d2d30;
  --border: #3c3c3c;
  --text: #d4d4d4;
  --muted: #858585;
  --accent: #0e639c;
  --accent-2: #1177bb;
  --danger: #c9463d;
  --highlight: #613214;
  --green: #4caf50;
  --orange: #ffb74d;
  --red: #ef5350;
}

html { height: 100%; overflow: hidden; }
body {
  height: 100dvh; height: 100vh;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  position: fixed; inset: 0;
}

.screen { position: fixed; inset: 0; display: none; flex-direction: column; overflow: hidden; }
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ============ AUTH ============ */
#screen-auth {
  justify-content: center; align-items: center;
  background: linear-gradient(160deg, #1e1e1e 0%, #2d2d30 100%);
  padding: 20px;
}
.auth-box { width: 100%; max-width: 360px; }
.logo { font-size: 32px; text-align: center; margin-bottom: 4px; letter-spacing: 1px; }
.logo span { color: var(--accent-2); }
.tagline { text-align: center; color: var(--muted); margin-bottom: 30px; font-size: 13px; }
.tabs { display: flex; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1; background: none; border: none; color: var(--muted);
  padding: 10px; font-size: 14px; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: #fff; border-bottom-color: var(--accent-2); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  padding: 12px; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 4px; font-size: 15px;
  -webkit-appearance: none;
}
.auth-form input:focus { outline: none; border-color: var(--accent-2); }
.auth-error { color: #ff6b6b; font-size: 13px; min-height: 18px; }

/* ============ BUTTONS ============ */
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 12px; border-radius: 4px; cursor: pointer;
  font-size: 15px; font-weight: 500;
}
.btn-primary:hover, .btn-primary:active { background: var(--accent-2); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); padding: 12px;
  border-radius: 4px; cursor: pointer; font-size: 15px;
}
.btn-secondary:hover { border-color: var(--accent-2); }
.btn-secondary:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  background: none; border: none; color: var(--text);
  font-size: 20px; padding: 8px 12px; cursor: pointer;
}

/* ============ HEADER ============ */
.app-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  flex-shrink: 0;
}
.app-header h2 { font-size: 17px; font-weight: 500; }

/* ============ PROJECTS ============ */
.projects-body { flex: 1; overflow-y: auto; padding: 16px; }
.projects-actions {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-bottom: 16px;
}
.projects-list { display: flex; flex-direction: column; gap: 10px; }

.project-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 14px;
  display: flex; justify-content: space-between; align-items: flex-start;
  cursor: pointer; gap: 10px;
}
.project-card:hover { border-color: var(--accent-2); }
.project-info { flex: 1; min-width: 0; }
.project-info h3 { font-size: 15px; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-info p { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-meta { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.git-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(76,175,80,.15); border: 1px solid rgba(76,175,80,.4);
  color: #8fe08f; border-radius: 8px;
  padding: 2px 8px; font-size: 11px;
  font-family: ui-monospace, monospace;
}
.project-actions { display: flex; gap: 6px; flex-shrink: 0; }
.project-actions button {
  background: none; border: none; color: var(--muted);
  font-size: 16px; padding: 6px; cursor: pointer;
}
.project-actions button:hover { color: #fff; }
.empty-state { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ============ SETTINGS ============ */
.settings-body { flex: 1; overflow-y: auto; padding: 16px; }
.setting-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 0; border-bottom: 1px solid var(--border);
  gap: 12px;
}
.setting-row label { font-size: 14px; flex: 1; }
.setting-input {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 4px;
  padding: 8px 10px; font-size: 14px;
  min-width: 120px; max-width: 220px;
  font-family: inherit;
}
.setting-input:focus { outline: none; border-color: var(--accent-2); }
.setting-toggle {
  width: 20px; height: 20px;
  accent-color: var(--accent-2);
  cursor: pointer;
}
.setting-row small { color: var(--muted); font-size: 11px; margin-left: 6px; }

/* ============ EDITOR ============ */
.editor-header {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  padding-top: calc(6px + env(safe-area-inset-top, 0px));
  flex-shrink: 0; min-height: 46px;
}
.editor-header-actions { display: flex; align-items: center; gap: 6px; }
.editor-title {
  flex: 1; text-align: center; font-size: 14px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 0 8px;
}
.git-badge-header {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(76,175,80,.15); border: 1px solid rgba(76,175,80,.4);
  color: #8fe08f; border-radius: 8px;
  padding: 2px 8px; font-size: 11px;
  font-family: ui-monospace, monospace;
  max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.editor-tabs {
  display: flex; background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
  flex-shrink: 0; min-height: 34px;
}
.editor-tabs::-webkit-scrollbar { display: none; }
.editor-tab {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; background: var(--panel);
  border-right: 1px solid var(--border);
  font-size: 13px; white-space: nowrap; cursor: pointer;
  color: var(--muted);
}
.editor-tab.active { background: var(--bg); color: #fff; }
.editor-tab .close { font-size: 15px; opacity: 0.6; padding: 0 3px; margin-left: 4px; }
.editor-tab .close:hover { opacity: 1; color: #ff6b6b; }

.editor-body { flex: 1 1 auto; min-height: 0; position: relative; }
#ace-editor { position: absolute; inset: 0; }

.editor-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  gap: 12px; color: var(--muted); font-size: 14px;
  pointer-events: none; background: var(--bg); z-index: 5;
}
.editor-empty-icon { font-size: 48px; opacity: 0.35; }

/* ============ IMAGE VIEWER ============ */
.image-viewer {
  position: absolute; inset: 0;
  background: #1a1a1a; z-index: 6;
  display: flex; flex-direction: column;
}
.image-viewer-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; font-size: 12px; color: var(--muted);
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.image-viewer-toggle {
  background: none; border: 1px solid var(--border);
  color: var(--text); border-radius: 4px;
  padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.image-viewer-stage {
  flex: 1; overflow: auto;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background-image:
    linear-gradient(45deg, #2a2a2a 25%, transparent 25%),
    linear-gradient(-45deg, #2a2a2a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2a2a 75%),
    linear-gradient(-45deg, transparent 75%, #2a2a2a 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}
.image-viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ============ STICKY KEYBOARD BAR ============ */
.keyboard-bar {
  display: none;
  background: var(--panel-2);
  border-top: 1px solid var(--border);
  padding: 6px 4px;
  gap: 4px;
  overflow-x: auto; overflow-y: hidden;
  flex-shrink: 0; flex-wrap: nowrap;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
}
.keyboard-bar::-webkit-scrollbar { display: none; }
.keyboard-bar.show { display: flex; }
.kb-btn {
  flex: 0 0 auto; min-width: 42px; height: 38px;
  padding: 0 12px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px; font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none;
  -webkit-user-drag: none;
  touch-action: manipulation;
}
.kb-btn:active { background: var(--accent); color: #fff; border-color: var(--accent); }
.kb-btn.wide { min-width: 58px; font-family: inherit; font-size: 12px; }

/* ============ BOTTOM TOOLBAR ============ */
.editor-toolbar {
  display: flex; background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 6px; gap: 4px; overflow-x: auto;
  flex-shrink: 0;
  padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
}
.editor-toolbar::-webkit-scrollbar { display: none; }
.tool-btn {
  flex: 1 0 auto; min-width: 60px;
  display: flex; flex-direction: column;
  align-items: center; gap: 2px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 6px 4px; font-size: 16px; cursor: pointer;
  white-space: nowrap;
}
.tool-btn span { font-size: 10px; color: var(--muted); }
.tool-btn:active { background: var(--accent); }
.tool-btn:active span { color: #fff; }

/* ============ SIDEBAR ============ */
.sidebar {
  position: absolute; top: 0; bottom: 0; left: 0;
  width: 280px; max-width: 85vw;
  background: var(--panel);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform .25s ease;
  z-index: 25;
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
  pointer-events: none;
}
.sidebar.open { transform: translateX(0); pointer-events: auto; }
.sidebar-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 1px; color: var(--muted);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sidebar-actions {
  display: flex; gap: 6px; padding: 10px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sb-action {
  flex: 1; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 10px 6px; font-size: 12px; cursor: pointer;
  white-space: nowrap;
}
.sb-action:hover, .sb-action:active { background: var(--accent); border-color: var(--accent); color: #fff; }
.file-tree { flex: 1; overflow-y: auto; padding: 6px 0; }
.tree-item {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; font-size: 14px; cursor: pointer;
  white-space: nowrap; user-select: none;
}
.tree-item:active { background: var(--panel-2); }
.tree-item.active { background: var(--accent); color: #fff; }
.tree-item .icon { width: 16px; text-align: center; font-size: 13px; }
.tree-item.folder { color: #dcb67a; }
.tree-item.file { color: var(--text); }
.tree-children { padding-left: 14px; }
.tree-actions { margin-left: auto; display: none; gap: 4px; }
.tree-item:active .tree-actions,
.tree-item:hover .tree-actions { display: flex; }
.tree-actions button {
  background: none; border: none; color: inherit;
  font-size: 13px; padding: 2px 4px; cursor: pointer;
}
.overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.5);
  display: none; z-index: 20;
}
.overlay.active { display: block; }

/* ============ PANELS ============ */
.panel {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  width: 100%;
  background: var(--panel);
  transform: translateX(100%);
  transition: transform .25s ease;
  z-index: 30;
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
  pointer-events: none;
  min-height: 0; height: 100%;
}
.panel.open { transform: translateX(0); pointer-events: auto; }
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.panel-header h3 { font-size: 15px; font-weight: 500; }
.panel-body { flex: 1; overflow-y: auto; padding: 14px; }
.panel-input {
  width: 100%; padding: 10px; margin-bottom: 8px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 4px; font-size: 14px; font-family: inherit;
}
.panel-input:focus { outline: none; border-color: var(--accent-2); }
.panel-row { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; flex-wrap: wrap; }
.panel-row button { flex: 1; }
.chk { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* ============ AI SETTINGS ============ */
.ai-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); margin: 18px 0 8px;
}
.ai-hint {
  font-size: 11px; color: var(--muted);
  margin-top: -4px; margin-bottom: 8px;
  padding: 8px 10px; background: rgba(14,99,156,.1);
  border-left: 3px solid var(--accent); border-radius: 4px;
  line-height: 1.4;
}

/* ============ AI CHAT PANEL ============ */
.ai-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-size: 11px; color: var(--muted);
  flex-shrink: 0;
}
.ai-model-badge {
  display: inline-block;
  background: var(--panel); border: 1px solid var(--border);
  padding: 3px 8px; border-radius: 10px;
}
.ai-session-badge {
  display: inline-block;
  background: transparent; color: var(--muted);
  font-size: 10px;
}
.ai-chat-scroll {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto;
  padding: 12px 12px 20px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
.ai-welcome { text-align: center; color: var(--muted); padding: 30px 12px; }
.ai-welcome-icon { font-size: 42px; margin-bottom: 10px; opacity: .6; }
.ai-welcome p { font-size: 13px; margin-bottom: 16px; }
.ai-suggestions { display: flex; flex-direction: column; gap: 6px; max-width: 260px; margin: 0 auto; }
.ai-suggestion {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px;
  padding: 10px 12px; font-size: 13px; cursor: pointer;
  text-align: left;
}
.ai-suggestion:hover { border-color: var(--accent-2); }

.ai-msg {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.55;
  word-wrap: break-word;
  animation: aiFade .2s ease;
  overflow-wrap: anywhere;
}
@keyframes aiFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.ai-msg.user {
  align-self: flex-end;
  background: var(--accent); color: #fff;
  border-bottom-right-radius: 3px;
  white-space: pre-wrap;
}
.ai-msg.assistant {
  align-self: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 3px;
  white-space: normal;
}
.ai-msg.error {
  align-self: stretch;
  background: #4a1e1e;
  border: 1px solid #7a2d2d;
  color: #ffb3b3;
  font-size: 12px;
  white-space: pre-wrap;
}

/* ============ MARKDOWN ============ */
.ai-msg.assistant > *:first-child { margin-top: 0 !important; }
.ai-msg.assistant > *:last-child { margin-bottom: 0 !important; }
.ai-msg.assistant p { margin: 0 0 10px; }
.ai-msg.assistant p:last-child { margin-bottom: 0; }
.ai-msg.assistant h1,
.ai-msg.assistant h2,
.ai-msg.assistant h3,
.ai-msg.assistant h4,
.ai-msg.assistant h5,
.ai-msg.assistant h6 {
  margin: 14px 0 8px; line-height: 1.3; color: #fff; font-weight: 600;
}
.ai-msg.assistant h1 { font-size: 18px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.ai-msg.assistant h2 { font-size: 16px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.ai-msg.assistant h3 { font-size: 15px; color: #dcdcdc; }
.ai-msg.assistant h4 { font-size: 14px; }
.ai-msg.assistant h5, .ai-msg.assistant h6 { font-size: 13px; color: var(--muted); }
.ai-msg.assistant ul, .ai-msg.assistant ol { margin: 6px 0 10px; padding-left: 22px; }
.ai-msg.assistant li { margin-bottom: 4px; }
.ai-msg.assistant li > p { margin: 0; }
.ai-msg.assistant blockquote {
  border-left: 3px solid var(--accent-2);
  padding: 4px 12px; margin: 8px 0;
  color: var(--muted); background: rgba(17,119,187,.06);
}
.ai-msg.assistant hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.ai-msg.assistant a { color: #6cb6ff; text-decoration: none; border-bottom: 1px dotted #6cb6ff; }
.ai-msg.assistant a:hover { border-bottom-style: solid; }
.ai-msg.assistant strong { color: #fff; font-weight: 600; }
.ai-msg.assistant em { color: #e8e8e8; }
.ai-msg.assistant code {
  background: rgba(255,255,255,.08);
  border: 1px solid var(--border);
  color: #ffca7a;
  padding: 1px 5px; border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.ai-msg.assistant pre {
  margin: 8px 0; border-radius: 6px; overflow: hidden;
  background: #111; border: 1px solid var(--border);
}
.ai-msg.assistant pre code {
  display: block; padding: 10px 12px;
  background: transparent; border: none;
  color: var(--text); font-size: 12px; line-height: 1.5;
  overflow-x: auto; white-space: pre;
}
.ai-code-wrap { position: relative; }
.ai-code-copy {
  position: absolute; top: 6px; right: 6px;
  background: rgba(255,255,255,.08);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 8px; font-size: 11px;
  cursor: pointer; opacity: .75;
  transition: opacity .15s;
}
.ai-code-copy:hover { opacity: 1; background: var(--accent); border-color: var(--accent); }
.ai-msg.assistant table {
  border-collapse: collapse; margin: 8px 0;
  font-size: 12px; width: 100%;
}
.ai-msg.assistant th, .ai-msg.assistant td {
  border: 1px solid var(--border); padding: 6px 8px; text-align: left;
}
.ai-msg.assistant th { background: rgba(255,255,255,.04); font-weight: 600; }

/* ============ TYPING DOTS ============ */
.ai-typing-wrap { padding: 12px 14px; }
.ai-dots { display: inline-flex; gap: 4px; }
.ai-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: dotBounce 1.2s infinite;
}
.ai-dots span:nth-child(2) { animation-delay: .15s; }
.ai-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes dotBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ============ AI INPUT ============ */
.ai-input-bar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 12px 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
  box-shadow: 0 -6px 14px rgba(0,0,0,.35);
}
.ai-input {
  flex: 1; resize: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 15px;
  line-height: 1.5;
  font-family: inherit;
  min-height: 132px;
  max-height: 260px;
  transition: height .12s ease, border-color .15s ease;
  -webkit-appearance: none; appearance: none;
}
.ai-input:focus {
  outline: none; border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(17,119,187,.2);
}
.ai-input::placeholder { color: var(--muted); }
.ai-send {
  flex-shrink: 0;
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--accent); color: #fff;
  border: none; font-size: 24px; font-weight: 700; line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease, transform .08s ease;
  align-self: flex-end;
  margin-bottom: 4px;
  box-shadow: 0 4px 12px rgba(14,99,156,.35);
}
.ai-send:hover, .ai-send:active { background: var(--accent-2); }
.ai-send:active { transform: scale(.94); }
.ai-send:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

/* ============ GIT PANEL ============ */
.git-status-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px;
  margin-bottom: 12px;
}
.git-status-row {
  display: flex; justify-content: space-between;
  gap: 8px; padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid rgba(60,60,60,.4);
}
.git-status-row:last-child { border-bottom: none; }
.git-status-row .k { color: var(--muted); flex-shrink: 0; }
.git-status-row .v {
  color: var(--text); text-align: right;
  word-break: break-all;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}
.git-actions {
  display: grid; gap: 8px; margin: 12px 0;
}
.git-actions button { width: 100%; }
.git-changes-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); margin: 16px 0 8px;
}
.git-change-item {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 10px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; margin-bottom: 4px;
  font-family: ui-monospace, monospace;
}
.git-change-status {
  flex-shrink: 0; min-width: 24px; text-align: center;
  padding: 1px 6px; border-radius: 4px;
  font-weight: 600; font-size: 11px;
}
.git-change-status.M  { background: rgba(255,183,77,.2); color: var(--orange); }
.git-change-status.A  { background: rgba(76,175,80,.2);  color: var(--green); }
.git-change-status.D  { background: rgba(239,83,80,.2);  color: var(--red); }
.git-change-status.\?\? { background: rgba(134,133,133,.2); color: var(--muted); }
.git-change-path { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ PREVIEW PANEL ============ */
.preview-toolbar {
  display: flex; gap: 6px; padding: 8px 10px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
  background: var(--panel-2);
}
.preview-input {
  flex: 1; padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text); border-radius: 4px;
  font-size: 13px; font-family: ui-monospace, monospace;
}
.preview-input:focus { outline: none; border-color: var(--accent-2); }
.preview-icon-btn {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 8px 12px; font-size: 14px; cursor: pointer;
}
.preview-icon-btn:hover, .preview-icon-btn:active { background: var(--accent); border-color: var(--accent); color: #fff; }
.preview-frame-wrap { flex: 1; background: #fff; overflow: hidden; position: relative; }
#preview-frame { width: 100%; height: 100%; border: 0; background: #fff; display: block; }
.preview-footer {
  padding: 8px 12px; border-top: 1px solid var(--border);
  background: var(--panel); flex-shrink: 0;
}

/* ============ SEARCH / VERSIONS / COMMITS ============ */
.search-results { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.search-result {
  background: var(--panel-2); border-radius: 4px;
  padding: 8px 10px; cursor: pointer;
  border: 1px solid transparent; font-size: 13px;
}
.search-result:hover { border-color: var(--accent-2); }
.search-result .sr-path { color: var(--accent-2); font-size: 12px; margin-bottom: 4px; }
.search-result .sr-line { color: var(--muted); font-family: monospace; font-size: 12px; }
.search-result .sr-line mark { background: var(--highlight); color: #fff; padding: 0 2px; }

.versions-list { display: flex; flex-direction: column; gap: 6px; }
.version-item {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 10px; font-size: 13px;
  display: flex; justify-content: space-between; align-items: center;
}
.version-item .v-meta { color: var(--muted); font-size: 12px; }
.version-item .v-actions { display: flex; gap: 6px; }
.version-item button {
  background: none; border: 1px solid var(--border);
  color: var(--text); border-radius: 4px;
  padding: 4px 8px; font-size: 11px; cursor: pointer;
}
.version-item button:hover { background: var(--accent); border-color: var(--accent); }

.commits-list { display: flex; flex-direction: column; gap: 8px; }
.commit-item {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 12px;
}
.commit-item .c-msg { font-size: 14px; margin-bottom: 6px; font-weight: 500; }
.commit-item .c-meta { color: var(--muted); font-size: 11px; margin-bottom: 8px; }
.commit-item .c-stats { display: flex; gap: 10px; font-size: 12px; margin-bottom: 8px; }
.commit-item .c-stats .s-add { color: var(--green); }
.commit-item .c-stats .s-mod { color: var(--orange); }
.commit-item .c-stats .s-del { color: var(--red); }
.commit-item .c-actions { display: flex; gap: 6px; }
.commit-item .c-actions button {
  flex: 1; background: none; border: 1px solid var(--border);
  color: var(--text); border-radius: 4px;
  padding: 6px 8px; font-size: 12px; cursor: pointer;
}
.commit-item .c-actions button:hover { background: var(--accent); border-color: var(--accent); }
.commit-item .c-files {
  display: none; margin-top: 8px; padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px; font-family: monospace;
}
.commit-item.expanded .c-files { display: block; }
.commit-item .c-file { padding: 3px 0; color: var(--muted); }
.commit-item .c-file.added::before { content: "+ "; color: var(--green); }
.commit-item .c-file.modified::before { content: "~ "; color: var(--orange); }
.commit-item .c-file.deleted::before { content: "- "; color: var(--red); }

/* ============ MODAL ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: none; justify-content: center; align-items: center;
  z-index: 100; padding: 20px;
}
.modal-backdrop.active { display: flex; }
.modal {
  background: var(--panel); border-radius: 8px;
  padding: 20px; width: 100%; max-width: 420px;
  border: 1px solid var(--border);
  max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin-bottom: 10px; font-size: 16px; }
.modal-hint {
  font-size: 12px; color: var(--muted);
  margin-bottom: 14px; line-height: 1.4;
}
.modal-label {
  display: block; font-size: 12px; color: var(--muted);
  margin: 10px 0 4px;
}
.modal-label .req { color: var(--danger); }
.modal input, .modal textarea {
  width: 100%; padding: 10px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 4px;
  font-size: 14px; font-family: inherit;
}
.modal input:focus, .modal textarea:focus { outline: none; border-color: var(--accent-2); }
.modal-error {
  color: #ff6b6b; font-size: 12px;
  min-height: 16px; margin-top: 10px;
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 16px;
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(10px) scale(.96);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  border: 1px solid var(--border);
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  opacity: 0; visibility: hidden;
  pointer-events: none;
  transition:
    opacity .18s ease,
    transform .18s ease,
    visibility 0s linear .18s;
  z-index: 999;
  max-width: 90vw;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show {
  opacity: 1; visibility: visible;
  transform: translateX(-50%) translateY(0) scale(1);
  transition:
    opacity .18s ease,
    transform .18s ease,
    visibility 0s;
}

/* ============ DESKTOP ============ */
@media (min-width: 768px) {
  .panel { left: auto; width: 420px; border-left: 1px solid var(--border); }
  #preview-panel { width: 55vw; }
  #ai-panel { width: 480px; }
  .editor-toolbar { justify-content: center; }
  .tool-btn { flex: 0 0 auto; min-width: 80px; }
  .keyboard-bar { display: none !important; }
  .ai-input { min-height: 96px; max-height: 260px; font-size: 14px; }
  .ai-send { width: 50px; height: 50px; font-size: 20px; }
  .projects-actions { grid-template-columns: 1fr 1fr; }
}