:root {
  --red: #e03c31; --red-dark: #b52e24;
  --bg: #f4f4ef; --card: #ffffff;
  --text: #1a1a1a; --muted: #6b6b6b; --border: #e6e6e0;
  --low: #e07b31; --good: #2e8b57; --radius: 14px;
  --sidebar-w: 240px;
  --sidebar-bg: #1e1b1a;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 8px 28px rgba(0,0,0,.12);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; -webkit-font-smoothing: antialiased; }

/* LOGIN */
#login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--red); padding: 1rem; }
.login-box { background: white; border-radius: 20px; padding: 2rem 1.5rem; width: 100%; max-width: 360px; text-align: center; box-shadow: 0 8px 32px rgba(0,0,0,.2); }
.login-logo { font-size: 3rem; margin-bottom: .5rem; }
.login-box h1 { font-size: 1.6rem; font-weight: 800; }
.login-sub { color: var(--muted); margin-bottom: 1.5rem; font-size: .9rem; }
.login-box input { display: block; width: 100%; padding: .75rem; border: 1.5px solid var(--border); border-radius: 10px; font-size: 1rem; margin-bottom: .75rem; background: var(--bg); }
.login-box input:focus { outline: none; border-color: var(--red); }
.login-error { color: var(--red); font-size: .87rem; margin-top: .5rem; font-weight: 500; }

/* APP LAYOUT */
#app { display: flex; min-height: 100vh; }

/* SIDEBAR */
#sidebar { width: var(--sidebar-w); background: var(--sidebar-bg); color: #fff; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 30; transition: transform .25s ease; }
.sidebar-brand { display: flex; align-items: center; gap: .6rem; padding: 1.25rem 1.25rem 1rem; font-weight: 800; font-size: 1.25rem; }
.sidebar-brand .brand-logo { font-size: 1.6rem; }
.sidebar-brand .brand-name { letter-spacing: .3px; }
#main-nav { display: flex; flex-direction: column; gap: .15rem; padding: .5rem .75rem; flex: 1; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: .7rem; padding: .7rem .85rem; border: none; background: none; color: rgba(255,255,255,.62); font-size: .9rem; font-weight: 500; cursor: pointer; border-radius: 10px; text-align: left; transition: background .15s, color .15s; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--red); color: #fff; font-weight: 600; }
.nav-ico { font-size: 1.1rem; width: 1.4rem; text-align: center; }
.sidebar-footer { padding: .85rem; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-user { display: flex; align-items: center; gap: .65rem; margin-bottom: .65rem; }
.su-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--red); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1rem; text-transform: uppercase; flex-shrink: 0; }
.su-info { min-width: 0; }
.su-name { font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.su-role { font-size: .72rem; color: rgba(255,255,255,.5); }
.btn-logout { width: 100%; background: rgba(255,255,255,.08); border: none; color: rgba(255,255,255,.8); padding: .5rem; border-radius: 8px; font-size: .82rem; cursor: pointer; font-weight: 500; transition: background .15s; }
.btn-logout:hover { background: rgba(255,255,255,.15); color: #fff; }
#sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 25; }
#sidebar-overlay.show { display: block; }

/* MAIN */
#main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 1rem; padding: .9rem 1.5rem; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
#page-title { font-size: 1.15rem; font-weight: 700; flex: 1; }
.btn-menu { display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text); line-height: 1; }
#stats-bar { display: flex; gap: .5rem; }
.stat-chip { background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: .35rem .8rem; font-size: .78rem; color: var(--muted); white-space: nowrap; }
.stat-chip b { color: var(--red); font-weight: 700; }

#content { padding: 1.5rem; max-width: 900px; width: 100%; }

.tab { display: none; }
.tab.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
h2 { font-size: 1.05rem; font-weight: 700; }
.hint { font-size: .82rem; color: var(--muted); line-height: 1.5; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .85rem; }

/* MOBILE */
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  #sidebar.open { transform: translateX(0); }
  #main { margin-left: 0; }
  .btn-menu { display: block; }
  #content { padding: 1rem; }
  #topbar { padding: .8rem 1rem; }
  #stats-bar { display: none; }
}

/* CARDS */
.card { background: var(--card); border-radius: var(--radius); padding: 1rem; margin-bottom: .75rem; box-shadow: 0 1px 4px rgba(0,0,0,.06); border: 1px solid var(--border); }
.hint-card { font-size: .83rem; color: var(--muted); line-height: 1.7; }
.form-card h3 { font-size: .9rem; font-weight: 700; margin-bottom: .75rem; }
.form-card input { display: block; width: 100%; padding: .65rem .75rem; border: 1.5px solid var(--border); border-radius: 8px; font-size: .95rem; margin-bottom: .6rem; background: var(--bg); }
.form-card input:focus { outline: none; border-color: var(--red); }
.row-inputs { display: flex; gap: .5rem; }
.row-inputs input { flex: 1; }
.btn-row { display: flex; gap: .5rem; margin-top: .25rem; }

/* BUTTONS */
.btn-primary { background: var(--red); color: white; border: none; border-radius: 10px; padding: .7rem 1.2rem; font-size: .9rem; font-weight: 600; cursor: pointer; transition: background .15s; }
.btn-primary:hover { background: var(--red-dark); }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); border-radius: 10px; padding: .7rem 1.2rem; font-size: .9rem; font-weight: 600; cursor: pointer; }
.btn-full { width: 100%; }
.btn-icon { width: 32px; height: 32px; border-radius: 50%; border: none; background: var(--red); color: white; font-size: 1.3rem; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.btn-small { border: 1px solid var(--border); background: var(--bg); border-radius: 6px; padding: .3rem .5rem; font-size: .75rem; cursor: pointer; color: var(--muted); }
.btn-small.del { color: var(--red); }

/* INVENTORY */
.inv-item { background: var(--card); border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: .5rem; border: 1px solid var(--border); display: flex; align-items: center; gap: .75rem; }
.inv-item .item-info { flex: 1; min-width: 0; }
.inv-item .item-name { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inv-item .item-qty { font-size: 1.05rem; font-weight: 700; color: var(--good); white-space: nowrap; }
.inv-item.low .item-qty { color: var(--low); }
.inv-item.critical .item-qty { color: var(--red); }
.item-actions { display: flex; gap: .4rem; }

/* INVENTORY GROUPS */
.inv-group { margin-bottom: 1.25rem; }
.inv-group-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: .3rem .25rem .4rem; border-bottom: 2px solid var(--border); margin-bottom: .4rem; }
.item-recipe-qty { font-size: .72rem; color: var(--muted); margin-top: .1rem; }
.inv-item.inv-missing { opacity: .65; border-style: dashed; }
.inv-missing-qty { color: var(--muted) !important; font-size: .85rem; font-style: italic; }

/* SALE */
.sale-product-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 1rem; margin-bottom: .5rem; }
.sp-name { font-weight: 600; font-size: .95rem; flex: 1; }
.sp-controls { display: flex; align-items: center; gap: .75rem; }
.sp-count { font-size: 1.5rem; font-weight: 700; min-width: 32px; text-align: center; }
.sp-input { width: 56px; font-size: 1.4rem; font-weight: 700; text-align: center; border: 1.5px solid var(--border); border-radius: 8px; padding: .25rem; background: var(--bg); -moz-appearance: textfield; }
.sp-input::-webkit-outer-spin-button, .sp-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.sp-input:focus { outline: none; border-color: var(--red); }
.btn-big { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--border); background: white; font-size: 1.4rem; cursor: pointer; display: flex; align-items: center; justify-content: center; font-weight: 300; }
.btn-big:active { background: var(--bg); transform: scale(.95); }
.note-input { width: 100%; padding: .65rem .75rem; border: 1.5px solid var(--border); border-radius: 8px; font-size: .9rem; background: var(--bg); }
.note-input:focus { outline: none; border-color: var(--red); }
.sale-entry { background: var(--card); border-radius: 10px; padding: .65rem 1rem; margin-bottom: .4rem; display: flex; align-items: center; border: 1px solid var(--border); font-size: .88rem; gap: .5rem; box-shadow: var(--shadow); }
.sale-entry .sale-count { font-weight: 700; font-size: 1rem; color: var(--red); white-space: nowrap; }
.sale-entry .sale-time { font-size: .75rem; color: var(--muted); white-space: nowrap; }

/* BATCH (šarže) */
.batch-make { display: flex; gap: .5rem; align-items: center; }
.batch-select { flex: 2; min-width: 0; padding: .65rem .75rem; border: 1.5px solid var(--border); border-radius: 8px; font-size: .95rem; background: var(--bg); color: var(--text); }
.batch-select:focus { outline: none; border-color: var(--red); }
.batch-qty { flex: 1; min-width: 0; padding: .65rem .75rem; border: 1.5px solid var(--border); border-radius: 8px; font-size: .95rem; background: var(--bg); }
.batch-qty:focus { outline: none; border-color: var(--red); }
.batch-unit { font-weight: 700; color: var(--muted); white-space: nowrap; min-width: 1.5rem; }
.batch-info { margin-top: .6rem; font-size: .85rem; }
.batch-info .bi-green { color: var(--good); }
.batch-info .bi-grey { color: var(--muted); }
.semi-badge { display: inline-block; font-size: .72rem; padding: .12rem .55rem; border-radius: 10px; margin-left: .4rem; font-weight: 600; }
.semi-badge.green { background: #e8f5e9; color: var(--good); }
.semi-badge.grey { background: #f0f0ea; color: var(--muted); }
.ri-stock { font-size: .76rem; color: var(--good); white-space: nowrap; }
.ri-stock.missing { color: var(--low); }
.recipe-row { flex-wrap: wrap; gap: .3rem .5rem; }

/* DELIVERIES (dobavnice) history */
.delivery-card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: .6rem; overflow: hidden; box-shadow: var(--shadow); }
.delivery-head { display: flex; align-items: center; gap: .6rem; padding: .75rem 1rem; cursor: pointer; }
.delivery-icon { font-size: 1.3rem; }
.delivery-meta { flex: 1; min-width: 0; }
.delivery-title { font-weight: 600; font-size: .92rem; }
.delivery-sub { font-size: .75rem; color: var(--muted); margin-top: .1rem; }
.delivery-count { font-size: .78rem; font-weight: 600; color: var(--red); background: #fff3f2; padding: .2rem .55rem; border-radius: 12px; white-space: nowrap; }
.delivery-toggle { color: var(--muted); font-size: .9rem; transition: transform .2s; }
.delivery-card.open .delivery-toggle { transform: rotate(180deg); }
.delivery-items { display: none; padding: 0 1rem .75rem; border-top: 1px solid var(--border); }
.delivery-card.open .delivery-items { display: block; }
.delivery-item-row { display: flex; justify-content: space-between; padding: .4rem 0; border-bottom: 1px dashed var(--border); font-size: .85rem; }
.delivery-item-row:last-child { border-bottom: none; }
.delivery-item-row .di-qty { font-weight: 600; color: var(--text); }
.delivery-del { background: none; border: none; color: var(--red); cursor: pointer; font-size: .78rem; padding: .5rem 0 0; }

/* INVOICE */
.upload-btns { display: flex; gap: .5rem; }
.upload-btns .btn-primary { flex: 1; }
.upload-btns .btn-secondary { flex: 1; }
.camera-label { display: flex; align-items: center; justify-content: center; gap: .5rem; cursor: pointer; }
#invoice-preview { width: 100%; border-radius: 10px; margin: .75rem 0 .5rem; max-height: 250px; object-fit: contain; background: var(--bg); }
.pdf-preview { display: flex; align-items: center; gap: .75rem; background: var(--bg); border-radius: 10px; padding: 1rem; margin: .75rem 0 .5rem; border: 1.5px solid var(--border); }
.pdf-icon { font-size: 2rem; }
#pdf-filename { font-size: .9rem; font-weight: 500; color: var(--text); word-break: break-all; }
.loading-msg { text-align: center; padding: 1rem; color: var(--muted); font-size: .9rem; }
.parsed-item-card { background: var(--card); border-radius: 10px; margin-bottom: .5rem; border: 1px solid var(--border); overflow: hidden; }
.pi-match-info { font-size: .75rem; padding: .3rem .75rem; background: #e8f5e9; color: #2e7d32; font-weight: 500; }
.pi-match-info.pi-new { background: #fff8e1; color: #f57f17; }
.parsed-item { display: flex; gap: .5rem; align-items: center; padding: .6rem .75rem; }
.parsed-item input { padding: .45rem .6rem; border: 1.5px solid var(--border); border-radius: 7px; font-size: .88rem; background: var(--bg); }
.parsed-item input:focus { outline: none; border-color: var(--red); }
.pi-name { flex: 2; } .pi-qty { flex: 1; } .pi-unit { flex: 1; }
.pi-del { background: none; border: none; color: var(--red); font-size: 1.1rem; cursor: pointer; padding: .25rem; }

/* PRODUCTS */
.product-card { background: var(--card); border-radius: var(--radius); margin-bottom: .75rem; border: 1px solid var(--border); overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.product-header { display: flex; align-items: center; justify-content: space-between; padding: .85rem 1rem; gap: .75rem; }
.product-title { flex: 1; min-width: 0; }
.product-name { font-weight: 700; font-size: .95rem; }
.product-badge { display: inline-block; font-size: .7rem; padding: .1rem .5rem; border-radius: 10px; margin-left: .4rem; font-weight: 600; }
.product-badge.active { background: #e8f5e9; color: var(--good); }
.product-badge.inactive { background: #f5f5f5; color: var(--muted); }
.product-actions { display: flex; gap: .35rem; flex-wrap: wrap; justify-content: flex-end; }
.recipe-section { border-top: 1px solid var(--border); padding: .75rem 1rem; background: #fafaf8; }
.recipe-items { margin-bottom: .5rem; }
.recipe-row { display: flex; align-items: center; padding: .35rem 0; border-bottom: 1px solid var(--border); gap: .5rem; font-size: .88rem; }
.recipe-row:last-child { border-bottom: none; }
.ri-name { flex: 1; font-weight: 500; }
.ri-qty { color: var(--muted); white-space: nowrap; }
.add-recipe-inline { display: flex; gap: .4rem; margin-top: .5rem; align-items: center; }
.add-recipe-inline input { flex: 1; padding: .45rem .6rem; border: 1.5px solid var(--border); border-radius: 8px; font-size: .85rem; background: white; min-width: 0; }
.add-recipe-inline input:focus { outline: none; border-color: var(--red); }
.add-recipe-inline .btn-primary { padding: .45rem .85rem; border-radius: 8px; flex-shrink: 0; }

/* AI CHAT */
.ai-header { margin-bottom: .75rem; }
.chat-suggestions { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.suggestion-btn { background: white; border: 1.5px solid var(--border); border-radius: 20px; padding: .5rem .9rem; font-size: .82rem; color: var(--red); cursor: pointer; text-align: left; transition: background .15s; }
.suggestion-btn:hover { background: #fff5f5; }
.chat-messages { min-height: 200px; max-height: 55vh; overflow-y: auto; display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; padding-bottom: .5rem; }
.chat-msg { max-width: 90%; display: flex; flex-direction: column; gap: .2rem; }
.chat-msg.user { align-self: flex-end; align-items: flex-end; }
.chat-msg.ai { align-self: flex-start; }
.chat-bubble { padding: .65rem .9rem; border-radius: 16px; font-size: .9rem; line-height: 1.5; white-space: pre-wrap; }
.chat-msg.user .chat-bubble { background: var(--red); color: white; border-bottom-right-radius: 4px; }
.chat-msg.ai .chat-bubble { background: white; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-msg .chat-who { font-size: .72rem; color: var(--muted); padding: 0 .25rem; }
.chat-typing .chat-bubble { color: var(--muted); font-style: italic; }
.chat-bubble-md { white-space: normal; }
.chat-bubble-md h1,.chat-bubble-md h2,.chat-bubble-md h3 { font-size: .95rem; font-weight: 700; margin: .6rem 0 .3rem; }
.chat-bubble-md p { margin: .3rem 0; line-height: 1.5; }
.chat-bubble-md ul,.chat-bubble-md ol { padding-left: 1.2rem; margin: .3rem 0; }
.chat-bubble-md li { margin: .15rem 0; line-height: 1.4; }
.chat-bubble-md strong { font-weight: 700; }
.chat-bubble-md em { font-style: italic; }
.chat-bubble-md hr { border: none; border-top: 1px solid var(--border); margin: .5rem 0; }
.chat-bubble-md table { border-collapse: collapse; width: 100%; margin: .5rem 0; font-size: .82rem; }
.chat-bubble-md th { background: #f0f0ea; font-weight: 700; padding: .35rem .5rem; border: 1px solid var(--border); text-align: left; }
.chat-bubble-md td { padding: .3rem .5rem; border: 1px solid var(--border); }
.chat-bubble-md tr:nth-child(even) td { background: #fafaf8; }
.chat-bubble-md code { background: #f0f0ea; padding: .1rem .3rem; border-radius: 4px; font-size: .85em; font-family: monospace; }
.chat-input-bar { display: flex; gap: .5rem; align-items: flex-end; position: sticky; bottom: 0; background: var(--bg); padding: .5rem 0; }
.chat-input-bar textarea { flex: 1; padding: .65rem .75rem; border: 1.5px solid var(--border); border-radius: 12px; font-size: .9rem; font-family: inherit; resize: none; background: white; }
.chat-input-bar textarea:focus { outline: none; border-color: var(--red); }
.chat-input-bar .btn-primary { padding: .65rem 1rem; border-radius: 12px; white-space: nowrap; }

/* AUDIT */
.audit-entry { background: var(--card); border-radius: 10px; padding: .65rem 1rem; margin-bottom: .4rem; border: 1px solid var(--border); font-size: .85rem; }
.audit-top { display: flex; justify-content: space-between; gap: .5rem; margin-bottom: .2rem; }
.audit-action { font-weight: 700; }
.audit-user { color: var(--red); font-weight: 600; }
.audit-time { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.audit-details { color: var(--muted); font-size: .8rem; }

/* USERS */
.user-entry { background: var(--card); border-radius: 10px; padding: .75rem 1rem; margin-bottom: .5rem; border: 1px solid var(--border); display: flex; align-items: center; gap: .75rem; }
.user-entry .u-info { flex: 1; }
.user-entry .u-name { font-weight: 600; }
.user-entry .u-sub { font-size: .78rem; color: var(--muted, #888); }
.u-role { display: inline-block; font-size: .72rem; padding: .1rem .5rem; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); margin-top: .2rem; }
.u-role.admin { background: #fff3f3; border-color: #ffb3b0; color: var(--red); }
.role-select { display: flex; gap: 1.5rem; margin-bottom: .75rem; font-size: .9rem; }
.role-select label { display: flex; align-items: center; gap: .4rem; cursor: pointer; }

/* TOAST */
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: #1a1a1a; color: white; padding: .75rem 1.5rem; border-radius: 24px; font-size: .9rem; font-weight: 500; z-index: 100; box-shadow: 0 4px 16px rgba(0,0,0,.2); white-space: nowrap; }
.toast.hidden { display: none; }
.toast.error { background: var(--red); }
.toast.warning { background: var(--low); }

.hidden { display: none !important; }
.empty-state { text-align: center; color: var(--muted); padding: 2rem 1rem; font-size: .9rem; }

/* Zgodovina gibanj artikla */
.hist-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.hist-overlay.hidden { display: none; }
.hist-box { background: var(--card); border: 1px solid var(--border); border-radius: 12px; width: 100%; max-width: 560px; max-height: 80vh; display: flex; flex-direction: column; }
.hist-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem; border-bottom: 1px solid var(--border); }
.hist-head h3 { margin: 0; font-size: 1rem; }
#hist-body { overflow-y: auto; padding: .5rem 1rem 1rem; }
.mv { display: flex; align-items: baseline; gap: .6rem; padding: .5rem 0; border-bottom: 1px solid var(--border); font-size: .85rem; }
.mv:last-child { border-bottom: 0; }
.mv-delta { font-weight: 700; min-width: 5.5rem; text-align: right; font-variant-numeric: tabular-nums; }
.mv-delta.plus { color: #1a7f37; }
.mv-delta.minus { color: var(--red); }
.mv-main { flex: 1; min-width: 0; }
.mv-why { font-weight: 600; }
.mv-note { color: var(--muted); }
.mv-when { color: var(--muted); font-size: .75rem; white-space: nowrap; }
.mv-run { color: var(--muted); font-size: .75rem; }

.form-hint { color: var(--muted); font-size: .8rem; margin: .25rem 0 0; }
.take-row { display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem; border-bottom: 1px solid var(--border); }
.take-row:last-child { border-bottom: 0; }
.take-name { flex: 1; min-width: 0; font-weight: 600; font-size: .9rem; }
.take-exp { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.take-in { width: 5.5rem; text-align: right; }
.take-diff { min-width: 5rem; text-align: right; font-size: .8rem; font-variant-numeric: tabular-nums; }
.take-diff.plus { color: #1a7f37; }
.take-diff.minus { color: var(--red); }
.take-sum { display: flex; gap: 1rem; flex-wrap: wrap; padding: .75rem 0; color: var(--muted); font-size: .85rem; }
.take-past { display: flex; gap: .75rem; align-items: baseline; padding: .5rem 0; border-bottom: 1px solid var(--border); font-size: .85rem; }
