:root {
  --bg: #f3f4f1;
  --surface: #ffffff;
  --surface-2: #f8f8f6;
  --text: #151515;
  --muted: #6b6b6b;
  --line: #deded8;
  --line-strong: #c8c8c0;
  --dark: #111111;
  --dark-soft: #2a2a2a;
  --danger: #9b1c1c;
  --shadow: 0 24px 70px rgba(20, 20, 18, .10);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --rail: 286px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: "Poppins", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 10% 0%, rgba(0,0,0,.05), transparent 31rem),
    linear-gradient(135deg, #f7f7f4 0%, #eceeea 100%);
  color: var(--text);
  font-weight: 400;
}

button, input, select, textarea { font: inherit; }

button { cursor: pointer; }

svg { width: 18px; height: 18px; display: block; fill: currentColor; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  gap: 18px;
  padding: 18px;
}

.side-rail {
  position: sticky;
  top: 18px;
  height: calc(100vh - 36px);
  background: rgba(255,255,255,.78);
  border: 1px solid rgba(0,0,0,.08);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(18px);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px 18px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  background: var(--dark);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  letter-spacing: -.04em;
}

.brand-title { font-size: 17px; font-weight: 600; letter-spacing: -.03em; }
.brand-subtitle { font-size: 12px; color: var(--muted); margin-top: 2px; }

.rail-nav {
  display: grid;
  gap: 8px;
  padding: 18px 0;
}

.nav-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 14px;
  font-weight: 500;
  text-align: left;
  transition: .18s ease;
}

.nav-btn:hover { background: rgba(0,0,0,.05); color: var(--text); }
.nav-btn.is-active { background: var(--dark); color: #fff; box-shadow: 0 16px 36px rgba(0,0,0,.18); }

.nav-icon {
  width: 30px;
  height: 30px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.06);
}

.nav-btn.is-active .nav-icon { background: rgba(255,255,255,.14); }

.rail-action { margin-top: auto; width: 100%; min-height: 50px; }

.main-stage {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.top-bar {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgba(255,255,255,.78);
  border: 1px solid rgba(0,0,0,.08);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  padding: 18px 22px;
  backdrop-filter: blur(18px);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1;
  letter-spacing: -.055em;
  font-weight: 600;
}

h2 {
  margin-bottom: 3px;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: -.035em;
  font-weight: 600;
}

h3 {
  margin-bottom: 4px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.025em;
}

.top-actions, .toolbar-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-btn, .dark-btn, .ghost-btn, .icon-btn {
  border: 0;
  border-radius: 999px;
  min-height: 42px;
  padding: 0 18px;
  font-weight: 600;
  letter-spacing: -.015em;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease, color .18s ease;
}

.primary-btn, .dark-btn {
  background: var(--dark);
  color: #fff;
  box-shadow: 0 15px 30px rgba(0,0,0,.16);
}

.ghost-btn {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

.ghost-btn.danger { color: var(--danger); }

.icon-btn {
  width: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.primary-btn:hover, .dark-btn:hover, .ghost-btn:hover, .icon-btn:hover { transform: translateY(-1px); }
.primary-btn:active, .dark-btn:active, .ghost-btn:active, .icon-btn:active { transform: translateY(0); }

.view-panel { display: none; }
.view-panel.is-visible { display: block; }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: rgba(255,255,255,.84);
  border: 1px solid rgba(0,0,0,.08);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.notes-panel, .selected-panel, .products-panel, .details-form {
  padding: 18px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head p, .selected-summary p, .preview-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 0 14px;
  margin-bottom: 12px;
  min-height: 46px;
  color: var(--muted);
}

.search-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.notes-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 262px);
  overflow: auto;
  padding-right: 4px;
}

.note-card {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 20px;
  padding: 14px;
  display: grid;
  gap: 8px;
  transition: .18s ease;
}

.note-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.note-card.is-active { border-color: var(--dark); box-shadow: inset 0 0 0 1px var(--dark); }

.note-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.note-card h3 { margin: 0; font-size: 14px; }
.note-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #f1f1ee;
  color: #303030;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.empty-state {
  min-height: 200px;
  border: 1px dashed var(--line-strong);
  border-radius: 24px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  background: rgba(255,255,255,.56);
}

.empty-state strong { color: var(--text); display: block; margin-bottom: 4px; }

.selected-summary {
  min-height: 116px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.summary-stack { display: grid; gap: 8px; }

.summary-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.summary-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 11px;
  background: #fff;
  font-size: 12px;
  color: var(--muted);
}

.compact-preview {
  min-height: 620px;
  display: grid;
  place-items: center;
}

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

.form-field {
  display: grid;
  gap: 8px;
}

.form-field.full { grid-column: 1 / -1; }

.form-field label {
  font-size: 12px;
  color: #2e2e2e;
  font-weight: 600;
  letter-spacing: -.01em;
}

.form-field input, .form-field select, .form-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 16px;
  min-height: 48px;
  padding: 11px 14px;
  outline: 0;
  transition: border .18s ease, box-shadow .18s ease;
}

.form-field textarea {
  min-height: 96px;
  resize: vertical;
}

.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  border-color: var(--dark);
  box-shadow: 0 0 0 4px rgba(0,0,0,.07);
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 8px;
}

.products-grid {
  display: grid;
  gap: 10px;
}

.product-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 150px;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 20px;
  padding: 12px;
}

.product-number {
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--dark);
  color: #fff;
  font-weight: 600;
}

.preview-layout { display: grid; gap: 18px; }

.preview-toolbar {
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-scroll {
  border-radius: var(--radius-xl);
  overflow: auto;
  background: #d9dad5;
  border: 1px solid rgba(0,0,0,.08);
  box-shadow: var(--shadow);
  padding: 24px;
  min-height: calc(100vh - 176px);
  display: flex;
  justify-content: center;
}

.pdf-page {
  position: relative;
  width: min(100%, 1020px);
  aspect-ratio: 1588 / 2246;
  background: #fff url("delivery-note-template-1.png") center / 100% 100% no-repeat;
  box-shadow: 0 24px 60px rgba(0,0,0,.18);
  flex: 0 0 auto;
  overflow: hidden;
}

.compact-preview .pdf-page {
  width: min(100%, 560px);
  box-shadow: 0 18px 42px rgba(0,0,0,.14);
}

.pdf-field {
  position: absolute;
  z-index: 2;
  min-height: 1.1em;
  background: #fff;
  color: #111;
  display: flex;
  align-items: center;
  font-family: "Poppins", Arial, sans-serif;
  font-weight: 600;
  line-height: 1.08;
  overflow: hidden;
  white-space: nowrap;
  padding: 0 .15em;
  letter-spacing: -.02em;
}

.pdf-field.center { justify-content: center; text-align: center; }
.pdf-field.left { justify-content: flex-start; text-align: left; }
.pdf-field.right { justify-content: flex-end; text-align: right; }
.pdf-field.multi { white-space: normal; line-height: 1.16; align-items: center; }
.pdf-field.muted-text { font-weight: 500; }

.pdf-field.header { font-size: clamp(6px, 1.35vw, 15px); }
.pdf-field.body { font-size: clamp(7px, 1.55vw, 18px); }
.pdf-field.small { font-size: clamp(5.5px, 1.15vw, 13px); }
.pdf-field.product { font-size: clamp(5.5px, 1.25vw, 13px); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal.is-visible { display: flex; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.38);
  backdrop-filter: blur(10px);
}

.modal-card {
  position: relative;
  width: min(100%, 760px);
  max-height: min(92vh, 920px);
  overflow: auto;
  background: #fff;
  border-radius: 28px;
  box-shadow: 0 34px 90px rgba(0,0,0,.3);
  border: 1px solid rgba(255,255,255,.56);
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 3;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.modal-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  background: var(--dark);
  color: #fff;
  padding: 13px 16px;
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(0,0,0,.22);
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  font-size: 13px;
  max-width: min(360px, calc(100vw - 36px));
}

.toast.is-visible { transform: translateY(0); opacity: 1; }

.hidden { display: none !important; }

@media (max-width: 1080px) {
  :root { --rail: 92px; }
  .app-shell { grid-template-columns: var(--rail) 1fr; }
  .brand-block { justify-content: center; padding: 10px 0 16px; }
  .brand-block > div:not(.brand-mark) { display: none; }
  .nav-btn { justify-content: center; padding: 0; font-size: 0; }
  .nav-icon { width: 42px; height: 42px; }
  .rail-action { padding: 0; font-size: 0; }
  .rail-action::before { content: "+"; font-size: 22px; }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 780px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 12px;
  }
  .side-rail {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    top: auto;
    height: 74px;
    z-index: 12;
    flex-direction: row;
    align-items: center;
    padding: 10px;
    border-radius: 24px;
  }
  .brand-block { display: none; }
  .rail-nav {
    grid-template-columns: repeat(4, 1fr);
    flex: 1;
    padding: 0;
  }
  .nav-btn { min-height: 52px; border-radius: 18px; }
  .rail-action {
    width: 52px;
    min-width: 52px;
    min-height: 52px;
    margin: 0 0 0 8px;
  }
  .main-stage { padding-bottom: 90px; }
  .top-bar, .preview-toolbar, .selected-summary {
    align-items: flex-start;
    flex-direction: column;
  }
  .top-actions, .toolbar-actions { width: 100%; justify-content: flex-start; }
  .details-form, .modal-form { grid-template-columns: 1fr; }
  .product-row { grid-template-columns: 44px 1fr; }
  .product-row .qty-field { grid-column: 2; }
  .preview-scroll { padding: 10px; min-height: 60vh; }
  .notes-list { max-height: none; }
}

@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff !important; }
  .side-rail, .top-bar, .preview-toolbar, .modal, .toast, .dashboard-grid, .details-form, .products-panel { display: none !important; }
  .app-shell, .main-stage, .view-panel, .preview-layout, .preview-scroll { display: block !important; padding: 0 !important; margin: 0 !important; min-height: 0 !important; background: #fff !important; box-shadow: none !important; border: 0 !important; }
  #previewView { display: block !important; }
  .pdf-page {
    width: 210mm !important;
    height: 297mm !important;
    aspect-ratio: auto !important;
    box-shadow: none !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .pdf-field { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
