:root {
  --bg: #f6f4f0;
  --card: #ffffff;
  --text: #1d1b19;
  --muted: #6f6a63;
  --accent: #2f7d6d;
  --accent-text: #ffffff;
  --accent-soft: #dcebe7;
  --border: #e4dfd7;
  --danger: #b3382c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1210;
    --card: #1a1f1c;
    --text: #e8ece9;
    --muted: #8e9992;
    --accent: #4fb39e;
    --accent-text: #06231d;
    --accent-soft: #23322d;
    --border: #2a322d;
    --danger: #e0695c;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 0;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 16px calc(84px + env(safe-area-inset-bottom));
}

h2 { margin: 8px 0 12px; font-size: 1.15rem; }
h3 { margin: 0 0 12px; }

.muted { color: var(--muted); }
.center { text-align: center; }
.label { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.big { font-size: 2rem; font-weight: 700; line-height: 1.2; margin: 4px 0; }

.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }

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

.last-card { background: var(--accent-soft); border-color: transparent; }
.last-card .big { font-size: 2.3rem; }

/* ----- gumbi ----- */
button, input { font: inherit; color: inherit; }

button {
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  padding: 0 16px;
  cursor: pointer;
}

button:disabled { opacity: .5; }

button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
button.secondary { width: 100%; background: transparent; margin: 4px 0 12px; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.link {
  min-height: 0; padding: 4px 2px; border: 0; background: none;
  color: var(--accent); text-decoration: underline; font-size: .95rem;
}
a.link { color: var(--accent); }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.quick button {
  min-height: 72px;
  font-size: 1.7rem;
  font-weight: 700;
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  line-height: 1;
}
.quick button small { display: block; font-size: .8rem; font-weight: 500; opacity: .85; margin-top: 4px; }
.quick button:active { filter: brightness(.9); }

.custom { display: flex; gap: 10px; }
.custom input { flex: 1; min-width: 0; }

input[type=number], input[type=datetime-local], input[type=password] {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 16px; /* sprječava zumiranje na iOS-u */
}

#timeInput { margin-top: 8px; }

.time-row { font-size: .9rem; color: var(--muted); text-align: right; }

/* ----- popis ----- */
.day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 18px 4px 6px;
  font-weight: 600;
}
.day-head span:last-child { color: var(--muted); font-weight: 400; font-size: .9rem; }

.entry {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%;
  min-height: 52px;
  margin-bottom: 6px;
  padding: 0 16px;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--border);
}
.entry .t { font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.entry .ml { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ----- pregled po danima ----- */
.day-row { margin-bottom: 12px; }
.day-row .top { display: flex; justify-content: space-between; margin-bottom: 4px; }
.day-row .top .d { font-weight: 600; }
.day-row .top .v { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 14px; border-radius: 7px; background: var(--accent-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 7px; }

/* ----- donja navigacija ----- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.tabs button { flex: 1; min-height: 52px; font-weight: 600; }
.tabs button.active { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* ----- obavijest ----- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + env(safe-area-inset-bottom));
  width: calc(100% - 32px); max-width: 520px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--text); color: var(--bg);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  z-index: 20;
}
.toast .link { color: var(--bg); font-weight: 700; }
.toast.err { background: var(--danger); color: #fff; }

/* ----- dijalog za uređivanje ----- */
dialog {
  width: calc(100% - 32px); max-width: 420px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card); color: var(--text);
  padding: 18px;
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog label { display: block; margin: 12px 0 4px; font-size: .9rem; color: var(--muted); }
.dlg-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.dlg-actions .danger { grid-column: 1 / -1; }

/* ----- prijava ----- */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  width: calc(100% - 32px); max-width: 360px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px;
}
.login-card h1 { margin: 0 0 16px; font-size: 1.5rem; }
.login-card label { display: block; margin-bottom: 4px; color: var(--muted); font-size: .9rem; }
.login-card button { width: 100%; margin-top: 14px; }
.error { color: var(--danger); margin: 10px 0 0; }
code { background: var(--bg); padding: 1px 4px; border-radius: 4px; }

[hidden] { display: none !important; }
