@use '../../styles/variables' as *;

.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--color-surface-lowest);
}

.toolbar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  background: var(--island-bg-color);
  border-bottom: 1px solid var(--color-gray-20);
  transition: opacity var(--duration-fast) var(--ease-out);
}

.toolbarHidden {
  height: 0;
  overflow: hidden;
  padding: 0;
  border: none;
  opacity: 0;
}

.left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.toolbarDivider {
  width: 1px;
  height: 24px;
  background: var(--default-border-color);
  margin: 0 var(--space-2);
}

.title {
  font-weight: 500;
  color: var(--color-gray-85);
  font-size: var(--text-md);
}

.saveStatus {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-sm);
  color: var(--color-gray-60);
}

.unsaved {
  color: var(--color-warning);
}

.spinner {
  animation: spin 1s linear infinite;
}

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

.canvas {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;

  :global(.excalidraw) {
    width: 100%;
    height: 100%;
  }

  :global(.excalidrew-wrapper) {
    width: 100%;
    height: 100%;
  }

  // Ensure Excalidraw's internal layout fills the container
  :global(.excalidraw .excalidraw-canvas-container) {
    width: 100% !important;
    height: 100% !important;
  }
}

.loadingCanvas {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface-lowest);
  color: var(--color-gray-60);
  font-size: var(--text-md);
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--color-muted);
  background: repeating-linear-gradient(
    45deg,
    var(--color-gray-10),
    var(--color-gray-10) 10px,
    transparent 10px,
    transparent 20px
  );

  p {
    margin: 0;
  }
}

.loading,
.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: var(--space-4);
  color: var(--color-gray-60);
}

.sub {
  font-size: var(--text-sm);
  margin-top: var(--space-2);
}

.revisionBadge {
  background: var(--color-primary);
  color: white;
  font-size: 10px;
  border-radius: 999px;
  padding: 1px 6px;
  margin-left: 4px;
}

.canvasWrapper {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.canvasNarrow {
  flex: 0 0 calc(100% - 280px);
}

.revisionPanel {
  width: 280px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--color-gray-20);
  background: var(--color-surface-lowest);
}

.revisionHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-gray-20);

  h3 {
    margin: 0;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--color-gray-85);
  }
}

.revisionList {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2);
}

.revisionItem {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  color: var(--color-gray-85);
  transition: background 0.15s ease;

  &:hover {
    background: var(--color-gray-10);
  }
}

.revisionActive {
  background: var(--color-primary-10);
  color: var(--color-primary);

  &:hover {
    background: var(--color-primary-20);
  }
}

.revisionMeta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.revisionLabel {
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.revisionDate {
  font-size: 11px;
  color: var(--color-gray-60);
}

.revisionEditor {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--color-gray-50);
  flex-shrink: 0;
}

.notesPanel {
  width: 280px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--color-gray-20);
  background: var(--color-surface-lowest);
}

.notesHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-gray-20);

  h3 {
    margin: 0;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--color-gray-85);
  }
}

.notesTextarea {
  flex: 1;
  resize: none;
  border: none;
  padding: var(--space-3) var(--space-4);
  font-family: inherit;
  font-size: var(--text-sm);
  line-height: 1.5;
  background: var(--color-surface-lowest);
  color: var(--color-on-surface);
  outline: none;

  &::placeholder {
    color: var(--color-gray-50);
  }
}

.revisionEmpty {
  text-align: center;
  color: var(--color-gray-50);
  font-size: var(--text-sm);
  padding: var(--space-4);
}

.sidePanel {
  width: 280px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--color-gray-20);
  background: var(--color-surface-lowest);
}

.sidePanelHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-gray-20);

  h3 {
    margin: 0;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--color-gray-85);
  }
}

.sidePanelContent {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2);
}

.sidePanelItem {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--border-radius-md);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  color: var(--color-gray-85);
  transition: background 0.15s ease;
  margin-bottom: var(--space-1);

  &:hover {
    background: var(--color-gray-10);
  }
}

.sidePanelItemTitle {
  font-size: var(--text-sm);
  font-weight: 500;
}

.sidePanelItemDesc {
  font-size: 11px;
  color: var(--color-gray-50);
}

.sidePanelSearch {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2);
  background: var(--color-surface-low);
  border-radius: var(--border-radius-md);
  border: 1px solid var(--color-gray-20);

  svg {
    color: var(--color-gray-50);
    flex-shrink: 0;
  }
}

.sidePanelInput {
  background: transparent;
  border: none;
  outline: none;
  color: var(--color-on-surface);
  font-size: var(--text-sm);
  width: 100%;
}

.sidePanelSelect {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2);
  background: var(--color-surface-low);
  border: 1px solid var(--color-gray-20);
  border-radius: var(--border-radius-md);
  color: var(--color-on-surface);
  font-size: var(--text-sm);
  cursor: pointer;
}

.sidePanelLoading,
.sidePanelEmpty,
.sidePanelError {
  text-align: center;
  padding: var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-gray-50);
}

.sidePanelError {
  color: var(--color-danger);
}

.presentationOverlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  pointer-events: auto;
  animation: presentationFadeIn 0.3s var(--ease-out);
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
}

@keyframes presentationFadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.presentationToolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--default-border-color);
  border-radius: var(--border-radius-xl);
  padding: var(--space-3) var(--space-5);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  margin-bottom: var(--space-4);
}

.presentationLabel {
  font-size: var(--text-sm);
  color: var(--color-gray-70);
  font-weight: 500;
  font-family: var(--ui-font);
}

.presentationSlides {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
  background: var(--island-bg-color);
  border: 1px solid var(--default-border-color);
  border-radius: var(--border-radius-lg);
  padding: var(--space-2);
  box-shadow: var(--shadow-island);
  max-width: 400px;
  overflow-x: auto;
}

.presentationSlideThumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 56px;
  padding: var(--space-2);
  border: 1px solid var(--color-gray-20);
  border-radius: var(--border-radius-md);
  background: transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--color-gray-70);

  &:hover {
    background: var(--color-gray-10);
    border-color: var(--color-gray-30);
  }
}

.presentationSlideActive {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.presentationSlideNumber {
  font-size: var(--text-xs);
  font-weight: 600;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--border-radius-full);
  background: var(--color-gray-20);
}

.presentationSlideActive .presentationSlideNumber {
  background: var(--color-primary);
  color: white;
}

.presentationSlideName {
  font-size: 10px;
  max-width: 60px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modalOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--island-bg-color);
  border: 1px solid var(--default-border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--modal-shadow);
  width: 420px;
  max-width: 90vw;
}

.modalHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-gray-20);
  h3 {
    margin: 0;
    font-size: var(--text-lg);
    color: var(--color-gray-85);
  }
}

.modalClose {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--color-gray-60);
  cursor: pointer;
  line-height: 1;
  &:hover { color: var(--color-gray-85); }
}

.modalBody {
  padding: var(--space-4) var(--space-5);
  label {
    display: block;
    font-size: var(--text-sm);
    color: var(--color-gray-70);
    margin-bottom: var(--space-2);
  }
}

.modalInput {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-gray-20);
  border-radius: var(--border-radius-md);
  background: var(--input-bg-color);
  color: var(--color-on-surface);
  font-size: var(--text-sm);
  outline: none;
  &:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
  }
}

.modalFooter {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5) var(--space-4);
}

.modalBtnSecondary {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--border-radius-md);
  border: 1px solid var(--color-gray-20);
  background: transparent;
  color: var(--color-gray-70);
  font-size: var(--text-sm);
  cursor: pointer;
  &:hover { background: var(--color-surface-low); }
}

.modalBtnPrimary {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--border-radius-md);
  border: none;
  background: var(--color-primary);
  color: white;
  font-size: var(--text-sm);
  cursor: pointer;
  &:hover { background: var(--color-primary-darker); }
  &:disabled { opacity: 0.6; cursor: not-allowed; }
}

@media (max-width: 768px) {
  .toolbar {
    height: auto;
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
    flex-wrap: wrap;
  }

  .left {
    flex: 1;
    min-width: 0;
    gap: var(--space-2);
  }

  .title {
    font-size: var(--text-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .canvasNarrow {
    flex: 1 !important;
  }

  .revisionPanel,
  .notesPanel,
  .sidePanel {
    position: fixed;
    right: 0;
    top: 48px;
    bottom: 0;
    width: 100%;
    max-width: 340px;
    z-index: 80;
  }
}

// Excalidraw context menu styling
:global(.context-menu),
:global(.excalidraw-context-menu) {
  background: var(--island-bg-color) !important;
  border: 1px solid var(--default-border-color) !important;
  border-radius: var(--border-radius-xl) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15) !important;
  padding: var(--space-1) !important;
  
  .context-menu-item,
  .menu-item {
    border-radius: var(--border-radius-lg) !important;
    padding: var(--space-2) var(--space-3) !important;
    margin: 2px 0 !important;
    font-size: var(--text-sm) !important;
    
    &:hover {
      background: var(--color-surface-low) !important;
    }
    
    &:first-child {
      border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0 !important;
    }
    
    &:last-child {
      border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg) !important;
    }
  }
  
  .context-menu-separator,
  .menu-item-separator {
    background: var(--default-border-color) !important;
    margin: var(--space-1) var(--space-2) !important;
  }
}

// Excalidraw dropdown menus
:global(.dropdown-menu),
:global(.excalidraw-dropdown) {
  background: var(--island-bg-color) !important;
  border: 1px solid var(--default-border-color) !important;
  border-radius: var(--border-radius-xl) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15) !important;
  padding: var(--space-1) !important;
  
  .dropdown-menu-item,
  .menu-item {
    border-radius: var(--border-radius-lg) !important;
    padding: var(--space-2) var(--space-3) !important;
    
    &:hover {
      background: var(--color-surface-low) !important;
    }
  }
}
