:root{
  --bg:#f6f8fb;
  --card:#ffffff;
  --text:#0f172a;
  --muted:#64748b;
  --line:#e2e8f0;
  --primary:#2563eb;
  --shadow: 0 10px 30px rgba(15,23,42,.08);
  --r:16px;
  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
}

*{box-sizing:border-box}
body{margin:0;font-family:var(--font);color:var(--text)}
.bg{background:var(--bg)}

a{color:inherit;text-decoration:none}
.card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--r);
  box-shadow:var(--shadow);
}
.h1{font-size:22px;font-weight:900;letter-spacing:.2px}
.muted{color:var(--muted)}
.small{font-size:12px}
.pad{padding:14px}

.btn{
  border:1px solid var(--line);
  background:#fff;
  padding:10px 14px;
  border-radius:12px;
  cursor:pointer;
  font-weight:700;
}
.btn:hover{border-color:#cbd5e1}
.btn.primary{
  background:var(--primary);
  border-color:var(--primary);
  color:#fff;
}
.btn.primary:hover{filter:brightness(.98)}

.inp{
  width:100%;
  border:1px solid var(--line);
  border-radius:12px;
  padding:10px 12px;
  outline:none;
  background:#fff;
}
.inp:focus{border-color:#93c5fd;box-shadow:0 0 0 3px rgba(37,99,235,.12)}
.lbl{display:block;margin:10px 0 6px 2px;font-weight:800;font-size:13px;color:#334155}
.err{margin-top:10px;color:#b91c1c;font-weight:800}

/* auth */
.auth-wrap{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px}
.auth-card{max-width:430px;width:100%;padding:22px}
.brand{display:flex;flex-direction:column;gap:10px;align-items:center;text-align:center;margin-bottom:12px}
.logo{width:120px;height:auto;object-fit:contain}
.logo-lg{width:min(220px, 70vw)}
.form{margin-top:8px}

/* layout */
.layout{display:flex;min-height:100vh}
.side{
  width:260px;
  padding:16px;
  border-right:1px solid var(--line);
  background:#fff;
}
.side-brand{display:flex;gap:12px;align-items:center;margin-bottom:18px}
.side-brand.only-logo{justify-content:center}
.logo-sm{width:52px;height:auto}
.logo-side{width:150px;max-width:70%;height:auto;object-fit:contain}

.side-title{font-weight:900}
.nav{display:flex;flex-direction:column;gap:6px}
.nav-item{
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid transparent;
  cursor:pointer;
}
.nav-item:hover{background:#f8fafc;border-color:#e2e8f0}
.nav-item.active{background:#eff6ff;border-color:#bfdbfe;color:#1d4ed8}
.linklike{background:transparent;border:1px solid transparent;text-align:left}

.main{flex:1;padding:18px;max-width:1400px;margin:0 auto;width:100%}
.topbar{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  margin-bottom:14px;
}
.top-actions{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
  justify-content:flex-end;
}
.top-actions .inp{width:auto;min-width:170px}
.table-wrap{overflow:auto;border-radius:var(--r)}
.tbl{width:100%;border-collapse:collapse}
.tbl th,.tbl td{padding:12px 10px;border-bottom:1px solid var(--line);text-align:left;white-space:nowrap}
.tbl th{position:sticky;top:0;background:#fff;z-index:1;font-size:12px;color:#334155}
.footer{margin-top:14px}

/* responsive */
@media (max-width: 920px){
  .layout{flex-direction:column}
  .side{
    width:100%;
    border-right:0;
    border-bottom:1px solid var(--line);
    display:flex;
    align-items:center;
    justify-content:space-between;
  }
  .side-brand{margin-bottom:0}
  .nav{display:flex;flex-direction:row;gap:10px}
}
@media (max-width: 480px){
  .auth-card{padding:16px}
  .logo-side{width:130px}
  .top-actions .inp{min-width:140px}
}
/* --- Protokol tabela: kompaktnije, bez ogromnih slova --- */
.tbl { font-size: 13px; }
.tbl th, .tbl td { padding: 8px 10px; vertical-align: top; }


/* =========================
   FIX: MODAL always on top
   ========================= */
.modal{
  position: fixed;
  inset: 0;
  display: none;              /* JS prebacuje na flex */
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.55);
  z-index: 9999;              /* iznad sticky headera i svega */
  padding: 16px;
}
.modal-card{
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  width: min(920px, 96vw);
  max-height: 90vh;
  overflow: auto;
}
.modal-card.wide{ width: min(1100px, 96vw); }

.modal-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:14px 14px 10px 14px;
  border-bottom:1px solid var(--line);
}
.modal-body{ padding: 14px; }
.modal-foot{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  padding: 12px 14px 14px 14px;
  border-top:1px solid var(--line);
}
.iconbtn{
  border:1px solid var(--line);
  background:#fff;
  border-radius:12px;
  padding:8px 10px;
  cursor:pointer;
  font-weight:900;
  line-height:1;
}

/* =========================
   FIX: TABLE fits (no right scroll)
   ========================= */
.table-wrap{
  overflow: hidden;           /* umjesto auto -> ne ide desno */
  border-radius: var(--r);
}

/* fixed layout -> kolone se poštuju i tekst se lomi */
.tbl{
  width:100%;
  border-collapse:collapse;
  table-layout: fixed;
  font-size: 13px;
}

/* makni nowrap (to je uzrok skrolanja i lomljenja dugmadi) */
.tbl th, .tbl td{
  padding: 8px 10px;
  vertical-align: top;
  white-space: normal;        /* ? omogućava wrap */
  word-break: break-word;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* sticky header ostaje, ali z-index mali u odnosu na modal */
.tbl th{
  position: sticky;
  top: 0;
  background:#fff;
  z-index: 2;
  font-size:12px;
  color:#334155;
}

/* kolone koje treba da ostanu kratke i u jednom redu */
.tbl th:nth-child(1), .tbl td:nth-child(1),  /* Datum */
.tbl th:nth-child(2), .tbl td:nth-child(2),  /* Broj */
.tbl th:nth-child(3), .tbl td:nth-child(3),  /* Status */
.tbl th:nth-child(13), .tbl td:nth-child(13) /* PDF */
{
  white-space: nowrap;
}

/* booleans centriraj */
.tbl th:nth-child(9), .tbl td:nth-child(9),
.tbl th:nth-child(10), .tbl td:nth-child(10),
.tbl th:nth-child(11), .tbl td:nth-child(11),
.tbl th:nth-child(13), .tbl td:nth-child(13){
  text-align:center;
}

/* =========================
   FIX: PDF dugme da ne ide u 2 reda
   (i da bude manje)
   ========================= */
.btn.tiny{
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}
/* =========================
   Protokol tabela – pametnije širine kolona
   ========================= */

/* =========================
   PROTOKOL: tabela + modal FIX (CISTO)
   ========================= */

/* modal uvijek iznad svega */
.modal{
  position: fixed;
  inset: 0;
  display: none;              /* JS prebacuje na flex */
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.55);
  z-index: 9999;
  padding: 16px;
}
.modal-card{
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  width: min(920px, 96vw);
  max-height: 90vh;
  overflow: auto;
}
.modal-card.wide{ width: min(1100px, 96vw); }

.modal-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:14px 14px 10px 14px;
  border-bottom:1px solid var(--line);
}
.modal-body{ padding: 14px; }
.modal-foot{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  padding: 12px 14px 14px 14px;
  border-top:1px solid var(--line);
}
.iconbtn{
  border:1px solid var(--line);
  background:#fff;
  border-radius:12px;
  padding:8px 10px;
  cursor:pointer;
  font-weight:900;
  line-height:1;
}

/* tabela - da sve stane u širinu main-a */
.main{ max-width: 1600px; }

.table-wrap{
  overflow: hidden;     /* nema horizontalnog scrolla */
  border-radius: var(--r);
}

/* fixed layout + wrap tekst (nema preklapanja) */
.tbl{
  width:100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12.5px;
}

.tbl th,.tbl td{
  padding: 8px 8px;
  border-bottom:1px solid var(--line);
  text-align:left;
  vertical-align: top;
  white-space: normal;
  word-break: break-word;
  overflow: hidden;
}

.tbl th{
  position: sticky;
  top: 0;
  background:#fff;
  z-index: 2;
  font-size: 12px;
  color:#334155;
}

/* centriraj DA/NE i PDF */
.tbl th:nth-child(9), .tbl td:nth-child(9),
.tbl th:nth-child(10), .tbl td:nth-child(10),
.tbl th:nth-child(11), .tbl td:nth-child(11),
.tbl th:nth-child(13), .tbl td:nth-child(13){
  text-align:center;
}

/* pametne širine kolona (zbir ~1600px da stane bez skrola) */
.tbl th:nth-child(1), .tbl td:nth-child(1){ width: 92px;  white-space: nowrap; }  /* Datum */
.tbl th:nth-child(2), .tbl td:nth-child(2){ width: 78px;  white-space: nowrap; }  /* Broj */
.tbl th:nth-child(3), .tbl td:nth-child(3){ width: 86px;  white-space: nowrap; }  /* Status */
.tbl th:nth-child(4), .tbl td:nth-child(4){ width: 170px; }                       /* Pacijent */
.tbl th:nth-child(5), .tbl td:nth-child(5){ width: 120px; }                       /* JMBG/ID */
.tbl th:nth-child(6), .tbl td:nth-child(6){ width: 230px; }                       /* Firma */
.tbl th:nth-child(7), .tbl td:nth-child(7){ width: 95px;  white-space: nowrap; }  /* Placanje */
.tbl th:nth-child(8), .tbl td:nth-child(8){ width: 110px; }                       /* Dokument */
.tbl th:nth-child(9), .tbl td:nth-child(9){ width: 60px;  white-space: nowrap; }  /* Nos */
.tbl th:nth-child(10),.tbl td:nth-child(10){width: 70px;  white-space: nowrap; }  /* Stolica */
.tbl th:nth-child(11),.tbl td:nth-child(11){width: 95px;  white-space: nowrap; }  /* Pulmo/Koza */
.tbl th:nth-child(12),.tbl td:nth-child(12){width: 240px; }                       /* Rezultat */
.tbl th:nth-child(13),.tbl td:nth-child(13){width: 64px;  white-space: nowrap; }  /* PDF */

/* PDF dugme da uvijek stane u kolonu */
.btn.tiny{
  padding: 6px 8px;
  border-radius: 10px;
  font-size: 11.5px;
  line-height: 1;
  white-space: nowrap;
  min-width: 52px;
}

/* Rezultat: tačno 2 linije (na DIV-u, ne na TD-u!) */
.clamp2{
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;

  line-height: 1.35;
  max-height: calc(1.35em * 2);
  padding: 1px 0;
}

/* FINAL FIX: tabela uvijek vidljiva, bez "smaknuto udesno" */
.table-wrap{
  overflow-x: auto !important;
  overflow-y: auto !important;
}
