:root {
  --bg-page: #F6F4EF;
  --bg-sidebar: #F2EFE8;
  --bg-toolbar: #ECE8DF;
  --bg-card: #FFFFFF;
  --border: #DDD7CB;
  --border-soft: #E8E3D9;
  --text-main: #2A322E;
  --text-sec: #56635C;
  --text-muted: #828E88;
  --accent: #3E6B59;
  --accent-hover: #315647;
  --accent-soft: #E8F2EC;
  --teal: #176A74;
  --teal-soft: #E6F4F6;
  --danger: #B43A2E;
  --danger-soft: #FCEEEA;
  --shadow-sm: 0 2px 8px rgba(42, 50, 46, 0.06);
  --shadow-md: 0 8px 24px rgba(42, 50, 46, 0.10);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* ==================== PIN Auth Overlay ==================== */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg-page);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 368px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 26px 24px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.auth-emblem { margin-bottom: 6px; }
.auth-brand {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
}
.auth-title {
  margin: 4px 0 4px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
}
.auth-desc {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--text-muted);
}

.pin-slots {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 18px;
}
.pin-slot {
  width: 40px;
  height: 46px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #FAF9F6;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
}
.pin-slot.filled {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.pin-slot.filled::after {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 12px;
  background: #F8F6F1;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  margin-bottom: 14px;
}
.kp-btn {
  height: 50px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #FFFFFF;
  color: var(--text-main);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s, transform 0.06s;
}
.kp-btn:active {
  background: var(--accent-soft);
  transform: scale(0.97);
}
.kp-sub {
  font-size: 14px;
  color: var(--text-sec);
  background: #F3F0EA;
}

.auth-error {
  min-height: 20px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--danger);
  margin-bottom: 10px;
}

.auth-submit-btn {
  width: 100%;
  height: 46px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #FFFFFF;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.auth-submit-btn:disabled { opacity: 0.6; cursor: default; }

/* ==================== App Shell ==================== */
.app-shell {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Left Sidebar */
.sidebar {
  width: 264px;
  min-width: 264px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: width 0.2s ease, min-width 0.2s ease, opacity 0.2s ease;
  z-index: 20;
}
.sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
  overflow: hidden;
  opacity: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg-toolbar);
}
.sidebar-kicker {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--accent);
}
.sidebar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 2px;
}

.sidebar-search-wrap {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border-soft);
}
.sidebar-search {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #FFFFFF;
  color: var(--text-main);
  font-size: 13.5px;
  outline: none;
}
.sidebar-search:focus { border-color: var(--accent); }

.candidates-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  list-style: none;
  margin: 0;
  padding: 6px 8px;
}
.candidates-list li {
  padding: 11px 12px;
  margin-bottom: 5px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.candidates-list li:hover { background: rgba(255,255,255,0.65); }
.candidates-list li.active {
  background: #FFFFFF;
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.cand-li-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.cand-li-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}
.cand-li-pos {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cand-li-pills {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.mini-pill {
  font-size: 10px;
  font-weight: 700;
  padding: 1.5px 6px;
  border-radius: 999px;
}
.mini-pill-ai { background: var(--teal-soft); color: var(--teal); }
.mini-pill-rec { background: var(--danger-soft); color: var(--danger); }
.mini-pill-draft { background: #FEF6E4; color: #9A6616; }

.list-placeholder {
  text-align: center;
  color: var(--text-muted);
  padding: 28px 12px !important;
  font-size: 13.5px;
  cursor: default !important;
}

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}
.link-btn {
  border: none;
  background: transparent;
  color: var(--text-sec);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

/* ==================== Main Right Area ==================== */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.topbar {
  min-height: 54px;
  padding: 6px 12px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #FFFFFF;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:active { background: var(--accent-soft); }

.cand-badge-wrap {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
}
.cand-name {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
}
.cand-pos {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

/* Resume / AI Evaluation Doc Switcher */
.doc-switcher {
  display: inline-flex;
  background: #E2DDD2;
  padding: 3px;
  border-radius: 9px;
  gap: 2px;
}
.doc-tab {
  border: none;
  background: transparent;
  color: var(--text-sec);
  font-size: 12.5px;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.doc-tab.active {
  background: #FFFFFF;
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.doc-tab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Recording Bar */
.rec-bar {
  display: inline-flex;
  align-items: center;
}
.rec-btn {
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid #DFB8B2;
  background: #FFF6F4;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.rec-btn:disabled { opacity: 0.45; cursor: default; }
.rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
}

.rec-live-group, .rec-ready-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px 3px 10px;
  border-radius: 999px;
  background: #FFF2EF;
  border: 1.5px solid #E2A39A;
}
.rec-ready-pill {
  background: var(--accent-soft);
  border-color: #B4D3C3;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 700;
}
.rec-pulse {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #DC2626;
  animation: pulse 1.1s ease-in-out infinite;
}
.rec-pulse.paused {
  background: #D97706;
  animation: none;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}
.rec-timer {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 700;
  color: #991B1B;
  min-width: 42px;
}
.rec-mini-btn {
  height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #FFFFFF;
  color: var(--text-main);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.rec-mark-btn {
  border-color: #D4B97E;
  background: #FFFBF0;
  color: #8A5A12;
}
.mark-count {
  display: inline-block;
  margin-left: 3px;
  padding: 0 5px;
  border-radius: 999px;
  background: #8A5A12;
  color: #FFFFFF;
  font-size: 10.5px;
}
.rec-stop-btn {
  border-color: #DC2626;
  background: #DC2626;
  color: #FFFFFF;
}
.rec-danger-mini {
  color: var(--danger);
  border-color: #E7C2BC;
}

.save-btn {
  height: 36px;
  padding: 0 14px;
  border-radius: 9px;
  border: none;
  background: var(--accent);
  color: #FFFFFF;
  font-size: 13.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.save-btn:active { background: var(--accent-hover); }
.save-btn:disabled { opacity: 0.45; cursor: default; }
.save-btn.dirty {
  box-shadow: 0 0 0 2px rgba(62, 107, 89, 0.28);
}

/* ==================== Ink Writing Toolbar ==================== */
.ink-toolbar {
  min-height: 46px;
  padding: 5px 12px;
  background: #F6F3EC;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.ink-toolbar::-webkit-scrollbar { display: none; }

.tool-group {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
.tool-group-right {
  margin-left: auto;
}
.tool-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  flex-shrink: 0;
}

.ink-btn {
  height: 33px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #FFFFFF;
  color: var(--text-main);
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.ink-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.ink-btn:disabled { opacity: 0.4; cursor: default; }
.ink-btn-muted { color: var(--text-sec); }

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(0,0,0,0.18);
}
.swatch-black { background: #18181B; }
.swatch-red { background: #B91C1C; }
.swatch-blue { background: #1D4ED8; }
.swatch-hi { background: #FACC15; border-radius: 3px; }

.size-btn {
  width: 31px;
  height: 31px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #FFFFFF;
  color: var(--text-main);
  font-size: 15px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.size-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.dot-s {
  border-radius: 50%;
  background: var(--text-main);
  display: inline-block;
}
.dot-thin { width: 4px; height: 4px; }
.dot-med { width: 7px; height: 7px; }
.dot-thick { width: 11px; height: 11px; }

.zoom-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.zoom-lbl {
  min-width: 48px;
  height: 31px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #FFFFFF;
  color: var(--text-sec);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.palm-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 31px;
  padding: 0 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #FFFFFF;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sec);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.palm-toggle input { width: 15px; height: 15px; accent-color: var(--accent); margin: 0; }

/* Draft Recovery Banner */
.draft-banner {
  background: #FEF8EA;
  border-bottom: 1px solid #E9D5A1;
  color: #7A5413;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
}
.draft-banner-actions { display: flex; gap: 8px; }
.draft-btn-ok {
  border: none;
  border-radius: 7px;
  background: #8F6118;
  color: #FFFFFF;
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.draft-btn-drop {
  border: 1px solid #D9BE7D;
  border-radius: 7px;
  background: #FFFFFF;
  color: #7A5413;
  padding: 5px 10px;
  font-size: 12.5px;
  cursor: pointer;
}

/* ==================== PDF + Ink Viewport ==================== */
.pdf-viewport {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #E8E4DC;
  padding: 18px 14px 48px;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.pdf-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  min-height: 100%;
}

.empty-stage {
  margin: auto;
  text-align: center;
  max-width: 440px;
  padding: 36px 24px;
  background: rgba(255,255,255,0.75);
  border: 1px dashed var(--border);
  border-radius: 16px;
}
.empty-stage-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
}
.empty-stage-sub {
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.6;
}

.page-wrapper {
  position: relative;
  background: #FFFFFF;
  border-radius: 4px;
  box-shadow: 0 4px 18px rgba(32, 39, 35, 0.14);
  overflow: hidden;
  flex-shrink: 0;
}

.page-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 30;
  background: rgba(42, 50, 46, 0.55);
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  pointer-events: none;
}

.pdf-canvas {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.ink-canvas, .live-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.ink-canvas {
  z-index: 10;
  pointer-events: none;
}
.live-canvas {
  z-index: 20;
  /* Default Pencil-only mode: let 1-finger pan/scroll natively while JS intercepts stylus touches */
  touch-action: pan-x pan-y pinch-zoom;
  cursor: crosshair;
}
body.finger-draw-on .live-canvas {
  touch-action: pinch-zoom;
}
body.tool-eraser .live-canvas {
  cursor: cell;
}

/* ==================== Bottom Telemetry & Overlays ==================== */
.bottom-bar {
  height: 28px;
  padding: 0 14px;
  background: var(--bg-toolbar);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
}
.autosave-msg { color: var(--accent); font-weight: 600; }

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 200;
  background: rgba(246, 244, 239, 0.84);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.loading-card {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px 32px;
  text-align: center;
  box-shadow: var(--shadow-md);
  min-width: 240px;
}
.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #E2EAE5;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 15px; font-weight: 700; color: var(--text-main); }
.loading-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 5px; }

.toast {
  position: fixed;
  bottom: 42px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  background: rgba(31, 45, 39, 0.92);
  color: #FFFFFF;
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  pointer-events: none;
}

@media (max-width: 900px) {
  .sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    box-shadow: var(--shadow-md);
  }
  .cand-pos { display: none; }
}
