:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #1c2a2e;
  --ink-dim: #5b6b6e;
  --border: #ddd6c7;
  --accent: #274e45;
  --accent-2: #7a1f34;
  --green: #4f7a5a;
  --green-bg: #e4ede4;
  --maroon: #7a2436;
  --maroon-bg: #f1e2e3;
  --status-sveikas: #4f8a5b;
  --status-silpnas: #c99a2e;
  --status-ligotas: #c1522f;
  --status-zuves: #d1362b;
  --status-atsodintas: #3c6fa8;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 25, 0.12), 0 1px 2px rgba(20, 30, 25, 0.08);
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181a;
    --surface: #1d2325;
    --surface-2: #232a2c;
    --ink: #eef0ee;
    --ink-dim: #9aa6a3;
    --border: #333c3e;
    --accent: #6fae94;
    --accent-2: #d98a9b;
    --green: #7fbf8e;
    --green-bg: #223026;
    --maroon: #d98a9b;
    --maroon-bg: #351f26;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: transparent;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 0.55em 0.9em;
  min-height: 44px;
}
button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.ghost {
  background: transparent;
  border-color: transparent;
}
button.danger {
  color: var(--maroon);
  border-color: var(--maroon);
}
button:active { transform: translateY(1px); }

input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.5em 0.7em;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  min-height: 44px;
  width: 100%;
}
textarea { min-height: 80px; }
label { font-size: 0.85rem; color: var(--ink-dim); display: block; margin-bottom: 0.25em; }

.app-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(30, 58, 51, 0.68);
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  color: #fff;
  padding: 0.7em 1em;
  display: flex; align-items: center; gap: 0.75em;
  box-shadow: var(--shadow);
  flex-wrap: nowrap;
}
.app-header h1 {
  font-size: 1.1rem; margin: 0; font-weight: 700; letter-spacing: 0.02em;
  white-space: nowrap; flex: none;
}
.app-header .spacer { flex: 1; min-width: 0; }
.tabs { display: flex; gap: 0.3em; overflow-x: auto; flex: 1 1 auto; min-width: 0; -webkit-overflow-scrolling: touch; }
.tabs button {
  background: rgba(255,255,255,0.1); color: #fff; border-color: rgba(255,255,255,0.3);
  white-space: nowrap; flex: none;
}
.tabs button.active { background: #fff; color: var(--accent); font-weight: 600; }

.offline-badge {
  font-size: 0.7rem; padding: 0.2em 0.6em; border-radius: 999px;
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.35);
  white-space: nowrap; flex: none;
}

@media (max-width: 600px) {
  .app-header { padding: 0.6em 0.7em; gap: 0.5em; }
  .app-header h1 { font-size: 0.95rem; }
  .app-header h1 .full-label { display: none; }
  .offline-badge { display: none; }
  .app-header .spacer { display: none; }
}

main { padding: 0.85em; padding-bottom: 4em; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 0.5em; align-items: center;
  margin-bottom: 0.85em;
}
.toolbar input[type="search"] { flex: 1; min-width: 160px; }
.toolbar select { width: auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Suvestinė ---------- */
.summary-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.6em; margin-bottom: 1em;
}
.stat-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.9em; box-shadow: var(--shadow);
}
.stat-tile .n { font-size: 1.6rem; font-weight: 700; }
.stat-tile .label { color: var(--ink-dim); font-size: 0.8rem; }
.status-legend { display: flex; flex-wrap: wrap; gap: 0.5em; margin: 0.5em 0 1em; }
.status-chip {
  display: inline-flex; align-items: center; gap: 0.4em;
  font-size: 0.85rem; padding: 0.3em 0.6em; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.dot { width: 0.7em; height: 0.7em; border-radius: 50%; display: inline-block; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.data-table th, table.data-table td {
  padding: 0.5em 0.6em; border-bottom: 1px solid var(--border); text-align: left;
}
table.data-table th { color: var(--ink-dim); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
table.data-table tbody tr:hover { background: var(--surface-2); cursor: pointer; }

/* ---------- Sąrašo vaizdas ---------- */
.list-row {
  display: flex; align-items: center; gap: 0.6em;
  padding: 0.6em 0.7em; border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.list-row:hover { background: var(--surface-2); }
.list-row .id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; min-width: 6.5em; }
.list-row .meta { color: var(--ink-dim); font-size: 0.85rem; }
.list-row .flex1 { flex: 1; }

/* ---------- Žemėlapis ---------- */
.map-wrap {
  overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); position: relative; touch-action: pan-x pan-y;
}
.map-controls {
  display: flex; gap: 0.4em; align-items: center; margin-bottom: 0.6em;
}
.row-block {
  display: flex; align-items: stretch; border-bottom: 2px solid var(--border);
}
.row-block.first-of-variety { border-top: 3px solid var(--ink); }
.row-label {
  width: 190px; min-width: 190px; padding: 0.4em 0.6em; display: flex; align-items: center; gap: 0.5em;
  font-size: 0.82rem; border-right: 2px solid var(--border);
  position: sticky; left: 0; background: var(--surface); z-index: 2;
}
.row-label .thumb {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border);
  background: var(--surface-2); flex: none; cursor: zoom-in;
}
.row-label .rn { font-weight: 700; width: 2.2em; text-align: right; color: var(--ink-dim); }
.row-label .vn { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-track {
  flex: 1; display: flex; align-items: center; gap: 3px; padding: 0.5em 0.6em;
  position: relative; min-width: 0;
}
.row-track.hatched::before {
  content: ""; position: absolute; inset: 3px 0; pointer-events: none;
  background: repeating-linear-gradient(45deg, rgba(120,100,40,0.35) 0 2px, transparent 2px 8px);
}
.row-track.diagonal::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(60deg, rgba(80,80,80,0.18) 0 1px, transparent 1px 14px);
}
.vine-dot {
  width: 14px; height: 14px; border-radius: 50%; flex: none; cursor: pointer;
  border: 1.5px solid rgba(0,0,0,0.25);
}
.vine-dot.inactive { opacity: 0.25; border-style: dashed; }
.row-summary { font-size: 0.72rem; color: var(--ink-dim); white-space: nowrap; padding-left: 0.5em; }

.grafted-flag { font-weight: 700; font-size: 0.75rem; padding: 0.1em 0.4em; border-radius: 4px; }
.grafted-flag.S { color: var(--green); background: var(--green-bg); }
.grafted-flag.N { color: var(--maroon); background: var(--maroon-bg); }

/* ---------- Modalas ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 15, 12, 0.55);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100;
}
@media (min-width: 720px) {
  .modal-backdrop { align-items: center; }
}
.modal {
  background: var(--surface); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; box-shadow: 0 -4px 24px rgba(0,0,0,0.25);
  padding: 1em 1em 2em;
}
@media (min-width: 720px) {
  .modal { border-radius: 16px; }
}
.modal-header { display: flex; align-items: center; gap: 0.6em; margin-bottom: 0.75em; }
.modal-header h2 { margin: 0; font-size: 1.15rem; flex: 1; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6em; margin-bottom: 0.8em; }
@media (max-width: 480px) { .field-grid { grid-template-columns: 1fr; } }
.section-title {
  font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-dim);
  margin: 1.2em 0 0.5em; font-weight: 700;
}
.journal-entry {
  border: 1px solid var(--border); border-radius: 8px; padding: 0.6em 0.7em; margin-bottom: 0.5em;
  background: var(--surface-2);
}
.journal-entry .je-head { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; }
.je-type { font-weight: 700; }
.journal-photos { display: flex; gap: 0.4em; flex-wrap: wrap; margin-top: 0.4em; }
.journal-photos img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

.badge {
  display: inline-flex; align-items: center; gap: 0.35em; padding: 0.2em 0.55em; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600;
}

.status-select-row { display: flex; flex-wrap: wrap; gap: 0.4em; }
.status-pill {
  padding: 0.35em 0.7em; border-radius: 999px; border: 1.5px solid var(--border); font-size: 0.82rem;
  background: var(--surface); cursor: pointer;
}
.status-pill.active { color: #fff; border-color: transparent; }

.id-copy { font-family: ui-monospace, monospace; font-weight: 700; letter-spacing: 0.02em; cursor: pointer; }

/* ---------- Veislių kortelės ---------- */
.variety-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.7em; }
.variety-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 0.8em; cursor: pointer; display: flex; gap: 0.7em; align-items: center;
}
.variety-tile img { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); background: var(--surface-2); }
.variety-tile .rows-note { font-size: 0.78rem; color: var(--ink-dim); }

.status-tag {
  font-size: 0.7rem; padding: 0.12em 0.5em; border-radius: 5px; font-weight: 700;
}
.status-tag.patvirtinta { background: var(--green-bg); color: var(--green); }
.status-tag.reikia-patikrinti { background: #f7e8c9; color: #8a6415; }

.month-table th, .month-table td { vertical-align: top; }
.source-list { font-size: 0.85rem; padding-left: 1.1em; }
.source-list li { margin-bottom: 0.25em; }

.calendar-table-wrap { overflow-x: auto; }

.qr-box { text-align: center; padding: 0.5em; background: #fff; border-radius: 8px; }

.empty-state { text-align: center; color: var(--ink-dim); padding: 2em 1em; }

.footer-note { text-align: center; color: var(--ink-dim); font-size: 0.78rem; padding: 1.5em 0.5em; }

.icon-btn { padding: 0.4em 0.55em; min-height: 38px; }

@media print {
  .app-header, .toolbar, main > *:not(.print-labels) { display: none !important; }
}
.print-labels { display: none; }
.print-labels.show { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.print-labels .label { border: 1px dashed #999; padding: 6px; text-align: center; font-size: 10px; }
.print-labels .label img { width: 100%; }

/* ---------- Fiksuotas vynuogyno nuotraukų fonas ---------- */
/* Visada matomas (nepriklausomai nuo slinkimo) sluoksnis už visko — bento tinklelis
   iš tikrų vynuogyno nuotraukų + tamsintas gradientas skaitomumui. Virš jo sėdi
   .page-panel — nepermatoma "kortelė" su visu funkciniu turiniu, kad lentelės/
   sąrašai liktų puikiai skaitomi. */
.bg-photos {
  position: fixed;
  inset: 0;
  z-index: -2;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 2px;
}
.bg-photos div {
  background-size: cover;
  background-position: center;
}
.bg-photos div:nth-child(1) { grid-column: 1 / 3; grid-row: 1 / 3; }
.bg-photos div:nth-child(2) { grid-column: 3 / 5; grid-row: 1 / 2; }
.bg-photos div:nth-child(3) { grid-column: 3 / 4; grid-row: 2 / 4; }
.bg-photos div:nth-child(4) { grid-column: 4 / 5; grid-row: 2 / 3; }
.bg-photos div:nth-child(5) { grid-column: 4 / 5; grid-row: 3 / 4; }
.bg-photos div:nth-child(6) { grid-column: 1 / 2; grid-row: 3 / 5; }
.bg-photos div:nth-child(7) { grid-column: 2 / 3; grid-row: 3 / 5; }
.bg-photos div:nth-child(8) { grid-column: 3 / 5; grid-row: 4 / 5; }
.bg-photos::after {
  content: "";
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, rgba(12,20,16,0.72) 0%, rgba(12,20,16,0.55) 15%, rgba(12,20,16,0.55) 85%, rgba(12,20,16,0.72) 100%);
}

.page-panel {
  position: relative;
  background: linear-gradient(165deg, #fdf7e8 0%, #f8ecc9 26%, #eef3df 60%, #e6f0e6 100%);
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 60px);
  box-shadow: 0 0 40px rgba(0,0,0,0.35);
}
@media (min-width: 760px) {
  .page-panel { border-radius: 18px 18px 0 0; margin-top: 0.6em; }
}
@media (prefers-color-scheme: dark) {
  .page-panel {
    background: linear-gradient(165deg, #1b2117 0%, #1d2419 26%, #1a2420 60%, #171e1c 100%);
  }
}
