/* cart_web — minimal PDF-viewer-style UI. No frameworks. */

:root {
  --bg: #1c1d20;
  --panel: #25272b;
  --panel2: #2c2f34;
  --border: #3a3e45;
  --text: #e6e7ea;
  --text-dim: #a0a4ab;
  --accent: #6aa9ff;
  --accent-soft: rgba(106, 169, 255, 0.15);
  --error: #ff7676;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
        Helvetica, Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.topbar h1 a {
  color: inherit;
  text-decoration: none;
}
.topbar .sub {
  color: var(--text-dim);
  font-weight: 400;
  margin-left: 6px;
  font-size: 13px;
}

.status {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--panel2);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.status.busy   { color: var(--accent); border-color: var(--accent); }
.status.error  { color: var(--error); border-color: var(--error); }
.status.done   { color: #76d39c; border-color: #76d39c; }

.ghost-btn {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  margin-left: auto;
  margin-right: 12px;
  cursor: pointer;
}
.ghost-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.ghost-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Drop / paste tab bar */
.tab-bar {
  display: flex;
  gap: 0;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1;
  font-family: inherit;
  font-size: 12px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  border-bottom: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  padding: 8px 10px;
  cursor: pointer;
  margin-bottom: -1px;
}
.tab.active {
  background: var(--panel2);
  color: var(--text);
  border-color: var(--border);
  border-bottom-color: var(--panel2);
}
.tab-panel {
  padding-top: 12px;
  /* Lock all three panels to the same outer height so switching tabs
   * doesn't shift the Render Options / Pages sections below.
   * 170 px = drop-zone's natural rendered height; the Code textarea
   * stretches to fill the rest, the Sample buttons stack at the top. */
  height: 170px;
  display: flex;
  flex-direction: column;
}
.tab-panel.hidden { display: none; }
.ps-paste { flex: 1; min-height: 0; }
.ps-paste {
  width: 100%;
  height: 100px;
  resize: vertical;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  box-sizing: border-box;
}
.block-btn {
  display: block;
  width: 100%;
  margin: 8px 0 0 0;
}

/* Log panel: pinned to the bottom of the sidebar (margin-top: auto
 * inside the sidebar's flex column), collapsible via its header. */
.log-panel {
  margin-top: auto;
  padding-top: 18px;
}
.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  color: var(--text-dim);
  border: none;
  padding: 0 0 8px 0;
  font-family: inherit;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  cursor: pointer;
}
.log-header:hover { color: var(--text); }
.log-chevron {
  font-size: 10px;
  display: inline-block;
  transition: transform 0.15s;
}
.log-panel.collapsed .log-chevron { transform: rotate(180deg); }
.log-panel #log {
  display: block;
  margin: 0;
  max-height: 240px;
  overflow: auto;
  padding: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-all;
}
.log-panel.collapsed #log { display: none; }

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100vh - 49px);
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
}

.sidebar h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 18px 0 8px 0;
  font-weight: 600;
}
.sidebar section:first-child h2 { margin-top: 0; }

/* Drop zone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 28px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: var(--panel2);
}
.dropzone:hover, .dropzone:focus {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  border-style: solid;
}
.dz-inner { pointer-events: none; }
.dz-icon {
  display: inline-block;
  width: 44px;
  height: 44px;
  line-height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}
.dz-text { color: var(--text); margin: 4px 0; }
.dz-text.small { color: var(--text-dim); font-size: 12px; }
.dz-text code {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

/* Controls */
.controls .ctl {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
}
.controls .ctl > span {
  flex: 0 0 80px;
  color: var(--text-dim);
  font-size: 12px;
}
.controls select,
.controls input[type=number] {
  flex: 1;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}
.controls .ctl-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.controls .ctl-row input { width: 80px; }
.controls .ctl-check {
  margin-top: 8px;
  align-items: flex-start;
}
.controls .ctl-check input { margin-top: 3px; }
.controls .ctl-check span { flex: 1; font-size: 12px; color: var(--text-dim); }
.hidden { display: none !important; }

/* Page list */
.page-list ol {
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 320px;
  overflow: auto;
}
.page-list li {
  padding: 4px 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 4px;
}
.page-list li:hover { background: var(--panel); color: var(--text); }
.page-list li.active { background: var(--accent-soft); color: var(--accent); }

/* Log */
.meta pre {
  background: #15171a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  margin: 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--text-dim);
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Viewer */
.viewer {
  overflow-y: auto;
  padding: 24px;
  background: #18191c;
}
.viewer .empty {
  text-align: center;
  margin-top: 12vh;
  color: var(--text-dim);
}
.viewer .empty .hint { font-size: 12px; opacity: 0.75; margin-top: 8px; }

.page-card {
  margin: 0 auto 24px auto;
  width: fit-content;
  background: #fff;
  border: 1px solid #000;
  box-shadow: var(--shadow);
  border-radius: 2px;
  display: block;
  cursor: zoom-in;
}
.page-card > img,
.page-card > canvas {
  display: block;
  image-rendering: pixelated;
}
.page-label {
  text-align: center;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 24px;
}

/* Error banner */
.error-banner {
  background: rgba(255, 118, 118, 0.12);
  border: 1px solid var(--error);
  color: var(--error);
  padding: 10px 14px;
  border-radius: 8px;
  margin: 0 auto 20px auto;
  max-width: 900px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

/* Render spinner */
.spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 32px auto;
  padding: 24px;
  color: var(--fg-dim);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
}
.spinner-ring {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,0.12);
  border-top-color: var(--accent, #4a9eff);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Print view: one rendered page per sheet, no UI chrome. Same path
 * fires for the toolbar button and for Cmd/Ctrl+P. */
@media print {
  @page { margin: 0; }
  html, body { background: #fff; color: #000; margin: 0; padding: 0; }
  .topbar, .sidebar, .ghost-btn,
  .empty, .page-label, .error-banner, .spinner { display: none !important; }
  .layout, .viewer {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    overflow: visible !important;
    height: auto !important;
    width: auto !important;
  }
  .page-card {
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    width: 100% !important;
    page-break-after: always;
    break-after: page;
  }
  .page-card:last-of-type {
    page-break-after: auto;
    break-after: auto;
  }
  .page-card > img,
  .page-card > canvas {
    display: block;
    width: 100% !important;
    height: auto !important;
    max-width: 100%;
    image-rendering: pixelated;
  }
}
