@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Source+Serif+4:opsz,wght@8..60,600&display=swap");

:root {
  --bg-0: #e8eef5;
  --bg-1: #f7fafc;
  --card: rgba(255, 255, 255, 0.88);
  --card-solid: #ffffff;
  --text: #122033;
  --muted: #5a6b7d;
  --accent: #0a6e6b;
  --accent-strong: #085955;
  --accent-soft: #d8f0ee;
  --border: #c9d5e1;
  --error: #b42318;
  --error-bg: #fff1f0;
  --shadow: 0 10px 30px rgba(18, 32, 51, 0.06);
  --radius: 14px;
  --space: clamp(0.75rem, 1.2vw, 1.25rem);
  --pad: clamp(0.9rem, 2vw, 1.5rem);
  --font: "Manrope", "Segoe UI", sans-serif;
  --display: "Source Serif 4", Georgia, serif;
  --touch: 44px;
  --max: 72rem;
  color-scheme: light;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: clamp(0.95rem, 0.9rem + 0.25vw, 1.05rem);
  color: var(--text);
  line-height: 1.5;
  background:
    radial-gradient(1200px 600px at 10% -10%, #cfe8e6 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #d5e3f4 0%, transparent 50%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  background-attachment: fixed;
}

.container {
  width: min(100% - 1.5rem, var(--max));
  margin: 0 auto;
  padding: clamp(1rem, 2.5vw, 2.25rem) 0 clamp(2.5rem, 5vw, 4rem);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: clamp(0.75rem, 2vw, 1.5rem);
  margin-bottom: clamp(0.5rem, 1.5vw, 1rem);
}

.page-header h1 {
  margin: 0 0 0.35rem;
  font-family: var(--display);
  font-size: clamp(1.45rem, 1.1rem + 1.6vw, 2.35rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.page-header .muted {
  margin: 0.15rem 0;
}

.meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.55rem;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  font-size: 0.9em;
}

.lang-switcher {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: min(12rem, 100%);
  font-size: 0.92rem;
  font-weight: 500;
}

.lang-switcher.inline {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  min-width: auto;
}

.muted { color: var(--muted); }
.small { font-size: 0.85em; word-break: break-all; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  margin: clamp(0.75rem, 1.5vw, 1.15rem) 0;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.card h2 {
  margin-top: 0;
  font-size: clamp(1.05rem, 0.95rem + 0.4vw, 1.25rem);
  font-weight: 700;
}

.collapsible {
  padding-top: 0.55rem;
  padding-bottom: 0.55rem;
}

.collapse-toggle {
  display: flex;
  width: 100%;
  min-height: var(--touch);
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0;
  padding: 0.2rem 0;
  background: transparent;
  border: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.collapse-toggle h2 {
  margin: 0;
  font-size: clamp(1.05rem, 0.95rem + 0.4vw, 1.25rem);
}

.collapse-chevron {
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.18s ease;
  flex-shrink: 0;
}

.collapsible:not(.collapsed) .collapse-chevron {
  transform: rotate(225deg);
}

.collapse-body {
  padding-top: 0.85rem;
}

.collapsible.collapsed .collapse-body {
  display: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(0.7rem, 1.5vw, 1rem) clamp(0.75rem, 1.8vw, 1.25rem);
}

.span-2 { grid-column: span 2; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.94em;
  font-weight: 500;
}

input,
select,
button,
textarea {
  font: inherit;
  min-height: var(--touch);
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-solid);
  color: var(--text);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, white);
  outline-offset: 2px;
}

button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s ease, transform 0.1s ease;
}

button:hover {
  background: var(--accent-strong);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}

.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.65rem;
  grid-column: 1 / -1;
  min-height: var(--touch);
}

.checkbox input {
  width: 1.15rem;
  height: 1.15rem;
  min-height: 0;
  padding: 0;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) repeat(4, minmax(0, 1fr)) auto;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
  align-items: end;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
}

.item-row .remove-item {
  min-width: var(--touch);
  padding-inline: 0.75rem;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.actions {
  margin: 1.25rem 0 2rem;
  position: sticky;
  bottom: 0.75rem;
  z-index: 5;
}

.actions button[type="submit"] {
  width: min(100%, 22rem);
  min-height: 3rem;
  box-shadow: 0 10px 24px rgba(10, 110, 107, 0.25);
}

.hidden { display: none !important; }

.error {
  background: var(--error-bg);
  border-color: #f3b6b1;
}

.error pre {
  white-space: pre-wrap;
  color: var(--error);
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.result-grid {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 1rem 1.25rem;
  align-items: start;
}

.result-grid img {
  width: min(160px, 100%);
  height: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  margin-top: 0.75rem;
}

.links a {
  color: var(--accent-strong);
  font-weight: 600;
  text-underline-offset: 0.15em;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
}

table {
  width: 100%;
  min-width: 28rem;
  border-collapse: collapse;
  margin: 0.35rem 0;
  background: rgba(255, 255, 255, 0.5);
}

th, td {
  border-bottom: 1px solid var(--border);
  padding: 0.7rem 0.65rem;
  text-align: left;
  font-size: 0.94em;
}

th {
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

/* Print / RI */
.print-page { background: #fff; }
.print-sheet {
  width: min(100% - 1.5rem, 52rem);
  margin: 1rem auto;
  padding: clamp(1rem, 2vw, 1.75rem);
}
.print-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 2px solid #222;
  padding-bottom: 1rem;
}
.totals { text-align: right; }
.totals .grand { font-size: 1.15rem; }
.qr-block {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-top: 1.5rem;
  border-top: 1px dashed var(--border);
  padding-top: 1rem;
  flex-wrap: wrap;
}

/* Mobile phones */
@media (max-width: 639px) {
  :root { --touch: 48px; }

  .page-header {
    flex-direction: column;
  }

  .lang-switcher {
    width: 100%;
  }

  .grid,
  .item-row {
    grid-template-columns: 1fr;
  }

  .span-2,
  .checkbox {
    grid-column: auto;
  }

  .result-grid {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .actions {
    bottom: 0;
    margin-left: -0.25rem;
    margin-right: -0.25rem;
  }

  .actions button[type="submit"] {
    width: 100%;
  }

  .print-header {
    flex-direction: column;
  }

  table { min-width: 24rem; }
}

/* Tablets */
@media (min-width: 640px) and (max-width: 1023px) {
  :root { --max: 48rem; }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .item-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .item-row > label:first-child {
    grid-column: 1 / -1;
  }

  .item-row .remove-item {
    justify-self: start;
  }

  .result-grid {
    grid-template-columns: 140px minmax(0, 1fr);
  }
}

/* PC / laptop */
@media (min-width: 1024px) and (max-width: 1599px) {
  :root { --max: 64rem; }

  .item-row {
    grid-template-columns: minmax(10rem, 2.2fr) repeat(4, minmax(5rem, 1fr)) auto;
  }
}

/* Large PC / TV */
@media (min-width: 1600px) {
  :root {
    --max: 84rem;
    --touch: 52px;
    --radius: 18px;
  }

  body {
    font-size: clamp(1.05rem, 0.9rem + 0.35vw, 1.25rem);
  }

  .container {
    padding-top: 2.5rem;
  }

  .page-header h1 {
    font-size: clamp(2.2rem, 1.4rem + 1.2vw, 3rem);
  }

  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .span-2 {
    grid-column: span 2;
  }

  .checkbox {
    grid-column: 1 / -1;
  }

  .item-row {
    grid-template-columns: minmax(12rem, 2.4fr) repeat(4, minmax(6rem, 1fr)) auto;
    gap: 0.9rem;
    padding: 1rem;
  }

  .result-grid {
    grid-template-columns: 200px minmax(0, 1fr);
    gap: 1.5rem;
  }

  .result-grid img {
    width: 200px;
  }

  .actions button[type="submit"] {
    min-height: 3.5rem;
    width: min(100%, 28rem);
    font-size: 1.1em;
  }

  th, td {
    padding: 0.9rem 0.8rem;
    font-size: 1em;
  }
}

/* Very wide TV / 4K */
@media (min-width: 2400px) {
  :root { --max: 96rem; }

  body {
    font-size: 1.35rem;
  }

  .card {
    padding: 1.75rem 2rem;
  }
}

@media (hover: none) and (pointer: coarse) {
  a, button, select, input {
    touch-action: manipulation;
  }
}

@media print {
  body {
    background: #fff;
  }

  .no-print { display: none !important; }
  .print-sheet {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .card {
    box-shadow: none;
    backdrop-filter: none;
  }
}
