/* ── Layout ── */
.page { max-width: 720px; margin: 0 auto; padding: 28px 20px 64px; }

/* ── Search row (input + scan button) ── */
.search-row { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.search-wrap { position: relative; flex: 1; min-width: 0; }
.search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; display: flex; }
.search-input {
  width: 100%; padding: 14px 110px 14px 44px;
  border: 1.5px solid var(--border); border-radius: 14px;
  font-family: var(--font); font-size: 1rem; color: var(--text);
  background: var(--bg); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.search-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,122,255,0.12); }
.search-input::placeholder { color: var(--text-muted); }

.search-badge {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em;
  padding: 3px 8px; border-radius: 6px; white-space: nowrap;
  pointer-events: none; transition: background 0.15s, color 0.15s;
}
.search-badge.type-text    { background: #f0f0f5; color: var(--text-muted); }
.search-badge.type-cnk     { background: #fff3e0; color: #b36200; }
.search-badge.type-cnk-ok  { background: #ff9500; color: #fff; }
.search-badge.type-fmd     { background: #e3f0ff; color: var(--blue-dark); }
.search-badge.type-fmd-ok  { background: var(--blue); color: #fff; }

/* ── Scan button ── */
.btn-scan {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  height: 50px; padding: 0 16px;
  background: var(--bg); border: 1.5px solid var(--border); border-radius: 14px;
  font-family: var(--font); font-size: 0.88rem; font-weight: 600; color: var(--text-muted);
  cursor: pointer; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  transition: color 0.15s, border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.btn-scan:hover {
  color: var(--blue); border-color: var(--blue);
  background: var(--blue-light);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.1);
}
.btn-scan svg { flex-shrink: 0; }

/* ── Autocomplete dropdown ── */
.autocomplete {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 50;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: 14px; box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  overflow: hidden; display: none;
}
.autocomplete.open { display: block; }
.ac-item { display: flex; flex-direction: column; padding: 12px 16px; cursor: pointer; transition: background 0.1s; border-bottom: 1px solid var(--border); }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.focused { background: var(--bg-subtle); }
.ac-name { font-size: 0.92rem; font-weight: 600; color: var(--text); }
.ac-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.ac-code { font-size: 0.72rem; font-family: monospace; color: var(--blue); margin-top: 2px; }
.ac-empty { padding: 20px 16px; text-align: center; font-size: 0.9rem; color: var(--text-muted); }
.ac-loading { padding: 16px; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--text-muted); font-size: 0.88rem; }

/* ── Add form ── */
.add-form-wrap {
  background: var(--bg); border: 1.5px solid var(--blue); border-radius: 16px;
  padding: 20px; margin-bottom: 20px;
  box-shadow: 0 4px 20px rgba(0,122,255,0.08);
  display: none;
}
.add-form-wrap.open { display: block; animation: slideDown 0.18s ease; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

.selected-med { margin-bottom: 16px; }
.selected-med-name { font-size: 1rem; font-weight: 700; color: var(--text); }
.selected-med-meta { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }

.add-form-fields { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: end; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); }
.form-group input {
  padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border);
  font-family: var(--font); font-size: 0.92rem; color: var(--text);
  background: var(--bg); outline: none; transition: border-color 0.15s;
}
.form-group input:focus { border-color: var(--blue); }

/* quantity stepper */
.qty-stepper { display: flex; align-items: center; gap: 0; border: 1.5px solid var(--border); border-radius: 10px; overflow: hidden; }
.qty-btn { width: 36px; height: 40px; background: var(--bg-subtle); border: none; font-size: 1.1rem; font-weight: 500; color: var(--text); cursor: pointer; transition: background 0.12s; flex-shrink: 0; }
.qty-btn:hover { background: var(--border); }
.qty-val { min-width: 36px; text-align: center; font-size: 0.95rem; font-weight: 600; color: var(--text); padding: 0 4px; border-left: 1.5px solid var(--border); border-right: 1.5px solid var(--border); line-height: 40px; }

.add-form-actions { display: flex; gap: 10px; margin-top: 16px; }
.btn-add {
  flex: 1; padding: 12px; border-radius: 12px; border: none;
  background: var(--blue); color: #fff; font-family: var(--font);
  font-size: 0.92rem; font-weight: 600; cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-add:hover { background: var(--blue-dark); }
.btn-add:active { transform: scale(0.98); }
.btn-add:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-cancel-add { padding: 12px 20px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--bg); color: var(--text-muted); font-family: var(--font); font-size: 0.92rem; font-weight: 600; cursor: pointer; transition: background 0.15s; }
.btn-cancel-add:hover { background: var(--bg-subtle); }

.form-error { font-size: 0.82rem; color: var(--red); margin-top: 8px; display: none; }
.form-error.visible { display: block; }

/* ── Household tabs ── */
.hh-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.hh-tab { padding: 6px 16px; border-radius: 20px; border: 1.5px solid var(--border); background: var(--bg); font-family: var(--font); font-size: 0.85rem; font-weight: 600; color: var(--text-muted); cursor: pointer; transition: all 0.15s; }
.hh-tab.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.hh-tab:hover:not(.active) { background: var(--bg-subtle); }

/* ── Search section label ── */
.search-section-label {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-muted);
  margin-bottom: 8px;
}

/* ── Cabinet section ── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; margin-top: 28px; }
.section-title { font-size: 1rem; font-weight: 700; color: var(--text); }
.section-count { font-size: 0.82rem; color: var(--text-muted); }

/* ── Filter input ── */
.filter-wrap { position: relative; margin-bottom: 12px; }
.filter-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; display: flex; }
.filter-input {
  width: 100%; padding: 9px 12px 9px 36px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-family: var(--font); font-size: 0.88rem; color: var(--text);
  background: var(--bg); outline: none;
  transition: border-color 0.15s;
}
.filter-input:focus { border-color: var(--blue); }
.filter-input::placeholder { color: var(--text-muted); }

/* ── Cabinet table ── */
.cabinet-table-wrap { overflow-x: auto; border-radius: 14px; border: 1px solid var(--border); background: var(--bg); box-shadow: 0 1px 6px rgba(0,0,0,0.04); }
.cabinet-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.cabinet-table thead th {
  padding: 11px 14px; text-align: left;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-muted);
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.cabinet-table thead th:last-child { width: 36px; }
.cabinet-table thead th[data-col] {
  cursor: pointer; user-select: none;
  transition: color 0.15s, background 0.15s;
}
.cabinet-table thead th[data-col]:hover { color: var(--text); background: #ededf2; }
.cabinet-table thead th[data-col].sort-active { color: var(--blue); }
.sort-icon { display: inline-block; margin-left: 5px; opacity: 0.35; font-style: normal; font-size: 0.7rem; vertical-align: middle; transition: opacity 0.15s; }
th[data-col]:hover .sort-icon { opacity: 0.6; }
th.sort-active .sort-icon { opacity: 1; }
.cabinet-table tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; animation: fadeIn 0.2s ease; }
.cabinet-table tbody tr:last-child { border-bottom: none; }
.cabinet-table tbody tr:hover { background: var(--bg-subtle); }
.cabinet-table tbody td { padding: 12px 14px; vertical-align: middle; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.td-name { font-weight: 600; color: var(--text); max-width: 220px; }
.td-name-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.td-expiry { white-space: nowrap; }
.td-batch { color: var(--text-muted); font-size: 0.82rem; font-family: monospace; }
.td-added { color: var(--text-muted); font-size: 0.8rem; white-space: nowrap; }

.qty-badge { background: var(--blue-light); color: var(--blue); font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 6px; }

.expiry-badge { font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.expiry-expired { background: #fff0ef; color: var(--red); }
.expiry-soon    { background: #fff5e0; color: var(--orange); }
.expiry-ok      { background: #eafff0; color: #1a7f37; }
.expiry-none    { color: var(--text-muted); font-size: 0.8rem; }

.btn-delete { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 6px; border-radius: 8px; display: flex; align-items: center; justify-content: center; transition: color 0.15s, background 0.15s; }
.btn-delete:hover { color: var(--red); background: #fff0ef; }

/* ── Empty row ── */
.tr-empty td { padding: 40px 14px; text-align: center; color: var(--text-muted); font-size: 0.9rem; }

/* ── Skeleton rows ── */
.skeleton { background: linear-gradient(90deg, var(--border) 25%, #f0f0f5 50%, var(--border) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 4px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.sk-cell { height: 14px; border-radius: 4px; }

/* ── Scan overlay ── */
.scan-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.75);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.scan-overlay.open { display: flex; }
.scan-modal {
  background: var(--bg); border-radius: 20px;
  width: min(400px, 100%); overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,0.4);
}
.scan-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.scan-title { font-size: 1rem; font-weight: 700; color: var(--text); }
.scan-close {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--bg-subtle); color: var(--text-muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.scan-close:hover { background: var(--border); }
.scan-viewfinder {
  position: relative; aspect-ratio: 1; background: #111; overflow: hidden;
}
.scan-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-line {
  position: absolute; left: 10%; right: 10%; height: 2px;
  background: linear-gradient(90deg, transparent, var(--blue), transparent);
  box-shadow: 0 0 8px var(--blue);
  animation: scanSweep 1.8s ease-in-out infinite;
  pointer-events: none;
}
@keyframes scanSweep { 0%, 100% { top: 15%; } 50% { top: 85%; } }
.scan-corners { position: absolute; inset: 0; pointer-events: none; }
.scan-corners span {
  position: absolute; width: 24px; height: 24px;
  border-color: rgba(255,255,255,0.9); border-style: solid; border-width: 0;
}
.scan-corners span:nth-child(1) { top: 10%;    left: 10%;  border-top-width: 3px; border-left-width: 3px;   border-radius: 3px 0 0 0; }
.scan-corners span:nth-child(2) { top: 10%;    right: 10%; border-top-width: 3px; border-right-width: 3px;  border-radius: 0 3px 0 0; }
.scan-corners span:nth-child(3) { bottom: 10%; left: 10%;  border-bottom-width: 3px; border-left-width: 3px; border-radius: 0 0 0 3px; }
.scan-corners span:nth-child(4) { bottom: 10%; right: 10%; border-bottom-width: 3px; border-right-width: 3px; border-radius: 0 0 3px 0; }
.scan-hint {
  text-align: center; font-size: 0.85rem; color: var(--text-muted);
  padding: 14px 20px 0; min-height: 44px; line-height: 1.4;
}
.btn-scan-file {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 14px 20px 20px; padding: 12px;
  border: 1.5px dashed var(--border); border-radius: 12px;
  font-family: var(--font); font-size: 0.88rem; font-weight: 500; color: var(--text-muted);
  cursor: pointer; transition: border-color 0.15s, color 0.15s;
}
.btn-scan-file:hover { border-color: var(--blue); color: var(--blue); }

/* ── Responsive ── */
@media (max-width: 600px) {
  .add-form-fields { grid-template-columns: 1fr 1fr; }
  .add-form-fields .form-group:last-child { grid-column: 1 / -1; }
  .nav-title { display: none; }
  .td-batch, .td-added { display: none; }
}
