:root {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #0f2b46;
  --primary-accent: #1d4ed8;
  --primary-soft: #eff6ff;

  --good: #059669;
  --good-bg: #ecfdf5;
  --good-border: #6ee7b7;

  --medium: #d97706;
  --medium-bg: #fffbeb;
  --medium-border: #fcd34d;

  --bad: #dc2626;
  --bad-bg: #fef2f2;
  --bad-border: #fca5a5;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.16);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
}

.container {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 0 14px;
}

/* Header */
.app-header {
  background: linear-gradient(135deg, #0f2b46 0%, #163d63 100%);
  color: #ffffff;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 0 20px;
  box-shadow: 0 4px 16px rgba(15, 43, 70, 0.18);
  position: sticky;
  top: 0;
  z-index: 30;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-text h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.header-text p {
  margin: 3px 0 0;
  font-size: 0.84rem;
  color: rgba(255, 255, 255, 0.82);
}

.header-pill {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Main */
.app-main {
  padding-top: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.user-card.has-error {
  border-color: var(--bad);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

/* Access Gate & Personal Member Banner */
.access-gate {
  text-align: center;
  padding: 36px 22px;
  margin-top: 18px;
}

.gate-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.access-gate h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  color: var(--text);
}

.access-gate p {
  margin: 0 0 18px;
  font-size: 0.92rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.member-banner {
  background: linear-gradient(135deg, #eff6ff 0%, #ffffff 100%);
  border-color: #bfdbfe;
}

.member-banner-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.member-banner-name {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.01em;
}

.member-banner-meta {
  margin-top: 3px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.member-status-pill {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
  white-space: nowrap;
}

.member-status-pill.is-sent {
  background: var(--good-bg);
  color: var(--good);
  border: 1px solid var(--good-border);
}

.field-label {
  display: block;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.field-label .req {
  color: var(--bad);
}

.field-label .opt {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.82rem;
}

.text-input,
.textarea-input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  /* Prevents iOS zoom on focus */
  color: var(--text);
  background: var(--surface-muted);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.text-input:focus,
.textarea-input:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--primary-accent);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.textarea-input {
  resize: vertical;
  min-height: 76px;
}

.field-error {
  margin: 6px 0 0;
  color: var(--bad);
  font-size: 0.82rem;
  font-weight: 600;
}

/* Filter Bar */
.filter-bar {
  margin: 12px 0 10px;
}

.chips-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.chips-scroll::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.helper-hint {
  margin: 8px 2px 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Material Cards */
.materials-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
}

.material-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.material-card.is-selected {
  border-color: var(--primary-accent);
  box-shadow: 0 4px 16px rgba(29, 78, 216, 0.1);
}

.material-card.has-error {
  border-color: var(--bad);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

.material-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.thumb-btn {
  position: relative;
  flex-shrink: 0;
  width: 78px;
  height: 78px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #f1f5f9;
  padding: 4px;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb-btn img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.thumb-zoom-badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.65);
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.material-info {
  flex: 1;
  min-width: 0;
}

.material-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

.badge-brand {
  background: var(--primary-soft);
  color: var(--primary-accent);
}

.badge-code {
  background: #f1f5f9;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.badge-light {
  background: #fef3c7;
  color: #92400e;
}

.material-name {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}

.material-desc {
  margin: 3px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Quantity bar at top of card */
.qty-bar {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.qty-bar-label {
  display: flex;
  flex-direction: column;
}

.qty-bar-label strong {
  font-size: 0.86rem;
  color: var(--text);
}

.qty-bar-label span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Entries inside a material card */
.entries-wrap {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.entry-block {
  background: var(--surface-muted);
  border: 1.5px solid var(--border);
  border-radius: 13px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: fadeSlide 0.18s ease;
}


  .entry-block.has-error {
    border-color: var(--bad);
    background: #fff7f7;
  }

  .entry-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .unit-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--primary);
    background: #e0ecff;
    padding: 3px 10px;
    border-radius: 999px;
  }

  .unit-status-hint {
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--text-muted);
  }

  .unit-status-hint.complete {
    color: var(--good);
  }

  .control-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .control-label {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  /* 3-way Segmented Pills */
  .pill-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .pill-btn {
    appearance: none;
    border: 1.5px solid var(--border);
    background: #ffffff;
    color: var(--text);
    font: inherit;
    font-size: 0.88rem;
    font-weight: 700;
    padding: 10px 6px;
    border-radius: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all 0.14s ease;
    user-select: none;
  }

  .pill-btn:active {
    transform: scale(0.97);
  }

  .pill-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  .pill-btn[data-val="good"] .pill-dot {
    background: var(--good);
  }

  .pill-btn[data-val="medium"] .pill-dot {
    background: var(--medium);
  }

  .pill-btn[data-val="bad"] .pill-dot {
    background: var(--bad);
  }

  .pill-btn.active[data-val="good"] {
    background: var(--good-bg);
    border-color: var(--good);
    color: #065f46;
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.16);
  }

  .pill-btn.active[data-val="medium"] {
    background: var(--medium-bg);
    border-color: var(--medium);
    color: #92400e;
    box-shadow: 0 2px 8px rgba(217, 119, 6, 0.16);
  }

  .pill-btn.active[data-val="bad"] {
    background: var(--bad-bg);
    border-color: var(--bad);
    color: #991b1b;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.16);
  }

  @keyframes fadeSlide {
    from {
      opacity: 0;
      transform: translateY(-4px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .lighting-box {
    background: #fffdf5;
    border: 1px solid #fde68a;
    border-radius: 11px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 7px;
  }

  .lighting-box.has-error {
    border-color: var(--bad);
    background: #fff5f5;
  }

  .lighting-box .control-label {
    display: flex;
    align-items: center;
    gap: 5px;
    color: #92400e;
  }

  .qty-stepper {
    display: inline-flex;
    align-items: center;
    border: 1.5px solid var(--border-strong);
    border-radius: 12px;
    background: #ffffff;
    overflow: hidden;
    flex-shrink: 0;
  }

  .material-card.is-selected .qty-stepper {
    border-color: var(--primary-accent);
    background: var(--primary-soft);
  }

  .qty-btn {
    width: 42px;
    height: 40px;
    border: none;
    background: transparent;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }


    .qty-btn:disabled {
      opacity: 0.3;
      cursor: not-allowed;
    }

    .qty-btn:not(:disabled):active {
      background: rgba(29, 78, 216, 0.14);
    }

    .qty-val {
      min-width: 34px;
      text-align: center;
      font-size: 1rem;
      font-weight: 800;
      color: var(--text);
    }

    .comment-input {
      width: 100%;
      font: inherit;
      font-size: 15px;
      color: var(--text);
      background: #ffffff;
      border: 1.5px solid var(--border);
      border-radius: 10px;
      padding: 9px 12px;
      height: 42px;
    }

    .comment-input:focus {
      outline: none;
      border-color: var(--primary-accent);
      box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.1);
    }

    /* Sticky Submit Bar */
    .sticky-bar {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(255, 255, 255, 0.96);
      backdrop-filter: blur(10px);
      border-top: 1px solid var(--border);
      padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
      box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08);
      z-index: 40;
    }

    .sticky-inner {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
    }

    .sticky-summary {
      display: flex;
      flex-direction: column;
      min-width: 0;
    }

    .sticky-summary strong {
      font-size: 0.92rem;
      color: var(--text);
    }

    .sticky-summary span {
      font-size: 0.76rem;
      color: var(--text-muted);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .btn-submit {
      flex-shrink: 0;
      border: none;
      background: var(--primary);
      color: #ffffff;
      font: inherit;
      font-size: 0.96rem;
      font-weight: 700;
      padding: 13px 26px;
      border-radius: 12px;
      cursor: pointer;
      box-shadow: 0 4px 12px rgba(15, 43, 70, 0.24);
      transition: transform 0.12s ease, background 0.15s ease;
    }

    .btn-submit:active {
      transform: scale(0.97);
    }

    .btn-submit:hover {
      background: #173c61;
    }

    /* Footer */
    .app-footer {
      text-align: center;
      padding: 8px 0 24px;
    }

    .discrete-admin-link {
      font-size: 0.76rem;
      color: #94a3b8;
      text-decoration: none;
    }

    .discrete-admin-link:hover {
      color: var(--primary-accent);
      text-decoration: underline;
    }

    /* Empty State */
    .empty-state {
      text-align: center;
      padding: 36px 20px;
      background: var(--surface);
      border: 1px dashed var(--border-strong);
      border-radius: var(--radius);
      color: var(--text-muted);
    }

    /* Modals */
    .modal-backdrop {
      position: fixed;
      inset: 0;
      background: rgba(15, 23, 42, 0.65);
      backdrop-filter: blur(4px);
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 16px;
      z-index: 100;
    }

    .modal-backdrop[hidden] {
      display: none;
    }

    .lightbox-box {
      background: #ffffff;
      border-radius: var(--radius);
      width: 100%;
      max-width: 480px;
      max-height: 88vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      box-shadow: var(--shadow-lg);
    }

    .lightbox-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 14px 16px;
      border-bottom: 1px solid var(--border);
      gap: 10px;
    }

    .lightbox-header h3 {
      margin: 0;
      font-size: 1rem;
    }

    .lightbox-meta {
      font-size: 0.78rem;
      color: var(--text-muted);
    }

    .icon-close-btn {
      border: none;
      background: #f1f5f9;
      color: var(--text);
      width: 34px;
      height: 34px;
      border-radius: 50%;
      font-size: 1.4rem;
      line-height: 1;
      cursor: pointer;
      flex-shrink: 0;
    }

    .lightbox-img-wrap {
      padding: 16px;
      background: #f8fafc;
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: auto;
    }

    .lightbox-img-wrap img {
      max-width: 100%;
      max-height: 68vh;
      object-fit: contain;
      border-radius: 8px;
    }

    /* Success & Confirm Modals */
    .success-box {
      background: #ffffff;
      border-radius: 18px;
      width: 100%;
      max-width: 460px;
      max-height: 92vh;
      padding: 16px 14px 14px;
      display: flex;
      flex-direction: column;
      text-align: center;
      box-shadow: var(--shadow-lg);
    }

    .success-icon {
      width: 38px;
      height: 38px;
      border-radius: 50%;
      background: var(--good-bg);
      color: var(--good);
      border: 2px solid var(--good-border);
      font-size: 1.2rem;
      font-weight: 800;
      display: flex;
      align-items: center;
      justify-content: center;
      margin: 0 auto 8px;
    }

    .success-box h2 {
      margin: 0;
      font-size: 1.05rem;
    }

    .success-sub {
      margin: 3px 0 10px;
      font-size: 0.78rem;
      color: var(--text-muted);
    }

    .success-summary-list {
      text-align: left;
      background: var(--surface-muted);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 6px 8px;
      overflow-y: auto;
      max-height: 62vh;
      display: flex;
      flex-direction: column;
      gap: 0;
      margin-bottom: 12px;
    }

    .summary-row {
      font-size: 0.72rem;
      line-height: 1.2;
      padding: 4px 0;
      border-bottom: 1px solid var(--border);
    }

    .summary-row:last-child {
      border-bottom: none;
      padding-bottom: 1px;
    }

    .summary-row-main {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 6px;
    }

    .summary-row-name {
      font-weight: 700;
      color: var(--text);
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .summary-row-unit {
      font-weight: 600;
      color: var(--text-muted);
      margin-left: 3px;
    }

    .summary-tags {
      display: flex;
      align-items: center;
      flex-shrink: 0;
      gap: 4px;
    }

    .summary-row-comment {
      margin-top: 2px;
      font-size: 0.66rem;
      color: #64748b;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .tag-chip {
      background: #ffffff;
      border: 1px solid var(--border);
      border-radius: 5px;
      padding: 1px 5px;
      font-size: 0.66rem;
      font-weight: 700;
      line-height: 1.25;
      white-space: nowrap;
    }

    .tag-chip.good {
      color: #065f46;
      border-color: var(--good-border);
      background: var(--good-bg);
    }

    .tag-chip.medium {
      color: #92400e;
      border-color: var(--medium-border);
      background: var(--medium-bg);
    }

    .tag-chip.bad {
      color: #991b1b;
      border-color: var(--bad-border);
      background: var(--bad-bg);
    }

    .confirm-icon {
      width: 38px;
      height: 38px;
      border-radius: 50%;
      background: var(--primary-soft);
      color: var(--primary-accent);
      border: 2px solid #bfdbfe;
      font-size: 1.15rem;
      font-weight: 800;
      display: flex;
      align-items: center;
      justify-content: center;
      margin: 0 auto 8px;
    }

    .confirm-actions {
      display: grid;
      grid-template-columns: 1fr 1.3fr;
      gap: 10px;
    }

    .btn-secondary-full {
      width: 100%;
      border: 1.5px solid var(--border-strong);
      background: var(--surface);
      color: var(--text);
      font: inherit;
      font-size: 0.94rem;
      font-weight: 700;
      padding: 13px;
      border-radius: 12px;
      cursor: pointer;
    }

    .btn-secondary-full:active {
      background: var(--surface-muted);
    }

    .btn-primary-full {
      width: 100%;
      border: none;
      background: var(--primary);
      color: #ffffff;
      font: inherit;
      font-size: 0.96rem;
      font-weight: 700;
      padding: 13px;
      border-radius: 12px;
      cursor: pointer;
    }

    /* Toast */
    .toast {
      position: fixed;
      left: 50%;
      bottom: calc(86px + env(safe-area-inset-bottom, 0px));
      transform: translateX(-50%);
      background: #0f172a;
      color: #ffffff;
      font-size: 0.86rem;
      font-weight: 600;
      padding: 10px 16px;
      border-radius: 999px;
      box-shadow: var(--shadow-lg);
      z-index: 120;
      max-width: 90vw;
      text-align: center;
    }

    .toast.error {
      background: #b91c1c;
    }