:root {
  --green: #7fd98a;
  --green-light: #c8efcd;
  --yellow: #ffd966;
  --naveline: #f1e9c9;
  --industry: #e7e6e6;
  --grid: #252525;
  --page: #f3f5f6;
  --card: #ffffff;
  --text: #202124;
  --muted: #6b7280;
  --primary: #1769aa;
  --danger: #b42318;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--page);
  color: var(--text);
}
button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid #d9dde2;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { margin: 0; font-size: 23px; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 14px; }
.top-actions { display: flex; gap: 10px; align-items: center; }
.status-pill { padding: 7px 10px; border-radius: 999px; background: #eef7ee; font-size: 13px; }

.page-shell { width: min(1820px, calc(100% - 28px)); margin: 18px auto 40px; }
.card, .sheet-card { background: var(--card); border: 1px solid #d9dde2; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .inline-field label { font-weight: 700; font-size: 13px; }
.field input, .inline-field input { border: 1px solid #adb5bd; border-radius: 6px; padding: 9px 10px; background: #fff; }
.field.compact input { padding: 8px; }

.btn { border: 1px solid transparent; border-radius: 7px; padding: 9px 13px; font-weight: 700; background: #fff; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.secondary { border-color: #abb3bb; color: #263238; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 6px 9px; font-size: 13px; }
.btn:hover { filter: brightness(.97); }

.sheet-card { padding: 16px; overflow: auto; }
.sheet-grid { display: grid; grid-template-columns: minmax(960px, 1fr) 300px; gap: 42px; align-items: start; min-width: 1290px; }
.excel-title, .excel-section-title { background: var(--green); border: 1px solid var(--grid); text-align: center; }
.excel-title { padding: 4px 8px; margin-bottom: 20px; font-size: 17px; }
.excel-section { margin-bottom: 20px; }
.excel-section-title { padding: 4px 8px; font-size: 16px; }
.table-wrap { overflow-x: auto; }
.excel-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.excel-table th, .excel-table td { border: 1px solid var(--grid); padding: 3px 5px; text-align: center; height: 25px; }
.excel-table thead th { background: var(--green); font-weight: 400; }
.excel-table tfoot th, .excel-table tfoot td { background: var(--green-light); }
.excel-table tbody tr.clementine-row td { background: var(--yellow); }
.excel-table tbody tr.naveline-row td { background: var(--naveline); }
.excel-table tbody tr.industria-row td { background: var(--industry); }
.excel-table tbody tr:hover td { box-shadow: inset 0 0 0 999px rgba(255,255,255,.12); }
.excel-table .actions-col { width: 76px; }
.row-action { border: 0; background: rgba(255,255,255,.78); border-radius: 5px; padding: 4px 7px; font-size: 12px; }
.empty-row td { background: #fafafa !important; color: var(--muted); font-style: italic; height: 38px; }

.grand-total-wrap { margin: 6px 0 18px; }
.compact-summary th { width: 115px; background: #dcebd9; text-align: left; }
.compact-summary td { background: #dcebd9; }
.bottom-summary { display: flex; align-items: start; gap: 90px; margin-top: 14px; }
.pay-table { width: 520px; }
.pay-table thead th { background: #d9d9d9; }
.pay-table tbody th, .pay-table tbody td { background: #f4f4f4; }
.pay-table .pay-cell { background: var(--yellow); }
.cascatura-table { width: 230px; }
.cascatura-table th { background: #d9d9d9; }
.cell-input { width: 100%; border: 0; background: transparent; text-align: center; outline: none; }

.sheet-side { display: flex; flex-direction: column; gap: 22px; }
.side-block { width: 100%; }
.side-table { width: 100%; }
.side-table th, .side-table td { height: 25px; }
.side-table .delete-bin { border: 0; background: transparent; font-size: 16px; line-height: 1; }
.bins-controls { display: flex; align-items: end; gap: 8px; margin: 9px 0; }
.inline-field { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.inline-field input { width: 100%; }
.remaining-table th { background: var(--green); }
.daily-table tbody td { background: var(--green-light); }
.daily-table tfoot th, .daily-table tfoot td { background: var(--green-light); }

.dialog { border: 0; border-radius: 12px; padding: 0; width: min(620px, calc(100% - 24px)); box-shadow: 0 18px 55px rgba(0,0,0,.3); }
.large-dialog { width: min(1080px, calc(100% - 24px)); }
.dialog::backdrop { background: rgba(0,0,0,.38); }
.dialog-header, .dialog-footer { display: flex; align-items: center; gap: 12px; padding: 15px 18px; border-bottom: 1px solid #e2e5e8; }
.dialog-footer { border-bottom: 0; border-top: 1px solid #e2e5e8; }
.dialog-header h2 { margin: 0; font-size: 20px; }
.dialog-header p { margin: 4px 0 0; color: var(--muted); }
.dialog-body { padding: 18px; }
.icon-button { margin-left: auto; border: 0; background: transparent; font-size: 28px; line-height: 1; }
.dialog-footer-spacer { flex: 1; }
.form-grid { display: grid; gap: 14px; }
.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.category-editors { display: grid; gap: 14px; margin-top: 16px; }
.category-editor { border: 1px solid #c7ccd1; border-radius: 8px; overflow: hidden; }
.category-editor-header { display: flex; align-items: center; gap: 8px; padding: 9px 12px; background: var(--green); border-bottom: 1px solid #c7ccd1; font-weight: 700; }
.category-fields { padding: 12px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.category-fields.disabled { opacity: .45; pointer-events: none; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-top: 15px; }

.history-header { display: flex; justify-content: space-between; align-items: center; padding: 18px; border-bottom: 1px solid #e1e4e8; }
.history-header h2 { margin: 0 0 4px; }
.history-header p { margin: 0; color: var(--muted); }
.history-list { padding: 12px 18px 18px; display: grid; gap: 8px; }
.history-row { border: 1px solid #d9dde2; border-radius: 8px; padding: 12px; display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; }
.history-row strong { display: block; }
.history-row span { color: var(--muted); font-size: 13px; }

.toast { position: fixed; right: 18px; bottom: 18px; background: #1f2937; color: white; border-radius: 8px; padding: 10px 14px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .2s; z-index: 100; }
.toast.show { opacity: 1; transform: translateY(0); }
.hidden { display: none !important; }

@media (max-width: 800px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; flex-wrap: wrap; }
  .page-shell { width: calc(100% - 14px); }
  .two-cols, .category-fields { grid-template-columns: 1fr 1fr; }
  .campaign-toolbar .toolbar-select { flex: 1 1 150px; }
  .campaign-toolbar .btn { flex: 1 1 190px; }
}

/* =========================================================
   Accesso Google + sessione server
   ========================================================= */
.login-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(145deg, #eef5ef 0%, #f7f8f9 52%, #edf3f7 100%);
}

.login-card {
  width: min(460px, 100%);
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  padding: 34px;
  background: #fff;
  border: 1px solid #d9dde2;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(31, 41, 55, .12);
  text-align: center;
}

.login-card h1 {
  margin: 14px 0 8px;
  font-size: 27px;
}

.login-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.login-badge {
  display: inline-block;
  padding: 7px 11px;
  background: var(--green-light);
  border: 1px solid #98c99f;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
}

.google-signin {
  min-height: 44px;
  display: flex;
  justify-content: center;
  margin-top: 24px;
}

.login-error {
  width: 100%;
  max-width: 100%;
  margin-top: 16px !important;
  padding: 10px 12px;
  background: #fff1f0;
  border: 1px solid #f0b5b0;
  border-radius: 8px;
  color: var(--danger) !important;
  font-size: 13px;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.user-pill {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 7px 10px;
  border-radius: 999px;
  background: #f1f3f5;
  border: 1px solid #d9dde2;
  font-size: 13px;
}

/* =========================================================
   Inserimento giornaliero + finitura estetica
   ========================================================= */

/* I mesi e le bolle vengono ora gestiti automaticamente. */
#newMonthButton,
#newBollaButton,
#newMonthDialog {
  display: none !important;
}

.campaign-toolbar {
  align-items: center;
}

.toolbar-select {
  min-width: 150px;
  height: 38px;
  padding: 0 34px 0 11px;
  border: 1px solid #abb3bb;
  border-radius: 9px;
  background: #f7f9f7;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

#campaignMonthPicker {
  min-width: 132px;
}

.card,
.sheet-card {
  border-radius: 14px;
}

.toolbar {
  border-radius: 14px;
}

.excel-title {
  border-radius: 9px;
  overflow: hidden;
}

.excel-section {
  border-radius: 9px;
  overflow: hidden;
}

.excel-section-title {
  border-radius: 9px 9px 0 0;
}

.table-wrap {
  border-radius: 0 0 9px 9px;
}

.grand-total-wrap,
.bottom-summary .excel-table,
.side-table {
  border-radius: 9px;
  overflow: hidden;
}

.side-block > .excel-section-title {
  border-radius: 9px 9px 0 0;
}

.side-block > .side-table:first-of-type {
  border-radius: 0 0 9px 9px;
}

.history-row,
.category-editor,
.login-error,
.toast {
  border-radius: 10px;
}

.btn,
.row-action,
.field input,
.inline-field input {
  border-radius: 8px;
}

.row-action {
  border: 1px solid rgba(37, 37, 37, .20);
  background: rgba(37, 37, 37, .05);
}

.sheet-input {
  width: 100%;
  min-width: 0;
  padding: 4px 5px;
  border: 1px solid rgba(37, 37, 37, .24);
  border-radius: 6px;
  outline: none;
  background: transparent;
  text-align: center;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.sheet-input:hover {
  background: rgba(37, 37, 37, .035);
}

.sheet-input:focus {
  background: rgba(200, 239, 205, .35);
  border-color: #4f9d5b;
  box-shadow: 0 0 0 2px rgba(79, 157, 91, .12);
}

.today-row .locked-cell,
.today-row .calculated-cell {
  font-weight: 600;
}

.draft-row td {
  box-shadow: inset 0 0 0 999px rgba(37,37,37,.025);
}

.draft-row .sheet-input {
  border-style: dashed;
}

.draft-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 3px 7px;
  border: 1px dashed rgba(37,37,37,.30);
  border-radius: 999px;
  background: rgba(37,37,37,.035);
  color: #4b5563;
  font-size: 11px;
  font-weight: 700;
}
