/* Reset and Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body,
html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: rgb(40, 40, 40);
}

/* Material Icons configuration */
.material-symbols-outlined {
  font-size: 20px;
  font-variation-settings:
    'FILL' 0,
    'wght' 400,
    'GRAD' 0,
    'opsz' 20
}

/* Drag and Drop Overlay */
#drag-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
}

#drag-overlay.hidden {
  display: none;
}

.drag-text {
  color: white;
  font-size: 32px;
  font-weight: 500;
  pointer-events: none;
  background: rgba(32, 33, 36, 0.9);
  padding: 24px 48px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

/* Layout Container */
#app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

/* ----------------- Toolbar ----------------- */
#toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 48px;
  background-color: #323639;
  color: #F1F3F4;
  padding: 0 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  z-index: 100;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

#toolbar-left,
#toolbar-center,
#toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#toolbar-left {
  flex: 1;
}

#toolbar-center {
  flex: 0;
  justify-content: center;
}

#toolbar-right {
  flex: 1;
  justify-content: flex-end;
}

/* Toolbar Buttons */
.icon-button {
  background: transparent;
  border: none;
  color: #bdc1c6;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.icon-button:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: #F1F3F4;
}

.icon-button.active {
  background-color: rgba(138, 180, 248, 0.12);
  color: #8ab4f8;
}

.icon-button:active {
  background-color: rgba(138, 180, 248, 0.2);
  transform: scale(0.95);
}

.divider {
  width: 1px;
  height: 20px;
  background-color: rgba(255, 255, 255, 0.1);
  margin: 0 4px;
}

/* Document Title */
#document-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
  color: #e8eaed;
  margin-left: 4px;
}

/* Inputs (Page Number, Zoom) */
.toolbar-input {
  background-color: #202124;
  border: 1px solid transparent;
  color: #F1F3F4;
  height: 28px;
  border-radius: 4px;
  padding: 0 8px;
  font-family: inherit;
  font-size: 13px;
  transition: background-color 0.2s, border-color 0.2s;
}

.toolbar-input:hover,
.toolbar-input:focus {
  background-color: #202124;
  border: 1px solid #1A73E8;
  outline: none;
}

#page-input {
  width: 50px;
  text-align: right;
  -moz-appearance: textfield;
  appearance: textfield;
}

#page-input::-webkit-outer-spin-button,
#page-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

#page-count {
  font-size: 13px;
  color: #bdc1c6;
  white-space: nowrap;
}

/* Zoom Controls Group */
.zoom-controls {
  display: flex;
  align-items: center;
  background-color: rgba(255, 255, 255, 0.05);
  border-radius: 18px;
  padding: 2px;
}

.zoom-input-container {
  display: flex;
  align-items: center;
  position: relative;
}

#zoom-input {
  width: 60px;
  background: transparent;
  border: none;
  color: #F1F3F4;
  text-align: center;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
}

#zoom-input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

/* Premium Loading Spinner */
.premium-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(138, 180, 248, 0.1);
  border-left-color: #8ab4f8;
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.hidden {
  display: none !important;
}


/* ----------------- Main Content Area ----------------- */
#main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ----------------- Thumbnails Sidebar (Left) ----------------- */
#sidebar {
  width: 200px;
  background-color: #323639;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  overflow-y: auto;
  transition: width 0.2s;
  display: flex;
  flex-direction: column;
}

#sidebar.hidden {
  width: 0;
  border-right: none;
  overflow: hidden;
}

#thumbnail-view {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.thumbnail-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.thumbnail {
  width: 100%;
  background-color: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color 0.1s;
}

.thumbnail-container.active .thumbnail {
  border-color: #1A73E8;
}

.thumbnail-page-num {
  font-size: 12px;
  color: #bdc1c6;
  margin-top: 6px;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 14px;
  height: 14px;
}

::-webkit-scrollbar-track {
  background: rgb(40, 40, 40);
}

::-webkit-scrollbar-thumb {
  background: #525659;
  border-radius: 8px;
  border: 3px solid rgb(40, 40, 40);
}

::-webkit-scrollbar-thumb:hover {
  background: #73777A;
}

/* Viewer Container */
#viewer-container {
  flex: 1;
  overflow: auto;
  position: relative;
  touch-action: pan-x pan-y;
  background-color: rgb(40, 40, 40);
}

#viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  gap: 16px;
  position: relative;
  transform-origin: top center;
}

/* Individual PDF Page Canvas styling */
.page-container {
  position: relative;
  background-color: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  display: inline-block;
  margin: 0 auto;
  /* CSS scale scaling logic from chrome */
  width: calc(var(--page-width, 816px) * var(--scale-factor, 1));
  height: calc(var(--page-height, 1056px) * var(--scale-factor, 1));
}

.page-container > canvas:not(.lower-canvas):not(.upper-canvas):not(.webgl-overlay),
.page-container > img {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.webgl-overlay {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  mix-blend-mode: screen;
}

/* Switch to nearest-neighbour only when zoomed above 100% so pixels stay sharp
   without the aliasing that pixelated causes when downscaling. */
.pdfViewer.zoom-in .page-container > img {
  image-rendering: pixelated;
}

/* ----------------- AI Unredactor Tools Sidebar (Right) ----------------- */
#tools-sidebar {
  width: 320px;
  background-color: #323639;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  overflow-y: auto;
  transition: width 0.2s, padding 0.2s;
  display: flex;
  flex-direction: column;
  padding: 16px;
  color: #e8eaed;
  font-family: 'Inter', system-ui, sans-serif;
}

#tools-sidebar.hidden {
  width: 0;
  padding: 0;
  border-left: none;
  overflow: hidden;
}

.tool-card {
  background-color: #202124;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.tool-card h2 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: #e8eaed;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-card h2 span.step {
  background: #8ab4f8;
  /* Google blue for dark mode */
  color: #202124;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
}

/* Redaction Overlay (uses calc to scale cleanly with Chrome zoom!) */
.redaction-overlay {
  position: absolute;
  background-color: rgba(253, 224, 71, 0.4);
  border: 1px solid rgba(234, 179, 8, 0.8);
  cursor: pointer;
  z-index: 60; /* above etv-overlay (4) and etv-overlay.active-tool (50) */
  /* CSS CALC MAGIC */

  left:   calc(var(--px-x,      0) * var(--scale-factor, 1));
  top:    calc(var(--px-y,      0) * var(--scale-factor, 1));
  width:  calc(var(--px-width,  0) * var(--scale-factor, 1));
  height: calc(var(--px-height, 0) * var(--scale-factor, 1));
}

.redaction-overlay:hover {
  background-color: rgba(253, 224, 71, 0.6);
  border-color: #ca8a04;
}

.redaction-label {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  outline: none;
  color: black;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 500;
  user-select: text;
  pointer-events: auto;
  overflow: hidden;
  white-space: pre;
}

.redaction-label:focus {
  background-color: rgba(255, 255, 255, 0.4);
}

.redaction-overlay.selected {
  background-color: rgba(138, 180, 248, 0.4);
  border: 2px solid #8ab4f8;
  /* Chrome blue outline */
  box-shadow: 0 0 0 2px rgba(138, 180, 248, 0.2);
  z-index: 20;
}

.resizer {
  position: absolute;
  background: transparent;
  z-index: 30;
}

.resizer-l {
  left: -4px;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
}

.resizer-r {
  right: -4px;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
}

.resizer-t {
  top: -4px;
  left: 0;
  right: 0;
  height: 8px;
  cursor: ns-resize;
}

.resizer-b {
  bottom: -4px;
  left: 0;
  right: 0;
  height: 8px;
  cursor: ns-resize;
}

.resizer:hover {
  background: rgba(138, 180, 248, 0.5);
}

/* Sub-controls inside Tool Card */
.control-group {
  margin-bottom: 10px;
}

.control-group label {
  display: block;
  font-size: 12px;
  color: #9aa0a6;
  margin-bottom: 4px;
}

.tool-input {
  width: 100%;
  background-color: #323639;
  border: 1px solid #5f6368;
  color: #e8eaed;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 13px;
}

.tool-input:focus {
  outline: none;
  border-color: #8ab4f8;
}

.tool-btn {
  background-color: #8ab4f8;
  color: #202124;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  width: 100%;
  transition: background-color 0.15s;
}

.tool-btn:hover {
  background-color: #aecbfa;
}

.tool-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tool-btn.secondary {
  background-color: transparent;
  color: #8ab4f8;
  border: 1px solid #5f6368;
}

.tool-btn.secondary:hover {
  background-color: rgba(138, 180, 248, 0.08);
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.checkbox-lbl {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #e8eaed;
  cursor: pointer;
}

.checkbox-lbl input {
  accent-color: #8ab4f8;
}



/* ----------------- Sub-Toolbar (Ribbon) ----------------- */
#unified-options-bar-container {
  display: flex;
  flex-direction: column;
  background-color: #292a2d;
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
  z-index: 90;
  padding: 6px 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

#text-toolbar-row {
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  flex-wrap: nowrap;
  white-space: nowrap;
  min-height: 44px;
}

#text-options-bar,
#fabric-options-bar,
#webgl-options-bar,
#etv-options-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: transparent;
  padding: 0 16px;
  flex-shrink: 0;
  color: #e8eaed;
  font-size: 13px;
}

#fabric-options-bar.hidden,
#webgl-options-bar.hidden,
#etv-options-bar.hidden {
  display: none;
}

.options-group {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  position: relative;
  padding: 4px 0;
}

.options-group-header {
  font-size: 10px;
  text-transform: uppercase;
  color: #9aa0a6;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
  user-select: none;
}

.options-group-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.options-divider {
  width: 1px;
  height: 32px;
  background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.1), transparent);
  flex-shrink: 0;
  margin: 0 4px;
  align-self: center;
}

.options-label {
  font-size: 12px;
  color: #bdc1c6;
}

/* Inputs & selects (Chrome style) */
.toolbar-select,
.toolbar-input-small,
#text-options-bar select,
#text-options-bar input[type="number"] {
  background-color: #1f1f1f !important;
  border: 1px solid #3c4043 !important;
  color: #e8eaed !important;
  border-radius: 4px;
  padding: 0 8px;
  font-size: 12px;
  height: 26px;
  font-family: inherit;
  transition: border-color 0.15s, background-color 0.15s;
  outline: none;
}

.toolbar-select:hover,
.toolbar-input-small:hover {
  border-color: #5f6368 !important;
  background-color: #252525 !important;
}

.toolbar-select:focus,
.toolbar-input-small:focus {
  border-color: #8ab4f8 !important;
  background-color: #1f1f1f !important;
  box-shadow: 0 0 0 1px #8ab4f8;
}

/* Specific Widths */
#font, #fabric-font-family { min-width: 120px; }
#size, #calc-scale, #tolerance, #fabric-font-size, #fabric-letter-spacing { width: 44px; text-align: center; }

/* Customizing Checkboxes */
.checkbox-lbl {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #e8eaed;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.03);
  transition: background 0.2s;
}

.checkbox-lbl:hover {
  background: rgba(255, 255, 255, 0.08);
}

.checkbox-lbl input {
  accent-color: #8ab4f8;
  width: 14px;
  height: 14px;
}

/* ----------------- Disclaimer Modal ----------------- */
#disclaimer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 10000;
  display: flex;
  justify-content: center;
  align-items: center;
}

#disclaimer-overlay.hidden {
  display: none;
}

#disclaimer {
  background: #202124;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 28px 32px;
  max-width: 540px;
  width: 90%;
  color: #e8eaed;
  font-size: 13px;
  line-height: 1.6;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

#disclaimer h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
  color: #f28b82;
  display: flex;
  align-items: center;
  gap: 8px;
}

#disclaimer h3::before {
  content: "⚠";
  font-size: 18px;
}

#disclaimer p {
  margin-bottom: 10px;
  color: #bdc1c6;
}

#disclaimer p strong {
  color: #e8eaed;
}

#disclaimer-accept {
  margin-top: 18px;
  width: 100%;
  padding: 10px;
  background: #1A73E8;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

#disclaimer-accept:hover {
  background: #1557b0;
}

/* ----------------- Mobile Specific Styles (Portrait) ----------------- */
@media (max-width: 768px) {
  #toolbar {
    height: auto;
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 8px;
  }

  #toolbar-left {
    order: 1;
    flex: 0 0 auto;
  }

  #toolbar-center {
    order: 3;
    flex: 1 0 100%;
    margin-top: 4px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    padding: 4px;
  }

  #toolbar-right {
    order: 2;
    flex: 1;
    justify-content: flex-end;
  }

  #document-title {
    display: none; /* Auto-hide title on mobile to save space */
  }

  .zoom-controls {
    display: none; /* Zoom is secondary on mobile; pinch-zoom is preferred */
  }

  /* Overlay Sidebars */
  #sidebar, #tools-sidebar {
    position: fixed;
    top: 56px; /* Below toolbar */
    bottom: 0;
    width: 280px;
    z-index: 1000;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
    border: none;
  }

  #sidebar {
    left: 0;
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  #sidebar.hidden {
    transform: translateX(-100%);
    display: flex !important; /* Keep flex context for animation */
    pointer-events: none;
  }

  #tools-sidebar {
    right: 0;
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  #tools-sidebar.hidden {
    transform: translateX(100%);
    display: flex !important;
    pointer-events: none;
  }

  #sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
    backdrop-filter: blur(2px);
    transition: opacity 0.3s;
  }

  #sidebar-backdrop.hidden {
    display: none;
  }

  /* Sub-toolbar (Ribbon) refinements */
  #unified-options-bar-container {
    height: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .options-group-controls {
    gap: 12px; /* More finger spacing */
  }

  /* Ribbon scrolling - ensure scrollbar is less obtrusive but present if needed */
  #text-toolbar-row::-webkit-scrollbar {
    height: 4px;
  }
  #text-toolbar-row::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
  }
}

