:root {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --surface-alt: #faf8f5;
  --dark: #181615;
  --dark-2: #262220;
  --text: #1c1917;
  --text-muted: #6b645e;
  --border: #e6e0d8;
  --accent: #b88b3c;
  --accent-hover: #9e742b;
  --accent-soft: #f7efe0;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(24, 22, 21, 0.06);
  --shadow-lg: 0 12px 32px rgba(24, 22, 21, 0.14);
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --bottom-nav-h: 64px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  overflow-x: hidden;
}

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-accent { color: var(--accent); }
.font-bold { font-weight: 700; }
.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 18px; }
.mb-1 { margin-bottom: 6px; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 18px; }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  font-family: inherit;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--dark); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--dark-2); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { background: var(--accent-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--surface-alt); }
.btn-ghost { background: transparent; color: inherit; }
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,0.08); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.btn-block { width: 100%; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  color: var(--text);
}

/* INPUTS */
.form-group { margin-bottom: 12px; }
.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
}
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

/* CARDS & LAYOUT */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card-title { font-size: 16px; font-weight: 700; margin: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.kpi-value { font-size: 20px; font-weight: 800; margin-top: 4px; }
.kpi-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-dark { background: var(--dark); color: #fff; }
.badge-accent { background: var(--accent-soft); color: var(--accent-hover); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }

/* TABLES */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  background: var(--surface-alt);
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }

/* TABS */
.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.tab-btn {
  padding: 9px 14px;
  border: none;
  background: transparent;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab-btn.active {
  color: var(--dark);
  border-bottom-color: var(--accent);
}

/* LOGIN SCREEN */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #181615 0%, #2c2521 100%);
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 18px;
  padding: 26px 22px;
  box-shadow: var(--shadow-lg);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.login-brand h1 { margin: 0; font-size: 22px; letter-spacing: 1px; }
.login-brand p { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.brand-logo {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--dark);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 22px;
  flex-shrink: 0;
}
.brand-logo.sm { width: 36px; height: 36px; font-size: 18px; border-radius: 9px; }

.pin-display-wrap { text-align: center; margin-bottom: 16px; }
.pin-label { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 12px 0;
}
.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: all 0.15s;
}
.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.1);
}
.login-error {
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 600;
  margin-top: 6px;
}
.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.pin-key {
  height: 54px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  transition: background 0.1s;
}
.pin-key:active { background: var(--border); }
.pin-key-action { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.login-hint { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 10px; }

/* APP SHELL */
.app-shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: var(--sidebar-w);
  background: var(--dark);
  color: #f3efe9;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  transition: transform 0.25s ease;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-name { display: block; font-weight: 800; letter-spacing: 1px; font-size: 16px; }
.brand-sub { display: block; font-size: 11px; color: #a89f96; }
.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  color: #d6cfc7;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.user-badge { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.user-name { font-weight: 600; font-size: 13.5px; }
.user-role { font-size: 11.5px; color: #a89f96; }

.main-wrap {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.page-title { margin: 0; font-size: 17px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
}
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.sync-pill.offline .sync-dot { background: var(--danger); }
.sync-pill.syncing .sync-dot { background: var(--warning); }
.queue-badge {
  background: var(--warning);
  color: #fff;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 11px;
}

.main-content {
  padding: 18px;
  flex: 1;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* CATALOG CARDS */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.product-img {
  width: 100%;
  height: 170px;
  object-fit: cover;
  background: var(--surface-alt);
}
.product-body { padding: 14px; flex: 1; display: flex; flex-direction: column; }
.product-title { font-weight: 700; font-size: 15px; margin: 0 0 4px; }
.product-price { font-size: 16px; font-weight: 800; color: var(--accent-hover); margin: 6px 0; }
.product-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 10px; }

/* SALES SPLIT LAYOUT */
.sales-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 16px;
  align-items: start;
}

/* KANBAN */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(250px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 12px;
}
.kanban-col {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 360px;
}
.kanban-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.kanban-card.is-brak { border-left: 4px solid var(--danger); }

/* MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 22, 21, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 14px;
}
.modal-dialog {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 680px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-dialog.wide { max-width: 920px; }
.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body {
  padding: 18px;
  overflow-y: auto;
}
.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* TOAST */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
}
.toast {
  background: var(--dark);
  color: #fff;
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--warning); }

/* MOBILE BOTTOM NAV & RESPONSIVE */
.mobile-only { display: none; }
.bottom-nav { display: none; }
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 35;
}

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sales-layout { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .mobile-only { display: inline-flex; }
  .hide-sm { display: none; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; padding-bottom: var(--bottom-nav-h); }
  .main-content { padding: 12px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 30;
    justify-content: space-around;
    align-items: center;
    padding: 4px;
  }
  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 600;
    padding: 4px 2px;
    cursor: pointer;
  }
  .bottom-nav-item.active { color: var(--accent-hover); }
  .bottom-nav-icon { font-size: 18px; }
}

/* SENNIK PRINT STYLES */
.print-area { display: none; }
.sennik-preview-80 {
  width: 80mm;
  margin: 0 auto;
  padding: 4mm;
  border: 1px dashed var(--border);
  background: #fff;
  color: #000;
  font-family: Arial, sans-serif;
}
.sennik-preview-a4 {
  width: 100%;
  max-width: 210mm;
  margin: 0 auto;
  padding: 14mm;
  border: 1px solid var(--border);
  background: #fff;
  color: #000;
  font-family: Arial, sans-serif;
}

@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area {
    display: block !important;
    width: 100%;
    margin: 0;
    padding: 0;
  }
  body.print-80mm @page { size: 80mm auto; margin: 2mm; }
  body.print-a4 @page { size: A4 portrait; margin: 10mm; }
}
