:root {
  --white: #ffffff;
  --bg: #f2f7fc;
  --light-blue: #dcebfa;
  --blue: #3f8fd6;
  --blue-hover: #2f7dc2;
  --navy: #17324f;
  --text: #24384c;
  --muted: #6b8299;
  --border: #cfe0f0;
  --danger: #d64545;
  --success: #2e9e6b;
  --radius: 12px;
  --shadow: 0 4px 18px rgba(23, 50, 79, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--light-blue) 0%, var(--bg) 55%, var(--white) 100%);
  padding: 20px;
}

.login-card {
  background: var(--white);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 42px 38px;
  width: 100%;
  max-width: 410px;
  border: 1px solid var(--border);
}

.login-card .logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.logo-badge {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--blue), var(--navy));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
}

.login-card h1 { font-size: 22px; color: var(--navy); }
.login-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 26px; }

/* ---------- Form elements ---------- */

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 6px;
}

.field input, .field select {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14.5px;
  background: var(--white);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(63, 143, 214, 0.15);
}

.field input[readonly] { background: var(--light-blue); color: var(--navy); font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border: none;
  border-radius: 10px;
  font-size: 14.5px;
  font-weight: 600;
  background: var(--blue);
  color: #fff;
  transition: background 0.15s;
}

.btn:hover { background: var(--blue-hover); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn.full { width: 100%; }
.btn.secondary { background: var(--light-blue); color: var(--navy); }
.btn.secondary:hover { background: #cbe2f7; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #bb3a3a; }
.btn.navy { background: var(--navy); }
.btn.navy:hover { background: #0f2438; }
.btn.small { padding: 7px 13px; font-size: 13px; border-radius: 8px; }

.error-msg {
  background: #fdeaea;
  color: var(--danger);
  border: 1px solid #f3c8c8;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  margin-bottom: 16px;
  display: none;
}

.success-msg {
  background: #e7f6ee;
  color: var(--success);
  border: 1px solid #bfe6d2;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  margin-bottom: 16px;
  display: none;
}

/* ---------- App layout ---------- */

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-weight: 700;
  color: var(--navy);
  font-size: 16.5px;
}

.topbar .brand .logo-badge { width: 36px; height: 36px; font-size: 17px; border-radius: 9px; }

.topbar .user-info { display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--muted); }
.topbar .user-info b { color: var(--navy); }

.container { max-width: 1180px; margin: 0 auto; padding: 30px 24px 60px; }

.page-title { font-size: 21px; color: var(--navy); margin-bottom: 4px; }
.page-sub { color: var(--muted); font-size: 14px; margin-bottom: 24px; }

/* ---------- Category grid ---------- */

.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

.cat-card {
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
  text-align: left;
}

.cat-card:hover {
  border-color: var(--blue);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.cat-card .icon {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  background: var(--light-blue);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  margin-bottom: 14px;
}

.cat-card h3 { font-size: 15.5px; color: var(--navy); margin-bottom: 6px; }
.cat-card .meta { font-size: 12.5px; color: var(--muted); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge.blue { background: var(--light-blue); color: var(--blue-hover); }
.badge.navy { background: var(--navy); color: #fff; }
.badge.green { background: #e7f6ee; color: var(--success); }
.badge.red { background: #fdeaea; color: var(--danger); }

/* ---------- Panels / cards ---------- */

.panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
  margin-bottom: 22px;
}

.panel h2 { font-size: 17px; color: var(--navy); margin-bottom: 18px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px 18px;
}

.two-col { display: grid; grid-template-columns: 1fr 420px; gap: 22px; align-items: start; }
@media (max-width: 980px) { .two-col { grid-template-columns: 1fr; } }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 20px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--blue);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  margin-bottom: 18px;
  background: none;
  border: none;
}
.back-link:hover { text-decoration: underline; }

/* ---------- Tables ---------- */

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.data th {
  text-align: left;
  padding: 10px 12px;
  background: var(--light-blue);
  color: var(--navy);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

table.data th:first-child { border-radius: 8px 0 0 8px; }
table.data th:last-child { border-radius: 0 8px 8px 0; }
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--border); }
table.data tr:hover td { background: #f7fbff; }

/* ---------- Tabs ---------- */

.tabs { display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }

.tab-btn {
  padding: 9px 18px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--white);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.tab-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ---------- Label preview ---------- */

.label-preview-wrap {
  background: var(--light-blue);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* Nalepnica - sadrzaj 150 x 100 mm (polozeno), stampa se rotirano na papir 100 x 150 mm */
.device-label {
  background: #fff;
  color: #000;
  font-family: Arial, Helvetica, sans-serif;
  width: 150mm;
  height: 100mm;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  page-break-inside: avoid;
  padding: 0 6mm;
}

/* Gornjih 30mm prazno (prostor za logo), ikone u desnom delu vrha */
.device-label .lbl-top {
  height: 30mm;
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 4mm;
  padding-bottom: 1.5mm;
}

.device-label .lbl-top svg,
.device-label .lbl-top img { display: block; }
.device-label .icon-weee { width: 16.5mm; height: 22.5mm; object-fit: contain; }
.device-label .icon-ce { width: 22.5mm; height: 15mm; object-fit: contain; align-self: flex-end; margin-bottom: 1mm; }

/* Sadrzaj: levo polja, desno QR - razvucen preko cele povrsine */
.device-label .lbl-content {
  display: flex;
  gap: 4mm;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}

.device-label .lbl-fields {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.device-label .fld {
  display: flex;
  align-items: center;
  font-size: 4.1mm;
}

.device-label .fld-name { font-weight: 700; white-space: nowrap; margin-right: 1.8mm; }

.device-label .fld-box {
  flex: 1;
  min-width: 0;
  border: 0.45mm solid #000;
  border-radius: 2mm;
  padding: 1mm 1.6mm;
  min-height: 7.5mm;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
}

.device-label .lbl-qr-col {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.device-label .lbl-qr img { width: 30mm; height: 30mm; display: block; }

/* Red sa strujnim podacima: 4 kucice sa jedinicama */
.device-label .lbl-electric {
  display: flex;
  gap: 2.5mm;
}

.device-label .el-item {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 1.4mm;
  font-size: 4.1mm;
  min-width: 0;
}

.device-label .el-item .fld-box { padding: 1mm 0.6mm; }
.device-label .el-unit { font-weight: 700; white-space: nowrap; }

/* Dva polja u jednom redu (Refrigerant / Climatic class) */
.device-label .lbl-pair { display: flex; gap: 5mm; }
.device-label .lbl-pair .fld { flex: 1; min-width: 0; }
.device-label .fld .fld-suffix { font-weight: 700; margin-left: 1.4mm; }

/* Podnozje (opciono) + 10mm praznog prostora na dnu */
.device-label .lbl-footer {
  text-align: center;
  font-size: 3.4mm;
  font-weight: 700;
  flex-shrink: 0;
  padding-top: 1.6mm;
}

.device-label .lbl-bottom-space { height: 10mm; flex-shrink: 0; }

/* Skaliranje pregleda na ekranu */
.preview-scale { transform-origin: top center; }
.label-preview-wrap .device-label { outline: 1px dashed #9ab6d0; zoom: 0.62; }

/* ---------- Print ----------
   Stampa ide kroz poseban iframe koji sadrzi samo .print-page elemente:
   papir 100x150 uspravno, sadrzaj nalepnice rotiran za 90 stepeni. */

.print-page {
  width: 100mm;
  height: 150mm;
  overflow: hidden;
  position: relative;
  page-break-after: always;
}

.print-page:last-child { page-break-after: auto; }

.print-page .device-label {
  transform: rotate(90deg) translateY(-100mm);
  transform-origin: top left;
  outline: none;
}

@media print {
  @page { size: 100mm 150mm; margin: 0; }
}

/* ---------- Modal ---------- */

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(23, 50, 79, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-back.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: 16px;
  padding: 30px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  max-height: 90vh;
  overflow-y: auto;
}

.modal h3 { color: var(--navy); font-size: 18px; margin-bottom: 20px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

.empty-note { color: var(--muted); font-size: 14px; text-align: center; padding: 30px 0; }
