/* ───────────────────────────────────────────────────────────────────────────
   FilPDF — izgled.
   Jedna paleta u promenljivim, dve teme. Ikone su SVG i naslede `currentColor`,
   pa se boje same slažu sa temom.
   ─────────────────────────────────────────────────────────────────────────── */

:root {
  --bg:        #eef0f4;   /* pozadina ljuske */
  --surface:   #ffffff;   /* trake, paneli */
  --surface2:  #f5f6f9;   /* uvučene površine */
  --hover:     #e6e9f0;
  --fg:        #1b1d24;
  --dim:       #6a7080;
  --line:      #dfe3ea;
  --line2:     #eceff4;
  --accent:    #3b6ef0;
  --accent-fg: #ffffff;
  --accent-sm: #3b6ef01f;
  --danger:    #d4453c;
  --canvas:    #8e93a3;   /* iza strana */
  --shadow:    0 1px 2px #0f172a12, 0 4px 14px #0f172a10;
  --shadow-lg: 0 10px 34px #0f172a24;

  --tabh: 36px;
  --barh: 44px;
  --edith: 42px;
  --statush: 28px;
  --railw: 68px;
  --sidew: 218px;
  --panelw: 340px;
  --panelw-wide: 580px;
  --r: 8px;
}

body.dark {
  --bg:        #15161d;
  --surface:   #1c1e27;
  --surface2:  #23262f;
  --hover:     #2b2f3b;
  --fg:        #d7dced;
  --dim:       #858da6;
  --line:      #2c3040;
  --line2:     #242833;
  --accent:    #6f95f7;
  --accent-fg: #10131c;
  --accent-sm: #6f95f726;
  --danger:    #f2707f;
  --canvas:    #0e0f14;
  --shadow:    0 1px 2px #0008, 0 4px 14px #0006;
  --shadow-lg: 0 12px 38px #000a;
}

* { box-sizing: border-box; }

/* MORA da stoji: `display:flex` iz pravila ispod inače pobedi HTML atribut
   `hidden` (UA stil je samo `display:none`), pa se skriveni paneli i dalje vide. */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font: 13px/1.5 "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  grid-template-rows: var(--tabh) var(--barh) 0 1fr var(--statush);
  height: 100vh;
}
body.editing { grid-template-rows: var(--tabh) var(--barh) var(--edith) 1fr var(--statush); }

/* Redovi se dodeljuju EKSPLICITNO. `#editbar` je skriven dok se ne edituje, a
   `display:none` ga izbacuje iz grida — bez ovoga se sve ispod pomeri za red
   naviše (main dobije 0 px, statusbar završi na sredini ekrana). */
#tabbar    { grid-row: 1; }
#toolbar   { grid-row: 2; }
#editbar   { grid-row: 3; }
#main      { grid-row: 4; }
#statusbar { grid-row: 5; }

.dim { color: var(--dim); }
.pad { padding: 10px 12px; }
.small { font-size: 12px; }
.spacer { flex: 1; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 7px; flex: none; }
.ico { display: inline-flex; align-items: center; justify-content: center; }
.ico svg { display: block; }

/* ── Tabovi ──────────────────────────────────────────────────────────────── */
#tabbar {
  display: flex; align-items: flex-end; gap: 3px;
  padding: 0 6px; background: var(--bg);
  overflow: hidden;
}
#tabs { display: flex; gap: 3px; overflow-x: auto; scrollbar-width: none; }
#tabs::-webkit-scrollbar { height: 0; }

.tab {
  display: flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 6px 0 12px;
  max-width: 240px; min-width: 122px;
  border-radius: var(--r) var(--r) 0 0;
  background: transparent; color: var(--dim);
  cursor: default; white-space: nowrap;
  transition: background .12s, color .12s;
}
.tab:hover { background: var(--hover); color: var(--fg); }
.tab.active { background: var(--surface); color: var(--fg); box-shadow: 0 -1px 0 var(--line) inset, -1px 0 0 var(--line), 1px 0 0 var(--line); }
.tablabel { overflow: hidden; text-overflow: ellipsis; flex: 1; font-size: 12.5px; }
.tab .dot { color: var(--accent); font-size: 15px; line-height: 0; }
.tabx {
  display: flex; align-items: center; justify-content: center;
  border: 0; background: transparent; color: inherit; opacity: 0;
  cursor: pointer; width: 19px; height: 19px; border-radius: 5px; font-size: 11px;
}
.tab:hover .tabx, .tab.active .tabx { opacity: .55; }
.tabx:hover { opacity: 1 !important; background: var(--line); }
.tabbtn {
  display: flex; align-items: center; justify-content: center;
  border: 0; background: transparent; color: var(--dim);
  width: 30px; height: 30px; border-radius: var(--r); cursor: pointer;
}
.tabbtn:hover { background: var(--hover); color: var(--fg); }

/* ── Gornja traka ────────────────────────────────────────────────────────── */
#toolbar, #editbar {
  display: flex; align-items: center; gap: 4px; padding: 0 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
#editbar { background: var(--surface2); }

.tb {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; background: transparent; color: var(--fg);
  min-width: 30px; height: 30px; padding: 0 7px;
  border-radius: 7px; cursor: pointer; font-size: 12.5px;
  transition: background .12s, color .12s;
}
.tb:hover { background: var(--hover); }
.tb.on { background: var(--accent-sm); color: var(--accent); }
.tb.accent { background: var(--accent); color: var(--accent-fg); font-weight: 600; padding: 0 12px; }
.tb.accent:hover { filter: brightness(1.07); }
.tb .lbl { white-space: nowrap; }

.group {
  display: flex; align-items: center; gap: 2px;
  background: var(--surface2); border: 1px solid var(--line2);
  border-radius: 9px; padding: 2px; margin: 0 3px;
}
.group .tb { height: 26px; min-width: 26px; }

#pagenum {
  width: 42px; text-align: center; height: 24px;
  border: 1px solid transparent; border-radius: 6px;
  background: var(--surface); color: var(--fg); font-size: 12.5px;
}
#pagenum:focus { border-color: var(--accent); outline: none; }
#pagecount { font-size: 12px; padding-right: 4px; }

#zoomsel {
  height: 26px; border: 1px solid transparent; border-radius: 6px;
  background: var(--surface); color: var(--fg); padding: 0 4px; font-size: 12.5px;
}

#findbox {
  display: flex; align-items: center; gap: 3px;
  background: var(--surface2); border: 1px solid var(--line2);
  border-radius: 9px; padding: 2px 4px 2px 2px;
}
#findinput {
  width: 200px; height: 26px; padding: 0 9px;
  border: 0; border-radius: 6px;
  background: var(--surface); color: var(--fg); font-size: 12.5px;
}
#findinput:focus { outline: 1px solid var(--accent); }
#findcount { min-width: 54px; font-size: 11.5px; text-align: center; }
.chk { display: flex; align-items: center; gap: 4px; color: var(--dim); font-size: 12px; cursor: pointer; padding: 0 3px; }

/* ── Traka za editovanje ─────────────────────────────────────────────────── */
.editname { font-weight: 600; font-size: 12.5px; }
.swatches { display: flex; gap: 5px; align-items: center; }
.swatch {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer; padding: 0;
  box-shadow: inset 0 0 0 1px #00000018;
}
.swatch.on { border-color: var(--fg); }
.rangewrap { display: flex; align-items: center; gap: 8px; margin-left: 12px; color: var(--dim); font-size: 12px; }
.rangewrap input[type="range"] { width: 110px; accent-color: var(--accent); }

/* ── Glavni deo ──────────────────────────────────────────────────────────── */
#main {
  display: grid;
  grid-template-columns: var(--railw) var(--sidew) 1fr 0;
  min-height: 0; overflow: hidden;
  background: var(--surface);
}
body.nosidebar #main { grid-template-columns: var(--railw) 0 1fr 0; }
body.haspanel #main { grid-template-columns: var(--railw) var(--sidew) 1fr var(--panelw); }
body.haspanel.nosidebar #main { grid-template-columns: var(--railw) 0 1fr var(--panelw); }
body.haspanel:has(#toolpanel.wide) #main { grid-template-columns: var(--railw) var(--sidew) 1fr var(--panelw-wide); }
body.haspanel.nosidebar:has(#toolpanel.wide) #main { grid-template-columns: var(--railw) 0 1fr var(--panelw-wide); }

/* ── Leva traka (rail) ───────────────────────────────────────────────────── */
#rail {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 6px; overflow-y: auto; overflow-x: hidden;
  background: var(--surface); border-right: 1px solid var(--line);
  scrollbar-width: none;
}
#rail::-webkit-scrollbar { width: 0; }

.railbtn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: 0; background: transparent; color: var(--dim);
  padding: 7px 2px 6px; border-radius: 9px; cursor: pointer;
  font-size: 9.5px; line-height: 1.15; text-align: center; width: 100%;
  transition: background .12s, color .12s;
}
.railbtn:hover { background: var(--hover); color: var(--fg); }
.railbtn.on { background: var(--accent-sm); color: var(--accent); }
.railbtn[disabled] { opacity: .35; cursor: default; }
.railbtn[disabled]:hover { background: transparent; color: var(--dim); }
.railsep { height: 1px; background: var(--line2); margin: 7px 8px; flex: none; }
.railcap {
  font-size: 8.5px; letter-spacing: .7px; text-transform: uppercase;
  color: var(--dim); opacity: .65; text-align: center; margin: 4px 0 2px;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-width: 0; overflow: hidden;
}
body.nosidebar #sidebar { display: none; }

#sidetabs { display: flex; gap: 2px; padding: 6px; }
.sidetab {
  flex: 1; border: 0; background: transparent; color: var(--dim);
  padding: 6px 4px; cursor: pointer; font-size: 12px; border-radius: 7px;
}
.sidetab:hover { background: var(--hover); color: var(--fg); }
.sidetab.active { background: var(--accent-sm); color: var(--accent); font-weight: 600; }
.sidepane { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }

.thumb {
  position: relative; margin: 0 auto 12px; width: fit-content;
  border-radius: 6px; cursor: pointer; line-height: 0;
  transition: transform .1s;
}
.thumb canvas {
  display: block; border-radius: 4px; background: #fff;
  box-shadow: var(--shadow); outline: 2px solid transparent;
  transition: outline-color .12s;
}
.thumb:hover canvas { outline-color: var(--line); }
.thumb.active canvas { outline-color: var(--accent); }
.thumbcap { display: block; text-align: center; font-size: 11px; color: var(--dim); line-height: 1.9; }
.thumb.active .thumbcap { color: var(--accent); font-weight: 600; }

ul.outline, ul.outline ul { list-style: none; margin: 0; padding: 0; }
.outlink {
  display: block; width: 100%; text-align: left; border: 0;
  background: transparent; color: var(--fg); cursor: pointer;
  padding: 5px 8px; font-size: 12px; border-radius: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.outlink:hover { background: var(--hover); }

/* ── Viewer ──────────────────────────────────────────────────────────────── */
#viewerwrap { position: relative; min-width: 0; overflow: hidden; }
#viewerContainer {
  position: absolute; inset: 0;        /* PDF.js zahteva absolute */
  overflow: auto; background: var(--canvas);
}
.pdfViewer .page {
  margin: 14px auto; border: 0;
  box-shadow: 0 1px 3px #00000026, 0 8px 26px #00000030;
  border-radius: 3px; overflow: hidden;
}
#viewerContainer .textLayer { user-select: text; }

/* Tamne strane: invertuje se samo iscrtan sadržaj, ne i UI */
body.invert .pdfViewer .canvasWrapper canvas { filter: invert(1) hue-rotate(180deg); }

/* Kad je alat za editovanje aktivan — pokazivač i suptilan okvir strane */
body.editing .pdfViewer .page { outline: 1px solid var(--accent-sm); }

/* ── Welcome ─────────────────────────────────────────────────────────────── */
#welcome {
  position: absolute; inset: 0; display: flex;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; background: var(--bg); text-align: center; padding: 30px;
  overflow-y: auto;
}
.wcard {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 30px 44px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.wlogo { font-size: 27px; font-weight: 650; letter-spacing: -.6px; }
.wbtns { display: flex; gap: 8px; margin-top: 14px; }
.bigbtn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; background: var(--accent); color: var(--accent-fg);
  padding: 10px 18px; border-radius: 9px; cursor: pointer;
  font-size: 13.5px; font-weight: 600;
}
.bigbtn:hover { filter: brightness(1.07); }
.bigbtn.ghost { background: var(--surface2); color: var(--fg); box-shadow: inset 0 0 0 1px var(--line); }
.bigbtn.ghost:hover { background: var(--hover); filter: none; }

#welcome-recent { width: min(580px, 100%); }
#welcome-recent h3 {
  margin: 0 0 8px; font-size: 10.5px; color: var(--dim); font-weight: 700;
  text-transform: uppercase; letter-spacing: .9px;
}
.recentitem {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left; border: 1px solid var(--line);
  background: var(--surface); color: var(--fg);
  padding: 8px 12px; margin-bottom: 6px; border-radius: 9px; cursor: pointer;
  transition: border-color .12s, transform .1s;
}
.recentitem:hover { border-color: var(--accent); transform: translateX(2px); }
.recentitem .ico { color: var(--dim); flex: none; }
.rtext { display: flex; flex-direction: column; min-width: 0; }
.rname { font-weight: 600; font-size: 12.5px; }
.rpath { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Panel alata ─────────────────────────────────────────────────────────── */
#toolpanel {
  background: var(--surface); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-width: 0; overflow: hidden;
}
#toolpanel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 8px 10px 14px; border-bottom: 1px solid var(--line);
  font-weight: 650; font-size: 13.5px;
}
#toolpanel-body { flex: 1; overflow-y: auto; padding: 12px 14px; }

.trow { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.tlabel { flex: 0 0 118px; color: var(--dim); font-size: 12px; }
.trow input[type="text"], .trow input[type="number"], .trow select {
  flex: 1; min-width: 0; height: 28px; padding: 0 9px;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface2); color: var(--fg); font-size: 12.5px;
}
.trow input:focus, .trow select:focus { outline: none; border-color: var(--accent); }
.trow input[type="range"] { flex: 1; accent-color: var(--accent); }
.trow input[type="color"] { width: 42px; height: 28px; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface2); }
.trow input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

.toolh { margin: 18px 0 9px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .9px; color: var(--dim); font-weight: 700; }
.toolbar-mini { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-bottom: 12px; }
.toolbar-mini .sep { height: 16px; margin: 0 3px; }

/* Lepljivo dno: kod dugačke mreže strana dugme „Tillämpa" mora ostati na ekranu */
.toolfoot {
  position: sticky; bottom: -12px; z-index: 2;
  background: var(--surface); border-top: 1px solid var(--line);
  margin-top: 14px; padding: 11px 0;
  display: flex; flex-direction: column; gap: 7px;
}

.tbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface2); color: var(--fg);
  padding: 6px 11px; border-radius: 7px; cursor: pointer; font-size: 12px;
  transition: background .12s, border-color .12s;
}
.tbtn:hover { background: var(--hover); }
.tbtn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 650; padding: 9px 11px; }
.tbtn.primary:hover { filter: brightness(1.07); }
.tbtn.danger { color: var(--danger); }
.tbtn.danger:hover { border-color: var(--danger); }
.tbtn.mini { padding: 2px 7px; }

.infotbl { display: grid; grid-template-columns: 110px 1fr; gap: 5px 12px; margin-bottom: 14px; }
.ik { color: var(--dim); font-size: 12px; }
.iv { word-break: break-all; font-size: 12px; }

.filelist { display: flex; flex-direction: column; gap: 5px; }
.fileitem {
  display: flex; align-items: center; gap: 9px;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px;
  background: var(--surface2); cursor: grab;
}
.fileitem:hover { border-color: var(--accent); }
.fidx { color: var(--dim); font-size: 11px; min-width: 14px; }
.fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }

/* Mreža strana u „Ordna sidor" */
.pagegrid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(122px, 1fr));
  gap: 12px; align-content: start;
}
.pcell {
  border: 2px solid var(--line2); border-radius: 8px; padding: 5px;
  background: var(--surface2); cursor: grab; text-align: center; line-height: 0;
  transition: border-color .12s, background .12s;
}
.pcell:hover { border-color: var(--line); }
.pcell.sel { border-color: var(--accent); background: var(--accent-sm); }
.pcell.dragging { opacity: .35; }
.pcell.dropto { border-color: var(--accent); border-style: dashed; }
.pcell canvas { max-width: 100%; background: #fff; border-radius: 3px; box-shadow: var(--shadow); }
.pcap { display: block; font-size: 11px; color: var(--dim); line-height: 2; }

/* ── Statusbar ───────────────────────────────────────────────────────────── */
#statusbar {
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--surface); border-top: 1px solid var(--line);
  font-size: 11.5px; overflow: hidden;
}
#status-file { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }
#status-msg { white-space: nowrap; }
.linkbtn {
  border: 0; background: transparent; color: var(--dim);
  cursor: pointer; font-size: 11.5px; padding: 3px 7px; border-radius: 6px;
}
.linkbtn:hover { color: var(--accent); background: var(--hover); }
#appver.hasupdate { color: var(--accent); font-weight: 600; }
#updatebtn { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
#updatebtn:hover { color: var(--accent-fg); filter: brightness(1.07); }

/* ── Drop zona / toast ───────────────────────────────────────────────────── */
#dropzone {
  position: fixed; inset: 0; z-index: 80;
  background: #0f172a55; backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.dropcard {
  background: var(--surface); color: var(--fg);
  border: 2px dashed var(--accent); border-radius: 16px;
  padding: 28px 44px; font-size: 16px; font-weight: 650;
  box-shadow: var(--shadow-lg);
}
#toast {
  position: fixed; bottom: 44px; left: 50%; transform: translateX(-50%);
  z-index: 90; background: var(--surface); color: var(--fg);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 18px; box-shadow: var(--shadow-lg); max-width: 70vw;
  font-size: 12.5px;
}

/* ── Skrolbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #8a90a555; border-radius: 7px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #8a90a599; background-clip: padding-box; }
