:root {
  --bg: #f3f0ea;
  --surface: #fffdf8;
  --ink: #1c2420;
  --muted: #5c6b63;
  --line: #d7d0c4;
  --accent: #0f6b4c;
  --accent-ink: #ffffff;
  --warn: #8a4b12;
  --danger: #8b1e1e;
  --ok: #1f6b3a;
  --radius: 10px;
  --pad: 1rem;
  --font: "Segoe UI", "Helvetica Neue", sans-serif;
  --header-bg: rgba(255, 253, 248, 0.96);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html {
  font-size: 16px;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
body.app-shell {
  margin: 0;
  height: 100%;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, #e7efe8 0, transparent 40%),
    linear-gradient(180deg, #efeae2, var(--bg));
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 50;
  pointer-events: none;
  background: transparent;
  transform-origin: left center;
  transform: scaleX(0);
  opacity: 0;
  transition: opacity 0.15s ease;
}
html.app-busy .app-progress {
  opacity: 1;
  background: linear-gradient(90deg, var(--accent), #3d9b74);
  animation: app-load 0.9s ease-in-out infinite;
}
@keyframes app-load {
  0% { transform: scaleX(0.15); opacity: 0.7; }
  50% { transform: scaleX(0.75); opacity: 1; }
  100% { transform: scaleX(0.2); opacity: 0.7; }
}

.app-header {
  position: relative;
  flex: 0 0 auto;
  z-index: 20;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  /* Keep chrome from being selected / dragged like a webpage */
  user-select: none;
  -webkit-user-select: none;
}
.app-header .inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.65rem var(--pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  font-size: 1.15rem;
}
.brand:hover { text-decoration: none; }
.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: block;
  flex-shrink: 0;
}
.brand-text { line-height: 1; }

.header-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}
.user-chip {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: right;
  min-width: 0;
}
.user-name {
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(9.5rem, 28vw);
}
.user-role {
  text-transform: capitalize;
  font-size: 0.72rem;
}
.logout-form { margin: 0; }

.subnav {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 var(--pad) 0.55rem;
}
.subnav a {
  font-size: 0.9rem;
  font-weight: 600;
}

/* Only the content pane scrolls — header stays anchored */
.app-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  overflow-anchor: auto;
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.menu-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.5rem), 1fr));
  gap: clamp(0.5rem, 2vw, 0.85rem);
  margin: 1rem 0 1.15rem;
  width: 100%;
}
a.menu-card {
  display: grid !important;
  place-items: center;
  min-height: clamp(4.25rem, 14vw, 5.5rem);
  padding: clamp(0.75rem, 2.5vw, 1.1rem);
  background: var(--surface) !important;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink) !important;
  text-decoration: none !important;
  text-align: center;
  font-weight: 700;
  font-size: clamp(0.95rem, 2.8vw, 1.1rem);
  line-height: 1.2;
  box-shadow: 0 1px 2px rgba(28, 36, 32, 0.06);
}
a.menu-card:hover,
a.menu-card:focus {
  text-decoration: none !important;
  border-color: var(--accent);
  background: #f4faf6 !important;
  color: var(--ink) !important;
}

main#app-main,
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem var(--pad) 2.5rem;
}

/* Soft swap: avoid white flash while HTMX loads next screen */
#app-main.htmx-swapping {
  opacity: 0.55;
  transition: opacity 80ms linear;
}
#app-main.htmx-added {
  opacity: 1;
}

h1 { font-size: 1.45rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 0.5rem; }
.muted { color: var(--muted); }
.stack { display: grid; gap: 0.75rem; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.dash-title {
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}
.dash-title h1 {
  margin: 0;
}
.dash-password {
  font-size: 0.9rem;
  white-space: nowrap;
  color: var(--muted);
}
.dash-password:hover {
  color: var(--accent);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem;
}
.card a.title {
  color: var(--ink);
  font-weight: 600;
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
  text-align: center;
}
.stat .n { font-size: 1.4rem; font-weight: 700; }
.stat .l { font-size: 0.75rem; color: var(--muted); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #e7efe8;
  color: var(--ok);
  border: 1px solid #c9dbcf;
}
.badge.draft, .badge.quoted { background: #f4efe4; color: var(--warn); border-color: #e4d5b8; }
.badge.completed, .badge.invoiced, .badge.paid, .badge.accepted, .badge.present { background: #e7efe8; color: var(--ok); }
.badge.rejected, .badge.absent, .badge.closed { background: #f6e6e6; color: var(--danger); border-color: #e6c6c6; }
.badge.active, .badge.sent, .badge.half_day { background: #e6eef8; color: #1d4f82; border-color: #c5d6ea; }

label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}
input, select, textarea, button {
  font: inherit;
}
input, select, textarea {
  width: 100%;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
.check-group {
  margin: 0 0 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.check-group legend { padding: 0 0.3rem; font-size: 0.9rem; font-weight: 600; }
.check-list { display: grid; gap: 0.4rem; }
.check-list > label.check-option {
  display: block;
  margin: 0;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  background: var(--surface);
  font-size: 0.95rem;
  line-height: 1.25;
  cursor: pointer;
}
.check-option-line {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
}
.check-option:hover { background: #f2eee4; }
.check-option-line > input[type="checkbox"] {
  display: block;
  flex: 0 0 1.1rem;
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.check-option-line > span { display: block; min-width: 0; }
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
button.secondary, .btn.secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
button.danger {
  background: var(--danger);
  border-color: var(--danger);
}
button:hover, .btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }

.btn-logout {
  padding: 0.45rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.btn-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
  filter: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  text-align: left;
  padding: 0.55rem 0.35rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }

/* Wide tables scroll horizontally instead of being clipped on small phones */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.table-wrap table { min-width: max-content; }
.table-wrap th,
.table-wrap td { white-space: nowrap; }

.error {
  background: #f8eaea;
  color: var(--danger);
  border: 1px solid #e6c6c6;
  padding: 0.7rem;
  border-radius: 8px;
  margin-bottom: 0.75rem;
}
.empty { color: var(--muted); padding: 0.75rem 0; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--pad);
}
.login-card {
  width: min(100%, 380px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.25rem;
}
.login-card h1 {
  margin-bottom: 0.25rem;
}
.login-card .tagline {
  color: var(--muted);
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.list-item {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
}
.list-item .meta { font-size: 0.85rem; color: var(--muted); }

.usage-add,
.usage-edit {
  display: grid;
  gap: 0.55rem;
}
.usage-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}
.usage-add input.locked {
  background: #eef1f5;
  color: var(--muted);
  cursor: not-allowed;
}
.usage-list {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
}
.usage-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  background: #fff;
  display: grid;
  gap: 0.5rem;
}
.usage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.usage-delete button {
  width: 100%;
}

.quote-form {
  display: grid;
  gap: 0.65rem;
}
.quote-lines {
  display: grid;
  gap: 0.65rem;
}
.quote-line {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  background: #fff;
  display: grid;
  gap: 0.5rem;
}
.quote-line .quote-line-amount {
  background: #eef1f5;
  color: var(--muted);
  font-weight: 600;
}
.quote-line-remove {
  justify-self: start;
}
.quote-total {
  margin: 0.25rem 0 0;
  font-size: 1.05rem;
  text-align: right;
}
.quote-total strong {
  font-size: 1.2rem;
}
@media (min-width: 520px) {
  .usage-item {
    grid-template-columns: 1fr auto;
    align-items: end;
  }
  .usage-delete {
    margin: 0;
  }
  .usage-delete button {
    width: auto;
    min-width: 5.5rem;
  }
}
@media (max-width: 420px) {
  .usage-fields {
    grid-template-columns: 1fr 1fr;
  }
  .usage-fields label:last-child {
    grid-column: 1 / -1;
  }
}

.line-rows { display: grid; gap: 0.5rem; }
.line-row {
  display: grid;
  grid-template-columns: 1fr 4.5rem 5.5rem;
  gap: 0.4rem;
}

.badge.auto {
  background: #f4efe4;
  color: var(--warn);
  border-color: #e4d5b8;
}

.menu-sub {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
}

.subsection {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}
.subsection h3 { margin: 0 0 0.5rem; font-size: 1rem; }

/* Calendar */
.calendar { margin: 0.5rem 0 1rem; }
.calendar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.calendar-weekday {
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0.2rem 0;
}
.calendar-cell {
  position: relative;
  display: block;
  min-height: 2.6rem;
  padding: 0.2rem 0.25rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.8rem;
}
.calendar-cell.empty-cell {
  background: transparent;
  border-color: transparent;
}
button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.calendar-cell.weekend { background: #f6f3eb; }
.calendar-cell.scheduled { background: #eaf2f8; border-color: #bfd3e3; }
.calendar-cell.today { border-color: var(--accent); }
.calendar-cell.worked { background: #e7efe8; }
.calendar-cell.payment-pending { background: #fff1d6; border-color: #e5a83b; }
.calendar-cell.payment-paid { background: #dff2e5; border-color: #3d9b62; }
.swatch.pending { background: #e5a83b; }
.swatch.paid { background: #3d9b62; }
.calendar-cell.selected { outline: 2px solid var(--accent); }
.calendar-num { font-weight: 600; }
.calendar-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #1d4f82;
}
.calendar-cell .calendar-dot { position: absolute; top: 6px; right: 6px; }
.calendar-hours {
  position: absolute;
  bottom: 3px;
  right: 4px;
  font-size: 0.62rem;
  color: var(--ok);
  font-weight: 600;
}
.calendar-legend {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  align-items: center;
}
.calendar-legend span { display: inline-flex; align-items: center; gap: 0.3rem; }
.calendar-legend .swatch {
  width: 12px; height: 12px; border-radius: 3px; display: inline-block;
}
.calendar-legend .swatch.worked { background: #e7efe8; border: 1px solid #c9dbcf; }

@media (max-width: 380px) {
  .calendar-grid { gap: 3px; }
  .calendar-cell {
    min-height: 2.3rem;
    padding: 0.15rem 0.15rem;
    font-size: 0.72rem;
  }
  .calendar-cell .calendar-dot { top: 4px; right: 4px; width: 6px; height: 6px; }
  .calendar-hours { font-size: 0.55rem; bottom: 2px; right: 2px; }
}

@media print {
  .app-header, .subnav, .menu-grid, .app-progress, .no-print { display: none !important; }
  html, body.app-shell {
    height: auto;
    overflow: visible;
  }
  .app-scroll {
    overflow: visible;
  }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .card { border: none; padding: 0; }
}
