

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  background-color: transparent;
  color: #333333;
  line-height: 1.5;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

#root {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.app-layout-wrapper {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  overflow: hidden;
}

.app-main-content {
  flex-grow: 1;
  overflow: hidden; 
  display: flex; 
  flex-direction: column; 
}

.document-workspace {
  flex-grow: 1; 
  padding: 1rem;
  background-color: transparent;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: auto; 
}

.document-area {
  background-color: #ffffff; 
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  overflow: visible; 
  position: relative;
  border-radius: 3px;
  touch-action: manipulation; 
  flex-shrink: 0;
  width: 100%;
}

.document-area > img { 
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  border-radius: 3px;
}

.placeholder-document {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%; 
  aspect-ratio: 210 / 297;
  box-sizing: border-box;
  border: 2px dashed #cccccc;
  color: #757575;
  font-size: 0.9rem;
  border-radius: 6px;
  text-align: center;
  padding: 1rem;
  background-color: #fafafa;
}

/* --- Overlay & Selection Styles --- */
.overlay-item {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: move;
  border: 2px solid transparent;
  transition: border-color 0.2s, box-shadow 0.2s;
  border-radius: 6px;
}

.overlay-item.selected {
  border-color: #FF9800;
  box-shadow: 0 0 0 3px rgba(255, 152, 0, 0.2);
}

.overlay-item:focus {
    /* Kept for accessibility, though selection is primary */
    border-color: #F57C00;
}

.overlay-item img, .overlay-item .text-overlay > div {
  border-radius: 4px; /* Ensure content inside respects the rounded corners */
}


.overlay-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none; 
  user-select: none;
  -webkit-user-drag: none;
}

.resize-handle {
  box-sizing: border-box;
  background-color: #FF9800; 
  width: 14px; 
  height: 14px;
  position: absolute;
  bottom: -8px; /* Adjusted for new border */
  right: -8px; /* Adjusted for new border */
  border-radius: 50%; 
  border: 2px solid white;
  cursor: nwse-resize;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  z-index: 1; /* To be above the shadow */
}

/* --- Bottom Controls & Toolbar --- */
.app-bottom-controls {
  background-color: #ffffff;
  padding: 0.75rem 1rem;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  justify-content: center; /* Center the wrapper */
  z-index: 1000;
  flex-shrink: 0; 
  position: relative;
}

.toolbar-main-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    width: 100%;
    max-width: 480px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
}

.toolbar-button {
  background-color: #f0f0f0;
  color: #333;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.toolbar-button:hover {
  background-color: #e0e0e0;
}

.toolbar-button:active {
  transform: scale(0.95);
}

.toolbar-button:disabled {
  background-color: #f5f5f5;
  color: #bdbdbd;
  cursor: not-allowed;
}

.toolbar-button.primary {
  background-color: #FF9800;
  color: white;
}

.toolbar-button.primary:hover {
  background-color: #F57C00;
}

/* --- Toolbar Menus --- */
.toolbar-menu {
  position: absolute;
  bottom: calc(100% + 8px); /* Position above the toolbar */
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
  padding: 0.5rem;
  z-index: 1010;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: 200px;
}

.toolbar-menu.add-menu {
  left: 50%;
  transform: translateX(-50%);
}
.toolbar-menu.export-menu {
  right: 0;
}

.toolbar-menu-item {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.toolbar-menu-item:hover {
  background-color: #f5f5f5;
}

.toolbar-menu-item:disabled {
    color: #bdbdbd;
    background-color: transparent;
    cursor: not-allowed;
}

.toolbar-menu-item:disabled:hover {
    background-color: transparent;
}


.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.dynamic-ruler-display {
  position: absolute;
  bottom: -25px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.75);
  color: white;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-family: monospace;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* --- Gallery Styles --- */
.gallery-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease-in-out, visibility 0s 0.3s linear;
}

.gallery-overlay.visible {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease-in-out;
}

.gallery-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 320px;
  max-width: 90vw;
  height: 100%;
  background: #fdfdfd;
  box-shadow: 4px 0 15px rgba(0,0,0,0.1);
  transform: translateX(-100%);
  transition: transform 0.3s ease-in-out;
  z-index: 2000;
  display: flex;
  flex-direction: column;
}

.gallery-sidebar.open {
  transform: translateX(0);
}

.gallery-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1rem 0.5rem 1rem;
  flex-shrink: 0;
}

.gallery-header h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.gallery-close-button {
  background: none;
  border: none;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  color: #757575;
  padding: 0 0.5rem;
}

.gallery-tabs {
    display: flex;
    border-bottom: 1px solid #e0e0e0;
    padding: 0 1rem;
    flex-shrink: 0;
}

.gallery-tab-button {
    flex: 1;
    padding: 0.75rem 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    background: none;
    border: none;
    cursor: pointer;
    color: #757575;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    margin-bottom: -1px; /* Aligns with parent border */
}

.gallery-tab-button:hover {
    color: #333;
}

.gallery-tab-button.active {
    color: #FF9800;
    border-color: #FF9800;
}

.gallery-tab-button:disabled {
    color: #bdbdbd;
    cursor: not-allowed;
}

.gallery-content {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1rem;
}

.gallery-status-indicator {
  padding: 2rem;
  text-align: center;
  color: #757575;
  font-size: 1rem;
}

.gallery-status-indicator.error {
  color: #d32f2f;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 1rem;
}

.gallery-item {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
  display: flex;
  flex-direction: column;
  position: relative; /* For positioning delete button */
}

.gallery-item:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transform: translateY(-3px);
  border-color: #bdbdbd;
}

.gallery-item-thumbnail {
  width: 100%;
  aspect-ratio: 1 / 1.41;
  background-color: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-item-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-item-details {
  padding: 0.5rem 0.6rem;
  background-color: #fff;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.gallery-item-name {
  font-size: 0.8rem;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.gallery-item-date {
    font-size: 0.7rem;
    color: #757575;
    text-align: center;
    margin-top: 2px;
}

.gallery-item-delete-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(2px);
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #c43131;
    opacity: 0;
    transition: opacity 0.2s ease, background-color 0.2s ease;
    z-index: 5;
}

.gallery-item:hover .gallery-item-delete-btn {
    opacity: 1;
}

.gallery-item-delete-btn:hover {
    background: rgba(255, 255, 255, 1);
    color: #a11a1a;
}


.gallery-doc-title {
  margin: 0 0 1rem 0;
  font-size: 1rem;
  font-weight: 600;
  word-break: break-all;
}

/* --- Save Modal Styles --- */
.save-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
}

.save-modal-content {
    background: #fff;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 400px;
    animation: fadeInScale 0.2s ease-out;
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.save-modal-content h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.save-modal-description {
    margin: 0 0 1rem 0;
    color: #555;
    font-size: 0.95rem;
}

.save-modal-input-group {
    display: flex;
    align-items: stretch;
    margin-bottom: 1rem;
}

.save-modal-input {
    flex-grow: 1;
    border: 1px solid #ccc;
    padding: 0.6rem 0.8rem;
    font-size: 1rem;
    border-radius: 8px 0 0 8px;
    outline: none;
    transition: border-color 0.2s;
}

.save-modal-input:focus {
    border-color: #FF9800;
    box-shadow: 0 0 0 3px rgba(255, 152, 0, 0.2);
}

.save-modal-extension {
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-left: none;
    padding: 0.6rem 0.8rem;
    font-size: 1rem;
    border-radius: 0 8px 8px 0;
    color: #555;
}

.save-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.save-modal-btn {
    padding: 0.6rem 1.2rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.save-modal-btn.cancel {
    background-color: #f0f0f0;
    color: #333;
    border: 1px solid #e0e0e0;
}

.save-modal-btn.cancel:hover {
    background-color: #e0e0e0;
}

.save-modal-btn.save {
    background-color: #FF9800;
    color: white;
}

.save-modal-btn.save:hover {
    background-color: #F57C00;
}

/* Page Selection in Save Modal */
.page-selection-container {
    margin-top: 1.5rem;
    border-top: 1px solid #eee;
    padding-top: 1rem;
}

.page-selection-container h4 {
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: #444;
}

.page-selection-header {
    margin-bottom: 0.5rem;
}

.page-selection-header label {
    font-weight: 500;
    font-size: 0.95rem;
}

.page-selection-list {
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 0.5rem;
    background-color: #fafafa;
}

.page-selection-item {
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.page-selection-item:hover {
    background-color: #f0f0f0;
}

.page-selection-item input {
    margin-right: 0.5rem;
}

.current-page-tag {
    font-size: 0.8rem;
    color: #FF9800;
    font-weight: 600;
}

/* --- Text Tool --- */
.text-overlay {
    white-space: pre-wrap;
    min-width: 20px;
}
.text-overlay.selected {
    /* Ensure the inner editor has a transparent background so the selection border is visible */
    background-color: transparent;
}
.text-overlay > div[contenteditable="true"] {
    caret-color: #333;
}
.text-overlay > div[contenteditable="true"]:empty::before {
    content: attr(data-placeholder);
    color: #999;
    pointer-events: none;
}

.contextual-toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.text-tool-btn {
    width: 38px;
    height: 38px;
}
.text-tool-btn.active {
    background-color: #FFD54F; /* Light yellow for active state */
    color: #333;
}

.text-toolbar-select {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    background-color: #fff;
    font-size: 0.9rem;
    max-width: 120px;
}

.font-size-input {
    width: 55px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 8px;
    background-color: #fff;
    font-size: 0.9rem;
    text-align: center;
}

.text-tool-separator {
    width: 1px;
    height: 24px;
    background-color: #e0e0e0;
    margin: 0 4px;
}

/* --- Drawing Panel --- */
.drawing-panel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.2);
    z-index: 2500;
    display: flex;
    flex-direction: column;
}
.drawing-canvas {
    position: absolute;
    cursor: crosshair;
    touch-action: none;
}
.drawing-toolbar {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #fff;
    padding: 10px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 2501;
}
.drawing-toolbar button {
    padding: 8px 16px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #f8f8f8;
    cursor: pointer;
    font-weight: 500;
}
.drawing-toolbar input[type="range"] {
    cursor: pointer;
}
.drawing-toolbar button.primary {
    background-color: #FF9800;
    color: white;
    border-color: #F57C00;
}
.drawing-toolbar button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- New Color Palette Styles --- */
.color-picker-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
.color-palette {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    padding: 8px;
    display: flex;
    gap: 6px;
    z-index: 10;
    flex-wrap: wrap; /* Allow wrapping for more colors */
    width: 140px; /* Adjust width if needed */
}
.drawing-toolbar .color-palette {
    top: calc(100% + 10px);
    bottom: auto;
    width: auto;
    max-width: 250px;
}
.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.1);
    cursor: pointer;
    transition: transform 0.1s ease;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.color-swatch:hover {
    transform: scale(1.1);
}
.color-swatch.selected {
    box-shadow: 0 0 0 2px white, 0 0 0 4px #FF9800;
}
.color-swatch.no-color {
    background-color: #f0f0f0;
    color: #555;
}

.color-picker-button {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid #ddd;
    cursor: pointer;
    transition: transform 0.1s ease;
}
.color-picker-button:active {
    transform: scale(0.95);
}
.color-picker-button-draw {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 2px solid #fff;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* --- Suspense Loader --- */
.suspense-loader {
  display: flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.7);
  z-index: 9999;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 5px solid #f3f3f3; /* Light grey */
  border-top: 5px solid #FF9800; /* Orange */
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}