/* Dashboard — on top of poggio.css (the staff apps' shared design). Light only, like Cassa and Presenze.
   Chart colours: the validated categorical slots 1 and 2 (blue, orange) for the two stores, a warm gray
   for "the same dates a year before", one blue ramp for magnitude (heatmap). */
:root[data-app="dashboard"] { --accent: #1b64be; }
:root {
  --s1: #257de0;                 /* Poggio al Sole (categorical slot 1) */
  --s2: #f47230;                 /* Locanda (slot 2): below 3:1 on paper -> legend + table view always */
  --ctx: #8f877c;                /* a year before / older years: context, not a series to read first */
  --ctx2: #d9d1c6;               /* the older years in "Anni" */
  --grid: #ece6dd; --axis: #cbc3b8;
  --tbar: #b8ada0;               /* the bars inside tables: size only, no store (blue and orange mean a store) */
  --q100: #cce3fd; --q200: #9dc8f7; --q300: #6aabf1; --q400: #338ced; --q500: #2370cd; --q600: #1757ac; --q700: #0e3d7e;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.4 var(--font); }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1 1 auto; }
.err { color: var(--high); }
button, input, select { font: inherit; color: inherit; }

/* top bar: the views scroll sideways on a phone */
.p-tabs { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; max-width: 100%; }
.p-tabs::-webkit-scrollbar { display: none; }
.p-tabs a { cursor: pointer; }
.fresh { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* filters: one row above everything they scope */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 12px 18px 4px; max-width: 1400px; margin: 0 auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 8px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; white-space: nowrap; min-height: 38px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.per { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.per select, .per input { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 10px; min-height: 40px; }
.per input[type=date] { width: 150px; }
.per.off { opacity: .45; pointer-events: none; }
.ib { width: 40px; height: 40px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; cursor: pointer; font-size: 20px; line-height: 1; }
.ib:disabled { opacity: .35; cursor: default; }
.plabel { font-weight: 600; white-space: nowrap; }

main { max-width: 1400px; margin: 0 auto; padding: 8px 18px 40px; transition: opacity .15s; }
main.loading { opacity: .55; }
.banner { background: var(--high-bg); color: var(--high); border-radius: var(--radius); padding: 10px 14px; margin: 8px 0; }
.note { background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); padding: 8px 12px; margin: 8px 0; font-size: 13px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 16px 18px; margin: 14px 0; min-width: 0; }
.card h2 { font-size: 16px; font-weight: 600; margin: 0; }
.chead { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.chead .sub { color: var(--muted); font-size: 13px; }
.chead .tools { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 6px 12px; min-height: 34px; cursor: pointer; text-decoration: none; font-size: 13px; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--panel2); }
.btn.on { border-color: var(--accent); color: var(--accent); }
.btn.prim { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.big { min-height: 48px; padding: 10px 28px; font-size: 16px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }

/* figures: one hero, the rest as tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin: 10px 0; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 14px 16px; min-width: 0; }
.tile .lb { color: var(--muted); font-size: 13px; }
.tile .val { font-size: 24px; font-weight: 600; margin: 4px 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .dl { font-size: 13px; }
.tile .dl span + span { margin-left: 8px; }
.tile.hero { grid-column: span 2; }
.tile.hero .val { font-size: 48px; line-height: 1.05; letter-spacing: -.5px; }
@media (max-width: 520px) {         /* a phone: two tiles a row, the hero across both */
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tile { padding: 10px 12px; }
  .tile .val { font-size: 20px; }
  .tile.hero .val { font-size: 40px; }
  .tile .dl .muted { display: block; }
}
.up { color: var(--ok); font-weight: 600; }
.down { color: var(--high); font-weight: 600; }
.flat { color: var(--muted); }

/* charts: SVG, sized by their card */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font: 12px var(--font); fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .base { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .hit { fill: transparent; cursor: default; outline: none; }
.chart .hit:hover, .chart .hit:focus { fill: color-mix(in srgb, var(--ink) 5%, transparent); }
.chart .hit.wide:hover, .chart .hit.wide:focus { fill: transparent; }   /* the whole plot: the crosshair marks the month */
.chart .lyline { fill: none; stroke: var(--ctx); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .yl { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .cell:hover, .chart .cell:focus { stroke: var(--ink); stroke-width: 1.5; outline: none; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.legend i.ln { height: 0; border-top: 2px solid; border-radius: 0; width: 16px; }
.scale { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.scale i { width: 26px; height: 12px; border-radius: 2px; display: inline-block; }

/* the tooltip: values lead, labels follow */
.tip { position: fixed; z-index: 80; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-pop); padding: 8px 10px; font-size: 13px; min-width: 150px; max-width: 280px; }
.tip .th { color: var(--muted); margin-bottom: 4px; }
.tip .tr { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.tip .tr b { font-variant-numeric: tabular-nums; }
.tip .tr span { color: var(--muted); }
.tip .k { width: 12px; height: 0; border-top: 2px solid; flex: 0 0 auto; }

/* tables */
.tw { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; color: var(--muted); font-weight: 500; font-size: 13px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t th.sort { cursor: pointer; user-select: none; }
table.t th.sort.on { color: var(--ink); }
table.t td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tfoot td, table.t tr.tot td { font-weight: 600; border-top: 1px solid var(--line); }
table.t tbody tr.click { cursor: pointer; }
table.t tbody tr.click:hover { background: var(--panel2); }
td.barc { min-width: 160px; }
.bar { display: flex; align-items: center; gap: 8px; }
.bar b { font-weight: 500; font-variant-numeric: tabular-nums; min-width: 92px; text-align: right; }
.bar i { display: block; height: 8px; border-radius: 0 4px 4px 0; background: var(--tbar); min-width: 1px; }
.bar .tr0 { flex: 1 1 auto; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.high { background: var(--high-bg); color: var(--high); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.search { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 12px; min-height: 38px; min-width: 240px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }

/* Vendite: three figures, then lists as in the Loyverse app */
.center { text-align: center; }
.stats { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 12px; margin: 10px 0 6px; }
.st { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 14px 12px; text-align: center; min-width: 0; }
.st .v { font-size: 26px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.st.main .v { font-size: 34px; }
.st .lb { color: var(--muted); font-size: 13px; margin-top: 2px; }
.st .dl { font-size: 12px; margin-top: 4px; }
.lc { padding-bottom: 6px; }
.lrows { list-style: none; margin: 0; padding: 0; }
.lrows li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); min-height: 56px; }
.lrows li:first-child { border-top: 0; }
.lrows .ld { width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto; }
.lrows .ln { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.lrows .ln b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lrows .ln span { color: var(--muted); font-size: 13px; }
.lrows .lv { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 500; }

/* Aperti: the open tickets, live */
.livebar { display: flex; align-items: center; gap: 6px; margin: 10px 0 0; }
.dot.live { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin: 0; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .dot.live { animation: none; } }
.tickets { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.tk { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--bg); min-width: 0; }
.tk header { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.tk header b { font-size: 16px; }
.tk .tot { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.tk .meta { margin: 2px 0 6px; }
.tk .tnote { background: var(--warn-bg); color: var(--warn); border-radius: 6px; padding: 4px 8px; margin: 4px 0 6px; font-size: 13px; }
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; border-top: 1px dashed var(--line); }
.tl li:first-child { border-top: 0; }
.tl li.course { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding-top: 8px; border-top: 0; }
.tl .q { font-variant-numeric: tabular-nums; min-width: 2.2em; font-weight: 600; }
.tl .n { flex: 1 1 auto; min-width: 0; }
.tl .n small { display: block; color: var(--muted); font-size: 12px; }
.kc { font-size: 12px; white-space: nowrap; padding: 1px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); }
.kc.todo { background: transparent; border: 1px dashed var(--line); }
.kc.warn { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.kc.high { background: var(--high-bg); color: var(--high); font-weight: 600; }

/* the phone's bottom bar (hidden on wider screens: the views are tabs in the top bar there) */
.bnav { display: none; }

/* receipt detail */
.dlg-bd { position: fixed; inset: 0; z-index: 90; background: rgba(30,20,10,.35); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; overflow-y: auto; }
.dlg { background: var(--panel); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); width: min(760px, 100%); padding: 18px 20px; }
.dlg h3 { margin: 0 0 4px; font-size: 18px; }
.dlg .x { float: right; }

/* sign-in page */
body.loginpage { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login { text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 34px 38px; max-width: 420px; margin: 20px; }
.login img { border-radius: 12px; }
.login h1 { margin: 10px 0 4px; color: var(--accent); font-size: 26px; }
.login .btn { margin: 16px 0 8px; }

@media (max-width: 700px) {
  .filters, main { padding-left: 10px; padding-right: 10px; }
  .card { padding: 12px; }
  /* a phone: the views at the bottom, as in the Loyverse app; the period as ‹ day › */
  #tabs { display: none; }
  main { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .bnav { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--ink); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .bnav button { border: 0; background: none; color: #b9b2a8; font: inherit; font-size: 12px; display: flex; flex-direction: column;
    align-items: center; gap: 2px; padding: 6px 2px; min-height: 52px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bnav button b { font-size: 20px; line-height: 1.1; font-weight: 400; }
  .bnav button.on { color: #fff; }
  .filters { gap: 8px; }
  .seg { width: 100%; }
  .seg button { flex: 1 1 0; padding: 8px 6px; }
  .per { display: grid; grid-template-columns: 44px 1fr 44px; width: 100%; gap: 6px; }
  .per #prev { grid-column: 1; grid-row: 1; }
  .per .plabel { grid-column: 2; grid-row: 1; text-align: center; font-size: 18px; white-space: normal; align-self: center; }
  .per #next { grid-column: 3; grid-row: 1; }
  .per select { grid-column: 1 / -1; grid-row: 2; }
  .per input[type=date] { display: none; }
  .per.custom input[type=date] { display: block; width: auto; grid-column: 1 / -1; }
  .per.custom #from { grid-row: 3; }
  .per.custom #to { grid-row: 4; }
  .stats { gap: 6px; }
  .st { padding: 10px 6px; }
  .st .v { font-size: 18px; }
  .st.main .v { font-size: 22px; }
  .tickets { grid-template-columns: 1fr; }
}
