:root {
  --bg: #f2f4f6;
  --panel: #ffffff;
  --text: #1e2933;
  --muted: #64748b;
  --line: #d8dee5;
  --accent: #0f766e;
  --accent-soft: #d8f3ef;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  color: var(--text);
  background: linear-gradient(180deg, #f8fafc 0%, var(--bg) 100%);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 360px;
  min-width: 280px;
  max-width: 40vw;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.sidebar-header h1 {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

.sidebar-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.folder-panel {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 6px;
  max-height: 38vh;
  min-height: 140px;
}

.folder-panel label {
  font-size: 0.86rem;
  color: var(--muted);
}

.folder-tree {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: auto;
  min-height: 100px;
  padding: 6px;
}

.tree-node {
  margin: 1px 0;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tree-toggle,
.tree-label {
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--text);
}

.tree-toggle {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 0.76rem;
  line-height: 1;
}

.tree-toggle:hover {
  background: #edf2f7;
}

.tree-spacer {
  width: 22px;
  height: 22px;
  display: inline-block;
}

.tree-label {
  text-align: left;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 0.85rem;
  width: calc(100% - 26px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-label:hover {
  background: #edf2f7;
}

.tree-label.active {
  background: var(--accent-soft);
  color: #0c5f58;
  font-weight: 600;
}

.tree-label.has-images::after {
  content: " *";
  color: var(--accent);
}

.tree-children {
  margin-left: 16px;
}

.tree-children.is-collapsed {
  display: none;
}

.thumbs {
  padding: 12px;
  overflow: auto;
  display: grid;
  gap: 10px;
  align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}

.thumb {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  cursor: pointer;
  padding: 0;
}

.thumb.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.thumb img {
  width: 100%;
  display: block;
  object-fit: cover;
  aspect-ratio: 1/1;
}

.thumb span {
  display: block;
  padding: 8px;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

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

.toolbar label {
  font-size: 0.9rem;
  color: var(--muted);
}

.toolbar select,
.toolbar button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 7px 10px;
  cursor: pointer;
}

.toolbar button:hover {
  border-color: #9aa7b7;
}

.viewer-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.viewer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  background:
    radial-gradient(circle at 10% 10%, rgba(15, 118, 110, 0.08), transparent 30%),
    radial-gradient(circle at 90% 80%, rgba(30, 41, 51, 0.08), transparent 32%);
}

.viewer.dragging {
  cursor: grabbing;
}

.canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: 0 0;
}

.tile-grid {
  display: grid;
}

.tile {
  background-repeat: no-repeat;
  background-position: top left;
  background-size: 100% 100%;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
  padding: 12px;
  min-height: 90px;
}

.viewer-wrap .empty-state {
  position: absolute;
  inset: 0;
  font-size: 1rem;
  padding: 16px;
}

.status {
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 0.85rem;
}

body.presentation .sidebar,
body.presentation .toolbar,
body.presentation .status {
  display: none;
}

body.presentation .layout {
  display: block;
}

body.presentation .main {
  height: 100vh;
}

.presentation-exit {
  display: none;
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 60;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  padding: 8px 12px;
  cursor: pointer;
}

body.presentation .presentation-exit {
  display: block;
}

@media (max-width: 960px) {
  .sidebar {
    width: 44vw;
  }
}

@media (max-width: 768px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-width: none;
    min-width: 0;
    height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
