:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --text: #1f1f1f;
  --muted: #676357;
  --accent: #a43f22;
  --accent-soft: #f7d8cf;
  --border: #e0d8cc;
  --shadow: 0 16px 36px rgba(30, 20, 10, 0.15);
  --radius: 16px;
  --history-width: 300px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 18%, #fff6e9 0%, transparent 38%),
    radial-gradient(circle at 80% 84%, #ffe6db 0%, transparent 35%),
    linear-gradient(180deg, #fefcf8 0%, var(--bg) 60%, #ece6dc 100%);
}

.layout {
  display: grid;
  grid-template-columns: var(--history-width) minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  transition: grid-template-columns 0.25s ease;
}

.history-panel {
  display: block;
  position: relative;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: linear-gradient(165deg, #fffdfa 0%, #f9f4ec 100%);
  padding: 18px 16px;
  transition: padding 0.25s ease;
}

.history-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  background: transparent;
}

.history-resizer::after {
  content: "";
  position: absolute;
  top: 18px;
  bottom: 18px;
  left: 3px;
  width: 2px;
  border-radius: 999px;
  background: rgba(133, 110, 83, 0.22);
}

.history-title {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.history-subtitle {
  margin: 0 0 16px;
  font-size: 0.88rem;
  color: var(--muted);
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  gap: 10px;
}

.history-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 4px 14px rgba(64, 45, 22, 0.08);
  padding: 10px 12px;
  position: relative;
  transition: transform 0.12s ease, border-color 0.2s ease, background 0.2s ease;
}

.history-item:hover {
  transform: translateY(-1px);
  border-color: #d49e8f;
  background: #fff9f5;
}

.history-item.pinned {
  border-color: #cf8d79;
  background: #fff7f3;
}

.history-main {
  all: unset;
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 30px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-size: 0.9rem;
}

.history-main:focus-visible {
  outline: 2px solid #cf8d79;
  outline-offset: 2px;
  border-radius: 8px;
}

.history-pin {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 18px;
  height: 18px;
  border: 0;
  padding: 0;
  background: transparent;
  color: #9a8f82;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.history-pin:hover {
  color: #7f7467;
}

.history-pin.pinned {
  color: #a43f22;
}

.history-pin-icon {
  width: 14px;
  height: 14px;
  display: block;
}

.history-pin-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
}

.history-pin.pinned .history-pin-icon path {
  fill: currentColor;
}

.history-route {
  color: var(--accent);
  font-size: 0.84rem;
  letter-spacing: 0.02em;
  font-weight: 700;
}

.history-link-name {
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.25;
  word-break: break-word;
  overflow: hidden;
  display: -webkit-box;
  line-clamp: 2;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  max-height: calc(1.25em * 2);
}

.history-empty {
  color: var(--muted);
  font-size: 0.9rem;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #fffcf6;
}

.viewer-shell {
  width: 100%;
  max-width: 1400px;
  justify-self: stretch;
  height: 100vh;
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
  padding: 20px clamp(14px, 3vw, 28px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.viewer-shell.split-mode {
  max-width: none;
}

.header-toggle-btn {
  align-self: flex-end;
  padding: 7px 11px;
  font-size: 0.82rem;
}

.viewer-shell.header-collapsed {
  gap: 10px;
}

.viewer-shell.header-collapsed .viewer-header,
.viewer-shell.header-collapsed .toolbar,
.viewer-shell.header-collapsed .status,
.viewer-shell.header-collapsed .split-hint {
  display: none;
}

.viewer-header {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.viewer-title {
  margin: 0;
  font-size: clamp(1.05rem, 1.6vw, 1.35rem);
  letter-spacing: 0.02em;
}

.toolbar {
  width: 100%;
  display: block;
  gap: 14px;
  background: rgba(255, 255, 255, 0.76);
  backdrop-filter: blur(6px);
  border: 1px solid #efe4d3;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.source-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.source-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.list-io-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.upload-inline-label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.page-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

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

.source-panel input[type="text"] {
  flex: 1 1 280px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid #d5cbbb;
  border-radius: 10px;
  background: #fffefb;
  color: var(--text);
  font-size: 0.95rem;
}

.source-panel input[type="file"] {
  flex: 0 1 380px;
  max-width: 420px;
  font-size: 0.86rem;
  color: var(--muted);
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.9rem;
  cursor: pointer;
  color: #fff;
  background: var(--accent);
  transition: transform 0.08s ease, opacity 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 5px 14px rgba(164, 63, 34, 0.3);
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 7px 18px rgba(164, 63, 34, 0.36);
}

.btn.secondary {
  color: #6d2b15;
  background: #fff6f2;
  border-color: #e4c8bc;
  box-shadow: none;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid #e4c8bc;
  background: #fff6f2;
  color: #6d2b15;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:hover {
  background: #ffefe8;
}

.page-indicator {
  font-size: 1rem;
  color: var(--muted);
  font-weight: 700;
  min-width: 54px;
  text-align: center;
}

.page-entry {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.page-entry input {
  width: 86px;
  padding: 7px 8px;
  border: 1px solid #d5cbbb;
  border-radius: 9px;
  background: #fffefb;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 700;
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.zoom-btn,
.zoom-reset {
  border: 1px solid #e4c8bc;
  border-radius: 8px;
  background: #fff6f2;
  color: #6d2b15;
  font-size: 0.9rem;
  font-weight: 700;
  height: 34px;
  cursor: pointer;
}

.zoom-btn {
  width: 34px;
}

.zoom-reset {
  padding: 0 10px;
}

.zoom-level {
  min-width: 56px;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}

.zoom-btn:disabled,
.zoom-reset:disabled {
  opacity: 0.45;
  cursor: default;
}

.status {
  width: 100%;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
  min-height: 1.3rem;
}

.split-hint {
  width: 100%;
  margin: -6px 0 0;
  color: #7f6d59;
  font-size: 0.83rem;
  line-height: 1.3;
}

.viewer-grid {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.viewer-grid.split-enabled {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.viewer-pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.viewer-pane.is-hidden {
  display: none;
}

.pane-title {
  margin: 0;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8e7b66;
  font-weight: 700;
}

.viewer-pane.is-active .pane-title {
  color: #6d2b15;
}

.viewer-wrap {
  width: 100%;
  align-self: center;
  flex: 1;
  min-height: 0;
  display: block;
  border: 1px solid #e2d6c4;
  border-radius: var(--radius);
  background: radial-gradient(circle at center, #ffffff 0%, #fcf8f2 72%, #f8f1e6 100%);
  box-shadow: var(--shadow);
  padding: 16px;
  overflow-x: auto;
  overflow-y: auto;
}

.viewer-wrap.zoom-crop {
  overflow-x: hidden;
}

.pages-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.page-host {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: fit-content;
  max-width: 100%;
}

.page-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 8px;
}

.page-stack {
  position: relative;
  width: fit-content;
  max-width: 100%;
}

.page-stack.loading {
  background: #fffdfa;
  border: 1px dashed #deccb5;
  border-radius: 8px;
}

.pdf-canvas {
  display: block;
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(60, 45, 20, 0.24);
  background: white;
  max-width: 100%;
  height: auto;
}

.page-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.page-save-btn {
  width: 24px;
  height: 24px;
  border: 0;
  padding: 0;
  background: transparent;
  color: #8f8070;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.page-save-btn:hover {
  color: #6f6153;
}

.page-save-icon {
  width: 16px;
  height: 16px;
  display: block;
}

.page-save-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.annotation-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pdf-link {
  position: absolute;
  pointer-events: auto;
  border: 1px dashed transparent;
  border-radius: 4px;
  background: transparent;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.pdf-link:hover {
  background: rgba(164, 63, 34, 0.12);
  border-color: rgba(164, 63, 34, 0.65);
}

.pdf-link.external:hover {
  background: rgba(39, 90, 154, 0.14);
  border-color: rgba(39, 90, 154, 0.58);
}

@media (max-width: 1000px) {
  .page-tools {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 720px) {
  .source-panel input[type="file"],
  .source-panel .btn {
    width: 100%;
    max-width: none;
  }
}

@media (max-width: 900px) {
  body {
    height: auto;
    overflow: auto;
  }

  .list-io-controls {
    width: 100%;
    display: flex;
  }

  .layout {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .history-panel {
    height: auto;
    max-height: 34vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 14px 12px;
  }

  .history-resizer {
    display: none;
  }

  .viewer-shell {
    height: auto;
  }

  .header-toggle-btn {
    align-self: stretch;
  }

  .viewer-wrap {
    min-height: 60vh;
  }

  .viewer-grid.split-enabled {
    grid-template-columns: minmax(0, 1fr);
  }
}

.legal-links {
  flex: 0 0 auto;
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

.legal-links a {
  color: var(--muted);
}

.legal-links a:hover {
  color: var(--accent);
}
