:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --panel: #ffffff;
  --text: #181818;
  --muted: #64645f;
  --line: #deded7;
  --brand: #c1121f;
  --brand-dark: #7f1018;
  --accent: #0d5c63;
  --ok: #166534;
  --bad: #9f1239;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  width: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

a { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 64px;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
  background: #111;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 6px 18px rgba(0,0,0,.16);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand div { display: grid; gap: 2px; min-width: 0; }
.brand strong, .brand span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand-icon {
  width: 42px;
  height: 42px;
  object-fit: contain;
  flex: 0 0 auto;
}

.topbar span { color: #d7d7d0; font-size: 13px; }

.topbar form {
  flex: 0 0 auto;
}

.page {
  width: min(860px, 100%);
  margin: 0 auto;
  padding: 14px 12px 88px;
}

.section, .auth-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin: 0 0 12px;
  min-width: 0;
}

.auth-panel { margin-top: 40px; }

h1, h2 {
  margin: 0 0 14px;
  line-height: 1.12;
}

h1 { font-size: 26px; }
h2 { font-size: 19px; margin-top: 8px; }

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

.stack {
  display: grid;
  gap: 12px;
  width: 100%;
  min-width: 0;
}

.field-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  width: 100%;
  min-width: 0;
}

input, select, textarea, button {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 10px 12px;
  font: inherit;
  background: #fff;
  color: var(--text);
  max-width: 100%;
}

input[type="date"],
input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
}

textarea { resize: vertical; }

button {
  cursor: pointer;
  border: 0;
  font-weight: 800;
  line-height: 1.2;
  white-space: normal;
}

.primary, .ghost, .danger, .icon-btn, .link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  overflow-wrap: anywhere;
  text-align: center;
}

.primary {
  background: var(--brand);
  color: #fff;
}

.ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 42px;
  font-weight: 800;
}

.danger {
  background: #fff1f2;
  color: var(--bad);
  border: 1px solid #fecdd3;
  min-height: 38px;
  padding: 8px 10px;
}

.icon-btn {
  width: 42px;
  flex: 0 0 42px;
  min-height: 42px;
  border-radius: 999px;
  color: #fff;
  background: rgba(255,255,255,.12);
}

.quiet-link {
  display: inline-block;
  margin-top: 14px;
  color: var(--accent);
  font-weight: 700;
}

.time-grid, .stats, .filters, .inline-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  min-width: 0;
}

.filters, .inline-form {
  grid-template-columns: 1fr;
  align-items: end;
  margin-bottom: 14px;
}

.edit-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: 10px;
  align-items: end;
  min-width: 0;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin: 0;
  min-width: 0;
}

legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chips label { display: block; }
.chips label.is-hidden { display: none; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--text);
  max-width: 100%;
  overflow-wrap: anywhere;
}
.chips input:checked + span {
  background: #ffe8ea;
  border-color: var(--brand);
}

.stats article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 2px;
}

.stats span, .muted {
  color: var(--muted);
  font-size: 13px;
}

.stats strong { font-size: 24px; }

.bars {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(70px, 110px) minmax(44px, 1fr) minmax(64px, auto);
  align-items: center;
  gap: 8px;
  font-size: 13px;
  min-width: 0;
}

.bar-row span,
.bar-row b {
  min-width: 0;
  overflow-wrap: anywhere;
}

.bar-row i {
  display: block;
  height: 12px;
  min-width: 4px;
  background: var(--brand);
  border-radius: 999px;
}

.bar-row b { text-align: right; }

.list {
  display: grid;
  gap: 10px;
}

.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  min-width: 0;
}

.item > form {
  min-width: 0;
}

.item > form:not(.edit-grid) {
  justify-self: end;
  width: min(128px, 100%);
}

.item div:first-child {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.item span, .item p {
  color: var(--muted);
  margin: 0;
  overflow-wrap: anywhere;
}

.item p {
  grid-column: 1 / -1;
  font-size: 14px;
}

.item form {
  grid-column: 1 / -1;
}

.pill {
  align-self: start;
  white-space: nowrap;
  border-radius: 999px;
  background: #e8f5f6;
  color: var(--accent);
  padding: 6px 9px;
  font-size: 13px;
  font-weight: 900;
}

.muted-pill {
  background: #ededed;
  color: var(--muted);
}

.compact-item {
  grid-template-columns: 1fr;
}

.flash {
  width: min(860px, calc(100% - 24px));
  margin: 12px auto 0;
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 800;
}

.flash.success { background: #dcfce7; color: var(--ok); }
.flash.error { background: #ffe4e6; color: var(--bad); }

.info-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  margin-bottom: 18px;
}

.info-grid span { color: var(--muted); }

.empty {
  min-height: 45vh;
  display: grid;
  place-items: center;
  text-align: center;
}

.bottom-nav {
  position: fixed;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px 12px max(8px, env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--line);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
}

.bottom-nav a {
  min-height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  padding: 0 3px;
}

.bottom-nav a:focus, .bottom-nav a:hover {
  background: #f1f1ed;
  color: var(--text);
}

@media (min-width: 720px) {
  .page { padding-top: 24px; }
  .auth-panel { max-width: 420px; margin-left: auto; margin-right: auto; }
}

@media (max-width: 520px) {
  .page { padding-left: 8px; padding-right: 8px; }
  .section, .auth-panel { padding: 12px; }
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }
  .time-grid, .stats { grid-template-columns: 1fr; }
  .filters, .inline-form, .edit-grid {
    grid-template-columns: 1fr;
  }
  .bar-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .bar-row b { text-align: left; }
  .item { grid-template-columns: 1fr; }
  .item > form:not(.edit-grid) {
    justify-self: stretch;
    width: 100%;
  }
  .pill { justify-self: start; }
  .bottom-nav {
    gap: 2px;
    padding-left: 4px;
    padding-right: 4px;
  }
  .bottom-nav a {
    font-size: 11px;
    padding: 0 1px;
  }
}
