@import "../shared.css";

* { box-sizing: border-box; }

body {
  display: grid;
  grid-template-rows: auto 1fr;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  background: var(--background);
  border-bottom: 1px solid var(--border);
}

.toolbar-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--foreground);
}

.toolbar-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.workspace {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 0;
}

.sidebar {
  background: var(--background);
  border-right: 1px solid var(--border);
  display: grid;
  grid-template-rows: 1fr;
  min-width: 0;
  overflow: hidden;
}

.version-list {
  overflow: auto;
  padding: 8px;
}

.viewer-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  position: relative;
}

.viewer-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 12px;
  background: var(--background);
  border-bottom: 1px solid var(--border);
}

.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--page-bg);
  z-index: 5;
  color: var(--muted-foreground);
  font-size: 13px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.sidebar-overlay { display: none; }

.tree-group {
  margin-bottom: 4px;
}

.tree-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  color: var(--foreground);
  user-select: none;
  transition: background 0.1s;
}

.tree-group-header:hover { background: var(--accent); }

.tree-group-header .expand-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
  color: var(--muted-foreground);
}

.tree-group.collapsed .expand-icon { transform: rotate(-90deg); }

.tree-group-header .folder-icon {
  color: var(--muted-foreground);
}

.tree-group-header .version-count {
  margin-left: auto;
  font-weight: 400;
  font-size: 11px;
  color: var(--muted-foreground);
  background: var(--muted);
  padding: 1px 6px;
  border-radius: 9999px;
}

.tree-items { padding-left: 12px; }

.tree-group.collapsed .tree-items { display: none; }

.tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s;
}

.tree-item:hover { background: var(--accent); }

.tree-item.active {
  background: var(--primary);
  color: var(--primary-foreground);
  font-weight: 500;
}

.tree-item .item-info { flex: 1; min-width: 0; }

.tree-item .item-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-item .item-meta {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--muted-foreground);
  white-space: nowrap;
}

.tree-item.active .item-meta { color: var(--primary-foreground); opacity: 0.8; }

.tree-item .edit-btn {
  opacity: 0;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tree-item:hover .edit-btn { opacity: 1; }
.tree-item .edit-btn:hover { background: var(--accent); color: var(--foreground); }
.tree-item.active .edit-btn { color: var(--primary-foreground); }
.tree-item.active .edit-btn:hover { background: rgba(255,255,255,0.15); }

.edit-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  margin: 4px 0;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.edit-form input {
  height: 30px;
  font-size: 12px;
}

.edit-actions {
  display: flex;
  gap: 6px;
}

.edit-actions button {
  height: 28px;
  font-size: 12px;
  padding: 0 10px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--accent); color: var(--foreground); }

#viewer {
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--background);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 48px 24px;
  text-align: center;
  color: var(--muted-foreground);
  font-size: 14px;
}

.button-link {
  height: 32px;
  font-size: 13px;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  padding: 0 12px;
}

.button-link:hover { background: color-mix(in srgb, var(--primary) 90%, black); }

.mobile-only { display: none; }

@media (max-width: 768px) {
  .mobile-only { display: inline-flex; }

  .workspace { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 50;
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

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

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
  }

  .sidebar-overlay[hidden] { display: none; }
}
