:root {
  color-scheme: light;
  --ink: #17384f;
  --muted: #667782;
  --line: #d8e2e9;
  --paper: #ffffff;
  --canvas: #f3f7fa;
  --navy: #193f59;
  --teal: #2f7fb7;
  --teal-dark: #1d5d89;
  --amber: #ed9300;
  --red: #b42318;
  --shadow: 0 16px 40px rgba(25, 63, 89, .10);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: .25rem; font-size: clamp(1.45rem, 3vw, 2rem); letter-spacing: -.03em; }
h2 { margin-bottom: .15rem; font-size: 1.1rem; }
.eyebrow { margin: 0 0 .35rem; color: var(--teal); font-size: .72rem; font-weight: 800; letter-spacing: .16em; }
.muted, small, .table-heading p { color: var(--muted); }
small { display: block; margin-top: .2rem; white-space: nowrap; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .85rem 1.5rem; padding: .9rem max(1.25rem, calc((100vw - 1500px)/2)); background: var(--paper); border-bottom: 3px solid var(--amber); }
.page-brand, .section-title { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.page-brand > a { display: inline-flex; flex: 0 0 auto; }
.top-logo { display: block; width: 190px; height: auto; }
.section-icon { width: 48px; height: 48px; object-fit: contain; flex: 0 0 auto; }
.section-title h1, .page-brand h1 { margin-bottom: 0; }
.page { max-width: 1500px; margin: 0 auto; padding: 1.25rem; }
button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: .65rem 1rem; border: 0; border-radius: 8px; background: var(--teal); color: white; font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; }
button:hover, .button:hover { background: var(--teal-dark); }
.secondary, .ghost { background: transparent; color: var(--teal-dark); border: 1px solid #9bbdd4; }
.filters { display: grid; grid-template-columns: 150px 150px 1fr 1.4fr auto; gap: .8rem; align-items: end; padding: 1rem; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
label { display: grid; gap: .35rem; color: var(--muted); font-size: .78rem; font-weight: 700; }
input, select { width: 100%; min-height: 42px; padding: .58rem .7rem; border: 1px solid #bccad1; border-radius: 7px; background: #fff; color: var(--ink); font: inherit; }
textarea { width: 100%; min-height: 120px; resize: vertical; padding: .8rem; border: 1px solid #bccad1; border-radius: 9px; background: #fff; color: var(--ink); font: inherit; }
input:focus, select:focus { outline: 3px solid rgba(47,127,183,.16); border-color: var(--teal); }
textarea:focus { outline: 3px solid rgba(47,127,183,.16); border-color: var(--teal); }
.actions { display: flex; gap: .5rem; }
.metrics { display: grid; grid-template-columns: repeat(5, 1fr); gap: .8rem; margin: 1rem 0; }
.metrics article { padding: .9rem 1rem; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; }
.metrics span { display: block; color: var(--muted); font-size: .76rem; font-weight: 700; }
.metrics strong { display: block; margin-top: .15rem; color: var(--navy); font-size: 1.65rem; }
.metrics .warn { border-color: #f1b89d; background: #fff8f5; }
.metrics .warn strong { color: var(--red); }
.table-card { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.table-heading { padding: 1rem 1.1rem .7rem; }
.split-heading, .top-actions, .top-actions nav, .pagination { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.top-actions { justify-content: flex-end; }
.nav-link { padding: .5rem .7rem; border-radius: 7px; color: var(--muted); font-weight: 700; text-decoration: none; }
.nav-link.active, .nav-link:hover { background: #e5f1f8; color: var(--teal-dark); }
.nav-link.active { box-shadow: inset 0 -2px var(--amber); }
.contract-filters { grid-template-columns: 125px 125px 100px 160px 190px 120px 1fr auto; }
.berth-filters { grid-template-columns: 155px 155px 1fr 240px auto; }
.tabs { display: flex; gap: .5rem; margin-bottom: .8rem; }
.tab { padding: .7rem 1rem; border: 1px solid var(--line); border-radius: 9px; background: var(--paper); color: var(--muted); font-weight: 800; text-decoration: none; }
.tab.active { background: var(--navy); border-color: var(--navy); color: white; }
.person-filters { grid-template-columns: repeat(5, minmax(130px, 1fr)); }
.person-filters .wide { grid-column: span 2; }
.person-actions { align-self: end; }
.compact { min-height: 34px; padding: .4rem .65rem; }
.detail-heading { margin-bottom: 1rem; }
.detail-heading p { margin: .5rem 0 0; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.detail-card { padding: 1.1rem; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.detail-card dl { display: grid; grid-template-columns: minmax(145px, .6fr) 1.4fr; margin: .8rem 0 0; }
.detail-card dt, .detail-card dd { margin: 0; padding: .55rem 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.detail-card dt { color: var(--muted); font-size: .78rem; font-weight: 800; }
.vessel-card, .extra-card { margin-top: 1rem; }
.extra-fields { grid-template-columns: minmax(220px, .5fr) 1.5fr !important; }
.table-heading p { margin-bottom: 0; font-size: .82rem; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: .65rem .8rem; background: #eaf0f2; color: #455967; font-size: .72rem; letter-spacing: .04em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { padding: .72rem .8rem; border-top: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
tbody tr:hover { background: #f7fafb; }
.status { display: inline-block; padding: .25rem .5rem; border-radius: 999px; background: #e5eeef; color: #38515e; font-size: .72rem; font-weight: 800; }
.status-in-corso { background: #d7f4ec; color: #07634e; }
.status-programmato { background: #e2edff; color: #1d4e89; }
.status-anomalia { background: #fee4e2; color: var(--red); }
.status-spostato { background: #fff0d5; color: var(--amber); }
.status-attivo { background: #d7f4ec; color: #07634e; }
.status-scaduto, .status-non-accettato, .status-anomalia { background: #fee4e2; color: var(--red); }
.status-futuro, .status-confermato { background: #e2edff; color: #1d4e89; }
.status-bozza, .status-in-attesa, .status-conferma-parziale { background: #fff0d5; color: var(--amber); }
.mandate { display: inline-block; margin-top: .3rem; padding: .2rem .45rem; border-radius: 5px; background: #ede5ff; color: #59359a; font-size: .7rem; font-weight: 800; }
.anomaly-row { background: #fff8f5; }
.empty { padding: 3rem; text-align: center; color: var(--muted); }
.alert { margin-bottom: 1rem; padding: .8rem 1rem; border-radius: 8px; }
.alert.error { background: #fee4e2; border: 1px solid #f7aaa5; color: #8b1a12; }
.alert.warning { background: #fff4df; border: 1px solid #edc27d; color: #744300; }
.alert.success { background: #dff5eb; border: 1px solid #91d4b8; color: #075f46; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; background: radial-gradient(circle at 80% 10%, #d9eaf6 0, transparent 35%), radial-gradient(circle at 10% 90%, #fff0d8 0, transparent 28%), var(--canvas); }
.login-card { width: min(430px, 100%); padding: 2rem; background: var(--paper); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.brand-mark { display: grid; place-items: center; width: 46px; height: 46px; margin-bottom: 1rem; border-radius: 12px; background: var(--navy); color: white; font-size: 1.35rem; font-weight: 900; }
.login-logo { display: block; width: min(310px, 100%); height: auto; margin: -.5rem 0 1.15rem; }
.login-icon { display: block; width: 72px; height: 72px; object-fit: contain; margin-bottom: 1rem; }
.stack { display: grid; gap: 1rem; margin-top: 1.5rem; }
.assistant-page { max-width: 1200px; }
.assistant-card, .answer-card { margin-bottom: 1rem; padding: 1.25rem; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.assistant-form { display: grid; grid-template-columns: 1fr auto; gap: .8rem; align-items: end; margin-top: 1rem; }
.answer-text { margin: .8rem 0; font-size: 1.05rem; white-space: pre-wrap; }
.privacy-note { margin: .7rem 0 0; color: var(--amber); font-size: .78rem; font-weight: 700; }
.answer-meta { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.confidence { display: inline-block; padding: .28rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 800; }
.confidence-alta { background: #d7f4ec; color: #07634e; }
.confidence-media { background: #fff0d5; color: var(--amber); }
.confidence-bassa { background: #fee4e2; color: var(--red); }
.agent-notes { margin-top: .8rem; padding: .75rem .9rem; border-left: 3px solid var(--teal); background: #f1f8f7; font-size: .84rem; }
.agent-notes ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.warning-notes { border-left-color: var(--amber); background: #fff8eb; }
.compact-note { margin: .7rem 0 0; font-size: .78rem; }
details { max-width: 55%; color: var(--teal-dark); cursor: pointer; }
pre { max-height: 260px; overflow: auto; padding: .8rem; border-radius: 8px; background: #eef3f4; color: var(--ink); white-space: pre-wrap; }
.main-nav { display: flex; flex-wrap: wrap; justify-content: flex-end; }
.welcome-card { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; padding: 1.35rem 1.5rem; border-left: 5px solid var(--amber); border-radius: 14px; background: linear-gradient(120deg, var(--navy), #286f9e); color: white; box-shadow: var(--shadow); }
.welcome-card .eyebrow { color: #ffb844; }
.welcome-card .muted { margin: .35rem 0 0; color: #dceaf3; }
.welcome-card h2 { font-size: 1.45rem; }
.user-badge { padding: .45rem .75rem; border: 1px solid rgba(255,255,255,.35); border-radius: 999px; font-size: .78rem; font-weight: 800; white-space: nowrap; }
.link-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.link-card { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 1rem; min-height: 145px; padding: 1.25rem; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); color: var(--ink); text-decoration: none; box-shadow: var(--shadow); transition: transform .15s ease, border-color .15s ease; }
.link-card:hover { transform: translateY(-2px); border-color: #76acd0; }
.link-card p { margin: .35rem 0 0; color: var(--muted); }
.card-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; background: #e5f1f8; color: var(--teal-dark); font-weight: 900; box-shadow: inset 0 -3px var(--amber); }
.card-arrow { color: var(--teal); font-size: 1.5rem; }
.admin-card .card-icon { background: #ede5ff; color: #59359a; }
.user-create-card, .user-list { margin-bottom: 1rem; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); box-shadow: var(--shadow); }
.user-form { display: grid; grid-template-columns: 1fr 1fr 1.2fr auto; gap: .9rem; align-items: end; padding: 0 1.1rem 1.1rem; }
.permission-set { display: flex; flex-wrap: wrap; gap: .6rem 1rem; grid-column: 1 / -1; margin: 0; padding: .8rem; border: 1px solid var(--line); border-radius: 9px; }
.permission-set legend { padding: 0 .35rem; color: var(--muted); font-size: .76rem; font-weight: 800; }
.check-label { display: flex; grid-template-columns: auto 1fr; align-items: center; gap: .4rem; min-height: 42px; color: var(--ink); }
.check-label input { width: 18px; min-height: 18px; }
.user-list { padding-bottom: 1rem; }
.user-card { display: grid; grid-template-columns: 1.2fr 1fr 1.2fr auto; gap: .8rem; align-items: end; margin: 0 1rem 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: 10px; background: #f9fbfb; }
.user-card .permission-set { grid-column: 1 / -1; }
.user-card-heading { align-self: center; }
.user-card-heading strong { margin-right: .5rem; font-size: 1.05rem; }
.user-switches { display: flex; gap: .8rem; }
@media (max-width: 1400px) {
  .top-actions { width: 100%; justify-content: space-between; }
  .main-nav { justify-content: flex-start; }
}
@media (max-width: 1050px) {
  .filters { grid-template-columns: repeat(2, 1fr); }
  .filters .wide, .actions { grid-column: span 2; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .contract-filters { grid-template-columns: repeat(2, 1fr); }
  .berth-filters { grid-template-columns: repeat(2, 1fr); }
  .person-filters { grid-template-columns: repeat(2, 1fr); }
  .link-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .user-form, .user-card { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .filters { grid-template-columns: 1fr; }
  .filters .wide, .actions { grid-column: auto; }
  .actions { display: grid; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .topbar { align-items: flex-start; }
  .page-brand { align-items: flex-start; flex-direction: column; }
  .top-logo { width: 165px; }
  .section-icon { width: 40px; height: 40px; }
  .top-actions { align-items: flex-end; flex-direction: column-reverse; }
  .split-heading { align-items: flex-start; flex-direction: column; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-card dl, .extra-fields { grid-template-columns: 1fr !important; }
  .detail-card dd { padding-top: 0; border-top: 0; }
  .assistant-form { grid-template-columns: 1fr; }
  details { max-width: 100%; }
  .link-grid { grid-template-columns: 1fr; }
  .welcome-card { align-items: flex-start; flex-direction: column; }
  .user-form, .user-card { grid-template-columns: 1fr; }
  .permission-set, .user-card .permission-set { grid-column: auto; }
}
