/* ============================================
   OrderFlow — style (jasny motyw, PackFlow-inspired)
   ============================================ */

:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #e2e8f0;
  --border-soft: #eef2f7;
  --border-strong: #cbd5e1;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.1);
  --success: #10b981;
  --success-bg: #d1fae5;
  --success-text: #065f46;
  --success-border: #a7f3d0;
  --error: #ef4444;
  --error-bg: #fee2e2;
  --error-text: #991b1b;
  --error-border: #fecaca;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --info-bg: #dbeafe;
  --info-text: #1e40af;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 9999px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: 'DM Mono', 'Courier New', monospace; }
.muted { color: var(--text-muted); }
.hidden { display: none !important; }
.req { color: var(--error); margin-left: 2px; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ======== Nagłówek ======== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 32px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.2px;
  color: var(--text);
}
.brand svg { color: var(--accent); }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar-user #userLabel {
  color: var(--text-muted);
  font-size: 13px;
}

/* ======== Karty ======== */
.card {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h1, .card h2 {
  margin: 0 0 14px 0;
  font-weight: 600;
  color: var(--text);
}
.card h1 { font-size: 22px; }
.card h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ======== Formularze ======== */
.field {
  margin-bottom: 10px;
}

.field label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input::placeholder, textarea::placeholder { color: var(--text-light); }

input.mono, textarea.mono { font-family: 'DM Mono', monospace; }

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

input:hover:not(:focus), select:hover:not(:focus), textarea:hover:not(:focus) {
  border-color: var(--border-strong);
}

textarea { resize: vertical; min-height: 56px; }

select:not([size]) {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
}

select[size] {
  overflow-y: auto;
  cursor: pointer;
}
select[size] option {
  padding: 5px 8px;
  border-radius: 4px;
}
select[size] option:checked {
  background: var(--accent);
  color: #fff;
}

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

.row .field { margin-bottom: 10px; }
.field-zip { max-width: 160px; }
.row:has(.field-zip) { grid-template-columns: 160px 1fr; }

.checkbox-field label {
  display: flex;
  align-items: center;
  gap: 10px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
}
.checkbox-field input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.input-with-btn {
  display: flex;
  gap: 8px;
}
.input-with-btn input { flex: 1; }

.input-with-aside {
  display: flex;
  gap: 12px;
  align-items: center;
}
.input-with-aside select { flex: 1; }
.delivery-price {
  min-width: 90px;
  text-align: right;
  color: var(--accent);
  font-weight: 600;
}

/* ======== Przyciski ======== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
}

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

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(99, 102, 241, 0.25);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
  background: #f1f5f9;
  border-color: var(--border);
  color: #475569;
}
.btn-secondary:hover:not(:disabled) {
  background: #e2e8f0;
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) {
  background: #f1f5f9;
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-block { width: 100%; }
.btn-large { padding: 14px 24px; font-size: 16px; font-weight: 600; }

/* ======== Layout aplikacji ======== */
.app-wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.col { min-width: 0; }

@media (max-width: 1023px) {
  .grid { grid-template-columns: 1fr; }
  .app-wrap { padding: 16px; }
  .topbar { padding: 14px 18px; }
  .row { flex-wrap: wrap; }
}

/* ======== Ekran logowania ======== */
.login-wrap {
  min-height: calc(100vh - 68px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle at 20% 10%, rgba(99, 102, 241, 0.08), transparent 45%),
    radial-gradient(circle at 80% 90%, rgba(99, 102, 241, 0.06), transparent 40%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 32px;
}
.login-card h1 {
  margin: 0 0 8px 0;
  font-size: 24px;
  font-weight: 700;
}
.login-card p { margin-top: 0; margin-bottom: 20px; }
.login-card label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 14px 0 6px;
  font-weight: 600;
}
.login-error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin: 12px 0;
  font-size: 13px;
}

/* ======== Autocomplete ======== */
.autocomplete-wrap {
  position: relative;
}
.autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 320px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: var(--shadow-lg);
}
.autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-soft);
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 8px;
  align-items: start;
  font-size: 12px;
  transition: background 0.12s ease;
  line-height: 1.4;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: #f1f5f9; }
.autocomplete-item .ac-sku-col { display: flex; flex-direction: column; gap: 1px; }
.autocomplete-item .ac-sku { color: var(--accent); font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 500; }
.autocomplete-item .ac-ean { color: var(--text-light); font-family: 'DM Mono', monospace; font-size: 10px; }
.autocomplete-item .ac-name { color: var(--text); font-size: 12px; }
.autocomplete-item .ac-meta { color: var(--text-muted); font-family: 'DM Mono', monospace; font-size: 11px; text-align: right; white-space: nowrap; }
.autocomplete-empty { padding: 16px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ======== Tabela linii ======== */
.lines-wrap {
  overflow-x: auto;
  margin: 0 -4px;
  padding: 0 4px;
}
.lines-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.lines-table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.lines-table td {
  padding: 10px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
  color: var(--text);
}
.lines-table tbody tr:hover { background: #f8fafc; }
.lines-table .empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 8px;
  font-style: italic;
}
.lines-table .empty-row:hover { background: transparent; }

.lines-table .col-sku { width: 110px; font-family: 'DM Mono', monospace; }
.lines-table .col-qty { width: 80px; font-family: 'DM Mono', monospace; }
.lines-table .col-price { width: 110px; font-family: 'DM Mono', monospace; }
.lines-table .col-disc { width: 80px; font-family: 'DM Mono', monospace; }
.lines-table .col-total { width: 120px; text-align: right; font-family: 'DM Mono', monospace; font-weight: 600; color: var(--text); }
.lines-table .col-del { width: 40px; text-align: center; }

.lines-table input {
  background: transparent;
  border: 1px solid transparent;
  padding: 6px 8px;
  font-size: 14px;
  color: var(--text);
  border-radius: 6px;
  font-family: 'DM Mono', monospace;
  width: 100%;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.lines-table input:hover { border-color: var(--border); }
.lines-table input:focus {
  border-color: var(--accent);
  background: #f8fafc;
  box-shadow: none;
  outline: none;
}
.lines-table input[type="number"]::-webkit-inner-spin-button,
.lines-table input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.lines-table input[type="number"] {
  -moz-appearance: textfield;
}
.lines-table input.name-input { font-family: 'DM Sans', sans-serif; }
.lines-table .sku-cell { font-family: 'DM Mono', monospace; color: var(--text-muted); font-size: 12px; }

.btn-del {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: all 0.12s ease;
}
.btn-del:hover {
  color: var(--error-text);
  background: var(--error-bg);
}

.lines-actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ======== Podsumowanie ======== */
.summary {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  color: var(--text-muted);
}
.summary-row.summary-total {
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

/* ======== Submit ======== */
.submit-card {
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  margin-bottom: 20px;
}

/* ======== Walidacja ======== */
.validation-box {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-bottom: 20px;
  color: var(--error-text);
}
.validation-box ul { margin: 6px 0 0; padding-left: 20px; }
.validation-box strong { color: var(--error-text); }

/* ======== Sukces ======== */
.success-wrap {
  max-width: 480px;
  margin: 60px auto;
  padding: 24px;
}
.success-card {
  text-align: center;
  padding: 40px 32px;
}
.success-card h1 {
  margin: 0 0 24px 0;
  font-size: 24px;
  font-weight: 700;
}
.success-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--success-bg);
  color: var(--success-text);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}
.success-info {
  text-align: left;
  background: #f8fafc;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin: 0 0 24px 0;
}
.info-row {
  padding: 4px 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.success-card .btn { margin-top: 10px; }
.success-card .btn:first-of-type { margin-top: 0; }

/* ======== Toasty ======== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 400px;
  pointer-events: none;
}
.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  color: var(--text);
  min-width: 280px;
  pointer-events: auto;
  animation: slideIn 0.25s ease-out;
}
.toast.toast-error {
  border-left-color: var(--error);
  background: var(--card);
  color: var(--error-text);
}
.toast.toast-success {
  border-left-color: var(--success);
  color: var(--success-text);
}

@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ======== Spinner ======== */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.btn-secondary .spinner,
.btn-ghost .spinner {
  border: 2px solid rgba(99, 102, 241, 0.25);
  border-top-color: var(--accent);
}
@keyframes spin { to { transform: rotate(360deg); } }
