/* =========================================================================
 *  RM Analitica - Fogli di stile applicativi (app.css)
 * ========================================================================= */

:root {
  --navy: #143B6F;
  --navy-active: #22497A;
  --navy-line: rgba(255, 255, 255, 0.12);
  --tile: #3079CA;
  --tile-foot: #2561A2;
  --rust: #C15A31;
  --rust2: #A94B27;
  --orange: #E36A2C;
  --link: #1F6FB2;
  --ok: #2E9E4B;
  --okbg: #E7F6EC;
  --warn: #E08A2B;
  --warnbg: #FBF0DD;
  --warnink: #9A6414;
  --ko: #D0442E;
  --kobg: #F9E7E3;
  --ink: #24292F;
  --mut: #656D76;
  --line: #D0D7DE;
  --paper: #FFFFFF;
  --page: #F6F8FA;
  --soft: #F9FAFB;
  --shadow-sm: 0 1px 3px rgba(27, 31, 36, 0.08);
  --shadow: 0 2px 6px rgba(27, 31, 36, 0.08), 0 6px 18px rgba(27, 31, 36, 0.06);
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ---- Layout & Sidebar ---------------------------------------------------- */

.wrap {
  display: flex;
  min-height: 100vh;
}

.side {
  width: 244px;
  flex: 0 0 244px;
  background: linear-gradient(180deg, #173F76, #0F2A50);
  color: #D6E0EE;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 30;
}

.brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--navy-line);
}

.brand .word {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #FFFFFF;
  line-height: 1.1;
}

.brand .word i {
  color: var(--orange);
  font-style: normal;
}

.brand .sub {
  font-size: 11px;
  color: #8FA3BC;
  margin-top: 5px;
  line-height: 1.35;
}

.nav {
  padding: 10px 12px 28px;
  flex: 1;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: #C4D2E4;
  font-size: 13.5px;
  margin-bottom: 2px;
  border-left: 3px solid transparent;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav a .ix {
  width: 24px;
  height: 22px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.09);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #9FB6D6;
  flex: 0 0 24px;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #FFFFFF;
  text-decoration: none;
}

.nav a.on {
  background: var(--navy-active);
  color: #FFFFFF;
  border-left-color: var(--orange);
}

.nav a.on .ix {
  background: var(--orange);
  color: #FFFFFF;
}

.nav .grp {
  font-size: 10.5px;
  color: #7E93B4;
  padding: 16px 12px 6px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 700;
}

.side .foot {
  padding: 14px 18px 22px;
  font-size: 11px;
  color: #7E93B4;
  border-top: 1px solid var(--navy-line);
  line-height: 1.45;
}

.side .foot a {
  color: #B7C7DD;
}

/* ---- Main & Top Bar ----------------------------------------------------- */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.top {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  gap: 16px 20px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}

.crumb {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
}

.crumb .bldg {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--rust);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.crumb b {
  color: var(--rust);
  font-weight: 700;
}

.tool {
  margin-left: auto;
  display: flex;
  gap: 10px 16px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.fld {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lbl {
  font-size: 10.5px;
  color: var(--mut);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 700;
}

.sel {
  display: inline-flex;
  background: #EAEEF3;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px;
  flex-wrap: wrap;
  gap: 2px;
}

.sel a {
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--mut);
  white-space: nowrap;
  transition: all 0.15s ease;
}

.sel a:hover {
  color: var(--navy);
  text-decoration: none;
}

.sel a.on {
  background: var(--navy);
  color: #FFFFFF;
}

.sel a.ytd {
  color: var(--navy);
}

.sel a.ytd.on {
  background: var(--rust);
  color: #FFFFFF;
}

.sel .sep {
  width: 1px;
  background: #C9D2DC;
  margin: 2px 4px;
}

/* ---- Content Area ------------------------------------------------------- */

.content {
  padding: 24px 32px 60px;
  max-width: 1680px;
  width: 100%;
}

.head {
  margin-bottom: 20px;
}

.eyebrow {
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--rust);
  font-weight: 700;
  margin-bottom: 4px;
}

h1, h2.h {
  font-size: 20px;
  color: var(--navy);
  font-weight: 700;
  margin: 2px 0 6px;
}

h3.sh {
  font-size: 15px;
  color: var(--navy);
  font-weight: 700;
  margin: 24px 0 10px;
}

p.lead {
  color: var(--mut);
  font-size: 13.5px;
  max-width: 960px;
  margin: 6px 0 18px;
  line-height: 1.5;
}

.muted {
  color: var(--mut);
  font-size: 12.5px;
}

.code {
  font-family: Consolas, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--link);
  font-weight: 600;
  white-space: nowrap;
}

/* ---- Flash Messages ----------------------------------------------------- */

.flash {
  border-left: 4px solid var(--ok);
  background: var(--okbg);
  color: #1F6E35;
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13.5px;
  box-shadow: var(--shadow-sm);
}

.flash.ko {
  border-color: var(--ko);
  background: var(--kobg);
  color: #8E2A1B;
}

.flash.warn {
  border-color: var(--warn);
  background: var(--warnbg);
  color: var(--warnink);
}

.flash.info {
  border-color: var(--tile);
  background: #E8F1FB;
  color: #1D4F86;
}

.flash ul {
  margin: 6px 0 0 18px;
  padding: 0;
  font-size: 12.5px;
}

/* ---- Griglie & Box ------------------------------------------------------ */

.grid {
  display: grid;
  gap: 16px;
}

.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1280px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .g4, .g3, .g2 { grid-template-columns: 1fr; }
  .side { display: none; }
  .content { padding: 16px; }
  .top { padding: 12px 16px; }
}

.grid > .card {
  margin-bottom: 0;
}

/* ---- Cards -------------------------------------------------------------- */

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow: hidden;
}

.card .hd {
  background: var(--rust);
  color: #FFFFFF;
  padding: 11px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.card .hd h4, .card .hd b {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.card .hd .tag, .card .hd .count {
  background: rgba(255, 255, 255, 0.22);
  border-radius: 4px;
  padding: 2px 10px;
  font-size: 11.5px;
  font-weight: 700;
}

.card .hd a {
  color: #FFFFFF;
}

/* Padding del corpo della card */
.card .bd {
  padding: 18px 20px;
}

.card .bd.np {
  padding: 0;
}

.card.np .bd {
  padding: 0;
}

/* Form inclusi direttamente dentro la card senza .bd: garantisce padding e respiro */
.card > form.form,
.card > .form {
  padding: 18px 20px;
}

.card > form.form + p.muted,
.card > .form + p.muted {
  padding: 0 20px 16px;
  margin: 0;
}

.card .pnote {
  padding: 11px 20px;
  font-size: 12px;
  color: var(--mut);
  background: #F9FAFB;
  border-top: 1px solid var(--line);
}

.card .empty {
  padding: 20px;
  color: var(--mut);
  text-align: center;
}

/* ---- Tiles Cruscotto (Indicatori di Sintesi) ---------------------------- */

.tile {
  background: var(--tile);
  color: #FFFFFF;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 128px;
  justify-content: space-between;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.tile:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.tile .bd {
  padding: 16px 18px 12px;
  flex: 1;
}

.tile .tt, .tile .lbl {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  opacity: 0.95;
}

.tile .val {
  font-size: 26px;
  font-weight: 800;
  margin: 8px 0 4px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.tile .sub, .tile .lim {
  font-size: 12px;
  opacity: 0.88;
  line-height: 1.35;
}

.tile .ft, .tile .foot {
  background: var(--tile-foot);
  padding: 8px 18px;
  font-size: 11.5px;
  font-weight: 700;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

/* Supporto per tile che usano struttura compatta senza .bd */
.tile:not(:has(.bd)) {
  padding: 16px 18px 0;
}

.tile:not(:has(.bd)) > .foot,
.tile:not(:has(.bd)) > .ft {
  margin: 12px -18px 0;
}

/* Varianti colore dei tile */
.tile.ok {
  background: #2E8B57;
}
.tile.ok .ft, .tile.ok .foot {
  background: #236E44;
}

.tile.ko {
  background: var(--ko);
}
.tile.ko .ft, .tile.ko .foot {
  background: #A83321;
}

.tile.grey {
  background: #738090;
}
.tile.grey .ft, .tile.grey .foot {
  background: #5D6876;
}

/* ---- Tabelle ------------------------------------------------------------ */

table.t {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.t th {
  background: #F6F8FA;
  color: var(--mut);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 700;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

table.t td {
  padding: 8px 14px;
  border-bottom: 1px solid #EEF1F4;
  vertical-align: middle;
}

table.t td.n, table.t th.n {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

table.t tr:hover td {
  background: #F9FAFB;
}

table.t tr.tot td {
  font-weight: 700;
  background: #F4F6F8;
  border-top: 1px solid #D0D7DE;
  border-bottom: 1px solid #D0D7DE;
}

table.t tr.grand td {
  font-weight: 800;
  background: #EAF0F7;
  color: var(--navy);
  border-top: 2px solid var(--navy);
}

table.t tr.sec td {
  background: var(--navy);
  color: #FFFFFF;
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.4px;
}

table.t tr.sub td {
  color: var(--mut);
  font-size: 12.5px;
}

table.t tr.sub td:first-child {
  padding-left: 28px;
}

table.t tr.pct td {
  color: var(--mut);
  font-size: 12px;
  font-style: italic;
}

table.t td a.amt {
  color: inherit;
}

table.t td a.amt:hover {
  color: var(--link);
  text-decoration: underline;
}

/* Barrette grafiche nelle tabelle */
.bar {
  height: 8px;
  background: #EAEFF5;
  border-radius: 4px;
  overflow: hidden;
  min-width: 80px;
}

.bar i {
  display: block;
  height: 100%;
  background: var(--tile);
  border-radius: 4px;
}

/* ---- Pulsanti & Badge --------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  color: #FFFFFF;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.4;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: #0F2E56;
  text-decoration: none;
  color: #FFFFFF;
}

.btn.rust {
  background: var(--rust);
}
.btn.rust:hover {
  background: var(--rust2);
}

.btn.light {
  background: #EAEEF3;
  color: var(--navy);
  border-color: var(--line);
}
.btn.light:hover {
  background: #DCE3EB;
}

.btn.small {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
}

.btn.danger {
  background: #FFFFFF;
  color: var(--ko);
  border: 1px solid #E8B8AE;
}
.btn.danger:hover {
  background: var(--kobg);
}

.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 12px;
  white-space: nowrap;
}

.pill.ok { background: var(--okbg); color: var(--ok); }
.pill.ko { background: var(--kobg); color: var(--ko); }
.pill.warn { background: var(--warnbg); color: var(--warnink); }
.pill.grey { background: #EEF1F4; color: var(--mut); }
.pill.blue { background: #E8F1FB; color: #1D4F86; }

/* ---- Form & Input ------------------------------------------------------- */

form.inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: flex-end;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  color: var(--mut);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type=text],
input[type=date],
input[type=number],
input[type=password],
input[type=file],
select,
textarea {
  font-family: inherit;
  font-size: 13.5px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #FFFFFF;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type=file] {
  padding: 5px 8px;
  font-size: 12.5px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--tile);
  outline: none;
  box-shadow: 0 0 0 3px rgba(48, 121, 202, 0.18);
}

input.num {
  text-align: right;
  width: 150px;
}

textarea {
  width: 100%;
  font-family: Consolas, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.45;
}

/* ---- Login Box ---------------------------------------------------------- */

.login {
  max-width: 380px;
  margin: 10vh auto;
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid var(--line);
}

.login .hd {
  background: linear-gradient(180deg, #173F76, #0F2A50);
  color: #FFFFFF;
  padding: 24px 28px;
}

.login .hd .title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.login .hd .sub {
  font-size: 12px;
  color: #8FA3BC;
  margin-top: 4px;
}

.login .bd {
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---- Markdown / Documenti ----------------------------------------------- */

.md h1 { font-size: 20px; color: var(--navy); }
.md h2 { font-size: 17px; color: var(--navy); margin-top: 26px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.md h3 { font-size: 15px; color: var(--rust); }
.md table { border-collapse: collapse; margin: 10px 0; font-size: 13px; width: 100%; }
.md td, .md th { border: 1px solid var(--line); padding: 6px 10px; vertical-align: top; }
.md th { background: #F6F8FA; font-weight: 700; }
.md pre { background: #F6F8FA; padding: 12px; border-radius: 6px; font-size: 12.5px; overflow-x: auto; }
.md code { font-size: 12px; background: #F6F8FA; padding: 2px 5px; border-radius: 4px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

.scroll {
  overflow-x: auto;
}

/* ---- Ranking Cards (Contabilità Aree) ----------------------------------- */

.rank {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

@media (max-width: 1200px) {
  .rank {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .rank {
    grid-template-columns: 1fr;
  }
}

.rk {
  background: #FFFFFF;
  border: 1px solid var(--line);
  border-top: 5px solid #CCCCCC;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  position: relative;
}

.rk-pos {
  position: absolute;
  top: 10px;
  right: 12px;
  border-radius: 12px;
  padding: 1px 9px;
  font-weight: 800;
  font-size: 12px;
  color: #1C2B1F;
}

.rk-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--mut);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rk-pct {
  font-size: 30px;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.15;
  margin-top: 2px;
}

.rk-sub {
  font-size: 11.5px;
  color: var(--mut);
}

.rk-bar {
  height: 9px;
  background: #EEF1F4;
  border-radius: 5px;
  margin-top: 8px;
  position: relative;
}

.rk-bar i {
  display: block;
  height: 100%;
  border-radius: 5px;
}

.rk-bar b {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 15px;
  background: var(--navy);
}

.rk.avg {
  background: #F6F8FB;
  border-top-color: var(--navy);
}

.rk-macro {
  font-size: 11.5px;
  margin-top: 6px;
}

.rk-macro span {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  margin-right: 5px;
}

/* ---- Excel-like Master Report Table (table.xl) -------------------------- */

table.xl {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

table.xl td {
  border: 1px solid #BFBFBF;
  padding: 4px 8px;
  white-space: nowrap;
}

table.xl td.n {
  text-align: right;
}

table.xl td.c {
  text-align: center;
}

table.xl td.pc {
  color: #404040;
  font-size: 11.5px;
}

table.xl tr.xh1 td {
  background: linear-gradient(180deg, #9DC3E6, #BDD7EE);
  font-weight: 700;
  color: #1F3864;
}

table.xl tr.xh2 td {
  background: linear-gradient(180deg, #BDD7EE, #DDEBF7);
  font-weight: 700;
  color: #1F3864;
}

table.xl tr.xrev td {
  background: linear-gradient(180deg, #E2EFDA, #A9D08E);
  font-weight: 700;
}

table.xl tr.xrev2 td {
  background: #E2EFDA;
}

table.xl tr.xcost td {
  background: linear-gradient(180deg, #FCE4D6, #F4B084);
}

table.xl tr.xcost2 td {
  background: #F8CBAD;
  color: #3A3A3A;
}

table.xl tr.xcost2 td:first-child {
  padding-left: 22px;
}

table.xl tr.xtot td {
  background: #DBDBDB;
  font-weight: 700;
}

table.xl tr.xmdc td {
  background: #C9C9C9;
  font-weight: 800;
  font-size: 13px;
  border-top: 2px solid #7F7F7F;
}

table.xl tr.xmdc2 td {
  background: #00B050;
  font-weight: 800;
  font-size: 13px;
  color: #0B2E13;
  border-top: 2px solid #007A37;
}

table.xl tr.xbep td {
  background: #FFF2CC;
  font-weight: 700;
}

table.xl tr.xrank td {
  background: #F2F2F2;
  font-size: 12px;
}

table.xl td a.amt {
  color: inherit;
}

table.xl td a.amt:hover {
  color: var(--link);
  text-decoration: underline;
}

/* ---- Utility Spacing & Explanations ------------------------------------- */

.why {
  font-size: 12.5px;
  color: #3E4A57;
  background: #FBF4EF;
  border-left: 3px solid var(--rust);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin: 8px 0;
}

.method {
  font-size: 12.5px;
  color: #1D4F86;
  background: #E8F1FB;
  border-left: 3px solid var(--tile);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin: 8px 0;
}

.badge {
  display: inline-block;
  border-radius: 10px;
  padding: 1px 9px;
  font-weight: 800;
  font-size: 11.5px;
  color: #1C2B1F;
}

.badge.ok {
  background: var(--okbg);
  color: var(--ok);
}

.badge.warn {
  background: var(--warnbg);
  color: var(--warnink);
}

.badge.ko {
  background: var(--kobg);
  color: var(--ko);
}

.badge.grey {
  background: #EEF1F4;
  color: var(--mut);
}

.chk { color: var(--ok); font-weight: 800; }
.crs { color: var(--ko); font-weight: 800; }
.dash { color: #B5BEC8; }
.small { font-size: 12px; }
.bld { font-weight: 700; }

table.rep th.a { text-align: right; }
table.rep td.mc { background: #FBF4EF; }

details summary {
  cursor: pointer;
  color: var(--link);
  font-size: 12.5px;
  user-select: none;
}
details summary:hover {
  text-decoration: underline;
}
