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

:root {
  --bg:          #141414;
  --bg2:         #1c1c1c;
  --bg3:         #242424;
  --bg4:         #2e2e2e;
  --border:      #333;
  --border2:     #444;
  --text:        #e8e8e8;
  --text2:       #999;
  --text3:       #666;
  --accent:      #4f8ef7;
  --accent-dim:  #2a4a8a;
  --danger:      #e05252;
  --warn:        #e0a832;
  --green:       #52b05a;
  --purple:      #9c6fe0;

  --flag-general:      #4f8ef7;
  --flag-important:    #e05252;
  --flag-followup:     #e0a832;
  --flag-inconsist:    #9c6fe0;
  --flag-prosecutor:   #52b05a;

  --panel-header-h: 38px;
  --case-header-h:  46px;
  --divider-w:      5px;
  --radius:         6px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

/* ── Utilities ────────────────────────────────────────────────── */
.hidden { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 5px;
  padding: 6px 14px;
  border: none; border-radius: var(--radius);
  font-size: 13px; font-family: var(--font);
  cursor: pointer; white-space: nowrap;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #3a7ae0; }
.btn-secondary { background: var(--bg4); color: var(--text); border: 1px solid var(--border2); }
.btn-secondary:hover:not(:disabled) { background: var(--border2); }
.btn-ghost     { background: transparent; color: var(--text2); }
.btn-ghost:hover:not(:disabled) { background: var(--bg4); color: var(--text); }
.btn-danger    { background: var(--danger); color: #fff; }
.full-width    { width: 100%; }

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Home Screen ──────────────────────────────────────────────── */
#home-screen {
  height: 100vh;
  display: flex; flex-direction: column;
}

.home-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}

.home-logo {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
}
.home-logo img {
  height: 48px;
  width: auto;
  display: block;
}
.home-logo-text {
  font-size: 22px; font-weight: 700; letter-spacing: -0.5px;
  color: var(--text);
}

.case-search {
  flex: 1; max-width: 320px;
  background: var(--bg3); border: 1px solid var(--border2);
  color: var(--text); font-size: 13px; font-family: var(--font);
  padding: 7px 12px; border-radius: var(--radius);
  outline: none;
}
.case-search:focus { border-color: var(--accent); }
.case-search::placeholder { color: var(--text3); }

.cases-list {
  flex: 1; overflow-y: auto;
  padding: 24px 32px;
  display: flex; flex-direction: column; gap: 10px;
}

.case-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  transition: border-color 0.15s, background 0.15s;
}
.case-card:hover { border-color: var(--accent); background: var(--bg3); }
.case-card-name { font-size: 15px; font-weight: 500; }
.case-card-meta { font-size: 12px; color: var(--text2); margin-top: 3px; }
.case-card-delete {
  opacity: 0; background: transparent; border: none;
  color: var(--danger); font-size: 16px; cursor: pointer; padding: 4px 8px;
  border-radius: 4px; transition: opacity 0.15s;
}
.case-card:hover .case-card-delete { opacity: 0.6; }
.case-card-delete:hover { opacity: 1 !important; background: rgba(224,82,82,0.1); }

.empty-state {
  color: var(--text3); text-align: center;
  padding: 60px 0; font-size: 15px;
}

/* ── Case Header ──────────────────────────────────────────────── */
.case-header {
  height: var(--case-header-h);
  display: flex; align-items: center;
  padding: 0 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

.case-header-left {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}

.case-header-logo img {
  height: 26px; width: auto; display: block;
}

.case-header-appname {
  font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap;
}

.btn-reset {
  background: none; border: none; padding: 0; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  border-radius: var(--radius);
  padding: 4px 6px;
  transition: background 0.15s;
}
.btn-reset:hover { background: var(--bg3); }

.case-name {
  font-weight: 600; font-size: 15px;
  position: absolute; left: 50%; transform: translateX(-50%);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 40%;
  pointer-events: none;
}

.header-right {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
  margin-left: auto;
}

.save-status {
  font-size: 12px; color: var(--text3); white-space: nowrap;
  min-width: 140px; text-align: right;
}

/* ── Three-Panel Layout ───────────────────────────────────────── */
#case-view {
  display: flex; flex-direction: column;
  height: 100vh;
}

.three-panel {
  flex: 1; display: flex; overflow: hidden;
  min-height: 0;
}

.panel {
  display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}

.panel-left  { width: 260px; min-width: 120px; max-width: 500px; flex-shrink: 0; border-right: 1px solid var(--border); }
.panel-center { flex: 1; background: var(--bg); }
.panel-right { width: 300px; min-width: 180px; max-width: 600px; flex-shrink: 0; border-left: 1px solid var(--border); }

.panel-left.collapsed { width: 0 !important; min-width: 0; border: none; }

.divider {
  width: var(--divider-w);
  background: var(--border);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
  position: relative; z-index: 10;
}
.divider:hover, .divider.dragging { background: var(--accent); }

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

.panel-title { font-weight: 600; font-size: 13px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }

.panel-header select {
  background: var(--bg4); border: 1px solid var(--border); color: var(--text);
  font-size: 12px; padding: 3px 6px; border-radius: 4px; cursor: pointer;
}

/* ── File Tree ────────────────────────────────────────────────── */
.reconnect-banner, .orphaned-banner {
  padding: 7px 12px;
  font-size: 12px; color: var(--warn);
  border-bottom: 1px solid var(--border);
  background: var(--bg2); flex-shrink: 0;
}
.reconnect-link {
  background: none; border: none; color: var(--warn);
  font-size: 12px; cursor: pointer; padding: 0;
  text-decoration: underline;
}
.reconnect-link:hover { color: var(--text); }

.file-tree {
  flex: 1; overflow-y: auto; padding: 6px 0;
}

.drop-hint {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding: 40px 16px; color: var(--text3); text-align: center; font-size: 13px;
}
.drop-hint-icon { font-size: 32px; }

.folder-group { }
.folder-label {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px; font-size: 12px; font-weight: 600;
  color: var(--text2); cursor: pointer; user-select: none;
  text-transform: uppercase; letter-spacing: 0.3px;
}
.folder-label:hover { background: var(--bg3); }
.folder-caret { font-size: 10px; transition: transform 0.15s; }
.folder-label.collapsed .folder-caret { transform: rotate(-90deg); }
.folder-files { }
.folder-files.collapsed { display: none; }

.file-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 20px;
  cursor: pointer; font-size: 13px; color: var(--text);
  user-select: none; position: relative;
  border-left: 2px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-item:hover { background: var(--bg3); }
.file-item.active {
  background: var(--bg4);
  border-left-color: var(--accent);
  color: var(--accent);
}
.file-item .file-icon { flex-shrink: 0; font-size: 13px; }
.file-item .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.file-item .note-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
}
.file-item .unviewed-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text3); flex-shrink: 0;
}
.complete-btn {
  flex-shrink: 0;
  background: none; border: none; cursor: pointer;
  font-size: 12px; font-weight: 700;
  color: var(--text3);
  padding: 0 2px; line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.file-item:hover .complete-btn { opacity: 1; }
.file-item.completed .complete-btn { opacity: 1; color: var(--green); }
.file-item.unviewed .file-name {
  color: var(--text);
  font-weight: 500;
}

/* ── Viewer ───────────────────────────────────────────────────── */
.viewer-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--text3); gap: 12px;
}
.viewer-empty-icon { font-size: 48px; }

.viewer-wrap {
  display: flex; flex-direction: column;
  height: 100%; overflow: hidden;
}

/* PDF */
.viewer-toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2); flex-shrink: 0;
}
.toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.page-info { font-size: 13px; color: var(--text2); padding: 0 6px; }

.pdf-canvas-wrap {
  flex: 1; overflow: auto;
  padding: 16px;
  background: var(--bg);
}
.pdf-pages {
  display: flex; flex-direction: column;
  align-items: center;
  gap: 12px;
}
.pdf-page {
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  background: #fff;
}
.pdf-canvas {
  display: block;
  position: absolute; top: 0; left: 0;
}
.pdf-text-layer {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  line-height: 1;
  text-size-adjust: none;
  forced-color-adjust: none;
  user-select: text;
}
.pdf-text-layer span,
.pdf-text-layer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}
.pdf-text-layer ::selection {
  background: rgba(0, 100, 255, 0.25);
  color: transparent;
}
.pdf-highlight-canvas {
  position: absolute; top: 0; left: 0;
  pointer-events: none;
}

/* Video */
#video-viewer { background: #000; }
#video-player { flex: 1; width: 100%; min-height: 0; object-fit: contain; }

.speed-select {
  background: var(--bg4); border: 1px solid var(--border);
  color: var(--text); font-size: 12px; padding: 3px 6px;
  border-radius: 4px; cursor: pointer;
}

/* Audio */
.audio-wrap {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 20px;
  padding: 40px;
}
.audio-icon { font-size: 56px; }
.audio-filename { font-size: 15px; font-weight: 500; color: var(--text2); text-align: center; }
#audio-player { width: 100%; max-width: 480px; }

/* Image */
.image-wrap {
  flex: 1; overflow: auto;
  padding: 16px;
}
#image-display {
  display: block; margin: 0 auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

/* HTML */
#html-frame { flex: 1; border: none; background: #fff; }

/* ── Notes Panel ──────────────────────────────────────────────── */
.current-file-label {
  padding: 8px 12px;
  font-size: 12px; color: var(--text3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex-shrink: 0;
}

.notes-list {
  flex: 1; overflow-y: auto;
  padding: 8px 0;
}

.note-card {
  margin: 4px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--flag-general);
  border-radius: var(--radius);
  padding: 10px 12px;
  position: relative;
}
.note-card[data-flag="Important"]    { border-left-color: var(--flag-important); }
.note-card[data-flag="Questions"]     { border-left-color: var(--flag-followup); }
.note-card[data-flag="File-Error"]    { border-left-color: var(--flag-inconsist); }
.note-card[data-flag="Ask-Prosecutor"]{ border-left-color: var(--flag-prosecutor); }

.note-card-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 6px;
}
.note-anchor-tag {
  font-size: 11px; background: var(--bg4); color: var(--text2);
  padding: 1px 6px; border-radius: 10px; white-space: nowrap;
}
.anchor-link {
  cursor: pointer;
}
.anchor-link:hover {
  background: var(--accent-dim); color: var(--accent);
}
.note-flag-tag {
  font-size: 11px; font-weight: 600;
  padding: 1px 6px; border-radius: 10px;
}
.note-flag-tag.General      { background: rgba(79,142,247,0.15); color: var(--flag-general); }
.note-flag-tag.Important    { background: rgba(224,82,82,0.15);  color: var(--flag-important); }
.note-flag-tag.Questions    { background: rgba(224,168,50,0.15); color: var(--flag-followup); }
.note-flag-tag.File-Error    { background: rgba(156,111,224,0.15); color: var(--flag-inconsist); }
.note-flag-tag.Ask-Prosecutor{ background: rgba(82,176,90,0.15);  color: var(--flag-prosecutor); }

.note-card-body { font-size: 13px; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.note-card-actions {
  display: flex; gap: 6px; margin-top: 8px;
}
.note-action-btn {
  font-size: 11px; background: none; border: none; color: var(--text3);
  cursor: pointer; padding: 2px 4px; border-radius: 3px;
}
.note-action-btn:hover { background: var(--bg4); color: var(--text); }

/* Compose */
.note-compose {
  border-top: 1px solid var(--border);
  padding: 10px 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
  flex-shrink: 0; background: var(--bg2);
}
.compose-meta { display: flex; align-items: center; gap: 8px; }
.anchor-badge {
  font-size: 11px; background: var(--bg4); color: var(--accent);
  padding: 2px 8px; border-radius: 10px; white-space: nowrap;
}
.flag-select {
  flex: 1; background: var(--bg4); border: 1px solid var(--border);
  color: var(--text); font-size: 12px; padding: 4px 6px; border-radius: 4px;
}
.note-textarea {
  width: 100%; resize: vertical;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); font-family: var(--font); font-size: 13px;
  padding: 8px 10px; border-radius: var(--radius);
  outline: none; line-height: 1.5; min-height: 72px;
}
.note-textarea:focus { border-color: var(--accent); }

/* ── Modals ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 28px 32px;
  width: 400px; max-width: 92vw;
  display: flex; flex-direction: column; gap: 14px;
}
.modal h2 { font-size: 17px; font-weight: 600; }
.modal-body-text { color: var(--text2); font-size: 13px; line-height: 1.6; }

.field-label { font-size: 12px; color: var(--text2); font-weight: 500; }
.field-input {
  width: 100%; background: var(--bg); border: 1px solid var(--border2);
  color: var(--text); font-size: 14px; padding: 8px 12px;
  border-radius: var(--radius); outline: none; font-family: var(--font);
}
.field-input:focus { border-color: var(--accent); }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* ── Folders modal ────────────────────────────────────────────── */
.folders-list {
  display: flex; flex-direction: column; gap: 6px;
  min-height: 32px;
}
.folder-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg3);
  border-radius: var(--radius);
  font-size: 13px;
}
.folder-row-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1;
}

/* ── Tutorial modal ───────────────────────────────────────────── */
#tutorial-modal { width: 420px; position: relative; text-align: center; gap: 0; }
.tutorial-skip {
  position: absolute; top: 0; right: 0;
  background: none; border: none; color: var(--text3);
  font-size: 12px; cursor: pointer; padding: 4px 8px;
}
.tutorial-skip:hover { color: var(--text2); }
.tutorial-icon  { font-size: 40px; line-height: 1; margin-bottom: 12px; }
.tutorial-title { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
.tutorial-body  { font-size: 13px; color: var(--text2); line-height: 1.6; margin-bottom: 20px; }
.tutorial-body strong { color: var(--text); }
.tutorial-dots  { display: flex; justify-content: center; gap: 6px; margin-bottom: 20px; }
.tutorial-dot   { width: 7px; height: 7px; border-radius: 50%; background: var(--border2); }
.tutorial-dot.active { background: var(--accent); }
.tutorial-actions { display: flex; justify-content: space-between; gap: 10px; }
.tutorial-actions .btn { flex: 1; }

/* ── Shortcuts modal ──────────────────────────────────────────── */
.modal-wide { width: 480px; gap: 0; padding: 0; overflow: hidden; }

.shortcuts-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.shortcuts-header h2 { font-size: 16px; font-weight: 600; }

.shortcuts-section {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}
.shortcuts-section:last-child { border-bottom: none; }

.shortcuts-group-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text3); margin-bottom: 8px;
}

.shortcut-row {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 0; font-size: 13px;
}
.shortcut-row span:last-child {
  margin-left: auto; color: var(--text2); padding-left: 16px; text-align: right;
}
.kbd-or { color: var(--text3); font-size: 11px; }

kbd {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg4); border: 1px solid var(--border2);
  border-bottom-width: 2px;
  border-radius: 4px; padding: 2px 7px;
  font-family: var(--font); font-size: 12px; font-weight: 500;
  color: var(--text); white-space: nowrap; min-width: 24px;
}

/* ── PDF highlight tooltip ────────────────────────────────────── */
.pdf-highlight-tooltip {
  position: fixed;
  z-index: 200;
  transform: translateX(-50%);
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 4px 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  pointer-events: all;
}
.pdf-highlight-tooltip button {
  background: #e8c84a; color: #1a1400;
  border: none; border-radius: 4px;
  padding: 5px 12px; font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.pdf-highlight-tooltip button:hover { background: #d4b63a; }

/* ── Scrollbars ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }
