:root {
  --ink: #182024;
  --muted: #667178;
  --line: #d9e0e3;
  --paper: #ffffff;
  --soft: #f4f7f5;
  --accent: #116a5c;
  --accent-dark: #0c4d43;
  --danger: #a73535;
  --buy-red: #c92f2f;
  --done-green: #16804f;
  --warn: #8d5a00;
  --shadow: 0 18px 60px rgba(30, 42, 48, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(140deg, #eff5f1 0%, #f8faf9 52%, #edf2f3 100%);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: calc(100vh - 64px);
  display: grid;
  align-content: center;
  gap: 24px;
  max-width: 440px;
  margin: 0 auto;
}

.brand,
.topbar,
.section-head,
.shopping-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  justify-content: flex-start;
}

.brand-mark {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
}

h2 {
  font-size: 28px;
}

h3 {
  font-size: 22px;
}

.brand p,
.eyebrow,
.section-head span,
.hint {
  color: var(--muted);
}

.signature {
  display: grid;
  gap: 3px;
  justify-items: center;
  text-align: center;
}

.eyebrow {
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.public-family-form {
  padding: 16px;
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 7px;
  color: #344047;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid #cbd5d9;
  border-radius: 6px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fbfdfc;
}

input[type="file"] {
  padding: 10px;
  background: #ffffff;
}

input:focus,
select:focus {
  outline: 3px solid rgba(17, 106, 92, 0.16);
  border-color: var(--accent);
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 800;
}

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

.primary:hover {
  background: var(--accent-dark);
}

.secondary {
  background: #e8eeee;
  color: #223036;
}

#showPublicFamilyBtn {
  background: #c92f2f;
  color: white;
  box-shadow: 0 10px 28px rgba(201, 47, 47, 0.26);
}

#showPublicFamilyBtn:hover {
  background: #a92727;
}

.danger {
  background: #f7e5e5;
  color: var(--danger);
}

.warning {
  background: #fff0d2;
  color: var(--warn);
}

.error {
  min-height: 20px;
  color: var(--danger);
  font-weight: 700;
}

  .dashboard {
    gap: 16px;
  }

.topbar {
  padding: 18px 0 6px;
}

.admin-area,
  .products-area,
  .bought-block {
    display: grid;
    gap: 10px;
  }

.grid-form,
.admin-password-form,
.product-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) auto;
  gap: 14px;
  align-items: end;
  padding: 16px;
}

.admin-password-form {
  grid-template-columns: minmax(220px, 1fr) auto;
}

.family-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(120px, 0.45fr) auto;
  gap: 14px;
  align-items: end;
  padding: 16px;
}

.family-members {
  grid-column: 1 / -1;
  display: grid;
  gap: 12px;
}

.member-fields {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr);
  gap: 14px;
  padding-top: 2px;
}

.product-form {
  grid-template-columns: minmax(150px, 1fr) minmax(95px, 0.4fr) minmax(105px, 0.45fr) minmax(150px, 1fr) minmax(150px, 1fr) auto;
}

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

.form-message {
  grid-column: 1 / -1;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: left;
  vertical-align: middle;
  word-break: break-word;
}

th {
  background: var(--soft);
  font-size: 13px;
  text-transform: uppercase;
}

th:first-child,
td:first-child {
  width: 64px;
  text-align: center;
}

tr:last-child td {
  border-bottom: 0;
}

.family-start-row td {
  border-top: 3px solid var(--accent);
}

.family-start-row:first-child td {
  border-top: 0;
}

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

.reset-password-input {
  min-height: 38px;
}

.empty-row {
  color: var(--muted);
  text-align: center;
  padding: 28px;
}

.shopping-header {
  padding-top: 4px;
}

.shopping-header h3 {
  color: var(--buy-red);
}

.shopping-tools {
  display: flex;
  gap: 10px;
  align-items: center;
}

.mobile-add-toggle {
  display: none;
}

.progress-pill {
  min-width: 116px;
  border-radius: 999px;
  background: #e5f2ee;
  color: var(--accent-dark);
  padding: 9px 12px;
  text-align: center;
  font-weight: 800;
}

.shopping-list {
  display: grid;
  gap: 10px;
}

.shopping-item {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.shopping-item.has-photo {
  grid-template-columns: 48px 1fr auto;
}

.item-photo-button {
  width: fit-content;
  min-height: 0;
  margin-top: 8px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.item-photo {
  display: block;
  width: 96px;
  height: 76px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #f3f6f5;
}

.check-btn {
  width: 40px;
  height: 40px;
  min-height: 40px;
  display: grid;
  place-items: center;
  border: 2px solid #b9c7c9;
  border-radius: 50%;
  background: #ffffff;
  color: transparent;
  font-size: 22px;
  line-height: 1;
  padding: 0;
}

.check-btn.checked {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.item-main {
  min-width: 0;
}

.item-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  font-size: 20px;
  font-weight: 800;
  color: var(--buy-red);
}

.item-qty {
  border-radius: 999px;
  background: #f0f4f3;
  color: #405056;
  padding: 3px 9px;
  font-size: 13px;
  font-weight: 800;
}

.item-details {
  margin-top: 4px;
  color: var(--muted);
}

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

.item-actions button {
  min-height: 38px;
}

.shopping-item.is-bought {
  background: #eef8f2;
  border-color: rgba(22, 128, 79, 0.32);
}

.shopping-item.is-bought .item-title,
.shopping-item.is-bought .item-details {
  color: var(--done-green);
  text-decoration: line-through;
}

.shopping-item.is-bought .item-photo {
  opacity: 0.82;
}

.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(10, 16, 20, 0.82);
}

.photo-viewer img {
  max-width: min(100%, 920px);
  max-height: 82vh;
  border-radius: 8px;
  object-fit: contain;
  background: #ffffff;
}

.photo-viewer-close {
  position: fixed;
  top: 14px;
  right: 14px;
  min-height: 38px;
  background: #ffffff;
  color: #182024;
}

.empty-list {
  border: 1px dashed #bac7c8;
  border-radius: 8px;
  padding: 26px 14px;
  color: var(--muted);
  text-align: center;
  background: rgba(255, 255, 255, 0.65);
}

@media (max-width: 760px) {
  body {
    background: #f5f8f6;
  }

  .app-shell {
    width: 100%;
    padding: 14px 12px 28px;
  }

  .login-view {
    min-height: calc(100vh - 42px);
    gap: 18px;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
  }

  h1 {
    font-size: 26px;
  }

  h2 {
    font-size: 23px;
  }

  h3 {
    font-size: 20px;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .topbar {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
    gap: 8px;
    padding: 6px 0 0;
  }

  .topbar .icon-button {
    width: auto;
    min-height: 30px;
    padding: 5px 8px;
    font-size: 12px;
    opacity: 0.72;
  }

  .shopping-header {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: end;
    gap: 8px;
    padding-top: 0;
  }

  .shopping-header h3 {
    font-size: 24px;
    font-weight: 900;
  }

  .shopping-tools {
    width: auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
  }

  .progress-pill {
    width: auto;
    min-width: 0;
    padding: 5px 7px;
    font-size: 11px;
    opacity: 0.72;
  }

  .mobile-add-toggle {
    display: block;
    width: auto;
    min-height: 30px;
    padding: 5px 8px;
    font-size: 11px;
    background: #123f8c;
    color: #ffffff;
    opacity: 1;
  }

  .product-form.mobile-collapsed {
    display: none;
  }

  .grid-form,
  .admin-password-form,
  .family-form,
  .product-form {
    grid-template-columns: 1fr;
    padding: 14px;
    box-shadow: none;
  }

  .family-members,
  .member-fields {
    grid-template-columns: 1fr;
  }

  .form-actions {
    width: 100%;
    flex-direction: column;
  }

  .form-actions button,
  .topbar button {
    width: 100%;
  }

  .table-wrap {
    border: 0;
    background: transparent;
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tr {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 12px;
    overflow: hidden;
  }

  tr.family-start-row {
    border-top: 4px solid var(--accent);
  }

  tr.family-start-row:first-child {
    border-top: 1px solid var(--line);
  }

  td {
    display: grid;
    grid-template-columns: 112px 1fr;
    gap: 12px;
    min-height: 44px;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    text-align: left;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
  }

  th:first-child,
  td:first-child {
    width: 100%;
    text-align: left;
  }

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

  .row-actions button {
    width: 100%;
  }

  .empty-row {
    display: block;
    text-align: center;
  }

  .empty-row::before {
    content: "";
  }

  .shopping-item {
    grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    padding: 12px 10px;
    border-color: #cdd8da;
    box-shadow: 0 8px 24px rgba(30, 42, 48, 0.08);
  }

  .shopping-item.has-photo {
    grid-template-columns: 38px minmax(0, 1fr) auto;
  }

  .item-photo {
    width: 86px;
    height: 68px;
  }

  .photo-viewer {
    padding: 12px;
  }

  .photo-viewer img {
    max-height: 78vh;
  }

  .photo-viewer-close {
    top: 10px;
    right: 10px;
    min-height: 34px;
    padding: 7px 10px;
    font-size: 12px;
  }

  .item-actions {
    grid-column: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: auto;
  }

  .item-actions button {
    min-height: 32px;
    width: 74px;
    padding: 6px 8px;
    font-size: 12px;
  }

  .item-title {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    font-size: 20px;
    line-height: 1.15;
  }

  .item-title span:first-child {
    overflow-wrap: anywhere;
    font-weight: 900;
  }

  .item-qty {
    align-self: start;
    padding: 3px 7px;
    font-size: 12px;
  }

  .item-details {
    font-size: 13px;
  }

  .check-btn {
    width: 34px;
    height: 34px;
    min-height: 34px;
    font-size: 18px;
  }
}
