:root {
  --bg: #141b17;
  --surface: #1d2620;
  --surface-2: #25302a;
  --text: #ece8de;
  --text-muted: #99a39b;
  --accent: #c98a3e;
  --accent-soft: rgba(201, 138, 62, 0.16);
  --line: #32403a;
  --up: #c0775f;
  --down: #7aa888;
  --radius: 16px;
  --radius-sm: 10px;
  --font-display: ui-monospace, 'SF Mono', 'Roboto Mono', 'JetBrains Mono', monospace;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(84px + var(--safe-bottom));
  min-height: 100vh;
}

button {
  font-family: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + var(--safe-top)) 18px 14px;
  position: sticky;
  top: 0;
  background: linear-gradient(to bottom, var(--bg) 80%, transparent);
  z-index: 5;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2px;
  margin: 0;
}

.header-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-muted);
  text-decoration: none;
}

.icon-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- layout principale ---------- */

main { padding: 0 16px; max-width: 720px; margin: 0 auto; }

.view-intro {
  color: var(--text-muted);
  font-size: 13px;
  margin: 4px 2px 14px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- metric card ---------- */

.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
}

.metric-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.metric-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

.metric-history-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 0;
}

.metric-readout {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 8px;
}

.metric-value {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.metric-unit {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--text-muted);
}

.metric-delta {
  margin-left: auto;
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--text-muted);
}
.metric-delta.up { color: var(--up); }
.metric-delta.down { color: var(--down); }

.metric-chart { line-height: 0; margin: 4px 0 6px; }

.metric-meta {
  font-size: 11px;
  color: var(--text-muted);
}

/* sparkline */

.spark-svg { width: 100%; height: 56px; color: var(--accent); }
.spark-line { stroke: var(--accent); stroke-width: 2; }
.spark-dot { fill: var(--accent); }
.spark-baseline { stroke: var(--line); stroke-width: 1; }
.spark-tick { stroke: var(--line); stroke-width: 1; }
.spark-tick-last { stroke: var(--accent); stroke-width: 1.4; }
.spark-empty { color: var(--text-muted); font-size: 11px; font-family: var(--font-body); }

/* ---------- galleria ---------- */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.gallery-thumb {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 0;
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-thumb-date {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  font-family: var(--font-display);
  font-size: 10px;
  text-align: center;
  padding: 3px 0;
  background: rgba(20, 27, 23, 0.78);
  color: var(--text);
}

.empty-state {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 40px 20px;
}

/* ---------- FAB + tab bar ---------- */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(78px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #1a120a;
  border: none;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 24px rgba(201, 138, 62, 0.32);
  z-index: 10;
}

.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
  z-index: 8;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 0 8px;
  font-size: 11px;
}

.tab-btn.is-active { color: var(--accent); }

/* ---------- modali ---------- */

dialog.modal {
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  max-height: min(85vh, 720px);
  margin: auto;
}

dialog.modal::backdrop {
  background: rgba(8, 11, 9, 0.6);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 { font-size: 16px; margin: 0; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  padding: 0 4px;
}

.modal-body {
  padding: 16px 18px 18px;
  overflow-y: auto;
  max-height: calc(85vh - 130px);
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

/* ---------- form ---------- */

label { display: block; font-size: 12px; color: var(--text-muted); margin: 14px 0 6px; }
label:first-of-type { margin-top: 0; }

input[type="date"],
input[type="number"],
input[type="password"],
input[type="file"] {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 15px;
  font-family: var(--font-display);
}

input[type="file"] { font-family: var(--font-body); font-size: 13px; padding: 9px 10px; }

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}

.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
  line-height: 1.5;
}

.divider { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

.btn-primary, .btn-secondary {
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
}

.btn-primary { background: var(--accent); color: #1a120a; }
.btn-secondary { background: none; border-color: var(--line); color: var(--text); }
.btn-block { width: 100%; margin-top: 4px; }

/* ---------- tabella storico ---------- */

.history-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.history-table th, .history-table td {
  text-align: left;
  padding: 9px 6px;
  border-bottom: 1px solid var(--line);
}
.history-table th { font-size: 11px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.4px; }
.history-table td:nth-child(2) { font-family: var(--font-display); }
.history-table .row-delete {
  background: none; border: none; color: var(--up); font-size: 12px; padding: 0;
}
.history-table .empty { color: var(--text-muted); text-align: center; padding: 24px 0; }

/* ---------- lightbox ---------- */

.modal-lightbox { width: min(92vw, 600px); }
.lightbox-body {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
}
.lightbox-body img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: var(--radius-sm);
  object-fit: contain;
}
.lightbox-nav {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 18px;
  flex-shrink: 0;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translate(-50%, 12px);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- login ---------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 26px;
  text-align: center;
}

.login-mark { color: var(--accent); margin-bottom: 14px; display: flex; justify-content: center; }

.login-card h1 { font-size: 19px; margin: 0 0 6px; }

.login-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 22px;
  line-height: 1.5;
}

.login-card form { text-align: left; }

.login-card button[type="submit"] {
  width: 100%;
  margin-top: 18px;
  background: var(--accent);
  color: #1a120a;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
}

.login-error {
  background: rgba(192, 119, 95, 0.15);
  color: var(--up);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  margin: 0 0 16px;
}
