:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #657282;
  --line: #d8dee6;
  --soft-line: #edf0f4;
  --accent: #126c5a;
  --accent-strong: #0d5748;
  --danger: #b42318;
  --focus: rgba(18, 108, 90, 0.18);
  --shadow: 0 18px 42px rgba(23, 31, 42, 0.10);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
  white-space: nowrap;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  min-height: 38px;
  padding: 9px 10px;
}

input[readonly] {
  background: #f3f6f9;
  color: var(--muted);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 16px, calc(100% - 10px) 16px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

label input,
label select,
label textarea {
  color: var(--ink);
  font-weight: 400;
}

.is-hidden,
[hidden] {
  display: none !important;
}

.admin-only {
  display: none !important;
}

body.role-admin .admin-only.switch-label {
  display: flex !important;
}

body.role-admin .settings-users.admin-only {
  display: grid !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #101820;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  background: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  padding: 26px;
}

.login-logo {
  width: 210px;
  max-width: 100%;
  height: auto;
}

.login-card h1 {
  margin: 0;
  font-size: 28px;
}

.login-card p {
  margin: 0;
  color: var(--muted);
}

.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #17202b;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px;
}

.brand {
  display: flex;
  align-items: center;
}

.brand-logo {
  display: block;
  width: 150px;
  height: auto;
  flex: 0 0 auto;
}

.sidebar-note small {
  display: block;
  color: rgba(255, 255, 255, 0.68);
  margin-top: 2px;
}

.main-nav {
  display: grid;
  gap: 8px;
}

.nav-button {
  width: 100%;
  text-align: left;
  color: rgba(255, 255, 255, 0.78);
  background: transparent;
}

.nav-button.active,
.nav-button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.10);
}

.sidebar-note {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 14px;
}

.sidebar-note span {
  display: block;
  font-size: 20px;
  font-weight: 800;
}

.sidebar-user {
  display: grid;
  gap: 8px;
}

.sidebar-user .secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.workspace {
  padding: 28px;
  min-width: 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.view-header h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.1;
}

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

.header-actions,
.form-footer,
.items-header,
.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary {
  color: #fff;
  background: var(--accent);
}

.primary:hover {
  background: var(--accent-strong);
}

.secondary {
  color: var(--ink);
  background: #e4e9ef;
}

.secondary:hover {
  background: #d7dee7;
}

.danger {
  color: #fff;
  background: var(--danger);
}

.small {
  min-height: 32px;
  padding-inline: 10px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.delivery-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
  align-items: start;
}

.delivery-form,
.catalog-form,
.settings-form {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.settings-users {
  display: grid;
  gap: 14px;
  margin-top: 18px;
  padding: 18px;
}

.user-form {
  display: grid;
  gap: 14px;
}

.user-row {
  cursor: default;
}

.top-grid {
  align-items: end;
}

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

.switch-label {
  align-self: end;
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 38px;
  color: var(--ink);
}

.switch-label input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.switch-label.locked {
  opacity: 0.68;
}

.switch-label.locked span::after {
  content: " (zaključao admin)";
  color: var(--muted);
  font-weight: 600;
}

.autocomplete {
  position: relative;
}

.suggestions {
  display: none;
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 260px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 16px 30px rgba(23, 31, 42, 0.16);
}

.suggestions.open {
  display: block;
}

.suggestion {
  display: grid;
  gap: 2px;
  width: 100%;
  text-align: left;
  min-height: 0;
  padding: 10px;
  background: #fff;
  border-radius: 0;
}

.suggestion:hover {
  background: #edf6f4;
}

.suggestion strong,
.data-row strong,
.note-card strong {
  color: var(--ink);
}

.suggestion small,
.data-row small,
.note-card small {
  color: var(--muted);
}

.selected-client {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 12px;
  min-height: 64px;
}

.selected-client strong {
  color: var(--ink);
}

.items-header h2,
.list-head h2 {
  margin: 0;
  font-size: 18px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.items-table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
}

.items-table th,
.items-table td {
  border-bottom: 1px solid var(--soft-line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.items-table th {
  background: #f7f9fb;
  color: var(--muted);
  font-size: 12px;
}

.items-table input {
  min-height: 34px;
  padding: 7px 8px;
}

.product-cell {
  position: relative;
  min-width: 190px;
}

.qty-cell,
.price-cell,
.total-cell,
.unit-cell {
  width: 110px;
}

.remove-row {
  width: 36px;
  min-height: 34px;
  padding: 0;
  background: #f4e5e3;
  color: var(--danger);
  font-weight: 900;
}

.amount-column.hidden,
.amount-field.hidden {
  display: none;
}

.form-footer {
  border-top: 1px solid var(--soft-line);
  padding-top: 14px;
}

.form-footer span {
  color: var(--muted);
}

.side-list,
.catalog-list-panel {
  padding: 16px;
}

.list-head {
  margin-bottom: 12px;
}

.list-head input {
  max-width: 170px;
}

.note-list,
.data-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 180px);
  overflow: auto;
  padding-right: 2px;
}

.note-card,
.data-row {
  width: 100%;
  display: grid;
  gap: 4px;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.note-card.active,
.data-row.active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.note-card:hover,
.data-row:hover {
  background: #fbfcfd;
}

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

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  display: none;
  max-width: 360px;
  padding: 13px 16px;
  border-radius: 8px;
  color: #fff;
  background: #17202b;
  box-shadow: 0 14px 28px rgba(23, 31, 42, 0.24);
}

.toast.show {
  display: block;
}

.print-area {
  display: none;
}

.print-sheet {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  background: #fff;
  color: #000;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 11px;
  padding: 12mm 11mm;
}

.print-header {
  display: grid;
  grid-template-columns: 52mm 1fr;
  gap: 8mm;
  align-items: start;
  margin-bottom: 5mm;
}

.print-logo {
  display: block;
  width: 46mm;
  height: auto;
}

.print-company {
  text-align: right;
  line-height: 1.28;
}

.print-company strong {
  font-size: 13px;
}

.print-line {
  border-top: 1px solid #000;
  margin: 0 0 2mm;
}

.print-title {
  margin: 0 0 2mm;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
}

.print-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8mm;
  margin-bottom: 6mm;
}

.print-meta {
  line-height: 1.65;
}

.print-client-code {
  text-align: right;
  margin-bottom: 1mm;
}

.print-client-box {
  border: 1px solid #000;
  padding: 3mm;
  min-height: 20mm;
  line-height: 1.45;
}

.print-client-box strong {
  display: block;
  font-size: 13px;
  margin-bottom: 3mm;
}

.print-items {
  width: 100%;
  border-collapse: collapse;
  margin-top: 3mm;
}

.print-items th,
.print-items td {
  padding: 1.25mm 0.8mm;
  border-bottom: 1px solid #000;
  text-align: left;
}

.print-items th {
  border-top: 1px solid #000;
  font-weight: 800;
  font-size: 9px;
}

.print-items td {
  font-size: 9px;
}

.print-items .num,
.print-items .qty,
.print-items .money {
  text-align: right;
}

.print-note {
  margin-top: 4mm;
}

.print-note strong {
  display: block;
  margin-bottom: 1mm;
}

.print-note-box {
  border: 1px solid #000;
  min-height: 16mm;
  padding: 2mm;
  white-space: pre-wrap;
}

.print-signatures {
  display: grid;
  grid-template-columns: 1fr 80px 1fr;
  gap: 12mm;
  align-items: end;
  margin-top: 18mm;
  text-align: center;
}

.signature-line {
  border-top: 1px solid #000;
  padding-top: 1.5mm;
  font-style: italic;
}

.stamp {
  font-weight: 800;
}

.driver-line {
  width: 38%;
  margin-left: auto;
  margin-top: 10mm;
  border-top: 1px solid #000;
  padding-top: 1.5mm;
  text-align: center;
  font-size: 10px;
  font-style: italic;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 16px;
  }

  .main-nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-button {
    text-align: center;
  }

  .sidebar-note {
    display: none;
  }

  .sidebar-user {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .delivery-layout,
  .catalog-layout {
    grid-template-columns: 1fr;
  }

  .note-list,
  .data-list {
    max-height: 360px;
  }
}

@media (max-width: 760px) {
  body {
    background: #f3f6f9;
  }

  input,
  select,
  textarea {
    min-height: 46px;
    font-size: 16px;
  }

  button {
    min-height: 44px;
  }

  .app-shell {
    display: block;
    padding-bottom: calc(92px + env(safe-area-inset-bottom));
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 70;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    box-shadow: 0 12px 30px rgba(23, 31, 42, 0.22);
  }

  .brand-logo {
    width: 112px;
  }

  .main-nav {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 90;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
    gap: 6px;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 16px;
    background: rgba(23, 32, 43, 0.97);
    box-shadow: 0 18px 36px rgba(23, 31, 42, 0.32);
  }

  .nav-button {
    min-height: 44px;
    border-radius: 12px;
    padding: 4px 8px;
    text-align: center;
    font-size: 13px;
    font-weight: 800;
  }

  .nav-button.active,
  .nav-button:hover {
    color: #17202b;
    background: #fff;
  }

  .sidebar-note {
    display: none;
  }

  .sidebar-user {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
  }

  .sidebar-user small {
    max-width: 118px;
    overflow: hidden;
    color: rgba(255, 255, 255, 0.74);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sidebar-user .secondary {
    min-height: 34px;
    padding-inline: 10px;
  }

  .workspace {
    padding: 14px 12px calc(104px + env(safe-area-inset-bottom));
  }

  .panel {
    box-shadow: 0 10px 24px rgba(23, 31, 42, 0.08);
  }

  .delivery-layout,
  .catalog-layout {
    gap: 12px;
  }

  .note-list,
  .data-list {
    max-height: none;
  }

  .view-header,
  .form-footer,
  .items-header,
  .list-head {
    align-items: stretch;
    flex-direction: column;
  }

  .view-header {
    gap: 10px;
    margin-bottom: 10px;
  }

  .header-actions {
    position: sticky;
    top: 58px;
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    padding: 8px;
    border: 1px solid rgba(216, 222, 230, 0.82);
    border-radius: 12px;
    background: rgba(243, 246, 249, 0.96);
    box-shadow: 0 10px 24px rgba(23, 31, 42, 0.12);
  }

  .header-actions button {
    width: 100%;
    padding-inline: 8px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .view-header h1 {
    font-size: 26px;
  }

  .list-head input {
    max-width: none;
  }

  .suggestions {
    z-index: 95;
  }

  .delivery-form,
  .catalog-form,
  .settings-form,
  .settings-users,
  .side-list,
  .catalog-list-panel {
    padding: 14px;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    border-radius: 0;
    margin-inline: 0;
  }

  .items-table {
    display: block;
    min-width: 0;
    border-collapse: separate;
  }

  .items-table thead {
    display: none;
  }

  .items-table tbody {
    display: grid;
    gap: 12px;
  }

  .items-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 8px 18px rgba(23, 31, 42, 0.07);
  }

  .items-table td {
    display: block;
    width: auto;
    min-width: 0;
    border-bottom: 0;
    padding: 0;
  }

  .items-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
  }

  .items-table input,
  .items-table select {
    min-height: 46px;
    padding: 10px;
  }

  .product-cell,
  .items-table td[data-label="Naziv"],
  .items-table td[data-label="Barkod"],
  .row-actions {
    grid-column: 1 / -1;
  }

  .qty-cell,
  .price-cell,
  .total-cell,
  .unit-cell {
    width: auto;
  }

  .remove-row {
    width: 100%;
    min-height: 44px;
  }
}

@media (max-width: 460px) {
  .sidebar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 10px;
  }

  .main-nav {
    gap: 6px;
  }

  .nav-button {
    min-height: 36px;
    padding-inline: 8px;
  }

  .header-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .view-header h1 {
    font-size: 24px;
  }

  .eyebrow {
    font-size: 11px;
  }

  .sidebar-user {
    gap: 6px;
  }

  .sidebar-user small {
    display: none;
  }

  .items-table tr {
    grid-template-columns: 1fr;
  }

  .product-cell,
  .items-table td[data-label="Naziv"],
  .items-table td[data-label="Barkod"],
  .row-actions {
    grid-column: auto;
  }
}

@media print {
  @page {
    size: A4;
    margin: 0;
  }

  body {
    background: #fff;
  }

  .app-shell,
  .toast {
    display: none !important;
  }

  .print-area {
    display: block;
  }

  .print-sheet {
    width: auto;
    min-height: 297mm;
    box-shadow: none;
    padding: 12mm 11mm;
  }
}
