/* Material view — annotation editor */

/* ── Screen bottom padding — prevents edge-nav from hiding sheet content ── */
/* The fixed edge-nav buttons are 44px tall at screen bottom.               */
/* padding-bottom must exceed button height so the host ends above them.    */
.sheet-screen-v2 {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  padding: clamp(6px, 1dvh, 10px);
  padding-bottom: max(clamp(6px, 1dvh, 10px), env(safe-area-inset-bottom, 0px));
}

.sheet-layout-v2 {
  width: 100%;
  max-width: none;
  height: 100%;
}

/* ── Panel layout ─────────────────────────────────────────────── */

.sheet-panel-main-v3 {
  min-height: 0;
  padding: clamp(6px, 0.9dvh, 10px);
  overflow: hidden;
}

.sheet-side-panel-v3 {
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
}

/* ── Viewer shell — flex column, fills screen height ─────────── */

.sheet-viewer-shell-v4 {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 0.9dvh, 10px);
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* ── Dock container ───────────────────────────────────────────── */

.sheet-floating-dock-v4 {
  flex-shrink: 0;
  z-index: 16;
  transition: opacity 350ms ease;
}

.sheet-floating-dock-v4.dock-idle { opacity: 0.22; }
.sheet-floating-dock-v4:has(:focus-visible),
.sheet-floating-dock-v4:hover { opacity: 1 !important; }

/* ── Dockbar — single horizontal pill ────────────────────────── */

.dockbar {
  display: flex;
  align-items: center;
  gap: 3px;
  min-height: 46px;
  padding: 4px 8px;
  border-radius: 15px;
  background: rgba(14, 36, 23, 0.94);
  border: 1px solid rgba(196, 145, 42, 0.22);
  box-shadow: 0 4px 24px rgba(8, 18, 12, 0.35), 0 1px 0 rgba(196, 145, 42, 0.08) inset;
  color: #e8dcbf;
  overflow: hidden;
  /* Scroll horizontally on very small screens */
  overflow-x: auto;
  scrollbar-width: none;
}
.dockbar::-webkit-scrollbar { display: none; }

/* Back button */
.dockbar-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  color: rgba(232, 220, 191, 0.55);
  text-decoration: none;
  flex-shrink: 0;
  transition: background 140ms, color 140ms;
}
.dockbar-back:hover {
  background: rgba(255, 247, 228, 0.09);
  color: #e8dcbf;
}

/* Title */
.dockbar-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(232, 220, 191, 0.65);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(260px, 28vw);
  flex-shrink: 1;
  min-width: 0;
  padding: 0 4px;
}

.dockbar .dockbar-paging {
  margin-left: auto;
}

/* Separator line */
.dockbar-sep {
  width: 1px;
  height: 24px;
  background: rgba(196, 145, 42, 0.18);
  flex-shrink: 0;
  margin: 0 5px;
}

/* ── Legacy dock tool buttons ─────────────────────────────────── */

.dockbar-tools {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

/* Override global .tool-button for dockbar context */
.dockbar .tool-button {
  width: 44px;
  height: 44px;
  padding: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: transparent;
  color: rgba(232, 220, 191, 0.6);
  border: 1px solid transparent;
  transition: background 140ms, color 140ms, border-color 140ms;
  flex-shrink: 0;
}
.dockbar .tool-button:hover {
  background: rgba(255, 247, 228, 0.08);
  color: #e8dcbf;
}
.dockbar .tool-button.active {
  background: rgba(196, 145, 42, 0.18);
  color: #d4a83c;
  border-color: rgba(196, 145, 42, 0.38);
}

/* ── Size slider ─────────────────────────────────────────────── */

.dockbar-size {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.dockbar-size-label {
  /* Visually hidden, used for aria-labelledby */
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.dockbar-size input[type="range"] {
  width: 88px;
  accent-color: #c4912a;
  cursor: pointer;
  height: 4px;
}

.dockbar-size-val {
  font-size: 0.73rem;
  font-variant-numeric: tabular-nums;
  color: rgba(232, 220, 191, 0.5);
  min-width: 24px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Page navigation ──────────────────────────────────────────── */

.dockbar-paging {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* Shared icon button style (prev/next) */
.dockbar-icon-btn {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  background: transparent;
  border: 1px solid transparent;
  color: rgba(232, 220, 191, 0.65);
  cursor: pointer;
  transition: background 140ms, color 140ms;
  flex-shrink: 0;
}
.dockbar-icon-btn:hover:not(:disabled) {
  background: rgba(255, 247, 228, 0.08);
  color: #e8dcbf;
}
.dockbar-icon-btn:disabled { opacity: 0.25; cursor: default; }

.dockbar-page {
  font-size: 0.82rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #e8dcbf;
  min-width: 52px;
  text-align: center;
  flex-shrink: 0;
  white-space: nowrap;
}

/* ── Zoom controls ───────────────────────────────────────────── */

.dockbar-zoom {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.dockbar-zoom-btn {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(255, 247, 228, 0.05);
  border: 1px solid rgba(196, 145, 42, 0.15);
  color: rgba(232, 220, 191, 0.7);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 140ms;
  flex-shrink: 0;
}
.dockbar-zoom-btn:hover:not(:disabled) { background: rgba(255, 247, 228, 0.1); }
.dockbar-zoom-btn:disabled { opacity: 0.25; cursor: default; }

.dockbar-zoom-fit {
  height: 36px;
  min-height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  background: rgba(196, 145, 42, 0.1);
  border: 1px solid rgba(196, 145, 42, 0.25);
  color: #c4912a;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 140ms;
}
.dockbar-zoom-fit:hover { background: rgba(196, 145, 42, 0.18); }

/* ── Trailing actions (play + clear) ─────────────────────────── */

.dockbar-play,
.dockbar-clear {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  cursor: pointer;
  flex-shrink: 0;
  text-decoration: none;
  transition: background 140ms;
  margin-left: 2px;
}

.dockbar-play {
  background: rgba(196, 145, 42, 0.12);
  border: 1px solid rgba(196, 145, 42, 0.28);
  color: #c4912a;
}
.dockbar-play:hover { background: rgba(196, 145, 42, 0.22); }

.dockbar-clear {
  background: rgba(138, 44, 46, 0.08);
  border: 1px solid rgba(138, 44, 46, 0.18);
  color: rgba(220, 80, 75, 0.65);
}
.dockbar-clear:hover {
  background: rgba(138, 44, 46, 0.18);
  color: #e05555;
}

/* Push clear to the far right */
.dockbar-clear { margin-left: auto; }

/* ── Viewer host ─────────────────────────────────────────────── */

.editor-workspace {
  display: grid;
  grid-template-columns: clamp(88px, 7.5vw, 108px) minmax(0, 1fr);
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.editor-tool-rail {
  align-self: stretch;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 7px;
  border-radius: 15px;
  background: rgba(14, 36, 23, 0.94);
  border: 1px solid rgba(196, 145, 42, 0.22);
  box-shadow: 0 4px 22px rgba(8, 18, 12, 0.28), 0 1px 0 rgba(196, 145, 42, 0.08) inset;
  color: #e8dcbf;
  overflow-y: auto;
  scrollbar-width: thin;
}

.editor-tool-group {
  display: grid;
  gap: 5px;
}

.editor-history-group {
  padding-top: 8px;
  border-top: 1px solid rgba(196, 145, 42, 0.18);
}

.editor-tool-button {
  width: 100%;
  min-height: 46px;
  padding: 6px 4px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 4px;
  border-radius: 12px;
  background: transparent;
  border: 1px solid transparent;
  color: rgba(232, 220, 191, 0.68);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.05;
  text-align: center;
  cursor: pointer;
  transition: background 140ms, color 140ms, border-color 140ms, transform 140ms;
}

.editor-tool-button svg {
  width: 18px;
  height: 18px;
}

.editor-tool-button span {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.editor-tool-button:hover:not(:disabled) {
  background: rgba(255, 247, 228, 0.08);
  color: #e8dcbf;
}

.editor-tool-button.active {
  background: rgba(196, 145, 42, 0.18);
  color: #d4a83c;
  border-color: rgba(196, 145, 42, 0.38);
}

.editor-tool-button:disabled {
  opacity: 0.32;
  cursor: default;
}

.editor-tool-danger {
  margin-top: auto;
  color: rgba(237, 112, 98, 0.78);
  border-color: rgba(138, 44, 46, 0.16);
}

.editor-tool-danger:hover:not(:disabled) {
  background: rgba(138, 44, 46, 0.18);
  color: #ff8a7e;
}

.editor-size-control {
  display: grid;
  gap: 7px;
  padding: 8px 4px;
  border-top: 1px solid rgba(196, 145, 42, 0.18);
  color: rgba(232, 220, 191, 0.74);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
}

.editor-size-control input[type="range"] {
  width: 100%;
  accent-color: #c4912a;
}

.editor-size-control strong {
  color: #d4a83c;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.viewer-host-v3 {
  align-self: stretch;
  height: 100%;
  min-height: 0;
  min-width: 0;
  padding: 0;
  border-radius: 18px;
}

/* ── Edge page-turn buttons ──────────────────────────────────── */

/* P1-C: Large edge tap zones — work while drawing */
.sheet-edge-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 15;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.sheet-edge-prev,
.sheet-edge-next {
  pointer-events: auto;
  width: 64px;
  height: 44px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 200ms ease, background 160ms ease;
}

.sheet-edge-prev:not(:disabled):hover,
.sheet-edge-next:not(:disabled):hover,
.sheet-edge-prev:not(:disabled):focus-visible,
.sheet-edge-next:not(:disabled):focus-visible { opacity: 1; }

@media (hover: none) {
  .sheet-edge-prev:not(:disabled),
  .sheet-edge-next:not(:disabled) { opacity: 0.6; }
}

.sheet-edge-prev {
  border-radius: 0 20px 0 0;
  background: linear-gradient(to right, rgba(11, 29, 19, 0.10), transparent);
}
.sheet-edge-next {
  border-radius: 20px 0 0 0;
  background: linear-gradient(to left, rgba(11, 29, 19, 0.10), transparent);
}
.sheet-edge-prev:not(:disabled):hover { background: rgba(11, 29, 19, 0.14); }
.sheet-edge-next:not(:disabled):hover { background: rgba(11, 29, 19, 0.14); }

.sheet-edge-prev::after { content: "‹"; font-size: 2rem; color: var(--forest-mid); opacity: 0.55; line-height: 1; }
.sheet-edge-next::after { content: "›"; font-size: 2rem; color: var(--forest-mid); opacity: 0.55; line-height: 1; }
.sheet-edge-prev:disabled,
.sheet-edge-next:disabled { display: none; }

/* ── Skeleton loading ─────────────────────────────────────────── */

.viewer-loading-skeleton {
  width: 100%;
  min-height: 60vh;
  border-radius: 16px;
  background: linear-gradient(
    90deg,
    rgba(240, 233, 217, 0.5) 25%,
    rgba(240, 233, 217, 0.8) 50%,
    rgba(240, 233, 217, 0.5) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .viewer-loading-skeleton { animation: none; background: rgba(240, 233, 217, 0.6); }
}

/* ── Sidebar / info card ─────────────────────────────────────── */

.sheet-info-card-v3 {
  padding: 14px;
  gap: 10px;
}

.sheet-info-list-v3 {
  display: grid;
  gap: 8px;
}

.sheet-info-list-v3 > div {
  display: grid;
  gap: 2px;
}

.sheet-extra-actions-v3 summary { min-height: 40px; }

/* ── Dark mode ───────────────────────────────────────────────── */

[data-theme="dark"] .dockbar {
  background: rgba(8, 20, 13, 0.97);
  border-color: rgba(196, 145, 42, 0.16);
}

[data-theme="dark"] .editor-tool-rail {
  background: rgba(8, 20, 13, 0.97);
  border-color: rgba(196, 145, 42, 0.16);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .dockbar {
    background: rgba(8, 20, 13, 0.97);
    border-color: rgba(196, 145, 42, 0.16);
  }

  :root:not([data-theme="light"]) .editor-tool-rail {
    background: rgba(8, 20, 13, 0.97);
    border-color: rgba(196, 145, 42, 0.16);
  }
}

/* ── Responsive ──────────────────────────────────────────────── */

/* Tablet baseline: maximize score area and keep controls readable. */
@media (min-width: 740px) and (max-width: 1366px) {
  .sheet-screen-v2 {
    padding: 6px;
    padding-bottom: max(6px, env(safe-area-inset-bottom, 0px));
  }

  .sheet-layout-v2 {
    width: calc(100vw - 12px);
    height: 100%;
  }

  .sheet-panel-main-v3 {
    padding: 6px;
    border-radius: 18px;
  }

  .sheet-viewer-shell-v4 {
    gap: 6px;
  }

  .dockbar {
    min-height: 42px;
    padding: 3px 6px;
    border-radius: 13px;
  }

  .dockbar-title {
    max-width: 24vw;
    font-size: 0.74rem;
  }

  .dockbar-sep {
    margin: 0 3px;
  }

  .dockbar-back,
  .dockbar-icon-btn {
    width: 36px;
    height: 36px;
    min-height: 36px;
  }

  .dockbar-zoom-btn {
    width: 34px;
    height: 34px;
    min-height: 34px;
  }

  .dockbar-zoom-fit {
    height: 34px;
    min-height: 34px;
    padding: 0 8px;
  }

  .editor-workspace {
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 6px;
  }

  .editor-tool-rail {
    gap: 5px;
    padding: 5px;
    border-radius: 13px;
  }

  .editor-tool-group {
    gap: 4px;
  }

  .editor-tool-button {
    min-height: 42px;
    padding: 4px 3px;
    border-radius: 10px;
    font-size: 0.6rem;
  }

  .editor-tool-button svg {
    width: 16px;
    height: 16px;
  }

  .editor-size-control {
    gap: 5px;
    padding: 6px 3px;
    font-size: 0.6rem;
  }

  .viewer-host-v3 {
    border-radius: 14px;
  }
}

/* Portrait tablet: sidebar hidden, dock stays */
@media (orientation: portrait) and (max-width: 1024px) {
  .sheet-layout-v2 { grid-template-columns: 1fr; }
  .sheet-side-panel-v3 { display: none; }
  .dockbar-title { max-width: 22vw; }
  .editor-workspace { grid-template-columns: 84px minmax(0, 1fr); }
}

@media (orientation: portrait) and (min-width: 740px) and (max-width: 1024px) {
  .dockbar .dockbar-paging {
    margin-left: 0;
  }

  .dockbar {
    justify-content: space-between;
  }
}

/* Tablet landscape: keep the score editor inside the visible viewport. */
@media (orientation: landscape) and (max-height: 820px) and (max-width: 1280px) {
  .sheet-screen-v2 {
    padding: 6px;
  }

  .sheet-layout-v2 {
    grid-template-columns: 1fr;
    width: calc(100vw - 12px);
    height: 100%;
  }

  .sheet-side-panel-v3 {
    display: none;
  }

  .sheet-panel-main-v3 {
    padding: 6px;
  }

  .sheet-viewer-shell-v4 {
    gap: 6px;
  }

  .dockbar {
    min-height: 42px;
    padding: 3px 6px;
  }

  .dockbar-back,
  .dockbar-icon-btn {
    width: 36px;
    height: 36px;
    min-height: 36px;
  }

  .dockbar-zoom-btn,
  .dockbar-zoom-fit {
    height: 34px;
    min-height: 34px;
  }

  .editor-workspace {
    grid-template-columns: 82px minmax(0, 1fr);
    gap: 6px;
  }

  .editor-tool-rail {
    padding: 5px;
    gap: 5px;
  }

  .editor-tool-button {
    min-height: 40px;
    padding: 4px 3px;
    font-size: 0.58rem;
  }

  .editor-tool-button svg {
    width: 15px;
    height: 15px;
  }

  .editor-size-control {
    gap: 5px;
    padding: 6px 3px;
    font-size: 0.58rem;
  }
}

/* iPad Pro / larger tablets in landscape: keep metadata out of the editor. */
@media (orientation: landscape) and (min-width: 1024px) and (max-width: 1366px) {
  .sheet-layout-v2 {
    grid-template-columns: 1fr;
  }

  .sheet-side-panel-v3 {
    display: none;
  }

  .dockbar-title {
    max-width: 34vw;
  }
}

/* Small screens: tighten dockbar */
@media (max-width: 720px) {
  .sheet-panel-main-v3 { padding: 6px; }
  .dockbar { padding: 4px 6px; border-radius: 14px; gap: 2px; }
  .dockbar .tool-button { width: 40px; height: 40px; min-height: 40px; border-radius: 10px; }
  .dockbar-title { max-width: 100px; }
  .dockbar-size input[type="range"] { width: 64px; }
  .dockbar-page { min-width: 40px; }
  .editor-workspace {
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 6px;
  }
  .editor-tool-rail {
    border-radius: 14px;
    padding: 6px;
    gap: 6px;
  }
  .editor-tool-button {
    min-height: 43px;
    font-size: 0.6rem;
  }
  .editor-tool-button svg {
    width: 16px;
    height: 16px;
  }
}

/* Very small: allow dockbar to scroll */
@media (max-width: 480px) {
  .dockbar-title { display: none; }
  .editor-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .editor-tool-rail {
    flex-direction: row;
    align-items: stretch;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .editor-tool-group {
    display: flex;
    flex: 0 0 auto;
    gap: 5px;
  }
  .editor-history-group {
    padding-top: 0;
    padding-left: 8px;
    border-top: 0;
    border-left: 1px solid rgba(196, 145, 42, 0.18);
  }
  .editor-tool-button {
    width: 62px;
    min-height: 48px;
  }
  .editor-size-control {
    min-width: 118px;
    padding: 5px 8px;
    border-top: 0;
    border-left: 1px solid rgba(196, 145, 42, 0.18);
  }
  .editor-tool-danger {
    margin-top: 0;
    margin-left: auto;
  }
}
