:root {
  --bg: #f6f5f8;
  --card: #fff;
  --fg: #1d1b20;
  --mut: #6b6670;
  --line: #e3e0e7;
  --acc: #c2185b;
  --kir: #f8bbd0;
  --bad: #d32f2f;
  --warn: #fff4d6;
  --warn-fg: #6d4c00;
  --off: #f0eef3;
  --c-j: #f2a93b;
  --c-d: #3f8fd8;
  --c-n: #5b3fa6;
  --c-abs: #cbc5d3;
}

@media (prefers-color-scheme:dark) {
  :root {
    --bg: #121014;
    --card: #1e1b21;
    --fg: #eee9f1;
    --mut: #a39ca8;
    --line: #35303a;
    --acc: #f06292;
    --kir: #7a2848;
    --bad: #ff6b6b;
    --warn: #3a3014;
    --warn-fg: #ffd978;
    --off: #18161a;
    --c-j: #f0b650;
    --c-d: #5aa7f0;
    --c-n: #9c82e6;
    --c-abs: #4d4655;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
  overflow-x: hidden;
}

body {
  overflow-x: hidden;
  margin: 0;
  font: 16px/1.45 Poppins,-apple-system,system-ui,sans-serif;
  background: var(--bg);
  color: var(--fg);
  padding: env(safe-area-inset-top) 0 calc(72px + env(safe-area-inset-bottom));
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px;
}

h1 {
  font-size: 22px;
  margin: 8px 0 16px;
}

h2 {
  font-size: 17px;
  margin: 20px 0 8px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}

label {
  display: block;
  font-size: 14px;
  color: var(--mut);
  margin: 10px 0 4px;
}

input,select,button {
  font: inherit;
  color: inherit;
}

input[type=text],input[type=password],input[type=month],input[type=number],select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

/* iOS daje polju za mjesec vlastitu minimalnu širinu. */
input[type=month] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-width: 0;
  min-height: 46px;
  text-align: left;
}

input[type=month]::-webkit-date-and-time-value {
  text-align: left;
}

input[type=file] {
  display: block;
  width: 100%;
  max-width: 100%;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--off);
  cursor: pointer;
}

button.pri {
  background: var(--acc);
  color: #fff;
  width: 100%;
  font-weight: 600;
}

button:disabled {
  opacity: .45;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row>* {
  flex: 1;
}

.mut {
  color: var(--mut);
  font-size: 14px;
}

.msg {
  padding: 6px 10px;
  border-radius: 8px;
  margin: 6px 0;
  background: var(--warn);
  color: var(--warn-fg);
  font-size: 14px;
  white-space: pre-line;
}

.err {
  background: #fde3e3;
  color: #8a1212;
}

.hide {
  display: none!important;
}

nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

nav button {
  flex: 1;
  background: none;
  border-radius: 0;
  padding: 14px 2px;
  font-size: 12px;
  color: var(--mut);
}

nav button.on {
  color: var(--acc);
  font-weight: 600;
}

.grid {
  display: grid;
  grid-template-columns: repeat(7,minmax(0,1fr));
  gap: 4px;
}

.wd {
  text-align: center;
  font-size: 12px;
  color: var(--mut);
}

.day {
  aspect-ratio: 1;
  min-width: 0;
  overflow: hidden;
  border-radius: 9px;
  background: var(--bg);
  border: 2px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.day.cell {
  aspect-ratio: auto;
  justify-content: flex-start;
  padding: 2px 2px 4px;
  gap: 2px;
}

.day.cell img {
  width: 100%;
  aspect-ratio: 84/98;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.day.cell b {
  font-size: 14px;
}

.day small {
  font-size: 11px;
  color: var(--mut);
}

.day b {
  font-size: 16px;
}

.day.kir {
  background: var(--kir);
}

.day.low {
  border-color: var(--bad);
}

.day.unk b {
  color: var(--bad);
}

.day.hol small {
  color: var(--bad);
  font-weight: 600;
}

.day.off b {
  color: var(--mut);
  font-weight: 400;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 6px;
}

.stat {
  background: var(--bg);
  border-radius: 9px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.stat b {
  font-size: 18px;
}

.stat span {
  font-size: 12px;
  color: var(--mut);
}

.stats.kpi {
  grid-template-columns: repeat(2,minmax(0,1fr));
}

.stat b.up {
  color: var(--acc);
}

.chart {
  width: 100%;
  height: auto;
  display: block;
}

.chart .axis {
  font-size: 9px;
  fill: var(--mut);
}

.chart .axis.on {
  fill: var(--fg);
  font-weight: 600;
}

.chart .grid {
  stroke: var(--line);
  stroke-width: 1;
}

.chart .sel {
  fill: var(--bg);
}

.chart .hit {
  fill: transparent;
  cursor: pointer;
}

.chart .c-j {
  fill: var(--c-j);
}

.chart .c-d {
  fill: var(--c-d);
}

.chart .c-n {
  fill: var(--c-n);
}

.chart .c-abs {
  fill: var(--c-abs);
}

.chart .pay-line {
  fill: none;
  stroke: var(--acc);
  stroke-width: 2.2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart .pay-dot {
  fill: var(--card);
  stroke: var(--acc);
  stroke-width: 2;
}

.chart .pay-label {
  font-size: 10px;
  font-weight: 600;
  fill: var(--acc);
}

.chart .ph {
  fill: var(--acc);
  opacity: .35;
}

.chart .ph.on {
  opacity: 1;
}

.chart .avg {
  stroke: var(--fg);
  stroke-width: 1;
  stroke-dasharray: 4 3;
  opacity: .5;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--mut);
  margin-top: 8px;
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -1px;
}

.legend .c-j {
  background: var(--c-j);
}

.legend .c-d {
  background: var(--c-d);
}

.legend .c-n {
  background: var(--c-n);
}

.legend .c-abs {
  background: var(--c-abs);
}

.legend .pay {
  height: 3px;
  vertical-align: 3px;
  background: var(--acc);
}

.driver {
  margin: 10px 0;
}

.driver .row {
  justify-content: space-between;
  font-size: 14px;
}

.driver .row>* {
  flex: 0 1 auto;
}

.bar {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}

.bar i {
  display: block;
  height: 100%;
  background: var(--acc);
  border-radius: 3px;
}

.bar.neg i {
  background: var(--mut);
}

.msg ul {
  margin: 4px 0 0;
}

.extra {
  display: grid;
  grid-template-columns: 64px 72px 1fr auto;
  gap: 6px;
  margin-bottom: 6px;
}

.extra button {
  padding: 8px;
}

dialog {
  border: 0;
  border-radius: 16px;
  padding: 16px;
  background: var(--card);
  color: var(--fg);
  width: min(92vw,360px);
}

dialog::backdrop {
  background: #0006;
}

#d-cell {
  display: block;
  width: 96px;
  height: 112px;
  margin: 10px auto 0;
  border-radius: 8px;
  object-fit: cover;
}

.codes {
  display: grid;
  grid-template-columns: repeat(4,1fr);
  gap: 6px;
  margin: 12px 0;
}

.codes button.on {
  background: var(--acc);
  color: #fff;
}

.url {
  word-break: break-all;
  font-family: ui-monospace,monospace;
  font-size: 13px;
  background: var(--bg);
  padding: 10px;
  border-radius: 10px;
}

.month {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.month:last-child {
  border: 0;
}

.month .row {
  flex: 0 0 auto;
}

ol,ul {
  padding-left: 20px;
  margin: 6px 0;
}

#m-stage {
  width: 100%;
  display: block;
  border-radius: 10px;
  touch-action: manipulation;
  background: #000;
}

#m-stage.zoomed {
  touch-action: none;
}

#p-row {
  overflow-x: auto;
  border-radius: 10px;
  margin-bottom: 12px;
  background: #fff;
}

#p-row img {
  height: 88px;
  display: block;
}

#m-tiles {
  width: 100%;
  display: block;
  border-radius: 10px;
  margin-bottom: 12px;
}

.nudge {
  display: grid;
  grid-template-columns: 1fr repeat(4,48px);
  gap: 6px;
  align-items: center;
  margin: 4px 0;
}

.nudge button {
  padding: 10px 0;
  font-size: 18px;
}

.spin {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #fff8;
  border-top-color: #fff;
  border-radius: 50%;
  animation: s 1s linear infinite;
  vertical-align: -3px;
  margin-right: 6px;
}

@keyframes s {
  to {
    transform: rotate(1turn);
  }
}
