:root {
  --ink: #142 intermediate;
  --muted: #4a6560;
  --paper: #f3f0e8;
  --panel: rgba(255, 252, 246, 0.92);
  --line: rgba(26, 58, 58, 0.12);
  --teal: #1a5c54;
  --teal-deep: #0f3d38;
  --sand: #c4a574;
  --ok: #1f7a4c;
  --warn: #9a5b12;
  --out: #7a3b3b;
  --radius: 16px;
  --font-display: "Open Sans", sans-serif;
  --font-body: "Open Sans", sans-serif;
  --pad-x: max(0.9rem, env(safe-area-inset-left));
  --pad-r: max(0.9rem, env(safe-area-inset-right));
  --pad-b: max(1.5rem, env(safe-area-inset-bottom));
  --tap: 48px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding-bottom: var(--pad-b);
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(196, 165, 116, 0.35), transparent 55%),
    radial-gradient(ellipse 70% 45% at 100% 0%, rgba(26, 92, 84, 0.18), transparent 50%),
    linear-gradient(165deg, #e8efe9 0%, #f3f0e8 42%, #ebe4d6 100%);
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem 0.85rem;
  padding: max(0.9rem, env(safe-area-inset-top)) var(--pad-r) 0.55rem var(--pad-x);
  max-width: 920px;
  margin: 0 auto;
}

.brand {
  flex: 1 1 auto;
  min-width: 0;
}

.brand-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.65rem, 8vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--teal-deep);
  line-height: 1.08;
}

.brand-sub {
  margin: 0.2rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 100%;
  padding: 0.5rem 0.75rem;
  min-height: 2.25rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  font-size: 0.8rem;
  font-weight: 600;
  flex: 0 1 auto;
}

.status .dot {
  flex-shrink: 0;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #9aa8a4;
}

.status-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status[data-state="inside"] .dot { background: var(--ok); }
.status[data-state="outside"] .dot { background: var(--out); }
.status[data-state="error"] .dot { background: var(--warn); }
.status[data-state="watching"] .dot {
  background: var(--teal);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 0.35rem var(--pad-r) 1.25rem var(--pad-x);
  display: grid;
  gap: 0.85rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 0.95rem 1.05rem;
}

.panel h2 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--teal-deep);
}

.coords {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  word-break: break-word;
}

.place {
  margin: 0.35rem 0 0;
  font-weight: 600;
  color: var(--teal);
}

.rule-hint {
  margin: 0.55rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
  margin-top: 0.95rem;
}

.btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--tap);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--teal);
  color: #f7faf8;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.55);
  border-color: var(--line);
  color: var(--ink);
}

.month-bar {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.7rem;
}

.month-bar h2 {
  margin: 0;
}

.month-note {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border-radius: 12px;
  border: 1px solid var(--line);
  margin: 0 -0.15rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.88rem;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #e4ebe7;
  font-weight: 600;
  text-align: left;
  padding: 0.4rem 0.3rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-size: 0.75rem;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

tbody td,
tfoot td,
tfoot th {
  padding: 0.05rem 0.2rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  line-height: 1.15;
}

tbody tr:nth-child(even) {
  background: rgba(26, 92, 84, 0.03);
}

tbody tr.is-today {
  background: rgba(196, 165, 116, 0.28);
}

tbody tr.is-today td:first-child {
  font-weight: 700;
  color: var(--teal-deep);
}

.col-day {
  width: 18%;
}

.col-pensione {
  width: 30%;
}

.col-giorni {
  width: 22%;
}

.col-extra {
  width: 30%;
}

td.day-label {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding-left: 0.4rem;
  font-size: 0.85rem;
  line-height: 1.15;
}

input.cell {
  width: 100%;
  min-width: 0;
  min-height: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  padding: 0.2rem 0.25rem;
  font-family: inherit;
  font-size: 16px; /* evita zoom automatico su Android/iOS */
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
}

input.cell:focus {
  outline: none;
  border-color: var(--teal);
  background: #fff;
}

input.cell.auto {
  color: var(--teal-deep);
  font-weight: 600;
}

input.cell[readonly] {
  color: var(--muted);
  pointer-events: none;
}

tfoot {
  background: rgba(26, 92, 84, 0.12);
  font-weight: 700;
}

tfoot th {
  text-align: left;
  font-family: var(--font-display);
  padding-left: 0.45rem;
  font-size: 0.85rem;
}

tfoot td {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  padding: 0.35rem 0.25rem;
}

.due-line {
  margin: 0.9rem 0 0;
  padding: 0.85rem 0.9rem;
  border-radius: 12px;
  background: rgba(26, 92, 84, 0.1);
  border: 1px solid var(--line);
  font-size: 0.95rem;
  color: var(--ink);
  line-height: 1.4;
}

.due-line strong {
  display: inline-block;
  margin-top: 0.15rem;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  color: var(--teal-deep);
}

.pdf-actions {
  margin-top: 0.85rem;
}

.pdf-hint {
  margin: 0.45rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

.pdf-hint strong {
  color: var(--teal-deep);
  font-weight: 600;
}

.rules {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.5rem;
}

.rules li {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.2rem;
  padding: 0.75rem 0.8rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  font-size: 0.9rem;
}

.rules li span {
  font-weight: 600;
  color: var(--teal);
  font-variant-numeric: tabular-nums;
}

.rules li strong {
  font-variant-numeric: tabular-nums;
}

/* Telefono landscape / schermi un po' più larghi */
@media (min-width: 420px) {
  .actions {
    grid-template-columns: 1fr 1fr;
  }

  thead th {
    font-size: 0.8rem;
    padding: 0.45rem 0.4rem;
  }

  input.cell {
    padding: 0.2rem 0.35rem;
  }
}

/* Tablet / desktop */
@media (min-width: 640px) {
  :root {
    --pad-x: 1.25rem;
    --pad-r: 1.25rem;
    --radius: 18px;
  }

  .top {
    flex-wrap: nowrap;
    padding-top: 1.35rem;
  }

  .panel {
    padding: 1.1rem 1.15rem 1.2rem;
  }

  .panel h2 {
    font-size: 1.25rem;
  }

  .month-bar {
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.4rem 1rem;
  }

  .table-wrap {
    margin: 0;
  }

  table {
    font-size: 0.92rem;
  }

  thead th {
    font-size: 0.85rem;
    padding: 0.45rem 0.5rem;
  }

  tbody td,
  tfoot td,
  tfoot th {
    padding: 0.1rem 0.4rem;
  }

  .rules li {
    grid-template-columns: minmax(7.5rem, auto) 1fr;
    gap: 0.35rem 0.75rem;
  }

  .btn.primary:hover {
    background: var(--teal-deep);
  }

  .btn.ghost:hover {
    border-color: var(--teal);
    color: var(--teal-deep);
  }
}

@media (min-width: 900px) {
  main {
    gap: 1rem;
    padding-bottom: 2.5rem;
  }
}

.pdf-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  background: #0f3d38;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.pdf-viewer[hidden] {
  display: none !important;
}

.pdf-viewer-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  background: #0f3d38;
}

.pdf-viewer-bar .btn {
  min-height: 42px;
  width: auto;
  padding: 0.55rem 0.85rem;
  font-size: 0.9rem;
}

.pdf-viewer-bar .btn.ghost {
  justify-self: start;
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  color: #f7faf8;
}

.pdf-viewer-bar .btn.primary {
  justify-self: end;
  text-decoration: none;
}

.pdf-viewer-title {
  color: #f7faf8;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}

.pdf-viewer iframe {
  flex: 1;
  width: 100%;
  border: 0;
  background: #525659;
}
