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

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

:root {
  --bg:        #f5f6f7;
  --surface:   #ffffff;
  --surface-2: #f3f4f6;
  --surface-3: #e9eaec;
  --border:    #e2e4e9;
  --border-2:  #cdd0d5;
  --text:      #0f1117;
  --text-muted:#5c6370;
  --text-dim:  #9ba3ae;
  --accent:    #2563eb;
  --accent-h:  #1d4ed8;
  --accent2:   #1d4ed8;
  --success:   #16a34a;
  --danger:    #dc2626;
  --warning:   #d97706;
  --radius:    6px;
  --radius-lg: 10px;
  --shadow:    0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.09), 0 1px 4px rgba(0,0,0,0.05);
  --font: 'Inter', system-ui, sans-serif;
  --gradient: linear-gradient(135deg, #1e40af, #2563eb);
}

/* Legacy variable aliases for compatibility */
:root {
  --surface2: var(--surface-2);
  --surface3: var(--surface-3);
  --border2:  var(--border-2);
}

html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: #2563eb25; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }

.page { min-height: 100vh; display: flex; flex-direction: column; }
.container { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; width: 100%; }

/* ── Nav ──────────────────────────────────────────────────────────────── */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 0;
  position: sticky; top: 0; z-index: 100;
}
.nav-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; height: 52px;
}
.nav-brand {
  font-weight: 700; font-size: 0.95rem; color: var(--text);
  letter-spacing: -0.02em; display: flex; align-items: center; gap: 0.5rem;
}
.nav-brand-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); display: inline-block;
}
.nav-links { display: flex; align-items: center; gap: 0.5rem; }
.nav-user {
  color: var(--text-muted); font-size: 0.78rem;
  padding: 0.22rem 0.65rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 5px;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.9rem; border-radius: var(--radius);
  font-size: 0.82rem; font-weight: 600; cursor: pointer; border: none;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  text-decoration: none; font-family: var(--font); white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { filter: brightness(0.94); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-secondary {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-2);
}
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-2); background: var(--surface-2); }
.btn-sm { padding: 0.28rem 0.65rem; font-size: 0.76rem; }
.btn-lg { padding: 0.62rem 1.4rem; font-size: 0.92rem; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Form elements ────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
label {
  display: block; margin-bottom: 0.3rem; color: var(--text-muted);
  font-size: 0.74rem; font-weight: 600; letter-spacing: 0.01em;
}
input, select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius); color: var(--text); font-size: 0.875rem;
  padding: 0.55rem 0.75rem; outline: none;
  transition: border-color 0.1s, box-shadow 0.1s; font-family: var(--font);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px #2563eb14;
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }
.form-hint { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.25rem; }
.error-msg { color: var(--danger); font-size: 0.8rem; margin-top: 0.6rem; min-height: 1.2em; text-align: center; }

/* ── Auth ─────────────────────────────────────────────────────────────── */
.auth-page {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 2rem 1rem; min-height: 100vh; background: var(--bg);
}
.auth-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 2rem 2.25rem;
  width: 100%; max-width: 380px; box-shadow: var(--shadow-lg);
}
.auth-logo {
  display: flex; align-items: center; gap: 0.45rem;
  font-size: 0.95rem; font-weight: 700; color: var(--text);
  letter-spacing: -0.02em; margin-bottom: 1.75rem;
}
.auth-logo-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
}
.auth-title {
  font-size: 1.25rem; font-weight: 800;
  letter-spacing: -0.03em; margin-bottom: 0.2rem;
}
.auth-sub {
  color: var(--text-muted); font-size: 0.82rem; margin-bottom: 1.5rem;
}
.auth-footer {
  margin-top: 1.25rem; text-align: center;
  color: var(--text-muted); font-size: 0.82rem;
}

/* ── App library ─────────────────────────────────────────────────────── */
.library-wrap { flex: 1; }
.lib-toolbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 1rem 0; border-bottom: 1px solid var(--border); margin-bottom: 0;
}
.lib-toolbar-title {
  font-size: 0.88rem; font-weight: 700; color: var(--text);
  white-space: nowrap; display: flex; align-items: center; gap: 0.5rem;
}
.lib-toolbar-count {
  font-size: 0.72rem; font-weight: 600; color: var(--text-dim);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.1rem 0.45rem;
}
.lib-search {
  flex: 1; min-width: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.45rem 0.75rem 0.45rem 2.25rem;
  font-size: 0.82rem; color: var(--text); outline: none;
  transition: border-color 0.1s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 24 24' fill='none' stroke='%239ba3ae' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 0.7rem center;
  max-width: 280px;
}
.lib-search:focus { border-color: var(--accent); }
.lib-search::placeholder { color: var(--text-dim); }
.lib-quota {
  font-size: 0.72rem; color: var(--text-dim);
  white-space: nowrap; display: flex; align-items: center; gap: 0.5rem;
}
.lib-quota-bar {
  width: 80px; height: 3px;
  background: var(--surface-3); border-radius: 99px; overflow: hidden;
}
.lib-quota-fill {
  height: 100%; border-radius: 99px;
  background: var(--accent); transition: width 0.5s ease;
}

/* App list (table-style) */
.app-list {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden; margin: 1.25rem 0 2.5rem; background: var(--surface);
}
.app-list-section {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.35rem 1rem; background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.68rem; font-weight: 700; color: var(--text-dim);
  letter-spacing: 0.1em; text-transform: uppercase;
}
.app-list-section:not(:first-child) { border-top: 1px solid var(--border); }
.app-list-row {
  display: grid;
  grid-template-columns: 1fr 150px 76px 100px 36px 46px;
  align-items: center; padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit; transition: background 0.1s;
  gap: 0.5rem;
}
.app-list-row:last-child { border-bottom: none; }
.app-list-row:hover { background: var(--surface-2); text-decoration: none; }
.alr-name { min-width: 0; }
.alr-display { font-size: 0.85rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alr-desc { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 0.1rem; }
.alr-path { font-size: 0.73rem; font-family: monospace; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alr-status { display: flex; align-items: center; gap: 0.35rem; font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }
.alr-edit { font-size: 0.68rem; font-weight: 600; color: var(--text-muted); background: none; border: 1px solid var(--border-2); border-radius: 5px; padding: 0.15rem 0.5rem; white-space: nowrap; transition: color 0.1s, border-color 0.1s; text-decoration: none; visibility: hidden; }
.app-list-row:hover .alr-edit { visibility: visible; }
.alr-edit:hover { color: var(--text); border-color: var(--text-muted); }
.alr-owner { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alr-star { background: none; border: none; cursor: pointer; color: var(--text-dim); font-size: 0.9rem; padding: 0.2rem; line-height: 1; transition: color 0.1s; }
.alr-star:hover { color: var(--warning); }
.alr-star.starred { color: var(--warning); }
.alr-like { background: none; border: none; cursor: pointer; color: var(--text-dim); font-size: 0.78rem; padding: 0.2rem 0.3rem; line-height: 1; transition: color 0.1s; display: flex; align-items: center; gap: 0.2em; }
.alr-like:hover { color: #e11d48; }
.alr-like.liked { color: #e11d48; }
.like-count { font-size: 0.7rem; }

.status-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.status-active { background: var(--success); }
.status-provisioning { background: var(--warning); }
.status-error { background: var(--danger); }

.badge {
  display: inline-flex; align-items: center; padding: 0.12rem 0.4rem;
  border-radius: 4px; font-size: 0.65rem; font-weight: 700;
  letter-spacing: 0.03em; text-transform: uppercase; flex-shrink: 0;
}
.badge-vanilla { background: #fef9c3; border: 1px solid #fde047; color: #854d0e; }
.badge-react   { background: #e0f2fe; border: 1px solid #7dd3fc; color: #0c4a6e; }

.lib-empty {
  text-align: center; padding: 4rem 1rem; background: var(--surface);
}
.lib-empty-icon {
  width: 48px; height: 48px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; margin: 0 auto 1rem;
}
.lib-empty h2 { font-size: 0.95rem; font-weight: 700; margin-bottom: 0.3rem; }
.lib-empty p { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 1.25rem; }

/* ── Create ───────────────────────────────────────────────────────────── */
.create-wrap { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 3rem 1.5rem; }
.create-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 2rem;
  width: 100%; max-width: 520px; box-shadow: var(--shadow);
}
.create-card h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 0.2rem; }
.create-card .sub { color: var(--text-muted); font-size: 0.82rem; margin-bottom: 1.75rem; }
.url-preview {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.5rem 0.75rem;
  font-size: 0.78rem; color: var(--text-muted); margin-bottom: 1rem;
  font-family: monospace; display: flex; align-items: center; gap: 0.35rem;
}
.url-preview .path-part { color: var(--accent2); font-weight: 600; }
.frontend-options { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; margin-bottom: 1rem; }
.frontend-opt {
  border: 1px solid var(--border-2); border-radius: var(--radius);
  padding: 0.85rem; cursor: pointer; transition: border-color 0.1s, background 0.1s;
  position: relative;
}
.frontend-opt input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.frontend-opt:hover { border-color: var(--accent); background: #2563eb04; }
.frontend-opt.selected { border-color: var(--accent); background: #2563eb06; }
.frontend-opt-title { font-weight: 700; font-size: 0.85rem; margin-bottom: 0.2rem; display: flex; align-items: center; gap: 0.4rem; }
.frontend-opt.selected .frontend-opt-title::after {
  content: '✓'; font-size: 0.65rem; color: var(--accent);
  background: #2563eb14; border: 1px solid #2563eb28;
  border-radius: 50%; width: 14px; height: 14px;
  display: inline-flex; align-items: center; justify-content: center;
}
.frontend-opt-desc { font-size: 0.73rem; color: var(--text-muted); line-height: 1.5; }

/* ── App view ─────────────────────────────────────────────────────────── */
.app-view {
  flex: 1; display: grid; grid-template-columns: 1fr 260px;
  height: calc(100vh - 52px); overflow: hidden;
}
.chat-panel { display: flex; flex-direction: column; overflow: hidden; border-right: 1px solid var(--border); }
.chat-header {
  padding: 0.75rem 1.2rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); flex-shrink: 0; gap: 1rem;
}
.chat-header-left h2 { font-size: 0.88rem; font-weight: 700; }
.chat-header-left .chat-sub { font-size: 0.69rem; color: var(--text-muted); font-family: monospace; margin-top: 0.05rem; }
.chat-header-right { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.open-app-link {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.72rem; font-weight: 600; color: var(--accent);
  background: #2563eb0a; border: 1px solid #2563eb22;
  border-radius: 5px; padding: 0.24rem 0.55rem;
  text-decoration: none; transition: background 0.1s;
}
.open-app-link:hover { background: #2563eb18; text-decoration: none; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1rem;
  background: var(--bg);
}
.chat-hint {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; color: var(--text-muted); gap: 0.5rem;
}
.chat-hint-icon {
  width: 42px; height: 42px; border-radius: 9px;
  background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
}
.chat-hint h3 { font-size: 0.88rem; color: var(--text); font-weight: 600; }
.chat-hint p { font-size: 0.78rem; max-width: 220px; line-height: 1.6; }
.message { display: flex; flex-direction: column; gap: 0.2rem; max-width: 84%; }
.message.user { align-self: flex-end; align-items: flex-end; }
.message.agent { align-self: flex-start; align-items: flex-start; }
.message-bubble {
  padding: 0.6rem 0.85rem; border-radius: var(--radius);
  font-size: 0.862rem; line-height: 1.62; white-space: pre-wrap; word-break: break-word;
}
.message.user .message-bubble {
  background: var(--accent); color: #fff;
  border-radius: var(--radius) var(--radius) 3px var(--radius);
}
.message.agent .message-bubble {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) var(--radius) 3px;
}
.message-cost { font-size: 0.67rem; color: var(--text-dim); }
.message.streaming .message-bubble::after { content: '▋'; animation: blink 0.7s infinite; margin-left: 2px; color: var(--accent); }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }
.chat-input-area {
  padding: 0.75rem 1rem; border-top: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0;
}
.chat-input-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.chat-input-row textarea {
  flex: 1; resize: none; min-height: 38px; max-height: 140px; overflow-y: auto;
  background: var(--bg); border-color: var(--border);
  border-radius: var(--radius); padding: 0.52rem 0.75rem;
  font-size: 0.862rem; line-height: 1.5;
}
.quota-row { margin-top: 0.45rem; display: flex; align-items: center; gap: 0.75rem; }
.quota-label { font-size: 0.67rem; color: var(--text-dim); white-space: nowrap; }
.quota-track { flex: 1; height: 2px; background: var(--border); border-radius: 2px; overflow: hidden; }
.quota-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.4s; }

/* ── Files ────────────────────────────────────────────────────────────── */
.files-panel { display: flex; flex-direction: column; overflow: hidden; background: var(--surface); min-height: 0; }
.files-header {
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.files-header h3 { font-size: 0.68rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.files-list { flex: 1; overflow-y: auto; padding: 0.35rem; }
.files-empty { color: var(--text-dim); padding: 1.5rem 0.65rem; font-size: 0.77rem; text-align: center; }
.file-item {
  display: flex; align-items: center; padding: 0.32rem 0.5rem;
  border-radius: 5px; font-size: 0.77rem; transition: background 0.1s; gap: 0.38rem;
}
.file-item:hover { background: var(--surface-2); }
.file-item-icon { font-size: 0.9rem; flex-shrink: 0; line-height: 1; }
.file-item-name { color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item-size { color: var(--text-dim); font-size: 0.67rem; flex-shrink: 0; }
.file-item-actions { display: none; align-items: center; gap: 0.1rem; flex-shrink: 0; }
.file-item:hover .file-item-actions { display: flex; }
.file-action-btn {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 0.77rem; padding: 0.12rem 0.3rem; border-radius: 4px;
  line-height: 1; transition: color 0.1s, background 0.1s;
}
.file-action-btn:hover { color: var(--text); background: var(--surface-2); }
.file-action-del:hover { color: var(--danger) !important; background: transparent !important; }
.upload-area { padding: 0.6rem; border-top: 1px solid var(--border); flex-shrink: 0; }
.upload-btn { width: 100%; justify-content: center; }
.rename-modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
}
.rename-modal {
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius-lg); padding: 1.25rem;
  width: 320px; box-shadow: var(--shadow-lg);
}
.rename-modal-title { font-size: 0.85rem; font-weight: 700; margin-bottom: 0.75rem; }
.rename-input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border-2);
  border-radius: 6px; color: var(--text); font-size: 0.85rem;
  padding: 0.5rem 0.75rem; font-family: inherit; outline: none;
}
.rename-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #2563eb14; }
.rename-error { color: var(--danger); font-size: 0.72rem; margin-top: 0.35rem; min-height: 1em; }
.rename-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.85rem; }

/* ── Landing ─────────────────────────────────────────────────────────── */
.grad-text { color: var(--accent2); }
.section-label { font-size: 0.72rem; font-weight: 700; color: var(--accent2); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 0.65rem; }
.section-title { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 0.4rem; }
.section-sub { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 2.25rem; }
.landing-footer { border-top: 1px solid var(--border); padding: 1.5rem 0; text-align: center; color: var(--text-dim); font-size: 0.75rem; }

/* ── Mobile files ─────────────────────────────────────────────────────── */
.files-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 199; }
.files-toggle-btn { display: none; }

@media (max-width: 767px) {
  .app-view { grid-template-columns: 1fr; height: calc(100vh - 52px); height: calc(100dvh - 52px); }
  .chat-panel { border-right: none; }
  .files-panel {
    position: fixed; bottom: 0; left: 0; right: 0; height: 55vh; z-index: 200;
    border-top: 1px solid var(--border-2); border-right: none;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
    transform: translateY(100%); transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
    display: flex; flex-direction: column;
  }
  .files-panel.mobile-open { transform: translateY(0); }
  .files-toggle-btn { display: inline-flex; }
  .quota-label { display: none; }
  .nav-user { display: none; }
  .app-list-row { grid-template-columns: 1fr 36px 46px; }
  .app-list-row .alr-path,
  .app-list-row .alr-status,
  .app-list-row .alr-owner { display: none; }
  .lib-search { max-width: none; }
  .lib-quota { display: none; }
  @media (max-width: 400px) {
    .chat-input-row { flex-direction: column; align-items: stretch; }
    .chat-input-row .btn { width: 100%; justify-content: center; }
  }
}
