:root {
  color-scheme: dark;
  --bg: #111318;
  --surface: #1c1f27;
  --text: #f5f6f8;
  --muted: #a8adb8;
  --accent: #ff8a3d;
  --accent-text: #111318;
  --danger: #ff5d5d;
  --success: #4ade80;
}

* {
  box-sizing: border-box;
}

/* An author rule that sets `display` on an element (e.g. `.preview { display: flex }`)
   overrides the browser's default `[hidden] { display: none }` — same specificity, but
   author styles beat user-agent styles regardless. Without this, toggling `.hidden` in JS
   on .capture-button/.crop-screen/.preview has no visual effect and every screen stacks. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100%;
}

.screen {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

h1 {
  font-size: 1.8rem;
  margin: 0;
}

.back-to-rhpro {
  align-self: flex-start;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}

.back-to-rhpro:hover {
  color: var(--text);
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.link-button {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 6px 0;
  cursor: pointer;
  text-decoration: underline;
}

.idle-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.idle-actions .link-button {
  align-self: center;
}

.multi-page-status {
  margin: 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 138, 61, 0.12);
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}

.capture-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 220px;
  border-radius: 20px;
  background: var(--surface);
  border: 3px dashed #3a4050;
  cursor: pointer;
  font-size: 1.3rem;
  font-weight: 600;
  text-align: center;
  padding: 24px;
}

.capture-button .icon {
  font-size: 3.5rem;
}

.capture-button:active {
  background: #242833;
}

.capture-button.disabled {
  cursor: not-allowed;
  opacity: 0.5;
  pointer-events: none;
}

.crop-screen {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.camera-screen {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.camera-video {
  width: 100%;
  border-radius: 16px;
  border: 2px solid #333844;
  background: #000;
}

.crop-hint {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  text-align: center;
}

.crop-wrap {
  position: relative;
  width: 100%;
  line-height: 0;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid #333844;
  touch-action: none;
}

.crop-wrap img {
  width: 100%;
  display: block;
  user-select: none;
  -webkit-user-select: none;
}

.crop-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.crop-overlay polygon {
  fill: rgba(255, 138, 61, 0.18);
  stroke: var(--accent);
  stroke-width: 3;
}

.crop-overlay circle {
  fill: var(--accent);
  stroke: var(--bg);
  stroke-width: 3;
  cursor: grab;
}

.crop-overlay circle:active {
  cursor: grabbing;
}

.preview {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.preview img {
  width: 100%;
  border-radius: 16px;
  border: 2px solid #333844;
  cursor: zoom-in;
}


.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  cursor: zoom-out;
  padding: 16px;
}

.image-lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  touch-action: pinch-zoom;
}

.lightbox-pager {
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: default;
}

.lightbox-pager .secondary-button {
  padding: 10px 16px;
  min-height: auto;
}

.lightbox-page-label {
  color: var(--text);
  font-weight: 600;
}

.primary-button, .secondary-button {
  font-size: 1.3rem;
  font-weight: 700;
  padding: 18px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  min-height: 64px;
}

.primary-button {
  background: var(--accent);
  color: var(--accent-text);
}

.primary-button:disabled {
  opacity: 0.6;
}

.secondary-button {
  background: transparent;
  color: var(--text);
  border: 2px solid #3a4050;
}

.status {
  font-size: 1.05rem;
  min-height: 1.5em;
  text-align: center;
}

.status[data-kind="error"] {
  color: var(--danger);
}

.status[data-kind="success"] {
  color: var(--success);
}

.result-screen {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.result-card {
  padding: 18px;
  border-radius: 16px;
  background: var(--surface);
  border: 2px solid #333844;
}

.result-badge {
  margin: 0 0 12px;
  font-weight: 700;
  font-size: 1rem;
}

.result-badge[data-kind="ok"] {
  color: var(--success);
}

.result-badge[data-kind="review"] {
  color: var(--danger);
}

.result-fields {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
}

.result-fields dt {
  color: var(--muted);
  font-size: 0.9rem;
}

.result-fields dd {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.build-marker {
  margin: 8px 0 0;
  text-align: center;
  font-size: 0.75rem;
  color: #4a5060;
}

.rhpro-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 2px solid #333844;
}

.rhpro-status {
  margin: 0;
  font-size: 0.95rem;
}

.rhpro-status[data-kind="connected"] {
  color: var(--success);
}

.rhpro-status[data-kind="disconnected"] {
  color: var(--muted);
}

#rhproLoginLink {
  display: inline-block;
  text-decoration: none;
  text-align: center;
  min-height: 52px;
  font-size: 1.05rem;
  box-sizing: border-box;
}

.duplicate-warning {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 93, 93, 0.12);
  border: 2px solid var(--danger);
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 600;
}

.history-screen {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.history-header .secondary-button {
  min-height: 44px;
  padding: 10px 16px;
  font-size: 1rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 2px solid #333844;
  cursor: pointer;
}

.history-item-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.history-item-supplier {
  font-weight: 700;
  font-size: 1.05rem;
}

.history-item-amount {
  font-weight: 700;
  color: var(--accent);
}

.history-item-meta {
  color: var(--muted);
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.history-item-actions {
  display: flex;
  gap: 16px;
  margin-top: 2px;
}

.history-item-retry,
.history-item-delete {
  align-self: flex-start;
  font-size: 0.85rem;
  padding: 4px 0;
}

.history-item-delete {
  color: var(--danger);
}

.history-item-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.history-item-badge {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  align-self: flex-start;
}

.history-item-badge[data-kind="sent"] {
  background: rgba(74, 222, 128, 0.15);
  color: var(--success);
}

.history-item-badge[data-kind="not-sent"] {
  background: rgba(168, 173, 184, 0.15);
  color: var(--muted);
}

.history-item-badge[data-kind="review"] {
  background: rgba(255, 93, 93, 0.15);
  color: var(--danger);
}

.history-item-badge[data-kind="pages"] {
  background: rgba(168, 173, 184, 0.15);
  color: var(--muted);
}

.history-empty,
.history-loading {
  text-align: center;
  color: var(--muted);
  padding: 24px;
}
