@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);
}

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

.right {
  display: flex;
  align-items: center;
  gap: 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;

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

.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);
}

@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;
  }
}
