/* share.ccir.it — CSS proprietario (palette CCIR moderna) */

:root {
  --bg: #fafbf7;
  --bg-card: #ffffff;
  --bg-alt: #f2f4ea;
  --border: #e4e6dc;
  --border-strong: #cbcfbe;
  --text: #1a1f0e;
  --text-muted: #5b6354;
  --text-light: #9ca395;
  --primary: #759503;        /* CCIR verde moderno */
  --primary-hover: #5d7902;
  --primary-light: #f5f7ed;
  --primary-tint: #eaeed4;
  --accent: #eded2a;          /* accent giallo CCIR */
  --accent-soft: #fdfdcf;
  --info: #1e6091;
  --success: #4d7a0d;
  --warning: #c47900;
  --danger: #b91c1c;
  --shadow-sm: 0 1px 2px rgba(26,31,14,.06);
  --shadow: 0 1px 3px rgba(26,31,14,.08), 0 1px 2px rgba(26,31,14,.04);
  --shadow-md: 0 4px 6px rgba(26,31,14,.06), 0 2px 4px rgba(26,31,14,.04);
  --radius: 6px;
  --radius-lg: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  --mono: "SF Mono", Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-alt);
  padding: 2px 5px;
  border-radius: 3px;
}

/* ========== TOPBAR ========== */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 32px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-logo {
  background: var(--primary);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
  letter-spacing: 0.5px;
}
.brand-name { color: var(--text-muted); font-weight: 500; }

.topnav {
  display: flex;
  gap: 4px;
  flex: 1;
}
.topnav > a, .dropdown > a {
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s;
}
.topnav > a:hover, .dropdown > a:hover {
  background: var(--bg-alt);
  text-decoration: none;
  color: var(--text);
}
.topnav > a.active, .dropdown > a.active {
  background: var(--primary-light);
  color: var(--primary);
}

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 180px;
  padding: 4px;
  display: none;
  z-index: 100;
}
.dropdown:hover .dropdown-menu { display: block; }
.dropdown-menu a {
  display: block;
  padding: 8px 12px;
  color: var(--text);
  border-radius: 4px;
  font-size: 14px;
}
.dropdown-menu a:hover { background: var(--bg-alt); text-decoration: none; }

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}
.user-name {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

/* ========== CONTAINER ========== */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  min-height: calc(100vh - 56px - 50px);
}

/* ========== PAGE HEADER ========== */
.page-header {
  margin-bottom: 24px;
}
.page-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 16px;
}
.page-header h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
}
.page-header .muted { margin: 0; font-size: 13px; }
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ========== TABS ========== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.tab {
  padding: 8px 16px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all .15s;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ========== TOOLBAR ========== */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.filter-input, .filter-select {
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.filter-input { min-width: 260px; }
.filter-input:focus, .filter-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(185,28,28,.1);
}
.toolbar-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
}
.status-indicator {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-alt);
}
.status-indicator.saving { background: #fef3c7; color: #92400e; }
.status-indicator.saved { background: #d1fae5; color: #065f46; }
.status-indicator.error { background: #fee2e2; color: #991b1b; }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-alt); text-decoration: none; }
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon {
  border: none;
  background: transparent;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--text-muted);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: var(--bg-alt); color: var(--text); }
.btn-icon.btn-delete:hover { background: var(--primary-light); color: var(--danger); }

/* ========== TABLE ========== */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: var(--shadow-sm);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead {
  background: var(--bg-alt);
  position: sticky;
  top: 0;
  z-index: 2;
}
.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:hover {
  background: #fafbfc;
}
.data-table tbody tr.hidden { display: none; }

/* colonne specifiche protocollo */
.col-num     { width: 110px; }
.col-codice  { width: 80px; }
.col-data    { width: 100px; }
.col-status  { width: 80px; }
.col-meta    { width: 130px; }
.col-actions { width: 80px; }

/* cell editable */
.editable {
  cursor: text;
  min-width: 60px;
  position: relative;
}
.editable:hover { background: #fefce8; }
.editable:empty::after {
  content: "—";
  color: var(--text-light);
}
.editable.num { font-variant-numeric: tabular-nums; text-align: right; }
.editable.editing {
  padding: 0 !important;
  background: #fff !important;
}
.editable input.cell-input,
.editable select.cell-input,
.editable textarea.cell-input {
  width: 100%;
  border: 2px solid var(--primary);
  background: #fff;
  padding: 6px 10px;
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  border-radius: 3px;
}
.editable.saving { background: #fef3c7 !important; }
.editable.saved { background: #d1fae5 !important; transition: background .3s; }
.editable.error { background: #fee2e2 !important; }

.cell-meta {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
  white-space: nowrap;
}
.meta-time { color: var(--text-light); font-size: 10px; }
.cell-actions { text-align: right; white-space: nowrap; }

.cell-tag {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tag-italiani { color: #1e40af; }
.tag-russi { color: #b45309; }

/* badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-edit { background: #dbeafe; color: #1e40af; }
.badge-create { background: #d1fae5; color: #065f46; }
.badge-delete { background: #fee2e2; color: #991b1b; }

.diff-old { color: var(--danger); text-decoration: line-through; font-family: var(--mono); font-size: 11px; }
.diff-new { color: var(--success); font-family: var(--mono); font-size: 11px; }

/* ========== DASHBOARD CARDS ========== */
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}
.card-group {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card-group-title {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}
.card {
  display: block;
  background: var(--bg-alt);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center;
  transition: all .15s;
  text-decoration: none;
  color: var(--text);
}
.card:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  text-decoration: none;
  transform: translateY(-1px);
}
.card-year {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}
.card-count {
  font-size: 13px;
  margin-top: 2px;
}
.card-count span {
  color: var(--text-muted);
  font-size: 11px;
}
.card-add { background: transparent; border: 1px dashed var(--border-strong); }
.card-add .card-year { color: var(--text-muted); }

.page-section { margin-top: 32px; }
.page-section h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }

.table-mini { width: 100%; border-collapse: collapse; font-size: 12px; }
.table-mini th, .table-mini td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.table-mini th { font-weight: 600; color: var(--text-muted); }

/* ========== LOGIN ========== */
.login-body {
  background: linear-gradient(135deg, #f5f7ed 0%, #fafbf7 50%, #eaeed4 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-wrap { width: 100%; max-width: 380px; padding: 20px; }
.login-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  box-shadow: var(--shadow-md);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-logo {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 1px;
}
.login-name {
  font-size: 24px;
  font-weight: 700;
  margin-top: 12px;
}
.login-sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.field input, .field select {
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(185,28,28,.1);
}
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.login-footer { text-align: center; margin-top: 20px; color: var(--text-muted); }

/* ========== MODAL ========== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
}
.modal-card {
  position: relative;
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 600px;
  width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px rgba(0,0,0,.15);
}
.modal-card h3 { margin: 0 0 16px; font-size: 18px; }
.history-row { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.history-row:last-child { border: none; }
.history-meta { color: var(--text-muted); font-size: 11px; }

/* ========== FOOTER ========== */
.footer {
  background: #fff;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}
.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

/* ========== EMPTY/404 ========== */
.page-empty {
  text-align: center;
  padding: 80px 20px;
}

/* ========== PAGINATION ========== */
.pagination {
  display: flex;
  gap: 4px;
  margin-top: 16px;
  justify-content: center;
}
.pagination a {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
}
.pagination a.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.pagination a:hover { text-decoration: none; background: var(--bg-alt); }
.pagination a.active:hover { background: var(--primary); }

/* ========== QUICK WINS ========== */
/* Sticky header già attivo via thead. Ma rinforzo z-index e shadow */
.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-alt);
  z-index: 3;
  box-shadow: 0 1px 0 var(--border);
}

/* Scroll to top/bottom button (FAB) */
.fab-scroll {
  position: fixed;
  right: 24px;
  bottom: 70px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.fab-scroll button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--primary);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all .15s;
}
.fab-scroll button:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  transform: translateY(-2px);
}

/* Highlight nuova riga */
@keyframes rowFlash {
  0% { background: var(--accent-soft); }
  50% { background: var(--accent); }
  100% { background: transparent; }
}
.data-table tbody tr.row-new {
  animation: rowFlash 2.4s ease-out;
}

/* Riga corrente con focus */
.data-table tbody tr.row-focus td {
  background: var(--primary-light) !important;
}

/* Riga con data NULL (anomalia) */
.data-table tbody tr.row-warning {
  background: #fffbeb;
}
.data-table tbody tr.row-warning:hover {
  background: #fef3c7;
}

/* Toolbar info (count, filtri attivi) */
.toolbar-info {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 8px;
}
.toolbar-info strong {
  color: var(--text);
}

/* Bottone "jump to end" nella toolbar */
.btn-jump {
  font-size: 12px;
  padding: 6px 10px;
}
@media (max-width: 768px) {
  .topbar-inner { padding: 0 12px; gap: 12px; height: 50px; }
  .brand-name { display: none; }
  .topnav { gap: 0; overflow-x: auto; }
  .topnav > a, .dropdown > a { padding: 6px 10px; font-size: 13px; }
  .user-name { display: none; }
  .container { padding: 14px; }
  .page-header h1 { font-size: 20px; }
  .filter-input { min-width: 0; flex: 1; }
  .data-table { font-size: 12px; }
  .data-table td { padding: 6px 8px; }
}
