/* =====================================================
   Hurtownik PRO — czysty, jasny, nowoczesny
   Font: Montserrat
   ===================================================== */

:root {
  --bg:        #F6F7F9;   /* jasne, niemal białe tło */
  --bg-soft:   #EEF1F4;
  --surface:   #FFFFFF;
  --surface-2: #F8FAFB;

  --ink:       #1C2230;
  --ink-soft:  #5B6473;
  --ink-faint: #98A1B0;

  --line:      #E7EAEF;
  --line-soft: #F0F2F5;

  --brand:      #1F9D66;   /* świeża zieleń */
  --brand-deep: #17794F;
  --brand-tint: #E6F5EE;

  --danger:      #D8543C;
  --danger-deep: #B73E29;
  --danger-tint: #FBE9E4;

  --amber-tint: #FBF1DD;

  /* Statusy */
  --st-new-bg:#E7F0FE;    --st-new-tx:#2563B8;
  --st-inv-bg:#E6F5EE;    --st-inv-tx:#17794F;
  --st-ret-bg:#FBE9E4;    --st-ret-tx:#B73E29;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20,30,50,0.04), 0 6px 20px rgba(20,30,50,0.05);
  --shadow-lift: 0 4px 10px rgba(20,30,50,0.07), 0 18px 40px rgba(20,30,50,0.09);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Montserrat", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}
h1, h2, h3 { font-weight: 700; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
a { color: var(--brand-deep); }

/* ---------------- Topbar ---------------- */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,0.9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1040px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 24px; }
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: var(--ink); }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 11px; background: var(--brand); color: #fff; font-size: 21px; box-shadow: var(--shadow); }
.brand-text { font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }
.brand-text em { font-style: normal; color: var(--brand); }
.topbar-right { display: flex; align-items: center; gap: 18px; }
.logout { color: var(--ink-soft); text-decoration: none; font-size: 15px; font-weight: 500; }
.logout:hover { color: var(--ink); }

/* ---------------- Buttons ---------------- */
.btn {
  font-family: inherit; font-size: 15px; font-weight: 600;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 11px 18px; min-height: 46px;
  cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s, box-shadow .15s, background .15s, border-color .15s; color: var(--ink); background: var(--surface);
}
.btn:active { transform: translateY(1px); }
.btn-ico { font-size: 17px; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--brand-deep); box-shadow: var(--shadow-lift); }
.btn-danger { background: var(--danger-tint); color: var(--danger-deep); border-color: #f3cabf; }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-soft { background: var(--brand-tint); color: var(--brand-deep); border-color: #c9e9d8; }
.btn-soft:hover { background: #d7eee2; }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-block { width: 100%; }
.btn-tall { flex-direction: column; gap: 2px; padding: 13px 22px; min-height: 58px; }
.ba-main { font-size: 16px; font-weight: 700; }
.ba-sub { font-size: 12px; font-weight: 500; opacity: 0.9; }
.btn-pobierz { font-size: 14px; }

/* ---------------- Flash / notice ---------------- */
.flash-wrap { max-width: 1040px; margin: 16px auto -4px; padding: 0 24px; }
.flash { background: var(--brand-tint); color: var(--brand-deep); border: 1px solid #c9e9d8; border-radius: var(--radius-sm); padding: 13px 16px; font-size: 15px; font-weight: 500; }

main { max-width: 1040px; margin: 0 auto; padding: 26px 24px 56px; }

.notice { display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; background: var(--amber-tint); border: 1px solid #f0deb6; border-radius: var(--radius); padding: 18px 20px; margin-bottom: 22px; }
.notice-text { font-size: 15px; color: #7a5a17; }

/* ---------------- Page head ---------------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 28px; }
.conn-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px; text-decoration: none; border: 1px solid transparent; }
.chip-ok { background: var(--brand-tint); color: var(--brand-deep); border-color: #c9e9d8; }
.chip-warn { background: var(--amber-tint); color: #8a5a1b; border-color: #f0deb6; }
.chip-muted { background: var(--bg-soft); color: var(--ink-faint); border-color: var(--line); }

/* ---------------- Tabs ---------------- */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tab { display: inline-flex; align-items: center; gap: 9px; padding: 10px 16px; border-radius: 999px; background: var(--surface); border: 1.5px solid var(--line); text-decoration: none; color: var(--ink-soft); font-size: 15px; font-weight: 600; transition: background .15s, color .15s, border-color .15s; }
.tab:hover { color: var(--ink); border-color: #d4dae2; }
.tab-count { font-size: 13px; font-weight: 700; min-width: 24px; text-align: center; padding: 1px 7px; border-radius: 999px; background: var(--bg-soft); color: var(--ink-soft); }
.tab.is-active { color: #fff; background: var(--brand); border-color: var(--brand); box-shadow: var(--shadow); }
.tab.is-active .tab-count { background: rgba(255,255,255,0.25); color: #fff; }

/* ---------------- Search ---------------- */
.search { display: flex; align-items: center; gap: 9px; background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 8px 10px 8px 14px; margin-bottom: 16px; box-shadow: var(--shadow); }
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31,157,102,0.15); }
.search-ico { font-size: 17px; color: var(--ink-faint); }
.search-input { flex: 1; border: none; outline: none; background: transparent; font-family: inherit; font-size: 16px; color: var(--ink); padding: 6px 2px; min-width: 0; }
.search-input::placeholder { color: var(--ink-faint); }
.search-result { color: var(--ink-soft); font-size: 15px; margin: 0 0 16px; }

.sync-line { color: var(--ink-faint); font-size: 14px; margin: 0 0 20px; }
.sync-err { color: var(--danger-deep); }

/* ---------------- Order cards ---------------- */
.cards { display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; border-left: 5px solid var(--line); animation: rise .45s cubic-bezier(.2,.7,.3,1) both; }
.card:hover { box-shadow: var(--shadow-lift); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card-status-NEW    { border-left-color: var(--st-new-tx); }
.card-status-INVOICED{ border-left-color: var(--st-inv-tx); }
.card-status-RETURN { border-left-color: var(--st-ret-tx); }

.card-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-id { font-size: 14px; color: var(--ink-soft); font-weight: 600; }
.card-date { font-size: 14px; color: var(--ink-faint); }
.card-total { margin-left: auto; font-size: 23px; font-weight: 800; letter-spacing: -0.02em; }

.pill { display: inline-block; padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.pill-NEW    { background: var(--st-new-bg); color: var(--st-new-tx); }
.pill-INVOICED{ background: var(--st-inv-bg); color: var(--st-inv-tx); }
.pill-RETURN { background: var(--st-ret-bg); color: var(--st-ret-tx); }

.card-body { display: grid; grid-template-columns: 1.3fr 1fr; gap: 22px; padding: 2px 0 14px; }
@media (max-width: 720px) { .card-body { grid-template-columns: 1fr; gap: 12px; } }
.buyer-name { font-size: 19px; font-weight: 700; }
.buyer-sub { font-size: 14px; color: var(--brand-deep); margin-top: 2px; font-weight: 600; }
.buyer-addr { font-size: 15px; color: var(--ink-soft); margin-top: 6px; }
.card-items { list-style: none; margin: 0; padding: 0; }
.card-items li { font-size: 15px; color: var(--ink); padding: 2px 0; }
.item-qty { display: inline-block; min-width: 32px; font-weight: 700; color: var(--brand-deep); }

.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; border-top: 1px solid var(--line-soft); padding-top: 14px; }
.card-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.card-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.inv-chip { font-size: 14px; font-weight: 600; padding: 6px 12px; border-radius: 999px; text-decoration: none; }
.inv-done { background: var(--brand-tint); color: var(--brand-deep); }
.inv-corr { background: var(--st-ret-bg); color: var(--st-ret-tx); }
.inv-none { background: var(--bg-soft); color: var(--ink-faint); border: 1px solid var(--line); }

/* ---------------- Status select ---------------- */
.status-field { display: inline-flex; align-items: center; gap: 8px; }
.status-field-label { font-size: 14px; color: var(--ink-soft); }
.status-select {
  appearance: none; -webkit-appearance: none; font-family: inherit; font-size: 14px; font-weight: 700;
  border: 1.5px solid transparent; border-radius: 999px; padding: 8px 32px 8px 14px; cursor: pointer; color: var(--ink);
  background-repeat: no-repeat; background-position: right 12px center; background-size: 10px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='7'%3E%3Cpath fill='%231C2230' d='M0 0l5.5 7L11 0z'/%3E%3C/svg%3E");
}
.status-select:focus { outline: 3px solid rgba(31,157,102,0.25); outline-offset: 1px; }
.status-select.status-NEW     { background-color: var(--st-new-bg); color: var(--st-new-tx); }
.status-select.status-INVOICED{ background-color: var(--st-inv-bg); color: var(--st-inv-tx); }
.status-select.status-RETURN  { background-color: var(--st-ret-bg); color: var(--st-ret-tx); }
.status-select option { background: #fff; color: var(--ink); }
.status-field-lg .status-select { font-size: 15px; padding: 10px 36px 10px 16px; }

/* ---------------- Empty ---------------- */
.empty { text-align: center; padding: 54px 20px; color: var(--ink-soft); }
.empty-emoji { font-size: 48px; }
.empty-title { font-size: 22px; font-weight: 700; color: var(--ink); margin: 12px 0 6px; }
.empty-sub { font-size: 15px; color: var(--ink-soft); margin: 0; }

/* ---------------- Detail ---------------- */
.back-link { display: inline-block; margin-bottom: 16px; text-decoration: none; font-size: 15px; font-weight: 500; color: var(--ink-soft); }
.back-link:hover { color: var(--ink); }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; }
.detail-head h1 { font-size: 26px; margin: 10px 0 4px; }
.detail-meta { color: var(--ink-faint); font-size: 15px; margin: 0; }
.detail-total { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.detail-actions { display: flex; align-items: center; gap: 11px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 17px; margin: 16px 0 22px; box-shadow: var(--shadow); }
.detail-actions form { margin: 0; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 720px) { .detail-grid { grid-template-columns: 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-faint); margin-bottom: 10px; font-weight: 700; }
.panel-body { font-size: 16px; line-height: 1.7; margin: 0; }

.items { width: 100%; border-collapse: collapse; }
.items th { text-align: left; font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--ink-faint); padding: 8px 10px; border-bottom: 2px solid var(--line); }
.items td { padding: 11px 10px; border-bottom: 1px solid var(--line-soft); font-size: 15px; }
.items tfoot th { font-size: 16px; color: var(--ink); border-bottom: none; border-top: 2px solid var(--line); padding-top: 13px; }
.num { text-align: right; }
.sku { font-size: 12px; color: var(--ink-faint); }

.events { list-style: none; margin: 0; padding: 0; }
.events li { display: flex; align-items: center; gap: 11px; padding: 9px 0; border-bottom: 1px solid var(--line-soft); font-size: 15px; }
.events li:last-child { border-bottom: none; }
.event-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ink-faint); flex: none; }
.event-dot.kind-INVOICE_CREATED { background: var(--brand); }
.event-dot.kind-CORRECTION_CREATED { background: var(--danger); }
.event-dot.kind-STATUS_CHANGE { background: var(--st-new-tx); }
.event-dot.kind-ERROR { background: var(--danger-deep); }
.event-time { color: var(--ink-faint); font-size: 13px; min-width: 124px; }
.event-msg { color: var(--ink); }
.muted { color: var(--ink-faint); }

/* ---------------- Modal ---------------- */
.modal-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(28,34,48,0.45); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .18s ease both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal { width: 100%; max-width: 440px; background: var(--surface); border-radius: 18px; border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(28,34,48,0.28); padding: 24px; animation: pop .22s cubic-bezier(.2,.8,.3,1) both; }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-head h2 { font-size: 21px; }
.modal-x { border: none; background: none; font-size: 28px; line-height: 1; color: var(--ink-faint); cursor: pointer; padding: 0 4px; }
.modal-x:hover { color: var(--ink); }
.modal-summary { background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 13px 15px; margin: 15px 0; }
.ms-name { font-size: 18px; font-weight: 700; }
.ms-line { font-size: 14px; color: var(--ink-soft); margin-top: 2px; }
.modal-q { font-size: 17px; line-height: 1.45; margin: 4px 0 16px; }
.modal-warn { color: #8a5a1b; }
.modal-actions { display: flex; flex-direction: column; gap: 9px; }
.modal-actions form { margin: 0; }

/* ---------------- Toast (potwierdzenie) ---------------- */
.toast {
  position: fixed; top: 18px; left: 50%; z-index: 80;
  display: flex; align-items: center; gap: 12px;
  background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--brand);
  box-shadow: var(--shadow-lift); border-radius: 14px; padding: 13px 20px 13px 15px;
  font-size: 15px; font-weight: 700; color: var(--ink);
  animation: toastIn .45s cubic-bezier(.2,.8,.3,1) both;
}
.toast.toast-out { animation: toastOut .4s ease forwards; }
@keyframes toastIn  { from { opacity: 0; transform: translate(-50%, -18px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes toastOut { to { opacity: 0; transform: translate(-50%, -18px); } }
.toast-check { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-tint); display: inline-flex; align-items: center; justify-content: center; animation: checkPop .4s .1s cubic-bezier(.2,1.4,.4,1) both; }
@keyframes checkPop { from { transform: scale(0); } to { transform: scale(1); } }
.toast-check svg { width: 18px; height: 18px; }
.toast-check svg path { fill: none; stroke: var(--brand-deep); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 24; stroke-dashoffset: 24; animation: checkDraw .45s .25s ease forwards; }
@keyframes checkDraw { to { stroke-dashoffset: 0; } }

/* Stan ładowania przycisku (HTMX dodaje .htmx-request na czas żądania) */
.btn.htmx-request { opacity: 0.6; pointer-events: none; }

/* ---------------- Footer ---------------- */
.footsie { text-align: center; color: var(--ink-faint); font-size: 13px; padding: 26px 20px 36px; }

/* ---------------- Login ---------------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; background: var(--bg); }
.login-card { width: 100%; max-width: 390px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-lift); padding: 34px 32px; display: flex; flex-direction: column; gap: 15px; }
.login-brand { font-size: 25px; font-weight: 800; letter-spacing: -0.02em; display: flex; align-items: center; gap: 10px; }
.login-brand em { font-style: normal; color: var(--brand); }
.login-welcome { color: var(--ink-soft); font-size: 15px; margin: -4px 0 6px; }
.login-error { background: var(--st-ret-bg); color: var(--st-ret-tx); padding: 11px 13px; border-radius: var(--radius-sm); font-size: 15px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 14px; color: var(--ink-soft); font-weight: 600; }
.field input { font-family: inherit; font-size: 16px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink); }
.field input:focus { outline: 3px solid rgba(31,157,102,0.22); outline-offset: 1px; border-color: var(--brand); background: #fff; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
