.hidden { display: none !important; }

:root {
  --app-height: 100dvh;
  --bg: #0b0c14;
  --panel: #11131d;
  --text: #e8eaf0;
  --muted: #aab1c4;
  --accent: #ff6600;
  --accent-dark: #cc5500;
  --border: rgba(255,255,255,0.12);
  --success: #4ade80;
  --error: #ef4444;
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: var(--app-height);
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

#workspace-wrapper {
  display: contents;
}

#workspace {
  width: 100%;
  height: var(--app-height);
  position: relative;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#pdf-stage {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  -webkit-touch-callout: none;
  touch-action: none;
}

#pdf-pages {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  display: inline-block;
}

.pdf-page {
  display: block;
  margin: 0;
  padding: 0;
  background: #fff;
}

.measure-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  touch-action: none;
}

.measure-draft-path {
  fill: none;
  stroke: rgba(0, 0, 0, 0.9);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.measure-final-line {
  fill: none;
  stroke: var(--success);
  stroke-width: 4;
  stroke-linecap: round;
}

.calibration-draft-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.calibration-final-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
}

.panel {
  position: absolute;
  bottom: 60px;
  left: 0;
  right: 0;
  margin: 12px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  z-index: 100;
  max-height: 40vh;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.panel.hidden {
  display: none;
}

.panel h3 {
  margin: 0 0 12px;
  font-size: 16px;
  color: var(--accent);
}

.field-row {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
}

.field-row label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

.field-row input,
.field-row select {
  padding: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
}

.field-row input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0;
  padding: 8px;
  background: rgba(255, 102, 0, 0.05);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}

.measure-result {
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

.measure-result.hidden {
  display: none;
}

.measure-result-floating {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 170;
  max-width: calc(100% - 24px);
}

#measure-result-text {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}

.placeholder {
  position: absolute;
  inset: 0;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
  background: var(--bg);
}

.placeholder.hidden {
  display: none;
}

.placeholder-content {
  max-width: 100%;
}

.placeholder-icon {
  font-size: 64px;
  margin: 0 0 16px;
}

.placeholder strong {
  display: block;
  font-size: 20px;
  margin-bottom: 8px;
  color: var(--text);
}

.placeholder-text {
  display: block;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 24px;
}

.btn-large {
  padding: 14px 28px;
  font-size: 16px;
  width: 200px;
  max-width: 100%;
}

.or-separator {
  margin: 16px 0;
  font-size: 12px;
  color: var(--muted);
}

.recent-pdfs {
  margin-top: 20px;
  width: 100%;
  max-width: 300px;
}

.recent-pdfs.hidden {
  display: none;
}

.recent-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

#recent-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recent-item {
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}

.recent-item:active {
  background: var(--accent);
  color: #000;
}

#controls-bar {
  display: none;
}

#fab-container {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 150;
  display: flex;
  gap: 12px;
  flex-direction: column-reverse;
}

.fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.fab:active {
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.fab.hidden {
  display: none;
}

.fab-calibration {
  background: #000;
  color: var(--accent);
  border: 2px solid var(--accent);
}

.fab-calibration.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.fab-measure {
  background: #000;
  color: var(--accent);
  border: 2px solid var(--accent);
}

.fab-measure.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.fab-settings {
  background: #000;
  color: var(--accent);
  border: 2px solid var(--accent);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 300;
  display: flex;
  align-items: flex-end;
}

.modal.modal-center {
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  padding: 20px;
  width: 100%;
  max-height: 70vh;
  overflow-y: auto;
  z-index: 301;
}

.modal.modal-center .modal-content {
  width: calc(100% - 24px);
  max-width: 560px;
  border-radius: 12px;
  border: 1px solid var(--border);
  height: 100%;
  max-height: 100%;
}

.modal-content h3 {
  margin: 0 0 16px;
  font-size: 18px;
  color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.modal-actions .btn {
  flex: 1;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  color: var(--text);
  font-size: 14px;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

@media (orientation: portrait) {
  #pdf-stage {
    flex-direction: column;
  }
}

@media (orientation: landscape) {
  #controls-bar {
    width: 60px;
    height: auto;
    flex-direction: column;
    right: auto;
    bottom: 0;
    left: 0;
    top: 0;
  }
  
  #workspace {
    margin-right: 60px;
  }
}

/* Basic Button Styles */
.btn {
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-user-select: none;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
}

.btn-primary:active {
  background: var(--accent-dark);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text);
}

.btn-secondary:active {
  background: rgba(255, 255, 255, 0.25);
}
