:root {
  --paper: #f4f1eb;
  --card: #fffefa;
  --ink: #1e2926;
  --muted: #68716d;
  --line: #dddcd4;
  --green: #1f6b51;
  --green-dark: #15533e;
  --green-pale: #e7f1ec;
  --orange: #d77838;
  --red: #b6493f;
  --shadow: 0 18px 46px rgba(38, 48, 43, .08);
  --radius: 22px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { margin: 0; min-height: 100vh; background: var(--paper); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(31, 107, 81, .24);
  outline-offset: 2px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }

.topbar {
  height: 72px;
  padding: 0 max(22px, calc((100vw - 1220px) / 2));
  border-bottom: 1px solid rgba(69, 77, 73, .12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(244, 241, 235, .88);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; font-weight: 760; letter-spacing: -.02em; }
.brand-mark { width: 54px; height: 44px; background: var(--green); border-radius: 13px; padding: 10px; display: grid; gap: 4px; transform: rotate(-2deg); box-shadow: 0 9px 24px rgba(31, 107, 81, .22); }
.brand-mark span { display: block; height: 3px; border-radius: 4px; background: rgba(255,255,255,.92); }
.brand-mark span:nth-child(2) { width: 75%; }
.brand-mark span:nth-child(3) { width: 45%; }
.brand-mark.small { width: 35px; height: 30px; padding: 7px; border-radius: 9px; gap: 2px; }
.brand-mark.small span { height: 2px; }
.top-actions { display: flex; align-items: center; gap: 14px; }

.status-pill { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; color: var(--muted); background: rgba(255,255,255,.52); font-size: 12px; font-weight: 650; }
.status-pill i { width: 8px; height: 8px; border-radius: 50%; background: #9b9e9c; box-shadow: 0 0 0 4px rgba(155,158,156,.12); }
.status-pill.online { color: var(--green-dark); border-color: #b9d4c8; background: var(--green-pale); }
.status-pill.online i { background: #2a946d; box-shadow: 0 0 0 4px rgba(42,148,109,.14); }

.icon-button { width: 38px; height: 38px; border: 0; border-radius: 12px; display: grid; place-items: center; color: var(--muted); background: transparent; transition: .18s ease; }
.icon-button:hover { color: var(--ink); background: rgba(31,41,38,.07); }
.icon-button.surface { background: #fff; border: 1px solid var(--line); }
.icon-button svg, .button svg, .upload-icon svg, .job-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.shell { width: min(1220px, calc(100% - 44px)); margin: 0 auto; padding: 58px 0 90px; }
.hero { display: flex; justify-content: space-between; align-items: end; gap: 30px; margin-bottom: 26px; }
.eyebrow { color: var(--green); font-size: 11px; line-height: 1; font-weight: 800; letter-spacing: .16em; margin: 0 0 10px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 500; font-size: clamp(38px, 5vw, 58px); line-height: 1; letter-spacing: -.045em; }
h2 { margin: 0; font-size: 21px; letter-spacing: -.025em; }
.hero-copy { color: var(--muted); max-width: 385px; margin-bottom: 3px; line-height: 1.55; font-size: 14px; }

.workspace { display: grid; grid-template-columns: minmax(0, 1.48fr) minmax(330px, .72fr); gap: 22px; align-items: start; }
.preview-card, .settings-card, .queue-section { background: var(--card); border: 1px solid rgba(69,77,73,.13); border-radius: var(--radius); box-shadow: var(--shadow); }
.preview-card { min-height: 650px; overflow: hidden; }
.settings-card { padding: 25px; position: sticky; top: 94px; }
.settings-heading, .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.settings-heading .eyebrow, .section-heading .eyebrow { margin-bottom: 7px; }

.drop-zone { min-height: 650px; position: relative; }
.drop-zone.dragging { background: var(--green-pale); }
.drop-zone.dragging::after { content: "Atlaid, lai pievienotu"; position: absolute; inset: 18px; border: 2px dashed var(--green); border-radius: 16px; display: grid; place-items: center; z-index: 10; background: rgba(231,241,236,.94); color: var(--green); font-size: 21px; font-weight: 750; }
#file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop-empty { min-height: 650px; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 40px; text-align: center; background-image: radial-gradient(rgba(31,107,81,.08) 1px, transparent 1px); background-size: 18px 18px; }
.drop-empty::before { content: ""; position: absolute; width: 230px; height: 230px; border-radius: 50%; background: var(--card); box-shadow: 0 0 0 30px rgba(255,254,250,.72); z-index: 0; }
.drop-empty > * { z-index: 1; }
.upload-icon { width: 58px; height: 58px; border-radius: 18px; background: var(--green-pale); color: var(--green); display: grid; place-items: center; margin-bottom: 20px; }
.upload-icon svg { width: 27px; height: 27px; }
.drop-empty h2 { font-size: 24px; margin-bottom: 9px; }
.drop-empty p { color: var(--muted); margin-bottom: 12px; }
.drop-empty > span { color: #959a97; font-size: 12px; }
.text-button { border: 0; padding: 0; background: transparent; color: var(--green); font-weight: 700; text-decoration: underline; text-decoration-color: rgba(31,107,81,.28); text-underline-offset: 3px; }

.preview-wrap { min-height: 650px; display: flex; flex-direction: column; }
.preview-toolbar, .preview-footer { min-height: 70px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.preview-toolbar { border-bottom: 1px solid var(--line); }
.preview-footer { border-top: 1px solid var(--line); }
.file-chip { min-width: 0; display: flex; align-items: center; gap: 11px; }
.file-chip > span:last-child { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.file-chip strong { max-width: 350px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; }
.file-chip small { color: var(--muted); font-size: 11px; }
.file-type { padding: 7px 8px; border-radius: 8px; color: var(--red); background: #f7e9e7; font-weight: 800; font-size: 10px; }

.page-stage { flex: 1; min-height: 505px; overflow: hidden; display: grid; place-items: center; padding: 28px; background: #e9e8e3; position: relative; }
.canvas-shell { position: relative; max-width: 100%; max-height: 100%; line-height: 0; box-shadow: 0 16px 32px rgba(32,39,36,.17); background: white; }
#preview-canvas { display: block; max-width: 100%; max-height: 480px; width: auto; height: auto; }
.preview-error { max-width: 380px; text-align: center; line-height: 1.5; color: var(--muted); }
.crop-shade { position: absolute; inset: 0; background: rgba(14,23,20,.47); pointer-events: none; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--green), 0 0 0 3000px rgba(14,23,20,.47), inset 0 0 0 1px rgba(31,107,81,.35); cursor: move; background: transparent; }
.crop-box::after { content: "DRUKAS LAUKUMS"; position: absolute; left: 6px; top: 6px; color: white; background: var(--green); border-radius: 5px; font-size: 8px; letter-spacing: .08em; padding: 3px 5px; line-height: 1; }
.crop-box .handle { position: absolute; width: 14px; height: 14px; border: 2px solid #fff; background: var(--green); border-radius: 50%; }
.crop-box .nw { left: -8px; top: -8px; cursor: nwse-resize; }
.crop-box .ne { right: -8px; top: -8px; cursor: nesw-resize; }
.crop-box .sw { left: -8px; bottom: -8px; cursor: nesw-resize; }
.crop-box .se { right: -8px; bottom: -8px; cursor: nwse-resize; }
.page-nav, .crop-actions { display: flex; align-items: center; gap: 10px; }
.page-nav span { min-width: 54px; text-align: center; font-size: 12px; color: var(--muted); }
.page-nav b { color: var(--ink); }

.button { border: 0; border-radius: 12px; padding: 12px 17px; display: inline-flex; justify-content: center; align-items: center; gap: 9px; font-weight: 720; transition: .18s ease; }
.button.primary { background: var(--green); color: white; box-shadow: 0 10px 22px rgba(31,107,81,.17); }
.button.primary:hover:not(:disabled) { background: var(--green-dark); transform: translateY(-1px); }
.button:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.button.wide { width: 100%; }
.button.subtle { background: white; border: 1px solid var(--line); color: var(--ink); }
.button.compact { padding: 9px 11px; font-size: 11px; }
.button.compact svg { width: 16px; height: 16px; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; min-width: 0; }
.field > span, .segmented-field legend { color: #57615d; font-size: 11px; font-weight: 730; }
.field small { color: #89908d; font-size: 10px; line-height: 1.4; }
.field input, .field select { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 11px; padding: 0 11px; background: #fff; color: var(--ink); font-size: 12px; }
.field select { appearance: none; padding-right: 31px; background-image: linear-gradient(45deg,transparent 50%,#65706b 50%),linear-gradient(135deg,#65706b 50%,transparent 50%); background-position: calc(100% - 15px) 18px,calc(100% - 11px) 18px; background-size: 4px 4px,4px 4px; background-repeat: no-repeat; }
.field select:disabled { color: #929895; background-color: #f1f1ee; cursor: not-allowed; }
.stepper { display: grid; grid-template-columns: 36px 1fr 36px; height: 42px; border: 1px solid var(--line); border-radius: 11px; overflow: hidden; }
.stepper button, .stepper input { border: 0; border-radius: 0; height: 40px; background: white; text-align: center; padding: 0; }
.stepper button { color: var(--green); font-size: 18px; }
.stepper input { -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button { display: none; }
.segmented-field { border: 0; padding: 0; margin: 0 0 16px; }
.segmented-field legend { margin-bottom: 7px; }
.segmented { height: 42px; display: grid; grid-template-columns: 1fr 1fr; padding: 3px; background: #efefeb; border-radius: 11px; }
.segmented input { position: absolute; opacity: 0; }
.segmented label span { height: 36px; display: grid; place-items: center; border-radius: 8px; color: var(--muted); font-size: 11px; font-weight: 650; cursor: pointer; }
.segmented input:checked + span { color: var(--green-dark); background: white; box-shadow: 0 2px 7px rgba(44,52,48,.1); }
.advanced { border-top: 1px solid var(--line); margin: 5px 0 19px; padding-top: 14px; }
.advanced summary { list-style: none; cursor: pointer; color: var(--green); font-size: 11px; font-weight: 750; margin-bottom: 10px; }
.advanced summary::-webkit-details-marker { display: none; }
.check-row { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 11px; padding: 6px 0; }
.check-row input { accent-color: var(--green); }
.print-button { min-height: 48px; }

.queue-section { margin-top: 24px; padding: 25px; }
.queue-section .section-heading { margin-bottom: 10px; }
.jobs-list { display: grid; }
.empty-list { color: var(--muted); text-align: center; padding: 42px 10px 24px; font-size: 13px; }
.job-row { display: grid; grid-template-columns: 44px minmax(0,1fr) auto; align-items: center; gap: 14px; padding: 17px 3px; border-top: 1px solid var(--line); }
.job-icon { width: 40px; height: 40px; border-radius: 11px; background: #f0f0ec; color: var(--green); display: grid; place-items: center; }
.job-main { min-width: 0; }
.job-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.job-title strong { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-badge { border-radius: 999px; padding: 4px 7px; color: var(--muted); background: #efefeb; font-size: 9px; font-weight: 800; white-space: nowrap; }
.job-badge.queued, .job-badge.processing, .job-badge.printing { color: #8b571f; background: #faeddc; }
.job-badge.completed { color: var(--green-dark); background: var(--green-pale); }
.job-badge.failed, .job-badge.cancelled { color: #913c35; background: #f7e7e5; }
.job-badge.waiting_flip { color: #6b4c9c; background: #eee8f7; }
.job-description { color: var(--muted); margin: 5px 0 0; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-progress { height: 3px; margin-top: 9px; border-radius: 4px; overflow: hidden; background: #ecece7; }
.job-progress i { display: block; height: 100%; border-radius: inherit; background: var(--green); transition: width .3s ease; }
.job-meta { min-width: 115px; text-align: right; }
.job-meta time { color: #8b918e; font-size: 10px; }
.job-actions { display: flex; justify-content: flex-end; gap: 5px; margin-top: 5px; }
.job-actions button { border: 0; background: transparent; color: var(--green); font-size: 10px; font-weight: 700; padding: 4px; }
.job-actions button.danger { color: var(--red); }

.toast-region { position: fixed; right: 22px; top: 86px; z-index: 50; display: grid; gap: 9px; pointer-events: none; }
.toast { min-width: 260px; max-width: 380px; padding: 13px 15px; border-radius: 12px; color: white; background: #26322e; box-shadow: 0 15px 35px rgba(24,31,28,.2); font-size: 12px; line-height: 1.45; animation: toast-in .2s ease-out; }
.toast.error { background: #923e37; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-7px); } }

.login-page { display: grid; place-items: center; padding: 25px; background-image: radial-gradient(rgba(31,107,81,.1) 1px, transparent 1px); background-size: 22px 22px; }
.login-card { width: min(430px, 100%); padding: 45px; border: 1px solid rgba(69,77,73,.13); border-radius: 26px; background: var(--card); box-shadow: 0 24px 70px rgba(38,48,43,.13); }
.login-card .brand-mark { margin-bottom: 30px; }
.login-card h1 { font-size: 42px; margin-bottom: 16px; }
.login-card > .muted { font-size: 14px; line-height: 1.55; }
.login-form { display: grid; gap: 10px; margin: 26px 0 21px; }
.login-form label { color: var(--muted); font-size: 11px; font-weight: 750; }
.login-form input { height: 48px; border: 1px solid var(--line); border-radius: 12px; padding: 0 13px; margin-bottom: 5px; }
.alert { border-radius: 10px; padding: 11px 13px; margin: 20px 0 0; font-size: 12px; }
.alert.error { color: #8b342f; background: #f8e7e5; }

@media (max-width: 900px) {
  .shell { width: min(100% - 28px, 720px); padding-top: 38px; }
  .workspace { grid-template-columns: 1fr; }
  .settings-card { position: static; }
  .preview-card, .drop-zone, .drop-empty, .preview-wrap { min-height: 560px; }
  .page-stage { min-height: 415px; }
  #preview-canvas { max-height: 390px; }
  .hero-copy { display: none; }
}

@media (max-width: 560px) {
  .topbar { height: 62px; padding: 0 14px; }
  .status-pill span { display: none; }
  .status-pill { padding: 9px; }
  .shell { width: calc(100% - 20px); padding: 30px 0 65px; }
  h1 { font-size: 39px; }
  .hero { margin-left: 7px; }
  .preview-card, .settings-card, .queue-section { border-radius: 17px; }
  .preview-card, .drop-zone, .drop-empty, .preview-wrap { min-height: 500px; }
  .drop-empty { padding: 25px; }
  .page-stage { min-height: 350px; padding: 18px; }
  #preview-canvas { max-height: 330px; }
  .preview-toolbar, .preview-footer { padding: 12px; }
  .file-chip strong { max-width: 195px; }
  .crop-actions .button svg { display: none; }
  .settings-card, .queue-section { padding: 19px; }
  .field-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .job-row { grid-template-columns: 38px minmax(0,1fr); }
  .job-meta { grid-column: 2; min-width: 0; text-align: left; display: flex; align-items: center; justify-content: space-between; }
  .job-actions { margin: 0; }
  .toast-region { left: 12px; right: 12px; top: 73px; }
  .toast { min-width: 0; max-width: none; }
  .login-card { padding: 32px 25px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
