/* Fontovi su lokalni (rade i bez interneta na IIS serveru). */
@font-face { font-family: "Bricolage Grotesque"; font-weight: 600; font-display: swap; src: url("../fonts/bricolage-grotesque-latin-600-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2212; }
@font-face { font-family: "Bricolage Grotesque"; font-weight: 600; font-display: swap; src: url("../fonts/bricolage-grotesque-latin-ext-600-normal.woff2") format("woff2"); unicode-range: U+0100-02BA, U+1E00-1E9F, U+20A0-20C0; }
@font-face { font-family: "Bricolage Grotesque"; font-weight: 800; font-display: swap; src: url("../fonts/bricolage-grotesque-latin-800-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2212; }
@font-face { font-family: "Bricolage Grotesque"; font-weight: 800; font-display: swap; src: url("../fonts/bricolage-grotesque-latin-ext-800-normal.woff2") format("woff2"); unicode-range: U+0100-02BA, U+1E00-1E9F, U+20A0-20C0; }
@font-face { font-family: "Atkinson Hyperlegible"; font-weight: 400; font-display: swap; src: url("../fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2212; }
@font-face { font-family: "Atkinson Hyperlegible"; font-weight: 400; font-display: swap; src: url("../fonts/atkinson-hyperlegible-latin-ext-400-normal.woff2") format("woff2"); unicode-range: U+0100-02BA, U+1E00-1E9F, U+20A0-20C0; }
@font-face { font-family: "Atkinson Hyperlegible"; font-weight: 700; font-display: swap; src: url("../fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2212; }
@font-face { font-family: "Atkinson Hyperlegible"; font-weight: 700; font-display: swap; src: url("../fonts/atkinson-hyperlegible-latin-ext-700-normal.woff2") format("woff2"); unicode-range: U+0100-02BA, U+1E00-1E9F, U+20A0-20C0; }

:root {
  color-scheme: light;
  --paper: #F6F8FC;
  --grid: rgba(47, 91, 211, 0.07);
  --surface: #FFFFFF;
  --ink: #18233A;
  --muted: #5A6478;
  --line: #D6DCE8;
  --s1: #2F5BD3;
  --s2: #8A3FC7;
  --s1-soft: rgba(47, 91, 211, 0.12);
  --s2-soft: rgba(138, 63, 199, 0.12);
  --up: #17804A;
  --down: #C0392B;
  --focus: #F2A900;
  --on-accent: #FFFFFF;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;

  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #0F141E;
    --grid: rgba(110, 147, 255, 0.06);
    --surface: #171E2B;
    --ink: #E7ECF5;
    --muted: #98A2B6;
    --line: #2B3447;
    --s1: #7C9DFF;
    --s2: #C08DF2;
    --s1-soft: rgba(124, 157, 255, 0.16);
    --s2-soft: rgba(192, 141, 242, 0.16);
    --up: #4CC386;
    --down: #F07467;
    --on-accent: #0F141E;
  }
}

*, *::before, *::after { box-sizing: inherit; }
[hidden] { display: none !important; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }

body {
  margin: 0;
  font-family: var(--body);
  font-size: 1.0625rem;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--paper);
  /* Kockasti papir iz sveske. */
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
}

h1, h2 { font-family: var(--display); font-weight: 800; line-height: 1.1; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 5vw, 3.25rem); }
h2 { font-size: 1.35rem; }
p { margin: 0; }

.wrap { width: min(1120px, 100% - 2rem); margin-inline: auto; }

.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 1rem; top: 1rem; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Zaglavlje */
.masthead { padding: 2.5rem 0 1.5rem; }
.masthead-inner { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem 2rem; }
.lede { color: var(--muted); max-width: 52ch; margin-top: .6rem; }
.masthead-side { display: grid; justify-items: end; gap: .3rem; }
.last-payout { font-family: var(--display); font-weight: 600; color: var(--muted); }
.pending { color: var(--down); font-size: .95rem; }

/* Ljestvica – glavni element stranice */
.ruler-section { margin-bottom: 2rem; }
.ruler {
  position: relative;
  height: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 2.25rem;
  overflow: hidden;
}
.ruler-track { position: absolute; left: 2.25rem; right: 2.25rem; top: 0; bottom: 0; }
.ruler-band { position: absolute; left: 0; right: 0; top: 50%; height: 2px; background: var(--ink); transform: translateY(-1px); }
.tick { position: absolute; top: 50%; width: 0; }
.tick::before { content: ""; position: absolute; left: -1px; width: 2px; background: var(--ink); top: -6px; height: 12px; }
.tick.major::before { top: -14px; height: 28px; }
.tick-label { position: absolute; transform: translateX(-50%); white-space: nowrap; text-align: center; top: calc(50% + 22px); font-family: var(--display); font-weight: 600; font-size: .95rem; line-height: 1.2; }
.tick-label small { display: block; font-family: var(--body); font-weight: 400; font-size: .8rem; color: var(--muted); }

.marker { position: absolute; top: 50%; transform: translateX(-50%); }
.marker-dot { position: absolute; left: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%; background: var(--c); border: 3px solid var(--surface); box-shadow: 0 0 0 2px var(--c); }
.marker-ghost { position: absolute; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; border: 2px dashed var(--c); background: var(--surface); }
.marker-trail { position: absolute; top: 50%; height: 6px; margin-top: -3px; background: var(--c); opacity: .35; border-radius: 3px; }
.marker-flag { position: absolute; transform: translateX(-50%); white-space: nowrap; text-align: center; color: var(--c); font-family: var(--display); font-weight: 800; line-height: 1.15; }
.marker-flag span { display: block; font-family: var(--body); font-weight: 700; font-size: .85rem; }
.marker.above .marker-flag { bottom: 26px; }
.marker.below .marker-flag { top: 62px; }
.marker.below .marker-stem, .marker.above .marker-stem { position: absolute; left: -1px; width: 2px; background: var(--c); }
.marker.above .marker-stem { bottom: 9px; height: 16px; }
.marker.below .marker-stem { top: 9px; height: 52px; }
.ruler-empty { margin-top: .75rem; color: var(--muted); }

/* Učenici */
.students { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.25rem; margin-bottom: 2.5rem; }
.student {
  --c: var(--s1);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 6px solid var(--c);
  border-radius: 4px 10px 10px 4px;
  padding: 1.25rem 1.4rem;
  display: grid;
  gap: .35rem;
}
.student.s2 { --c: var(--s2); }
.student-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.student-name { font-family: var(--display); font-weight: 800; font-size: 1.5rem; color: var(--c); }
.payout { font-family: var(--display); font-weight: 800; font-size: 2.75rem; line-height: 1; margin-top: .4rem; font-variant-numeric: tabular-nums; }
.payout-cur { font-size: 1.25rem; margin-left: .2rem; }
.student-meta { color: var(--muted); }
.delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }

/* Unos i obračun */
.entry { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 1.5rem; margin-bottom: 2.5rem; align-items: start; }
@media (max-width: 820px) { .entry { grid-template-columns: 1fr; } }

.entry-form, .calc, .trend, .history, .rules details {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.5rem;
}
.entry-form { display: grid; gap: 1.15rem; }
.field { border: 0; margin: 0; padding: 0; display: grid; gap: .45rem; min-width: 0; }
.field legend, .field-label { font-weight: 700; padding: 0; margin-bottom: .45rem; }
.field legend + * { margin-top: 0; }
.optional { font-weight: 400; color: var(--muted); }
.hint { color: var(--muted); font-size: .9rem; }
.error { color: var(--down); font-size: .95rem; min-height: 0; }
.error:empty { display: none; }

input {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: .65rem .8rem;
  width: 100%;
}
#averageInput { font-family: var(--display); font-weight: 800; font-size: 2rem; max-width: 9ch; padding: .35rem .7rem; }
input[aria-invalid="true"] { border-color: var(--down); }

button { font: inherit; cursor: pointer; color: inherit; }
.segmented { display: flex; flex-wrap: wrap; gap: .4rem; }
.segmented button {
  border: 2px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: .45rem 1.1rem;
  font-weight: 700;
}
.segmented.small button { padding: .3rem .85rem; font-size: .95rem; }
.segmented button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.segmented button.s1[aria-pressed="true"] { background: var(--s1); border-color: var(--s1); color: var(--on-accent); }
.segmented button.s2[aria-pressed="true"] { background: var(--s2); border-color: var(--s2); color: var(--on-accent); }

.week-stepper { display: flex; align-items: center; gap: .5rem; }
.week-stepper output { flex: 1; text-align: center; font-family: var(--display); font-weight: 600; font-size: 1.15rem; padding: .45rem; border-bottom: 2px solid var(--line); }
.icon-btn { width: 2.6rem; height: 2.6rem; border-radius: 50%; border: 2px solid var(--line); background: transparent; font-size: 1.4rem; line-height: 1; }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }

.grade-keys { display: flex; gap: .5rem; }
.grade-keys button { width: 3rem; height: 3rem; border-radius: 8px; border: 2px solid var(--line); background: var(--paper); font-family: var(--display); font-weight: 800; font-size: 1.35rem; }
.grade-keys button:active { transform: translateY(1px); }
.grade-list { display: flex; flex-wrap: wrap; gap: .35rem; min-height: 2.25rem; align-items: center; }
.grade-list button { border: 1px solid var(--line); background: var(--paper); border-radius: 6px; padding: .2rem .6rem; font-weight: 700; }
.grade-list .avg { margin-left: .5rem; color: var(--muted); }

.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; }
.primary, .ghost, .danger { border-radius: 8px; padding: .7rem 1.3rem; font-weight: 700; border: 2px solid transparent; }
.primary { background: var(--ink); color: var(--surface); }
.primary:disabled { opacity: .5; cursor: progress; }
.ghost { background: transparent; border-color: var(--line); }
.danger { background: var(--down); color: #fff; }
.link-btn { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; font-size: .9rem; }

.calc { position: sticky; top: calc(1rem + env(safe-area-inset-top, 0px)); }
.calc h2 { margin-bottom: 1rem; }
.calc-wait { color: var(--muted); }
.equation { display: grid; gap: .6rem; font-variant-numeric: tabular-nums; }
.eq-row { display: flex; justify-content: space-between; gap: 1rem; padding-bottom: .55rem; border-bottom: 1px dashed var(--line); }
.eq-row span:first-child { color: var(--muted); }
.eq-row strong { font-weight: 700; text-align: right; }
.eq-total { display: flex; justify-content: space-between; align-items: baseline; padding-top: .3rem; }
.eq-total strong { font-family: var(--display); font-weight: 800; font-size: 2.6rem; line-height: 1; }
.eq-formula { font-family: var(--display); font-weight: 600; font-size: 1.1rem; margin-top: .4rem; }
.calc-note { color: var(--muted); font-size: .9rem; margin-top: .75rem; }

/* Grafikon i historija */
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem 1rem; margin-bottom: 1.1rem; }
.trend, .history { margin-bottom: 2.5rem; }
.chart-box { position: relative; height: 340px; }
.chart-empty { color: var(--muted); }

.table-scroll { overflow-x: auto; position: relative; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: .6rem .7rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .9rem; color: var(--muted); font-weight: 700; }
.num { text-align: right; }
td.pay { font-family: var(--display); font-weight: 800; font-size: 1.1rem; }
td.actions { text-align: right; }
td.actions button + button { margin-left: .9rem; }
tr.note-row td { border-bottom: 1px solid var(--line); padding-top: 0; color: var(--muted); font-size: .9rem; white-space: normal; }
tr.has-note td { border-bottom: 0; }
.history-empty { color: var(--muted); padding: 1rem 0; }

.rules { margin-bottom: 3rem; }
.rules summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: .6rem; }
.rules summary::-webkit-details-marker { display: none; }
.rules summary::before { content: "+"; font-family: var(--display); font-weight: 800; font-size: 1.4rem; width: 1rem; }
.rules details[open] summary::before { content: "−"; }
.rules-grid { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); gap: 2rem; margin-top: 1.25rem; }
@media (max-width: 640px) { .rules-grid { grid-template-columns: 1fr; } }
.rules-text { display: grid; gap: .8rem; max-width: 62ch; align-content: start; }
.reward-table td { padding: .35rem .7rem; }

/* Dijalozi i obavještenja */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); padding: 1.5rem; width: min(420px, 100% - 2rem); }
dialog::backdrop { background: rgba(10, 15, 25, .45); }
dialog form { display: grid; gap: .9rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 150%);
  background: var(--ink);
  color: var(--surface);
  padding: .75rem 1.25rem;
  border-radius: 8px;
  font-weight: 700;
  transition: transform .25s ease, visibility .25s;
  pointer-events: none;
  visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }

/* Jedini animirani trenutak: markeri klize na svoje mjesto kada se ljestvica iscrta. */
.marker, .marker-trail { transition: left .7s cubic-bezier(.2, .8, .2, 1), width .7s cubic-bezier(.2, .8, .2, 1); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

@media (max-width: 560px) {
  .ruler { height: 240px; padding: 0 1.25rem; }
  .ruler-track { left: 1.25rem; right: 1.25rem; }
  .tick-label.odd { display: none; }
  .payout { font-size: 2.25rem; }
  .entry-form, .calc, .trend, .history, .rules details { padding: 1.1rem; }
}
