/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green: #16A34A;
  --green-light: #DCFCE7;
  --green-dark: #15803D;
  --amber: #D97706;
  --amber-light: #FEF3C7;
  --red: #DC2626;
  --red-light: #FEE2E2;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --white: #FFFFFF;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ===== HEADER ===== */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between;
}
.header-left, .header-right { display: flex; align-items: center; gap: 12px; }
.app-logo { display: flex; align-items: center; gap: 10px; }
.app-name { font-weight: 700; font-size: 1.1rem; color: var(--gray-900); letter-spacing: -0.02em; }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--gray-300);
  transition: background 0.3s;
}
.status-dot.ok { background: var(--green); }
.status-dot.err { background: var(--red); }

.push-badge {
  background: var(--amber); color: var(--white);
  border: none; border-radius: 999px;
  padding: 4px 10px; font-size: 0.75rem; font-weight: 700;
  cursor: pointer;
}
.push-badge.hidden { display: none; }

/* ===== MAIN ===== */
.main-content {
  max-width: 600px; margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 16px;
}

/* ===== IMPORT ===== */
.import-section { display: flex; flex-direction: column; gap: 10px; }

textarea {
  width: 100%;
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 14px;
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--gray-900);
  resize: vertical;
  line-height: 1.6;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
textarea:focus { outline: none; border-color: var(--green); }
textarea::placeholder { color: var(--gray-400); }

/* ===== BUTTONS ===== */
.btn-primary {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 13px 20px;
  background: var(--green); color: var(--white);
  border: none; border-radius: var(--radius-md);
  font-family: var(--font); font-size: 0.95rem; font-weight: 600;
  cursor: pointer; transition: background 0.15s, transform 0.1s;
  box-shadow: var(--shadow-sm);
  -webkit-appearance: none;
}
.btn-primary:active { background: var(--green-dark); transform: scale(0.99); }
.btn-primary:disabled { background: var(--gray-300); cursor: not-allowed; transform: none; }

.btn-ghost {
  display: flex; align-items: center; justify-content: center;
  width: 100%; padding: 11px 20px;
  background: transparent; color: var(--gray-500);
  border: 1.5px solid var(--gray-200); border-radius: var(--radius-md);
  font-family: var(--font); font-size: 0.9rem; font-weight: 500;
  cursor: pointer;
  -webkit-appearance: none;
}

.btn-chip {
  padding: 6px 14px;
  border-radius: 999px;
  font-family: var(--font); font-size: 0.82rem; font-weight: 500;
  border: 1.5px solid var(--gray-200);
  background: var(--white); color: var(--gray-500);
  cursor: pointer; transition: all 0.15s;
  -webkit-appearance: none;
}
.btn-chip.active { background: var(--green-light); color: var(--green-dark); border-color: var(--green); }
.btn-chip:active { transform: scale(0.97); }

/* ===== RESULT ===== */
.result-section { display: flex; flex-direction: column; gap: 12px; }
.hidden { display: none !important; }

.section-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 0 2px 8px;
  margin-bottom: 4px;
}
.section-label.warn { color: var(--amber); }
.section-label.ok { color: var(--green-dark); }

/* ===== QUEUE CARDS ===== */
.queue-section, .matched-section { display: flex; flex-direction: column; gap: 8px; }

.queue-card {
  background: var(--white);
  border: 1.5px solid var(--amber-light);
  border-left: 4px solid var(--amber);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 10px;
}
.queue-raw { font-weight: 600; font-size: 0.95rem; color: var(--gray-900); }
.queue-raw .qty-badge {
  display: inline-block;
  background: var(--gray-100); color: var(--gray-500);
  border-radius: 6px; padding: 2px 7px;
  font-size: 0.78rem; font-weight: 500;
  margin-left: 6px;
}

.queue-suggestions { display: flex; flex-wrap: wrap; gap: 6px; }
.suggestion-chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--gray-100); color: var(--gray-700);
  font-size: 0.8rem; font-weight: 500;
  border: 1.5px solid var(--gray-200);
  cursor: pointer; transition: all 0.15s;
}
.suggestion-chip:hover { background: var(--green-light); border-color: var(--green); color: var(--green-dark); }
.suggestion-chip .conf { color: var(--gray-400); font-size: 0.75rem; margin-left: 4px; }

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

/* ===== ALIAS FORM ===== */
.alias-form, .new-prod-form {
  display: flex; flex-direction: column; gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--gray-100);
}

input[type="text"], input[type="number"], select {
  width: 100%; padding: 10px 12px;
  background: var(--gray-50);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 0.9rem; color: var(--gray-900);
  -webkit-appearance: none; appearance: none;
  transition: border-color 0.2s;
}
input:focus, select:focus { outline: none; border-color: var(--green); background: var(--white); }
input::placeholder { color: var(--gray-400); }

.alias-results, .np-link-results {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 200px; overflow-y: auto;
}
.search-result-item {
  padding: 10px 12px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 0.88rem; cursor: pointer;
  transition: background 0.1s;
}
.search-result-item:active { background: var(--green-light); }
.search-result-item .grp { color: var(--gray-400); font-size: 0.8rem; }

/* Conversion row */
.np-conversion {
  display: flex; align-items: center; gap: 8px;
}
.np-conversion select, .np-conversion input { flex: 1; }
.conv-label { color: var(--gray-500); font-size: 0.9rem; font-weight: 500; flex-shrink: 0; }

/* Link checkbox */
.np-link-label {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.85rem; color: var(--gray-500);
  cursor: pointer;
}
.np-link-label input[type="checkbox"] {
  width: 16px; height: 16px; flex-shrink: 0;
  accent-color: var(--green);
}
.np-link-search { display: flex; flex-direction: column; gap: 8px; }

/* ===== MATCHED ITEMS ===== */
.matched-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-left: 3px solid var(--green);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}
.matched-name { font-weight: 500; font-size: 0.92rem; color: var(--gray-900); }
.matched-qty {
  font-size: 0.82rem; color: var(--gray-400);
  background: var(--gray-100); padding: 3px 8px; border-radius: 6px;
  white-space: nowrap;
}

/* ===== CREATE LIST BUTTON ===== */
.create-list-section { display: flex; flex-direction: column; gap: 8px; }

.btn-create-list {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 16px 20px;
  background: var(--green); color: var(--white);
  border: none; border-radius: var(--radius-lg);
  font-family: var(--font); font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: background 0.15s, transform 0.1s;
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
  -webkit-appearance: none;
}
.btn-create-list:active { background: var(--green-dark); transform: scale(0.99); }
.btn-create-list:disabled { background: var(--gray-300); box-shadow: none; cursor: not-allowed; }

.create-hint { font-size: 0.82rem; color: var(--gray-400); text-align: center; }

/* ===== MODAL ===== */
.modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal-card {
  background: var(--white);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  width: 100%; max-width: 600px;
  display: flex; flex-direction: column; gap: 12px;
  max-height: 80dvh; overflow-y: auto;
}
.modal-title { font-weight: 700; font-size: 1.05rem; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: var(--gray-900); color: var(--white);
  padding: 12px 20px; border-radius: 999px;
  font-size: 0.88rem; font-weight: 500;
  z-index: 300; white-space: nowrap;
  animation: toastIn 0.2s ease, toastOut 0.2s ease 2.8s forwards;
  box-shadow: var(--shadow-lg);
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(-50%) translateY(8px); } }
