/* ==========================================================================
   FR SERVICE — app.css : auth, dashboard utente, pannello admin
   ========================================================================== */

/* ---- Auth (login / registrazione) ---- */
.auth-wrap {
  min-height: calc(100vh - 70px);
  display: grid; place-items: center;
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(47,128,237,.18), transparent 60%),
    linear-gradient(160deg, var(--navy-900), var(--navy-700));
  padding: 48px 20px;
}
.auth-card {
  width: 100%; max-width: 440px;
  background: #fff; border-radius: 18px; padding: 34px;
  box-shadow: var(--shadow-lg);
}
/* Registrazione: con i dati della societa servono piu campi, e su due colonne */
.auth-card--larga { max-width: 660px; }
.auth-card .form-sez {
  font-size: .82rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 700;
  margin: 26px 0 12px; padding-bottom: 7px; border-bottom: 1px solid var(--line);
}
.auth-card .form-sez:first-of-type { margin-top: 8px; }
.auth-card .form-nota { font-size: .84rem; color: var(--muted); margin: -6px 0 12px; }
.auth-card .opz { font-weight: 400; color: var(--muted); }
.auth-card .field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; align-items: start; }
.auth-card .field-row--3 { grid-template-columns: 110px 1fr 120px; }
@media (max-width: 560px) { .auth-card .field-row, .auth-card .field-row--3 { grid-template-columns: 1fr; } }
.auth-card .brand { justify-content: center; margin-bottom: 22px; }
.auth-card h1 { font-size: 1.5rem; text-align: center; margin-bottom: 4px; }
.auth-card .sub { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: .95rem; }
.auth-switch { text-align: center; margin-top: 18px; font-size: .92rem; color: var(--muted); }
.alert { padding: 11px 14px; border-radius: 9px; font-size: .9rem; margin-bottom: 16px; display: none; }
.alert.show { display: block; }
.alert.err { background: #fdecec; color: #b3261e; border: 1px solid #f6caca; }
.alert.ok  { background: #e9f7ef; color: #1d7a46; border: 1px solid #c2e8d2; }

/* ---- App shell (dashboard / admin) ---- */
.app-topbar {
  background: var(--navy-900); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; height: 64px; position: sticky; top: 0; z-index: 40;
}
.app-topbar .brand .bt strong { color: #fff; }
.app-topbar .right { display: flex; align-items: center; gap: 14px; font-size: .9rem; }
.app-topbar .right .who { color: #b9c8de; }
.app-topbar .right .who b { color: #fff; }

.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 64px); }
.app-side { background: #fff; border-right: 1px solid var(--line); padding: 22px 14px; }
.app-side a, .app-side button.navlink {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 14px; border-radius: 9px; color: var(--ink);
  font-weight: 600; font-size: .94rem; border: 0; background: none;
  cursor: pointer; text-align: left; margin-bottom: 2px;
}
.app-side a:hover, .app-side button.navlink:hover { background: var(--bg-soft2); text-decoration: none; }
.app-side .navlink.active { background: var(--accent); color: #fff; }
.app-main { padding: 30px 34px; background: var(--bg-soft); }
.app-main h1 { font-size: 1.6rem; }
.page-title { margin-bottom: 6px; }
.page-sub { color: var(--muted); margin-bottom: 26px; }

/* ---- Stat cards ---- */
.kpi { display: grid; grid-template-columns: repeat(4,1fr); gap: 18px; margin-bottom: 30px; }
.kpi .box { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; box-shadow: var(--shadow-sm); }
.kpi .box strong { display: block; font-size: 2rem; color: var(--navy-900); }
.kpi .box span { color: var(--muted); font-size: .86rem; }

/* ---- Panels ---- */
.panel { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 24px; box-shadow: var(--shadow-sm); margin-bottom: 24px; }
.panel h2 { font-size: 1.2rem; margin-bottom: 4px; }
.panel .hint { color: var(--muted); font-size: .9rem; margin-bottom: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.panel-head h2 { margin: 0; }

/* ---- Tables ---- */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.table tr:hover td { background: var(--bg-soft); }
.table .muted { color: var(--muted); }
.table-wrap { overflow-x: auto; }

/* ---- Badges ---- */
.badge2 { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .74rem; font-weight: 700; }
.badge2.nuova { background: #e7f0fe; color: #1f6fd6; }
.badge2.lavorazione { background: #fff3e0; color: #b9740f; }
.badge2.completata { background: #e9f7ef; color: #1d7a46; }
.badge2.user { background: #eef1f6; color: #50607a; }
.badge2.admin { background: #efe7fb; color: #6b34c9; }
.badge2.attivo { background: #e9f7ef; color: #1d7a46; }
.badge2.bloccato { background: #fdecec; color: #b3261e; }
.badge2.tipo { background: #e8f4f2; color: #1c7a6a; }

/* ---- Small buttons / actions ---- */
.btn-sm { padding: 7px 13px; font-size: .82rem; border-radius: 8px; font-weight: 600; cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--ink); }
.btn-sm:hover { background: var(--bg-soft2); }
.btn-sm.danger { color: #b3261e; border-color: #f3c9c9; }
.btn-sm.danger:hover { background: #fdecec; }
.btn-sm.pri { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-sm.pri:hover { background: #1f6fd6; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- Tabs (admin) ---- */
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---- Content editor (admin) ---- */
.editor-grid { display: grid; gap: 16px; }
.editor-grid .field { margin: 0; }

/* ---- Empty state ---- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* ---- Upload box ---- */
.dropzone { border: 2px dashed var(--line); border-radius: 12px; padding: 26px; text-align: center; background: var(--bg-soft); color: var(--muted); }
.dropzone strong { color: var(--navy-900); }

/* ---- Modal ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(10,22,40,.55); display: none; place-items: center; z-index: 100; padding: 20px; }
.modal-bg.show { display: grid; }
.modal { background: #fff; border-radius: 16px; padding: 28px; width: 100%; max-width: 520px; box-shadow: var(--shadow-lg); max-height: 90vh; overflow: auto; }
.modal h3 { margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---- Editor visuale (js/editor.js) ---- */
.fr-editor { border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; overflow: hidden; }
.fr-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,128,237,.12); }

.fr-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
  padding: 6px 8px; background: var(--bg-soft); border-bottom: 1px solid var(--line);
  position: relative;
}
.fr-btn {
  min-width: 30px; height: 30px; padding: 0 7px;
  border: 1px solid transparent; border-radius: 7px; background: transparent;
  color: var(--ink); font-size: .9rem; line-height: 1; cursor: pointer;
}
.fr-btn:hover { background: #fff; border-color: var(--line); }
.fr-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.fr-sep { width: 1px; height: 20px; margin: 0 5px; background: var(--line); }

.fr-palette {
  display: none; position: absolute; top: 100%; left: 8px; z-index: 5;
  gap: 6px; padding: 8px; background: #fff;
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-sm);
}
.fr-palette.show { display: flex; }
.fr-palette button { width: 22px; height: 22px; border: 1px solid var(--line); border-radius: 50%; cursor: pointer; }

.fr-area {
  min-height: 220px; max-height: 46vh; overflow: auto;
  padding: 16px 18px; font-size: .95rem; line-height: 1.65; color: var(--ink); outline: none;
}
.fr-area:empty::before { content: attr(data-placeholder); color: var(--muted); }
.fr-area > :first-child { margin-top: 0; }
.fr-area p { margin: 0 0 10px; }
.fr-area h2 { font-size: 1.25rem; margin: 18px 0 8px; }
.fr-area h3 { font-size: 1.08rem; margin: 16px 0 6px; }
.fr-area h4 { font-size: .98rem; margin: 14px 0 6px; }
.fr-area ul, .fr-area ol { margin: 0 0 10px; padding-left: 22px; }
.fr-area li { margin-bottom: 4px; }
.fr-area a { color: var(--accent); text-decoration: underline; }
.fr-area img { max-width: 100%; height: auto; border-radius: 10px; margin: 8px 0; }
.fr-area blockquote {
  margin: 12px 0; padding: 8px 16px; color: var(--muted);
  border-left: 3px solid var(--accent); background: var(--bg-soft);
}
.fr-area hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.fr-area table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.fr-area th, .fr-area td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; }

/* Vista codice HTML: la textarea originale riappare dentro l'editor */
.fr-editor textarea.fr-source {
  display: block; width: 100%; min-height: 220px; border: 0; border-radius: 0;
  padding: 14px 16px; resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .84rem; line-height: 1.6;
}
.fr-editor textarea.fr-source:focus { outline: none; }
.fr-status { padding: 0 10px 8px; font-size: .82rem; color: var(--muted); }
.fr-status:empty { display: none; }

/* ---- Chat privata cliente ↔ admin ---- */
.dot-badge {
  display: inline-block; min-width: 19px; padding: 1px 6px; margin-left: 6px;
  border-radius: 999px; background: #e5342b; color: #fff;
  font-size: .7rem; font-weight: 800; text-align: center; line-height: 1.5;
}
.dot-badge[hidden] { display: none; }   /* senza questo, display:inline-block vince su [hidden] */
.navlink.active .dot-badge { background: #fff; color: var(--accent); }

.chat-panel { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat-head { padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--bg-soft); font-size: .92rem; }
.chat-head .muted { color: var(--muted); font-weight: 400; }

.chat-thread {
  flex: 1; min-height: 320px; max-height: 52vh; overflow-y: auto;
  padding: 18px; display: flex; flex-direction: column; gap: 12px;
  background: var(--bg-soft);
}
.chat-thread .empty { margin: auto; }

.msg { display: flex; flex-direction: column; max-width: 74%; }
.msg.them { align-self: flex-start; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .bubble {
  padding: 11px 15px; border-radius: 14px; font-size: .92rem; line-height: 1.5;
  box-shadow: var(--shadow-sm); word-break: break-word;
}
.msg.them .bubble { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.mine .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg .meta { font-size: .72rem; color: var(--muted); margin-top: 4px; }

/* chat: graffetta per allegare e riga del file scelto */
.chat-clip {
  display: flex; align-items: center; justify-content: center;
  width: 42px; border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; font-size: 1.15rem; background: #fff; flex: 0 0 auto;
}
.chat-clip:hover { border-color: var(--accent); background: var(--bg-soft); }
.chat-allegato {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 14px; border-top: 1px solid var(--line);
  background: var(--bg-soft); font-size: .84rem;
}
.chat-allegato[hidden] { display: none; }
.chat-allegato .nome { font-weight: 600; word-break: break-all; }
.msg .file {
  display: inline-flex; align-items: center; gap: 7px; margin-top: 6px;
  padding: 7px 11px; border-radius: 9px; font-size: .84rem; font-weight: 600;
  text-decoration: none; background: rgba(255,255,255,.22); color: inherit;
  border: 1px solid rgba(255,255,255,.35); word-break: break-all;
}
.msg.them .file, .msg .bubble + .file {
  background: #fff; color: var(--navy-900); border-color: var(--line);
}
.msg .file:hover { text-decoration: underline; }
.msg .file .peso { font-weight: 400; opacity: .75; }

.chat-form { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--line); background: #fff; }
.chat-form[hidden] { display: none; }   /* [hidden] deve vincere su display:flex */
.chat-form textarea {
  flex: 1; resize: none; padding: 11px 13px; border: 1px solid var(--line);
  border-radius: 10px; font: inherit; font-size: .92rem;
}
.chat-form textarea:focus { outline: none; border-color: var(--accent); }
.chat-form .btn { align-self: stretch; }

/* admin: elenco conversazioni + thread */
.chat-admin { display: grid; grid-template-columns: 280px 1fr; gap: 18px; align-items: start; }
.chat-list {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-sm); overflow: hidden; max-height: 70vh; overflow-y: auto;
}
.chat-item {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left;
  padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line);
  background: #fff; cursor: pointer; font: inherit;
}
.chat-item:hover { background: var(--bg-soft2); }
.chat-item.active { background: var(--bg-soft2); box-shadow: inset 3px 0 0 var(--accent); }
.chat-item.unread .ci-prev, .chat-item.unread .ci-top b { font-weight: 800; color: var(--navy-900); }
.chat-item .ci-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .92rem; }
.chat-item .ci-sub { font-size: .76rem; color: var(--muted); }
.chat-item .ci-prev { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-side { display: flex; flex-wrap: wrap; gap: 6px; border-right: 0; border-bottom: 1px solid var(--line); }
  .app-side a, .app-side button.navlink { width: auto; margin: 0; }
  .app-main { padding: 22px 18px; }
  .kpi { grid-template-columns: 1fr 1fr; }
  .chat-admin { grid-template-columns: 1fr; }
  .chat-list { max-height: 240px; }
  .msg { max-width: 88%; }
}
