:root {
  color-scheme: light;
  --ink: #18211f;
  --muted: #64706c;
  --line: #d7dedb;
  --paper: #f6f7f4;
  --surface: #ffffff;
  --green: #113c33;
  --green-2: #276858;
  --wine: #8d2440;
  --gold: #b78635;
  --alert: #b9472e;
  --shadow: 0 12px 28px rgba(23, 32, 29, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: #e9eee9;
  color: var(--ink);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

body.locked {
  background: var(--green);
}

body.locked .app-shell {
  display: none;
}

.access-screen {
  display: none;
}

body.locked .access-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(90deg, rgba(12, 27, 24, .94), rgba(12, 27, 24, .62)),
    url("assets/wine-crm-header.png") center / cover;
}

.access-card {
  width: min(100%, 390px);
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .24);
}

.access-card .eyebrow {
  color: var(--wine);
}

.access-card h1 {
  margin-bottom: 12px;
  color: var(--green);
}

.access-copy,
.access-status {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.access-status {
  margin: 12px 0 0;
}

.app-shell {
  width: min(100%, 460px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--paper);
  box-shadow: 0 0 0 1px rgba(23, 32, 29, .08), 0 24px 80px rgba(23, 32, 29, .12);
}

.hero {
  position: relative;
  min-height: 176px;
  overflow: hidden;
  background: var(--green);
}

.hero-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(12, 27, 24, .94), rgba(12, 27, 24, .68) 52%, rgba(12, 27, 24, .24));
}

.hero-content {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  min-height: 176px;
  padding: calc(22px + env(safe-area-inset-top)) 18px 24px;
  color: #fff;
}

.eyebrow {
  margin: 0 0 7px;
  color: rgba(255, 255, 255, .76);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 29px; line-height: 1.04; letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 18px; letter-spacing: 0; }
h3 { margin-bottom: 0; font-size: 18px; letter-spacing: 0; }

main {
  position: relative;
  padding: 0 14px 24px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin-top: -36px;
  position: relative;
  z-index: 2;
}

.summary-grid article {
  min-height: 78px;
  padding: 13px 11px;
  border: 1px solid rgba(23, 32, 29, .10);
  border-radius: 8px;
  background: rgba(255, 255, 255, .97);
  box-shadow: var(--shadow);
}

.summary-grid span {
  display: block;
  font-size: 21px;
  font-weight: 800;
  color: var(--green);
  line-height: 1.1;
}

.summary-grid small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 14px -2px 16px;
  padding: 8px 2px;
  background: rgba(246, 247, 244, .94);
  backdrop-filter: blur(14px);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 52px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.tab svg, .icon-button svg, .primary-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab.active {
  background: #e3ece8;
  border-color: rgba(17, 60, 51, .16);
  color: var(--green);
}

.view { display: none; }
.view.active { display: block; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 12px;
}

.section-title.compact { margin-top: 24px; }

.primary-button, .text-button, .icon-button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  font-weight: 800;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  background: var(--green);
  color: #fff;
}

.primary-button.wide { width: 100%; margin-top: 4px; }
.primary-button.disabled { opacity: .55; pointer-events: none; }

.text-button {
  padding: 0 12px;
  background: #ece7dd;
  color: #604415;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  background: rgba(255, 255, 255, .16);
  color: inherit;
}

.hero-actions {
  display: flex;
  gap: 8px;
}

.filters {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.chip.active {
  color: #fff;
  border-color: var(--wine);
  background: var(--wine);
}

.task-list, .client-list, .wine-list, .notes-list, .map-list {
  display: grid;
  gap: 10px;
}

.item, .task {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(23, 32, 29, .03);
}

.item, .task {
  padding: 13px;
}

.task {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.task strong, .item strong {
  display: block;
  font-size: 15px;
  line-height: 1.25;
}

.meta, .note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 6px;
  padding: 0 8px;
  background: #eef3ef;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

.badge.wine { background: #f6e9ee; color: var(--wine); }
.badge.gold { background: #f6edda; color: #76510f; }
.badge.alert { background: #fae9e4; color: var(--alert); }

.task-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 76px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.empty {
  padding: 18px 14px;
  border: 1px dashed #cfd7d3;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, .55);
  text-align: center;
  font-size: 14px;
}

.modal {
  width: min(92vw, 430px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .28);
}

.detail-modal {
  width: min(94vw, 520px);
  max-height: 88vh;
}

.modal::backdrop {
  background: rgba(10, 18, 16, .5);
}

.modal form, .modal-body {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.modal-body form {
  padding: 0;
}

.modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  gap: 12px;
}

.modal .icon-button {
  background: #eef3ef;
  color: var(--green);
  font-size: 26px;
  line-height: 1;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.modal-subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.client-card-button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
  color: inherit;
  text-align: left;
}

.client-card-button:focus-visible {
  outline: 3px solid rgba(36, 95, 81, .22);
  outline-offset: 2px;
}

.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.date-editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f1ea;
}

.date-editor .wide {
  grid-column: 1 / -1;
}

.edit-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f9f6;
}

.span-full {
  grid-column: 1 / -1;
}

.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.detail-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}

.detail-field {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8f9f6;
}

.detail-field small {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.detail-field span {
  display: block;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.3;
}

.detail-section {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.detail-section .section-title {
  margin: 8px 0 0;
}

.detail-section h3 {
  font-size: 16px;
}

.reference-list {
  display: grid;
  gap: 8px;
}

.reference-card {
  border-left: 4px solid var(--wine);
  border-radius: 8px;
  padding: 11px;
  background: #fff;
}

.reference-card strong {
  display: block;
  font-size: 14px;
  line-height: 1.25;
}

.domain-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.domain-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.domain-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.domain-button strong,
.domain-card header strong {
  font-size: 15px;
}

.domain-card.active {
  border-color: rgba(143, 39, 69, .45);
  box-shadow: 0 0 0 3px rgba(143, 39, 69, .08);
}

.domain-reference {
  border-left: 4px solid var(--wine);
  border-radius: 7px;
  padding: 10px;
  background: #f8f9f6;
}

.reference-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.domain-reference strong {
  display: block;
  font-size: 14px;
  line-height: 1.25;
}

.danger-button {
  min-height: 30px;
  border: 1px solid #f0c9bf;
  border-radius: 7px;
  padding: 0 9px;
  background: #fff6f3;
  color: var(--alert);
  font-size: 12px;
  font-weight: 900;
}

.map-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #dde5e1;
  aspect-ratio: 1 / .78;
}

.map-panel iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.tour-toolbar {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.tour-toolbar span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.map-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
}

.map-card-main {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
}

.map-card input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin: 1px 0 0;
  accent-color: var(--green);
}

.map-card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(36, 95, 81, .12); }

@media (min-width: 760px) {
  body { padding: 26px 0; }
  .app-shell { border-radius: 18px; overflow: hidden; min-height: calc(100vh - 52px); }
}
