* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: Calibri, "Segoe UI", -apple-system, Arial, sans-serif;
  font-size: 13px; color: #1a1a1a; background: #f3f2f1;
  overflow: hidden;
}
#app { display: flex; flex-direction: column; height: 100vh; }
#app[hidden] { display: none; }

/* ===== Schermata di accesso — Material 3 ===== */
.login-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 30% 15%, #eef3fb, #e6e9f0 55%, #dfe2ea);
  font-family: Roboto, "Segoe UI", -apple-system, system-ui, sans-serif;
}
.login-screen[hidden] { display: none; }
.login-card {
  background: #fff; border-radius: 28px; padding: 40px 34px;
  width: min(92vw, 380px); text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 10px 30px rgba(0,0,0,.10);
}
.login-logo {
  width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 18px;
  display: grid; place-items: center; font-size: 30px;
  background: #e7f3ec; color: #107c41;
}
.login-title {
  margin: 0 0 6px; font-size: 26px; font-weight: 500;
  color: #1b1b1f; letter-spacing: .2px;
}
.login-sub { margin: 0 0 26px; font-size: 14px; line-height: 1.5; color: #5d5e66; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.pw-input {
  font: inherit; font-size: 15px; padding: 12px 14px;
  border: 1px solid #c4c6cf; border-radius: 12px; outline: none;
  background: #fbfbfe; color: #1b1b1f; transition: border-color .15s, box-shadow .15s;
}
.pw-input:focus { border-color: #107c41; box-shadow: 0 0 0 3px rgba(16,124,65,.15); }
.pw-btn {
  font: inherit; font-size: 15px; font-weight: 600; padding: 12px 18px;
  border: none; border-radius: 24px; cursor: pointer;
  background: #107c41; color: #fff; transition: background .15s, box-shadow .15s;
}
.pw-btn:hover { background: #0d6836; box-shadow: 0 2px 8px rgba(16,124,65,.30); }
.pw-btn:active { background: #0b5a2e; }
.login-msg { margin: 16px 0 0; font-size: 13px; line-height: 1.4; color: #b3261e; min-height: 18px; }

/* ===== Barra formula in alto, stile Excel ===== */
.formula-bar {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border-bottom: 1px solid #d0d0d0;
  padding: 4px 8px; flex: 0 0 auto;
}
.name-box {
  width: 70px; text-align: center; font-weight: 600;
  border: 1px solid #d0d0d0; border-radius: 3px; padding: 3px 4px; color: #444;
}
.formula-bar .fx { color: #888; font-style: italic; }
.formula-bar .cell-content { color: #333; flex: 1; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== Griglia ===== */
.grid-wrap { flex: 1 1 auto; overflow: auto; background: #fff; position: relative; }
table.grid { border-collapse: collapse; table-layout: fixed; }
table.grid th, table.grid td {
  border: 1px solid #e1e1e1; height: 22px; padding: 0 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
table.grid th {
  background: #f5f5f5; color: #555; font-weight: 600; text-align: center;
  position: sticky; top: 0; z-index: 2; user-select: none;
}
table.grid th.row-head {
  left: 0; z-index: 3; width: 42px; min-width: 42px; max-width: 42px;
}
table.grid td.row-head {
  background: #f5f5f5; color: #555; font-weight: 600; text-align: center;
  position: sticky; left: 0; z-index: 1; user-select: none;
  width: 42px; min-width: 42px; max-width: 42px;
}
table.grid td { width: 96px; min-width: 96px; max-width: 96px; background: #fff; cursor: cell; }
table.grid td.num { text-align: right; }
table.grid td.selected { outline: 2px solid #107c41; outline-offset: -2px; z-index: 1; }
table.grid td.err { color: #c00; }
table.grid td.pending { color: #888; font-style: italic; }

/* Chat: una sola colonna larga (A) che scorre giù come una chat */
body.sheet-chat table.grid td.chat-col {
  width: 720px; min-width: 720px; max-width: 720px;
  white-space: normal; vertical-align: top; height: auto;
  padding: 8px 12px; line-height: 1.45;
}
body.sheet-chat table.grid td.chat-user { background: #eef6ff; color: #11324d; }
body.sheet-chat table.grid td.chat-bot  { background: #f2fbf4; color: #14361f; }
body.sheet-chat table.grid td.chat-user::before {
  content: "Tu"; display: block; font-size: 11px; font-weight: 700; color: #2b6cb0; opacity: 0.8; margin-bottom: 2px;
}
body.sheet-chat table.grid td.chat-bot::before {
  content: "Claude"; display: block; font-size: 11px; font-weight: 700; color: #107c41; opacity: 0.8; margin-bottom: 2px;
}

/* Editor cella */
#editor {
  position: fixed; display: none; border: 2px solid #107c41;
  font-family: inherit; font-size: 13px; padding: 2px 4px; margin: 0;
  outline: none; z-index: 10; resize: none; background: #fff; line-height: 1.45;
}

/* Tab dei fogli in basso */
.tabs {
  flex: 0 0 auto; display: flex; align-items: center; gap: 2px;
  background: #f3f2f1; border-top: 1px solid #d0d0d0; padding: 4px 8px;
}
.tab {
  padding: 5px 16px; border: 1px solid transparent; border-bottom: none;
  background: #e7e6e5; color: #444; cursor: pointer; border-radius: 4px 4px 0 0;
  font-size: 12px;
}
.tab.active { background: #fff; color: #107c41; font-weight: 600; box-shadow: inset 0 -2px 0 #107c41; }
.hint { font-size: 11px; color: #888; margin-left: 8px; }
.who-badge { margin-left: auto; font-size: 11px; color: #5d5e66; padding-right: 6px; }
