:root {
  --blue: #0057b7;
  --blue-dark: #00438c;
  --yellow: #ffd700;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #16202c;
  --muted: #66717f;
  --line: #e2e6ec;
  --red: #c62828;
  --green: #2e7d32;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}
.flag span { display: block; height: 6px; }
.flag span:first-child { background: var(--blue); }
.flag span:last-child { background: var(--yellow); }

h1 { font-size: 1.4rem; margin: 0; }
.muted { color: var(--muted); margin: 0; font-size: .9rem; }
.error { color: var(--red); margin: .6rem 0 0; font-weight: 600; }
.success { color: var(--green); margin: .6rem 0 0; font-weight: 600; }
.right { text-align: right; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
input {
  font: inherit; width: 100%; padding: .6rem .7rem;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text);
}
input:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: var(--blue); }
input.invalid { border-color: var(--red); background: #fff5f5; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px;
  padding: .6rem 1rem; border: 1px solid transparent; text-decoration: none; display: inline-block;
}
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.ghost { background: #fff; color: var(--blue); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--blue); }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn.block { width: 100%; margin-top: 1rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.danger { color: var(--red); }

.topbar, main, .tabs { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding-top: 1.1rem; padding-bottom: .6rem; }
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs button {
  font: inherit; font-weight: 600; background: none; border: none; cursor: pointer; white-space: nowrap;
  padding: .7rem .9rem; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--blue); border-bottom-color: var(--blue); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.actions { display: flex; justify-content: space-between; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }

/* Budget */
.budget { display: grid; grid-template-columns: minmax(200px, 280px) 1fr; gap: 1rem 1.5rem; align-items: end; position: sticky; top: 0; z-index: 5; box-shadow: 0 4px 14px rgba(0,0,0,.05); }
.money-field { display: flex; align-items: center; gap: .4rem; }
.money-field input { font-size: 1.7rem; font-weight: 700; padding: .4rem .6rem; text-align: right; }
.money-field span { font-size: 1.5rem; font-weight: 700; }
.budget-stats { display: flex; gap: 1.6rem; flex-wrap: wrap; }
.budget-stats div { display: flex; flex-direction: column; }
.budget-stats strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.bar { grid-column: 1 / -1; height: 10px; background: #e8edf3; border-radius: 99px; overflow: hidden; }
#bar-fill { height: 100%; width: 0; background: var(--blue); transition: width .15s; }
#bar-fill.full { background: var(--green); }
#bar-fill.over { background: var(--red); }
.budget .error { grid-column: 1 / -1; margin: 0; }

/* Bestellzeilen */
.order-head, .order-row { display: grid; grid-template-columns: minmax(180px, 1.2fr) 2fr 110px; gap: .8rem; align-items: center; }
.order-head { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; padding-bottom: .4rem; border-bottom: 1px solid var(--line); }
.order-row { padding: .8rem 0; border-bottom: 1px solid var(--line); }
.order-row:last-child { border-bottom: none; }
.order-row.active { background: linear-gradient(90deg, #eef4fc, transparent 60%); }
.med-name { font-weight: 600; }
.med-meta { font-size: .85rem; color: var(--muted); }
.qty { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.qty input { width: 84px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; padding: .45rem .3rem; }
.qty .step { width: 36px; height: 36px; padding: 0; font-size: 1.2rem; line-height: 1; }
.chip { font: inherit; font-size: .82rem; font-weight: 600; padding: .35rem .55rem; border-radius: 99px; border: 1px solid var(--line); background: #fff; color: var(--blue); cursor: pointer; }
.chip:hover:not(:disabled) { border-color: var(--blue); }
.chip:disabled { opacity: .35; cursor: not-allowed; }
.chip.fill { background: var(--yellow); border-color: #e6c200; color: #3a3000; }
.line-total { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.max-hint { font-size: .78rem; color: var(--muted); width: 100%; }

/* Medikamentenliste */
.meds-head, .med-edit { display: grid; grid-template-columns: 1fr 130px 120px 44px; gap: .5rem; align-items: center; }
.meds-head { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; margin: .8rem 0 .3rem; }
.med-edit { margin-bottom: .5rem; }
.icon-btn { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--red); cursor: pointer; font-size: 1.1rem; }

/* Archiv */
.archive-row { display: grid; grid-template-columns: 90px 1fr auto; gap: .8rem; align-items: center; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.archive-row:last-child { border-bottom: none; }
.archive-row .nr { font-weight: 700; }
.archive-row .btns { display: flex; gap: .4rem; }

/* Login */
.login-body { min-height: 100vh; }
.login-card { max-width: 380px; margin: 12vh auto 0; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.6rem; }
.login-card h1 { margin-bottom: .2rem; }
.login-card form { margin-top: 1.4rem; }

@media (max-width: 720px) {
  .budget { grid-template-columns: 1fr; }
  .budget-stats { gap: 1rem; }
  .order-head { display: none; }
  .order-row { grid-template-columns: 1fr auto; }
  .order-row .qty { grid-column: 1 / -1; grid-row: 2; }
  .meds-head { display: none; }
  .med-edit { grid-template-columns: 1fr 1fr 44px; padding-bottom: .6rem; border-bottom: 1px solid var(--line); }
  .med-edit .name { grid-column: 1 / -1; }
  .archive-row { grid-template-columns: 1fr; }
}
