* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: #f3f5f7;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: #f3f5f7;
  color: #1a1f24;
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
}

a {
  color: #0f7a5f;
  text-decoration: none;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: #14211c;
  color: #eef3f0;
  flex-wrap: wrap;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.today-label {
  color: #b9c6bf;
  font-size: 13px;
}

.conn-text {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #2a3a33;
  color: #cfd9d4;
}

.conn-text.conn-ok {
  background: #1d5c45;
  color: #d7f0e4;
}

.conn-text.conn-warn {
  background: #5c4a1d;
  color: #f0e6d7;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: #e8edf0;
  color: #1a1f24;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
  opacity: 0.88;
}

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

.btn-primary {
  background: #0f7a5f;
  color: #fff;
}

.btn-danger {
  background: #b3402f;
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: #eef3f0;
  border-color: #3a4c43;
}

.btn-danger-ghost {
  background: transparent;
  color: #e8a99d;
  border-color: #6a3a30;
}

.btn-mini {
  padding: 3px 8px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

/* ---------- Pin screen ---------- */
.pin-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #14211c;
}

.pin-box {
  background: #fff;
  border-radius: 14px;
  padding: 32px;
  width: 320px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.pin-box .app-title {
  color: #14211c;
  margin-bottom: 4px;
}

.pin-sub {
  color: #6b7680;
  font-size: 13px;
  margin-bottom: 18px;
}

.pin-input {
  width: 100%;
  padding: 10px 12px;
  font-size: 18px;
  text-align: center;
  letter-spacing: 6px;
  border: 1px solid #cfd6db;
  border-radius: 8px;
  margin-bottom: 12px;
}

.pin-back {
  display: inline-block;
  margin-top: 14px;
  font-size: 13px;
}

.login-input {
  letter-spacing: normal;
  text-align: left;
  font-size: 14px;
}

.login-error {
  color: #c62828;
  font-size: 13px;
  margin: 0 0 12px;
}

/* ---------- Dropzone ---------- */
.dropzone {
  margin: 20px 24px 0;
  padding: 48px 20px;
  border: 2px dashed #b9c4cc;
  border-radius: 12px;
  background: #fff;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.drag-over {
  border-color: #0f7a5f;
  background: #eef8f3;
}

.drop-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.drop-sub {
  color: #6b7680;
  font-size: 13px;
  margin-bottom: 18px;
}

/* ---------- Status / preview ---------- */
.parse-status {
  margin: 14px 24px 0;
  font-size: 13px;
  color: #6b7680;
}

.preview-wrap {
  margin: 14px 24px 24px;
  background: #fff;
  border: 1px solid #e3e8ec;
  border-radius: 12px;
  overflow: auto;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.preview-table th {
  text-align: left;
  padding: 10px 12px;
  background: #f6f8f9;
  border-bottom: 1px solid #e3e8ec;
  color: #5a6670;
  font-weight: 600;
  white-space: nowrap;
}

.preview-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #eef1f3;
  vertical-align: top;
}

.preview-table .cell-file,
.preview-table .cell-product {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.json-row td {
  background: #0f1612;
  padding: 0;
}

.json-pre {
  max-height: 300px;
  overflow: auto;
  padding: 12px;
  color: #d7e4dd;
  font-size: 12px;
  font-family: "Consolas", monospace;
}

.json-edit {
  padding: 12px;
}

.json-text {
  width: 100%;
  min-height: 200px;
  resize: vertical;
  background: #0f1612;
  color: #d7e4dd;
  font-family: "Consolas", monospace;
  font-size: 12px;
  line-height: 1.5;
  border: 1px solid #2a3a33;
  border-radius: 8px;
  padding: 10px;
  tab-size: 2;
}

.json-text:focus {
  outline: none;
  border-color: #0f7a5f;
}

.json-edit-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.json-edit-actions .btn {
  background: #2a3a33;
  color: #eef3f0;
}

.json-edit-actions .btn-apply {
  background: #0f7a5f;
  color: #fff;
}

.json-edit-status {
  font-size: 12px;
  font-weight: 600;
  margin-left: 4px;
}

.json-edit-status.json-ok {
  color: #8fd4b6;
}

.json-edit-status.json-err {
  color: #e8a99d;
}

.preview-actions {
  display: flex;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid #e3e8ec;
}

.thumb {
  display: block;
  width: 44px;
  height: 44px;
  object-fit: cover;
  border: 1px solid #e3e8ec;
  border-radius: 6px;
  background: #f0f2f4;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.q-high {
  background: #1d5c45;
  color: #d7f0e4;
}

.q-mid {
  background: #8a6d1d;
  color: #fdf3d7;
}

.q-low {
  background: #8a2f22;
  color: #f8ded8;
}

.badge-lab {
  background: #2b4a63;
  color: #d8e8f5;
}

.badge-strain {
  background: #4a2b63;
  color: #e8d8f5;
}

.badge-ok {
  background: #e3f2e9;
  color: #1d5c45;
}

.badge-warn {
  background: #fdf3d7;
  color: #8a6d1d;
}

/* ---------- Catalog controls ---------- */
.controls {
  display: flex;
  gap: 10px;
  padding: 16px 24px;
  flex-wrap: wrap;
  align-items: center;
  background: #fff;
  border-bottom: 1px solid #e3e8ec;
}

.search-input,
.select-input {
  padding: 9px 12px;
  border: 1px solid #cfd6db;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: #1a1f24;
}

.search-input {
  flex: 1 1 220px;
  min-width: 200px;
}

.count-label {
  font-size: 13px;
  color: #6b7680;
  white-space: nowrap;
}

.terpene-rows {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.terpene-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.terpene-pct {
  width: 76px;
  padding: 9px 8px;
  border: 1px solid #cfd6db;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: #1a1f24;
  text-align: right;
}

.terpene-row .btn-mini {
  padding: 8px 9px;
  line-height: 1;
}

.terpene-row .terpene-op {
  padding: 9px 8px;
}

.terpene-active {
  border-color: #0f7a5f;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: #14211c;
  white-space: nowrap;
}

.reports-section {
  margin-top: 28px;
  padding-top: 8px;
}

.catalog-search {
  background: #fff;
  border-bottom: 1px solid #e3e8ec;
}

.fb-banner {
  margin: 14px 24px 0;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
}

.fb-warn {
  background: #fdf3d7;
  color: #8a6d1d;
  border: 1px solid #ecd98a;
}

.fb-error {
  background: #f8ded8;
  color: #8a2f22;
  border: 1px solid #e8b3a9;
}

.publish-result {
  align-self: center;
  font-size: 13px;
  font-weight: 600;
}

.publish-result.pub-ok {
  color: #1d5c45;
}

.publish-result.pub-error {
  color: #8a2f22;
}

.results-wrap {
  margin: 0 24px 20px;
  background: #fff;
  border: 1px solid #e3e8ec;
  border-radius: 12px;
  overflow: auto;
}

/* ---------- Grid / cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  padding: 24px;
}

.card {
  background: #fff;
  border: 1px solid #e3e8ec;
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(20, 33, 28, 0.12);
}

.card-top {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.card-company {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #0f7a5f;
  font-weight: 700;
  margin-bottom: 2px;
  text-align: center;
}

.card-product {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  text-align: center;
}

.card-cat {
  font-size: 12px;
  color: #6b7680;
  margin-bottom: 8px;
  text-align: center;
}

.card-metrics {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  justify-content: center;
}

.metric {
  font-size: 12px;
  color: #4a5560;
}

.metric b {
  color: #1a1f24;
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.card-date {
  font-size: 12px;
  color: #8a95a0;
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: auto;
}

.card-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.2px;
  color: #0f7a5f;
  background: #eef7f3;
  border: 1px solid #d6ebe3;
  border-radius: 6px;
  padding: 2px 6px;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  color: #8a95a0;
  padding: 60px 20px;
}

/* ---------- Modal ---------- */
body.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 13, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow: auto;
  overscroll-behavior: contain;
  z-index: 50;
}

.modal {
  background: #fff;
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.modal-wide {
  max-width: 1040px;
}

.modal h3 {
  margin-bottom: 6px;
}

.modal-sub {
  color: #6b7680;
  font-size: 14px;
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

#detail-close {
  background: #fff;
  color: #111;
  border-color: #cfd6db;
}

#detail-report {
  background: #b3402f;
  color: #fff;
  border-color: #b3402f;
}

.report-field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #4a5560;
  margin: 12px 0 4px;
}

#report-backdrop .search-input,
#report-backdrop .select-input,
.report-textarea {
  width: 100%;
  box-sizing: border-box;
}

#report-backdrop .select-input {
  flex: none;
  min-width: 0;
}

.report-textarea {
  padding: 9px 12px;
  border: 1px solid #cfd6db;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: #1a1f24;
  resize: vertical;
  font-family: inherit;
}

.report-readonly {
  background: #f3f5f6;
  color: #4a5560;
}

.report-msg {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 600;
}

.report-msg-ok {
  color: #1d5c45;
}

.report-msg-error {
  color: #8a2f22;
}

/* ---------- Detail ---------- */
.detail-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.detail-image-box {
  flex: 0 0 320px;
  position: sticky;
  top: 0;
}

.detail-zoom-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid #e3e8ec;
  border-radius: 10px;
  background: #fafbfc;
  touch-action: none;
}

.detail-zoom-bar {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 8px;
  background: rgba(20, 33, 28, 0.72);
  color: #eef3f0;
}

.zoom-btn {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #eef3f0;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.zoom-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.18);
}

.zoom-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.detail-zoom-pct {
  min-width: 42px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.detail-image {
  display: block;
  width: 100%;
  max-height: 75vh;
  object-fit: contain;
  transform-origin: 0 0;
  background: #fafbfc;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.detail-image.zoom-anim {
  transition: transform 0.15s ease;
}

.detail-image.zoom-grab {
  cursor: grab;
}

.detail-image.zoom-grabbing {
  cursor: grabbing;
}

.img-loading {
  min-height: 260px;
  background: #eef1f3;
}

.detail-zoom-hint {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 2;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.85);
  color: #6b7680;
  font-size: 11px;
}

.detail-image-box.img-error .detail-zoom-stage {
  display: none;
}

.detail-image-box.img-error::after {
  content: "Image unavailable";
  display: block;
  text-align: center;
  color: #8a95a0;
  font-size: 13px;
  padding: 40px 12px;
  border: 1px dashed #cfd6db;
  border-radius: 10px;
}

.detail-content {
  flex: 1;
  min-width: 0;
}

.detail-head {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.detail-product {
  font-size: 22px;
  font-weight: 700;
}

.detail-company {
  color: #0f7a5f;
  font-weight: 600;
  margin-bottom: 12px;
}

.detail-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  font-size: 13px;
  margin-bottom: 16px;
}

.detail-meta dt {
  color: #8a95a0;
}

.detail-meta .mono {
  font-family: "Consolas", monospace;
  word-break: break-all;
}

.detail-section {
  margin-bottom: 18px;
}

.detail-section h4 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #4a5560;
  margin-bottom: 8px;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.detail-table th {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid #e3e8ec;
  color: #8a95a0;
  font-weight: 600;
  font-size: 12px;
}

.detail-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #eef1f3;
}

.cell-value {
  font-weight: 600;
  white-space: nowrap;
}

.status-tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: #f0f2f4;
  color: #6b7680;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}

.item-note {
  color: #8a95a0;
  font-size: 12px;
}

.table-note {
  text-transform: none;
  letter-spacing: 0;
  color: #8a6d1d;
  font-weight: 600;
  margin-left: 8px;
}

.compound-chart {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.compound-row {
  display: grid;
  grid-template-columns: minmax(120px, 34%) 1fr auto;
  align-items: center;
  gap: 12px;
  cursor: default;
}

.compound-label {
  min-width: 0;
}

.compound-name {
  font-size: 13px;
  font-weight: 650;
  color: #222;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.compound-name.compound-total {
  font-weight: 700;
}

.compound-effects {
  font-size: 11px;
  font-weight: 600;
  color: #4a5560;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.compound-track {
  height: 14px;
  background: #f0f2f4;
  border-radius: 4px;
  overflow: hidden;
}

.compound-fill {
  height: 100%;
  border-radius: 4px;
  min-width: 2px;
}

.compound-value {
  font-size: 12px;
  font-weight: 600;
  color: #333;
  white-space: nowrap;
  text-align: right;
}

.compound-empty {
  color: #8a95a0;
  font-size: 13px;
}

/* ---------- Effect meter ---------- */
.effect-meter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.effect-meter-head h4 {
  margin-bottom: 0;
}

.effect-meter-track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(to right, #FFC107 0%, #66BB6A 40%, #4CAF50 50%, #42A5F5 60%, #1565C0 100%);
  overflow: hidden;
}

.effect-meter-marker {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 16px;
  border-radius: 3px;
  background: #14211c;
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transform: translateX(-50%);
}

.effect-meter-scale-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #8a95a0;
  margin-top: 3px;
}

.effect-meter-label {
  font-size: 14px;
  font-weight: 700;
}

.effect-meter-result {
  margin-top: 8px;
}

.effect-meter-sub {
  font-size: 12px;
  color: #8a95a0;
}

.effect-meter-compact {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.effect-meter-compact .effect-meter-track {
  width: 100%;
}

.effect-meter-tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.strain-block .effect-meter-compact {
  margin-top: 8px;
}

.strain-block {
  border: 1px solid #e3e8ec;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fafbfc;
}

.strain-name {
  font-size: 15px;
  font-weight: 700;
  color: #14211c;
}

.detail-flags ul {
  margin-left: 18px;
  color: #8a2f22;
  font-size: 13px;
}

.detail-flags li {
  margin-bottom: 3px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #14211c;
  color: #eef3f0;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  z-index: 100;
}

.toast-error {
  background: #8a2f22;
}

/* ---------- Footer ---------- */
.footer {
  padding: 18px 24px 30px;
  padding-bottom: calc(30px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  color: #8a95a0;
  font-size: 13px;
}

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  body {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 64px);
  }

  .detail-layout {
    flex-direction: column;
  }

  .detail-image-box {
    flex: none;
    width: 100%;
    position: static;
  }

  .detail-image {
    max-height: 60vh;
  }

  .modal-backdrop {
    padding: 16px 10px;
    align-items: flex-start;
  }

  .modal {
    padding: 16px;
  }
}
