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

:root {
  --bg:         #0f1117;
  --surface:    #1a1d27;
  --surface2:   #22263a;
  --border:     #2e3248;
  --accent:     #6c8fff;
  --accent-dim: #3a4f99;
  --text:       #e8eaf6;
  --text-muted: #7278a0;
  --success:    #4caf9a;
  --warn:       #f0a050;
  --radius:     10px;
  --header-h:   56px;
  --sidebar-w:  300px;
  --chat-h:     180px;
  --font:       'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono:       'Consolas', 'Courier New', monospace;
}

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }

/* ── Landing / sign-in page ────────────────────────────────── */
.landing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 40px 44px 36px;
  max-width: 460px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
}

.landing-logo-wrap {
  background: #fff;
  border-radius: 10px;
  display: inline-block;
  padding: 10px 18px;
  margin-bottom: 16px;
}

.landing-logo {
  height: 120px;
  width: auto;
  display: block;
}

.landing-tagline {
  color: var(--text-muted);
  font-size: .88rem;
  margin-bottom: 20px;
  letter-spacing: .01em;
}

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

.landing-instr-body {
  font-size: .87rem;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 22px;
}

.landing-signin-btn {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.landing-footer {
  font-size: .78rem;
  color: var(--text-muted);
  line-height: 1.7;
}

/* ── Auth overlay ──────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 1000; transition: opacity .3s; }
.overlay:not(.active) { opacity: 0; pointer-events: none; }

.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 48px 40px; max-width: 420px; width: 100%; text-align: center; }
.auth-card h1 { font-size: 2rem; font-weight: 700; letter-spacing: -.5px; margin-bottom: 8px; }
.tagline { color: var(--text-muted); margin-bottom: 28px; font-size: .9rem; }
.auth-note { font-size: .83rem; color: var(--text-muted); margin-bottom: 24px; line-height: 1.5; }
.auth-footer { margin-top: 20px; font-size: .75rem; color: var(--text-muted); }
.g_id_signin { display: flex; justify-content: center; }

/* ── Logo mark ─────────────────────────────────────────────── */
.logo-mark { width: 56px; height: 56px; border-radius: 14px; background: linear-gradient(135deg, var(--accent), #a78bfa); display: flex; align-items: center; justify-content: center; font-size: 1.6rem; font-weight: 800; color: #fff; margin: 0 auto 20px; }
.logo-mark-sm { width: 28px; height: 28px; border-radius: 7px; background: linear-gradient(135deg, var(--accent), #a78bfa); display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 800; color: #fff; }

/* ── App shell ─────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }
.hidden { display: none !important; }

/* ── Header ────────────────────────────────────────────────── */
.app-header { height: var(--header-h); background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 16px; flex-shrink: 0; }
.header-left { display: flex; align-items: center; gap: 10px; }
.app-title { font-size: 1.1rem; font-weight: 700; }
.app-subtitle { color: var(--text-muted); font-size: .8rem; }
.header-nav { display: flex; gap: 4px; margin-left: auto; }
.nav-link { padding: 6px 14px; border-radius: 6px; color: var(--text-muted); text-decoration: none; font-size: .85rem; transition: background .15s, color .15s; }
.nav-link:hover, .nav-link.active { background: var(--surface2); color: var(--text); }
.header-right { display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.user-name { font-size: .85rem; color: var(--text-muted); }

/* ── Main layout ───────────────────────────────────────────── */
.main-layout { display: flex; flex: 1; min-height: 0; overflow: hidden; }

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: .95rem; font-weight: 600; }

.dir-list { flex: 1; overflow-y: auto; padding: 10px 8px; }
.dir-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; margin-bottom: 4px; transition: background .15s, border-color .15s; }
.dir-item:hover { background: var(--surface2); }
.dir-item.active { background: var(--accent-dim); border-color: var(--accent); }
.dir-icon { font-size: 1.1rem; }
.dir-info { min-width: 0; }
.dir-name { font-size: .9rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dir-count { display: none; }

.file-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.file-panel-header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.current-dir-name { font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.file-list { flex: 1; overflow-y: auto; padding: 8px; }
.file-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; margin-bottom: 2px; }
.file-item:hover { background: var(--surface2); }
.file-item.active { background: var(--accent-dim); border-color: var(--accent); }
.file-thumb { width: 36px; height: 36px; border-radius: 4px; object-fit: cover; background: var(--surface2); flex-shrink: 0; }
.file-name { font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.file-cached { font-size: .7rem; color: var(--success); flex-shrink: 0; }
.file-thumb-icon { width: 36px; height: 36px; border-radius: 4px; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.pdf-pages-list { padding-left: 16px; border-left: 2px solid var(--accent-dim); margin: 2px 0 4px 12px; }
.pdf-page-item { padding: 6px 10px; font-size: .8rem; }

.file-actions { padding: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.range-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.export-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding-top: 4px; border-top: 1px solid var(--border); margin-top: 4px; }
.range-row label { font-size: .8rem; color: var(--text-muted); }
.range-row input { width: 52px; background: var(--bg); border: 1px solid var(--border); border-radius: 5px; padding: 4px 6px; color: var(--text); font-size: .8rem; }

/* ── Viewer panel ──────────────────────────────────────────── */
.viewer-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.viewer-placeholder { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); gap: 12px; }
.placeholder-icon { font-size: 3rem; }
.viewer-placeholder p { text-align: center; line-height: 1.7; }

.document-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.doc-toolbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; flex-wrap: wrap; }
.doc-title { font-weight: 600; font-size: .9rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-nav { display: flex; align-items: center; gap: 8px; }
.page-indicator { font-size: .8rem; color: var(--text-muted); white-space: nowrap; }
.toggle-label { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--text-muted); cursor: pointer; }

.doc-body { flex: 1; display: flex; overflow: hidden; }
.image-pane { flex: 1; overflow: auto; background: #0a0c14; display: flex; align-items: flex-start; justify-content: center; padding: 16px; position: relative; }
.doc-image { max-width: 100%; border-radius: 6px; box-shadow: 0 4px 24px rgba(0,0,0,.6); }
.image-loading { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); color: var(--text-muted); }
.image-pane.hidden-pane { display: none; }

.transcription-pane { width: 420px; flex-shrink: 0; border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.transcription-pane.full-width { width: 100%; border-left: none; }
.trans-toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.trans-label { font-size: .82rem; font-weight: 600; flex: 1; }
.transcription-content { flex: 1; overflow-y: auto; padding: 18px; font-family: var(--mono); font-size: .85rem; line-height: 1.8; white-space: pre-wrap; color: var(--text); }

/* ── Chat bar ──────────────────────────────────────────────── */
.chat-bar { background: var(--surface); border-top: 1px solid var(--border); padding: 10px 16px 14px; flex-shrink: 0; }
.chat-context-pill { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
#chat-context-label { font-size: .75rem; color: var(--text-muted); background: var(--surface2); padding: 3px 10px; border-radius: 20px; border: 1px solid var(--border); }
.pill-clear { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 4px; }
.chat-input-row { display: flex; gap: 10px; align-items: flex-end; }
.chat-textarea { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; color: var(--text); font-family: var(--font); font-size: .9rem; resize: none; max-height: 120px; outline: none; transition: border-color .2s; }
.chat-textarea:focus { border-color: var(--accent); }
.btn-send { width: 40px; height: 40px; border-radius: 10px; background: var(--accent); border: none; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background .15s; }
.btn-send:hover { background: #5575ee; }
.btn-send:disabled { background: var(--accent-dim); cursor: default; }

.chat-history { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.chat-msg { padding: 10px 14px; border-radius: 10px; font-size: .85rem; line-height: 1.6; max-width: 90%; }
.chat-msg.user { background: var(--accent-dim); align-self: flex-end; }
.chat-msg.assistant { background: var(--surface2); align-self: flex-start; }
.chat-msg.assistant pre { white-space: pre-wrap; font-family: var(--mono); font-size: .82rem; margin-top: 6px; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn-ghost { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 5px 12px; color: var(--text-muted); font-size: .82rem; cursor: pointer; transition: background .15s; }
.btn-ghost:hover { background: var(--surface2); }
.btn-icon { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; color: var(--text-muted); cursor: pointer; font-size: .85rem; transition: background .15s; }
.btn-icon:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.btn-icon:disabled { opacity: .4; cursor: default; }
.btn-back { background: none; border: none; color: var(--accent); cursor: pointer; font-size: .85rem; padding: 0; flex-shrink: 0; }
.btn-secondary { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; color: var(--text); font-size: .8rem; cursor: pointer; transition: background .15s; width: 100%; }
.btn-secondary:hover { background: var(--border); }
.btn-xs { background: var(--surface2); border: 1px solid var(--border); border-radius: 5px; padding: 3px 9px; color: var(--text-muted); font-size: .75rem; cursor: pointer; }
.btn-xs:hover { color: var(--text); }
.btn-transcribe { background: var(--accent-dim); border-color: var(--accent); color: var(--text); }
.btn-transcribe:hover { background: var(--accent); }

/* ── Loading modal ─────────────────────────────────────────── */
.loading-modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 999; }
.loading-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 32px 40px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Muted / util ──────────────────────────────────────────── */
.muted { color: var(--text-muted); font-size: .85rem; }
* { scrollbar-width: thin; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Form page ─────────────────────────────────────────────── */
.form-page { max-width: 680px; margin: 60px auto; padding: 0 20px; }
.form-page h1 { font-size: 1.6rem; margin-bottom: 8px; }
.form-page .subtitle { color: var(--text-muted); margin-bottom: 36px; }
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 36px; }
.form-group { margin-bottom: 22px; }
.form-group label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 7px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; color: var(--text); font-family: var(--font); font-size: .9rem; outline: none; transition: border-color .2s; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent); }
.form-group select option { background: var(--surface); }
.form-group textarea { resize: vertical; min-height: 100px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.btn-primary { background: var(--accent); border: none; border-radius: 8px; padding: 12px 28px; color: #fff; font-size: .95rem; font-weight: 600; cursor: pointer; transition: background .15s; }
.btn-primary:hover { background: #5575ee; }
.form-success { display: none; text-align: center; padding: 20px; }
.form-success .success-icon { font-size: 2.5rem; margin-bottom: 12px; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
  .transcription-pane { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .doc-body { flex-direction: column; }
}
@media (max-width: 600px) {
  :root { --sidebar-w: 100%; }
  .sidebar { position: absolute; z-index: 10; height: 100%; }
  .app-subtitle { display: none; }
}
