/* ============================================================
   Sistema di ticketing — foglio di stile
   Impostazione editoriale: serif per i titoli, carta chiara,
   inchiostro quasi nero, un solo accento (rosso ticket).
   ============================================================ */

@font-face {
  font-family: "Source Serif";
  src: local("Source Serif 4"), local("Source Serif Pro");
}

:root {
  --paper:      #FBF9F4;
  --paper-dim:  #F1EDE3;
  --ink:        #221E1A;
  --ink-soft:   #5B5449;
  --rule:       #DDD5C4;
  --accent:     #B3341D;   /* rosso mattone: usato per priorità/azioni, con parsimonia */
  --accent-ink: #FBF9F4;
  --ok:         #3E6B4F;
  --warn:       #9C6A16;
  --danger:     #B3341D;
  --font-display: Georgia, "Iowan Old Style", "Source Serif", "Times New Roman", serif;
  --font-body:    Georgia, "Iowan Old Style", "Source Serif", "Times New Roman", serif;
  --font-mono:    ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 3px;
  --shadow: 0 1px 2px rgba(34,30,26,.06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.15; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
code, .mono { font-family: var(--font-mono); font-size: .85em; }

.masthead {
  border-bottom: 2px solid var(--ink);
  background: var(--paper);
}
.masthead-inner {
  max-width: 76rem; margin: 0 auto; padding: 1rem 1.5rem;
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.masthead .brand { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.masthead .brand em { font-style: italic; color: var(--accent); }
.masthead nav { display: flex; gap: 1.25rem; align-items: baseline; font-size: .92rem; }
.masthead nav a { color: var(--ink-soft); text-decoration: none; padding-bottom: 2px; }
.masthead nav a.current, .masthead nav a:hover { color: var(--ink); border-bottom: 2px solid var(--accent); }
.masthead .who { font-size: .85rem; color: var(--ink-soft); }

.wrap { max-width: 76rem; margin: 0 auto; padding: 2rem 1.5rem 4rem; }
.wrap.narrow { max-width: 40rem; }

.lede { font-size: 1.05rem; color: var(--ink-soft); max-width: 46rem; margin-bottom: 1.75rem; }

.flash { padding: .75rem 1rem; border-left: 3px solid var(--ink); background: var(--paper-dim); margin-bottom: 1.25rem; font-size: .95rem; }
.flash.ok { border-color: var(--ok); }
.flash.error { border-color: var(--danger); }

/* -------- bottoni e form -------- */
.btn {
  display: inline-flex; align-items: center; gap: .4em;
  font-family: var(--font-body); font-size: .92rem; font-weight: 600;
  padding: .5em 1em; border: 1px solid var(--ink); border-radius: var(--radius);
  background: var(--paper); color: var(--ink); cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #8f2916; border-color: #8f2916; }
.btn.ghost { border-color: transparent; }
.btn.ghost:hover { background: var(--paper-dim); color: var(--ink); }
.btn.small { padding: .3em .7em; font-size: .82rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3em; color: var(--ink-soft); }
input, select, textarea {
  width: 100%; font: inherit; font-size: .95rem; padding: .55em .7em;
  border: 1px solid var(--rule); border-radius: var(--radius); background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
textarea { resize: vertical; font-family: var(--font-body); }
.field { margin-bottom: 1.1rem; }
.field-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.field-row > .field { flex: 1 1 12rem; }
.hint { font-size: .8rem; color: var(--ink-soft); margin-top: .3em; }
fieldset { border: 1px solid var(--rule); border-radius: var(--radius); padding: 1rem 1.2rem; margin: 0 0 1.1rem; }
legend { font-family: var(--font-display); font-weight: 600; padding: 0 .4em; }

/* -------- tabelle e liste ticket -------- */
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: .6em .7em; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-family: var(--font-display); font-weight: 600; color: var(--ink-soft); font-size: .82rem; }
tr:hover td { background: var(--paper-dim); }

.pill { display: inline-block; padding: .15em .6em; border-radius: 999px; font-size: .78rem; font-weight: 600; border: 1px solid currentColor; }
.pill.status-new     { color: var(--accent); }
.pill.status-open    { color: #8B5A00; }
.pill.status-pending { color: var(--ink-soft); }
.pill.status-on_hold { color: var(--ink-soft); }
.pill.status-resolved{ color: var(--ok); }
.pill.status-closed  { color: var(--ink-soft); background: var(--paper-dim); }

.prio { font-weight: 700; }
.prio-4 { color: var(--accent); }
.prio-3 { color: #8B5A00; }
.prio-2 { color: var(--ink); }
.prio-1 { color: var(--ink-soft); }

.due { font-size: .8rem; }
.due-ok, .due-met { color: var(--ok); }
.due-soon { color: var(--warn); }
.due-late, .due-missed { color: var(--danger); font-weight: 700; }

/* -------- dashboard: numeri protagonisti -------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); margin-bottom: 2rem; }
.stat { background: var(--paper); padding: 1.1rem 1.2rem; }
.stat .n { font-family: var(--font-display); font-size: 2.1rem; font-weight: 700; line-height: 1; }
.stat .l { font-size: .8rem; color: var(--ink-soft); margin-top: .3em; }
.stat.accent .n { color: var(--accent); }

.section-title { display: flex; align-items: baseline; justify-content: space-between; border-bottom: 1px solid var(--ink); padding-bottom: .4rem; margin: 2rem 0 1rem; }
.section-title h2 { margin: 0; }
.section-title .meta { font-size: .82rem; color: var(--ink-soft); }

/* -------- pagina ticket -------- */
.ticket-head { display: flex; justify-content: space-between; gap: 2rem; flex-wrap: wrap; margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--rule); }
.ticket-head h1 { max-width: 40rem; }
.ticket-meta dl { display: grid; grid-template-columns: auto auto; gap: .2em 1em; font-size: .87rem; margin: 0; }
.ticket-meta dt { color: var(--ink-soft); }
.ticket-meta dd { margin: 0; font-weight: 600; }

.thread { display: flex; flex-direction: column; gap: 1.1rem; margin-bottom: 1.5rem; }
.msg { border: 1px solid var(--rule); border-radius: var(--radius); padding: 1rem 1.2rem; background: #fff; }
.msg.customer { border-left: 3px solid var(--ink-soft); }
.msg.operator { border-left: 3px solid var(--accent); background: #FFFBF7; }
.msg.note { border-left: 3px solid var(--warn); background: #FFFCF2; }
.msg.system { border-left: 3px dashed var(--rule); color: var(--ink-soft); font-size: .88rem; }
.msg-head { display: flex; justify-content: space-between; font-size: .82rem; color: var(--ink-soft); margin-bottom: .5em; }
.msg-head b { color: var(--ink); }
.msg-body { white-space: normal; }
.msg-atts { margin-top: .7em; display: flex; flex-wrap: wrap; gap: .5em; }
.att { display: inline-flex; align-items: center; gap: .4em; font-size: .82rem; border: 1px solid var(--rule); border-radius: var(--radius); padding: .25em .6em; text-decoration: none; color: var(--ink); }
.att:hover { border-color: var(--ink); }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 2rem; align-items: start; }
.side-card { border: 1px solid var(--rule); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1.2rem; background: #fff; }
.side-card h3 { margin-bottom: .7em; }
.side-card .btn { width: 100%; justify-content: center; margin-top: .4em; }

.tabs { display: flex; gap: 1.5rem; border-bottom: 1px solid var(--rule); margin-bottom: 1.5rem; font-size: .92rem; }
.tabs a { text-decoration: none; color: var(--ink-soft); padding-bottom: .6rem; border-bottom: 2px solid transparent; }
.tabs a.current, .tabs a:hover { color: var(--ink); border-color: var(--accent); }

.empty { padding: 3rem 1rem; text-align: center; color: var(--ink-soft); border: 1px dashed var(--rule); border-radius: var(--radius); }
.empty h3 { color: var(--ink); }

.login-card { max-width: 24rem; margin: 4rem auto; border: 1px solid var(--rule); border-radius: var(--radius); padding: 2rem; background: #fff; }
.login-card h1 { text-align: center; }
.login-card .lede { text-align: center; margin: 0 auto 1.5rem; }
.digits-hint { text-align: center; font-family: var(--font-mono); letter-spacing: .3em; font-size: 1.1rem; color: var(--ink-soft); }

.badge-num { display: inline-flex; align-items: center; justify-content: center; min-width: 1.4em; height: 1.4em; border-radius: 999px; background: var(--accent); color: #fff; font-size: .72rem; font-weight: 700; padding: 0 .3em; }

.footer-note { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); font-size: .82rem; color: var(--ink-soft); }

@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .masthead-inner { flex-direction: column; align-items: flex-start; }
  .ticket-head { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
