:root {
  color-scheme: light;
  --canvas: #f5f3ee;
  --sidebar: #eef1ec;
  --surface: #ffffff;
  --surface-soft: #faf9f6;
  --ink: #19352d;
  --muted: #718078;
  --line: #dde3dd;
  --blue: #e66e2e;
  --blue-dark: #163f32;
  --mint: #3d8b70;
  --mint-soft: #e4f1eb;
  --coral: #e9783d;
  --coral-soft: #fff0e9;
  --shadow: 0 14px 38px rgba(24, 55, 45, .07);
  --shadow-lg: 0 28px 80px rgba(24, 55, 45, .15);
  font-family: "Segoe UI", Inter, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 108px;
  padding: 16px max(32px, calc((100vw - 1180px) / 2));
  border-bottom: 1px solid #e1e5df;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 28px rgba(24, 55, 45, .045);
}
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; background: linear-gradient(90deg, var(--blue) 0 14%, #f3b078 14% 20%, transparent 20%); }
.brand-lockup { display: flex; align-items: center; gap: 18px; min-width: 0; }
.brand-lockup img { display: block; width: 230px; height: 72px; object-fit: contain; }
.brand-lockup h1 { margin: 0; color: #132037; font-size: 18px; letter-spacing: -.3px; }
.eyebrow {
  margin: 0 0 6px;
  color: #d9682e;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.7px;
  text-transform: uppercase;
}
.top-actions { display: flex; align-items: center; gap: 8px; padding: 6px; border: 1px solid #e4e8e3; border-radius: 15px; background: #f8f9f6; }
.top-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 13px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #53635c;
  font-size: 11px;
  font-weight: 700;
  box-shadow: none;
  transition: background .18s, color .18s, transform .18s;
}
.top-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.top-btn:hover { background: #fff; color: var(--blue-dark); transform: translateY(-1px); }
#stationBtn { min-height: 46px; padding: 0 15px; background: var(--blue-dark); color: #fff; box-shadow: 0 7px 18px rgba(22, 63, 50, .17); }
#stationBtn:hover { background: #205342; color: #fff; }
#stationBtn .chevron { width: 14px; height: 14px; opacity: .7; }
#stationBtn > strong { font-size: 11px; white-space: nowrap; }
.station-dot { width: 7px; height: 7px; border-radius: 50%; background: #f28a4e; box-shadow: 0 0 0 4px rgba(242, 138, 78, .16); }
#logoutBtn { color: #8a5a49; }

.screen {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: 38px 32px 64px;
}

button:not(.top-btn):not(.station-card):not(.list-item):not(.icon-btn):not(.ghost-link):not(.scan-cta) {
  min-height: 46px;
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  background: var(--blue-dark);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(11, 44, 99, .14);
  transition: transform .18s, box-shadow .18s, background .18s;
}
button:not(.top-btn):not(.station-card):not(.list-item):not(.icon-btn):not(.ghost-link):not(.scan-cta):hover {
  background: #0f3429;
  box-shadow: 0 10px 24px rgba(15, 52, 41, .2);
  transform: translateY(-1px);
}
button.secondary, button.ghost {
  border: 1px solid var(--line) !important;
  background: #fff !important;
  color: #526075 !important;
  box-shadow: none !important;
}
button.danger { background: var(--coral-soft) !important; color: #d85e50 !important; box-shadow: none !important; }

label { display: grid; gap: 7px; color: #657186; font-size: 12px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: 0;
  background: #fbfcfd;
  color: var(--ink);
  transition: border-color .18s, box-shadow .18s, background .18s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(20, 159, 211, .1);
}
input:disabled { color: #6e7c90; background: #eef2f6; }

.panel, .product-card, .home-hero, .activity-section {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel, .product-card { display: grid; gap: 20px; padding: 26px; }
.panel h2, .panel h3, .product-card h2 { margin: 0; color: #132037; letter-spacing: -.35px; }
.panel h2, .product-card h2 { font-size: 22px; }
.panel h3 { font-size: 17px; }
.hint, .meta { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.error { margin: -7px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--coral-soft); color: #cc5548; font-size: 12px; font-weight: 700; }
.actions, .grid-two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

/* Login */
body:has(.login-card), body:has(.station-screen) {
  background:
    radial-gradient(circle at 8% 6%, rgba(230, 110, 46, .10), transparent 28%),
    radial-gradient(circle at 91% 85%, rgba(22, 63, 50, .10), transparent 30%),
    var(--canvas);
}
body:has(.login-card) .topbar, body:has(.station-screen) .topbar { position: relative; justify-content: center; min-height: 132px; background: transparent; border-bottom-color: transparent; box-shadow: none; }
body:has(.login-card) .topbar::after, body:has(.station-screen) .topbar::after { display: none; }
body:has(.login-card) .brand-lockup > div, body:has(.station-screen) .brand-lockup > div { display: none; }
body:has(.login-card) .brand-lockup img, body:has(.station-screen) .brand-lockup img { width: 265px; height: 92px; }
body:has(.login-card) .top-actions, body:has(.station-screen) .top-actions { position: absolute; right: max(24px, calc((100vw - 1180px) / 2)); }
body:has(.login-card) .top-actions { display: none; }
body:has(.station-screen) .top-actions { padding: 0; border: 0; background: transparent; }
.login-card {
  width: min(100%, 430px);
  margin: 1vh auto 0;
  padding: 38px;
  gap: 18px;
  box-shadow: var(--shadow-lg);
}
.login-logo { display: none; }
.login-card h2 { font-size: 28px; }
.login-copy { margin: 8px 0 2px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.login-card .primary-action { margin-top: 3px; min-height: 50px !important; background: var(--blue-dark) !important; }
.login-help { margin: 1px 0 0; color: #98a2b2; font-size: 10px; text-align: center; }

/* Selezione stazione */
.station-screen { padding-top: 2vh; }
.station-heading { max-width: 650px; margin: 0 auto 34px; text-align: center; }
.station-heading h2 { margin: 0; color: var(--ink); font-size: 36px; letter-spacing: -1.1px; }
.station-heading > p:last-child { margin: 10px 0 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.station-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; }
.station-card {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  min-height: 148px;
  padding: 28px 20px 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  box-shadow: var(--shadow);
  transition: transform .2s, border-color .2s, box-shadow .2s;
}
.station-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 5px; background: linear-gradient(90deg, var(--blue), #f1a05d); }
.station-card:hover { transform: translateY(-4px); border-color: #c9d8d0; box-shadow: 0 20px 48px rgba(24, 55, 45, .13); }
.station-number { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: var(--mint-soft); color: var(--blue-dark); font-size: 11px; font-weight: 800; }
.station-info { display: grid; gap: 5px; }
.station-info strong { color: var(--ink); font-size: 17px; text-transform: uppercase; letter-spacing: .25px; }
.station-info small { color: var(--muted); font-size: 10px; }
.station-arrow { color: var(--blue); font-size: 21px; }

/* Home */
.home-hero {
  position: relative;
  overflow: hidden;
  min-height: 275px;
  padding: 30px;
  color: #fff;
  background: linear-gradient(135deg, #163f32 0%, #245c49 100%);
}
.home-hero::after { content: ""; position: absolute; right: -55px; top: -75px; width: 230px; height: 230px; border: 1px solid rgba(11, 44, 99, .08); border-radius: 50%; }
.hero-top, .hero-copy, .scan-cta, .ghost-link { position: relative; z-index: 1; }
.hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.home-hero .eyebrow { color: #f2a170; }.home-hero h2 { margin: 0; color: #fff; font-size: 30px; letter-spacing: -.7px; }
.active-station { display: inline-flex; align-items: center; gap: 7px; margin-bottom: 11px; padding: 6px 9px; border: 1px solid rgba(255,255,255,.14); border-radius: 8px; background: rgba(255,255,255,.09); }
.active-station > span:not(.station-dot) { color: #bdd1c9; font-size: 8px; font-weight: 700; letter-spacing: .65px; text-transform: uppercase; }
.active-station > strong { color: #fff; font-size: 10px; font-weight: 850; letter-spacing: .3px; text-transform: uppercase; }
.active-station .station-dot { flex: none; }
.hero-count { min-width: 95px; padding: 12px 15px; border: 1px solid rgba(255,255,255,.13); border-radius: 11px; background: rgba(255,255,255,.10); }
.hero-count span, .hero-count strong { display: block; }
.hero-count span { color: #c8d9d2; font-size: 9px; text-transform: uppercase; letter-spacing: .8px; }
.hero-count strong { margin-top: 4px; color: #fff; font-size: 22px; }
.hero-copy { max-width: 560px; margin: 18px 0 24px; color: #d3dfda; font-size: 13px; line-height: 1.65; }
.scan-cta { display: flex; align-items: center; justify-content: space-between; width: min(100%, 400px); min-height: 56px; padding: 0 18px; border: 0; border-radius: 11px; background: #e66e2e; color: #fff; box-shadow: 0 12px 28px rgba(8,30,23,.22); }
.scan-cta:hover { background: #cf5c22; }
.scan-cta span { font-size: 14px; font-weight: 700; }.scan-cta b { color: #fff1e8; font-size: 11px; }
.ghost-link { margin-top: 12px; padding: 4px 0; border: 0; background: transparent; color: #d9e5df; font-size: 11px; font-weight: 700; }
.activity-section { margin-top: 16px; padding: 23px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.section-head h3 { margin: 0; font-size: 16px; }.section-head > span { display: grid; place-items: center; min-width: 26px; height: 26px; border-radius: 8px; background: #eef2f6; color: #637087; font-size: 11px; font-weight: 800; }
.activity-list, .list-stack { display: grid; gap: 9px; }
.list-item {
  width: 100%; padding: 14px 15px; border: 1px solid #e9edf2; border-radius: 10px; background: var(--surface-soft); color: var(--ink); text-align: left;
}
.list-item:hover { border-color: #cbd9e6; background: #fff; }
.list-title { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; font-weight: 700; }
.list-title b { color: var(--blue); font-size: 10px; }.list-item small { display: block; margin-top: 6px; color: var(--muted); font-size: 10px; }
.muted-section { box-shadow: none; }.empty-line, .empty { padding: 18px; border: 1px dashed #dce4eb; border-radius: 10px; color: #909bad; font-size: 11px; text-align: center; }

/* Pagine operative */
.scan-panel, .summary-head { margin-bottom: 15px; }
.nav-row { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 15px; }
.nav-row .back-btn { min-height: 38px !important; padding: 0 13px !important; border: 1px solid var(--line) !important; background: #fff !important; color: #526075 !important; box-shadow: none !important; font-size: 11px; }
.screen-title h2 { margin: 0; font-size: 21px; }.scan-box { display: grid; gap: 11px; padding: 16px; border-radius: 12px; background: #f4f7fa; }
.scan-input { height: 58px; background: #fff; font-size: 18px; font-weight: 700; letter-spacing: .5px; }
.product-card { margin-top: 15px; }.product-card > .badge { justify-self: start; }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 0 8px; border-radius: 6px; background: #edf1f6; color: #526075; font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px; }
.badge.ok { color: #28735a; background: var(--mint-soft); }.badge.neg { color: #c5572f; background: var(--coral-soft); }.badge.pos { color: #9b582b; background: #fff0df; }
.quantity-row, .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.qty-box, .stat { padding: 15px; border: 1px solid #e8edf2; border-radius: 11px; background: #f8fafc; }
.qty-box.wide { grid-column: span 2; }.qty-box span, .qty-box strong, .stat span, .stat strong { display: block; }
.qty-box span, .stat span { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .7px; }.qty-box strong, .stat strong { margin-top: 6px; color: #26344a; font-size: 21px; }
.diff-neg strong { color: #c5572f; }.diff-pos strong { color: #9b582b; }.diff-ok strong { color: #28735a; }
.network-stock { display: grid; gap: 12px; padding: 16px; border: 1px solid #e2e8e3; border-radius: 12px; background: #f7f8f5; }
.network-stock-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.network-stock-head div { display: grid; gap: 3px; }.network-stock-head span { color: #8b978f; font-size: 8px; font-weight: 800; letter-spacing: .7px; text-transform: uppercase; }.network-stock-head strong { color: var(--ink); font-size: 13px; }.network-stock-head small { color: #29906d; font-size: 9px; font-weight: 700; }
.network-stock-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.network-stock-item { padding: 12px 10px; border: 1px solid #e0e5e1; border-radius: 10px; background: #fff; }
.network-stock-item span,.network-stock-item strong,.network-stock-item small { display: block; }.network-stock-item span { overflow: hidden; color: #69776f; font-size: 9px; font-weight: 800; text-overflow: ellipsis; text-transform: uppercase; }.network-stock-item strong { margin: 7px 0 4px; color: var(--ink); font-size: 20px; }.network-stock-item small { color: #929d96; font-size: 8px; }
.network-stock-item.current { border-color: #e98954; box-shadow: inset 0 3px #e66e2e; }.network-stock-item.unavailable strong { color: #aeb7b1; }
.summary-row { display: grid; gap: 6px; padding: 14px; border: 1px solid #e9edf2; border-radius: 10px; background: #fafbfd; }
.summary-row .badge { justify-self: start; }.summary-row strong { font-size: 12px; }

/* Dialog archivio */
.dialog { width: min(92vw, 620px); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: #fff; color: var(--ink); box-shadow: var(--shadow-lg); }
.dialog::backdrop { background: rgba(7, 26, 56, .42); backdrop-filter: blur(4px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; }.dialog > .panel { margin: 14px; box-shadow: none; }.icon-btn { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 9px; background: #f5f8fb; color: #526075; }

@media (max-width: 900px) and (min-width: 721px) {
  .station-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  .topbar { min-height: 80px; padding: 9px 12px; }
  .brand-lockup { gap: 9px; }.brand-lockup img { width: 140px; height: 52px; }.brand-lockup h1 { font-size: 14px; }.brand-lockup .eyebrow { display: none; }
  .top-actions { gap: 3px; padding: 4px; border-radius: 12px; }
  .top-btn { min-width: 38px; min-height: 38px; padding: 0 9px; font-size: 9px; }
  #catalogBtn span, #logoutBtn span { display: none; }
  #stationBtn { min-height: 40px; padding: 0 10px; }
  #stationBtn > strong { font-size: 9px; }
  .screen { padding: 22px 12px 42px; }
  .login-card { margin-top: 2vh; padding: 26px 21px; }.login-card h2 { font-size: 25px; }
  body:has(.login-card) .topbar, body:has(.station-screen) .topbar {
    justify-content: center;
    min-height: calc(220px + env(safe-area-inset-top));
    padding-top: calc(118px + env(safe-area-inset-top));
    padding-bottom: 12px;
  }
  body:has(.login-card) .brand-lockup img, body:has(.station-screen) .brand-lockup img { width: 205px; height: 74px; }
  body:has(.station-screen) .top-actions { top: calc(52px + env(safe-area-inset-top)); right: 12px; bottom: auto; left: auto; }
  body:has(.station-screen) #logoutBtn { min-width: 76px; min-height: 48px; padding: 0 15px; border: 1px solid #dfe4df; border-radius: 12px; background: #fff; font-size: 10px; box-shadow: 0 8px 22px rgba(24,55,45,.08); }
  body:has(.station-screen) #logoutBtn svg { width: 18px; height: 18px; }
  body:has(.station-screen) #logoutBtn span { display: inline; }
  .station-screen { padding-top: 14px; }.station-heading h2 { font-size: 28px; }.station-grid { grid-template-columns: 1fr; gap: 10px; }.station-card { min-height: 94px; padding: 18px 16px 14px; }
  .home-hero { min-height: 0; padding: 22px 18px; }.home-hero h2 { font-size: 24px; }.hero-copy { margin: 14px 0 19px; }.hero-count { min-width: 76px; padding: 9px 11px; }
  .activity-section, .panel, .product-card { padding: 18px 15px; }.panel, .product-card { gap: 16px; }
  .actions { grid-template-columns: 1fr; }.grid-two { gap: 8px; }
  .quantity-row, .stats { gap: 7px; }.qty-box, .stat { padding: 11px 9px; }.qty-box strong, .stat strong { font-size: 18px; }
  .scan-input { height: 54px; font-size: 16px; }
  .network-stock-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 390px) {
  .brand-lockup img { width: 112px; }
  #stationBtn .chevron { display: none; }
  body:has(.station-screen) .top-actions { right: 12px; left: auto; }
  body:has(.login-card) .topbar, body:has(.station-screen) .topbar { justify-content: center; min-height: calc(220px + env(safe-area-inset-top)); padding-left: 12px; padding-right: 12px; padding-bottom: 12px; }
  body:has(.login-card) .brand-lockup img, body:has(.station-screen) .brand-lockup img { width: 205px; }
  body:has(.station-screen) .top-actions { top: calc(52px + env(safe-area-inset-top)); right: 12px; bottom: auto; left: auto; }
  .station-heading h2 { font-size: 24px; }
  .quantity-row { grid-template-columns: 1fr 1fr; }.quantity-row .qty-box:last-child { grid-column: 1 / -1; }
}

@media (max-width: 340px) {
  body:has(.login-card) .brand-lockup img, body:has(.station-screen) .brand-lockup img { width: 190px; }
  body:has(.station-screen) #logoutBtn { min-width: 72px; padding: 0 12px; }
}
