/* =============================================================
   OPS! Media Intranet — Design System v2
   Plus Jakarta Sans / DM Sans / DM Serif Display
   ============================================================= */

:root {
  --ink: #1A2742;
  --ink-soft: #2D3F5C;
  --brand: #0E4B8B;
  --brand-light: #EBF2FF;
  --brand-accent: #4A9EFF;
  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --surface2: #F8FAFC;
  --border: #E8ECF2;
  --muted: #6B7A96;
  --text: #1A2742;
  --white: #FFFFFF;
  /* Status */
  --status-unread: #EF4444;
  --status-unread-bg: #FEF2F2;
  --status-read: #16A34A;
  --status-read-bg: #DCFCE7;
  --status-warn: #D97706;
  --status-warn-bg: #FEF3C7;
  /* Category */
  --ed-color: #0E4B8B;
  --ed-bg: #EBF2FF;
  --ed-icon-bg: #0E4B8B;
  --gest-color: #D97706;
  --gest-bg: #FEF3C7;
  --gest-icon-bg: #F59E0B;
  --ist-color: #059669;
  --ist-bg: #DCFCE7;
  --ist-icon-bg: #16A34A;
  /* Shadows */
  --shadow-card: 0 8px 30px -8px rgba(26,39,66,.08), 0 2px 6px -2px rgba(26,39,66,.04);
  --shadow-hover: 0 16px 40px -10px rgba(26,39,66,.14);
  --shadow-sm: 0 1px 2px rgba(26,39,66,.05);
  /* Hero gradient */
  --hero-gradient: linear-gradient(135deg, #1A2742 0%, #1e3060 60%, #0E4B8B 130%);
  /* Legacy compat */
  --blue: #0E4B8B;
  --cyan: #0E4B8B;
  --dark: #1A2742;
  --gray: #F4F6FA;
}

/* ---- RESET ---- */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Plus Jakarta Sans', 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---- TOPBAR ---- */
.topbar {
  background: rgba(255,255,255,0.8);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  height: 72px;
  border-top: 3px solid var(--brand);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 200;
  border-bottom: 1px solid rgba(232,236,242,0.8);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.brand-logo { height: 34px; width: auto; display: block; }
.topbar-brand-badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 999px;
}
.topbar-nav { display: flex; gap: 4px; }
.topbar-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  padding: 7px 16px;
  border-radius: 999px;
  transition: all .2s;
  cursor: pointer;
}
.topbar-nav a:hover { color: var(--ink); background: var(--surface2); }
.topbar-nav a.active { background: var(--ink); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 14px;
  border-right: 1px solid var(--border);
}
.topbar-status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--status-read);
  box-shadow: 0 0 0 3px rgba(22,163,74,0.2);
  animation: pulse-green 2s infinite;
}
@keyframes pulse-green {
  0%,100% { box-shadow: 0 0 0 3px rgba(22,163,74,0.2); }
  50% { box-shadow: 0 0 0 5px rgba(22,163,74,0.08); }
}
.topbar-status-label { font-size: 12px; font-weight: 500; color: var(--muted); }
.topbar-user { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.topbar-user-info { text-align: right; }
.topbar-username { font-size: 13px; font-weight: 600; color: var(--ink); line-height: 1.2; }
.topbar-role { font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.18em; color: var(--brand); }
.topbar-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), #1565c0);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(14,75,139,0.3);
}
.btn-logout {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: inherit;
  transition: color .2s;
}
.btn-logout:hover { color: var(--ink); }

/* ---- LOGIN ---- */
#login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--dark); position: relative; overflow: hidden; }
#login-screen::before { content: ''; position: absolute; inset: 0; background:
  radial-gradient(ellipse at 20% 50%, rgba(0,174,239,0.12) 0%, transparent 60%),
  radial-gradient(ellipse at 80% 20%, rgba(27,79,138,0.25) 0%, transparent 50%),
  radial-gradient(ellipse at 60% 80%, rgba(0,174,239,0.08) 0%, transparent 50%);
  z-index: 0; }
#login-screen::after { content: ''; position: absolute; inset: 0; background-image:
  linear-gradient(rgba(0,174,239,0.04) 1px, transparent 1px),
  linear-gradient(90deg, rgba(0,174,239,0.04) 1px, transparent 1px);
  background-size: 48px 48px; z-index: 0; }
.login-card { position: relative; z-index: 1; background: rgba(255,255,255,.07); backdrop-filter: blur(20px) saturate(140%); border: 1px solid rgba(255,255,255,.12); border-radius: 24px; padding: 44px 48px; text-align: center; width: 100%; max-width: 420px; box-shadow: 0 24px 64px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.05); }
.login-logo { font-family: 'DM Serif Display', serif; font-size: 36px; color: var(--brand-accent); margin-bottom: 4px; }
.login-brand-logo { width: 100%; height: 100%; object-fit: contain; display: block; }
.login-sub { font-size: 14px; color: rgba(255,255,255,0.6); margin-bottom: 0; }
.login-divider { border: none; border-top: 1px solid rgba(255,255,255,.12); margin: 24px 0; }
.login-domain { color: rgba(255,255,255,.4); font-size: 12px; margin-top: 20px; }
.btn-google { display: flex; align-items: center; justify-content: center; gap: 12px; background: #fff; color: #1A2742; border: none; border-radius: 12px; padding: 14px 24px; font-size: 15px; font-weight: 600; cursor: pointer; width: 100%; transition: background .15s, box-shadow .15s, transform .1s; box-shadow: 0 2px 8px rgba(0,0,0,0.15); font-family: 'Plus Jakarta Sans', 'DM Sans', sans-serif; }
.btn-google:hover { background: #f5f5f5; box-shadow: 0 4px 16px rgba(0,0,0,0.2); transform: translateY(-1px); }
.btn-google svg { width: 20px; height: 20px; flex-shrink: 0; }

/* ---- LAYOUT ---- */
#app { display: none; }
.page { display: none; animation: fadeIn .3s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: translateY(0) } }
@keyframes floatA { 0%,100% { transform: translateY(0) scale(1) } 50% { transform: translateY(-30px) scale(1.05) } }
@keyframes floatB { 0%,100% { transform: translateY(0) scale(1) } 50% { transform: translateY(20px) scale(0.95) } }

/* ---- HOME ---- */
.home-main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* HERO CARD */
.home-hero-card {
  background: var(--hero-gradient);
  border-radius: 2rem;
  padding: 32px 40px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.home-hero-card::before {
  content: '';
  position: absolute;
  top: -60px; right: -60px;
  width: 260px; height: 260px;
  border-radius: 50%;
  background: rgba(14,75,139,0.5);
  filter: blur(60px);
}
.home-hero-card::after {
  content: '';
  position: absolute;
  bottom: -80px; left: -50px;
  width: 320px; height: 320px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  filter: blur(60px);
}
.hero-inner { position: relative; z-index: 1; }
.hero-date-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255,255,255,0.9);
  margin-bottom: 16px;
}
.home-greeting {
  font-size: 42px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.5px;
  line-height: 1.15;
  margin-bottom: 10px;
}
.home-greeting .hero-name-accent { color: var(--brand-accent); }
.hero-subtitle { color: rgba(255,255,255,0.65); font-size: 16px; max-width: 520px; }
#home-date { display: none; }

/* STAT CARDS */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.cat-card {
  background: var(--surface);
  border-radius: 24px;
  padding: 24px;
  cursor: pointer;
  transition: transform .25s, box-shadow .25s;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
}
.cat-card::before {
  content: '';
  position: absolute;
  top: -30px; right: -30px;
  width: 120px; height: 120px;
  border-radius: 50%;
  opacity: 0.07;
  filter: blur(20px);
}
.cat-card.ed::before { background: var(--ed-icon-bg); }
.cat-card.gest::before { background: var(--gest-icon-bg); }
.cat-card.ist::before { background: var(--ist-icon-bg); }
.cat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-hover); }
.cat-card-header-row {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}
.cat-card-icon-box {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.cat-card.ed .cat-card-icon-box { background: var(--ed-icon-bg); }
.cat-card.gest .cat-card-icon-box { background: var(--gest-icon-bg); }
.cat-card.ist .cat-card-icon-box { background: var(--ist-icon-bg); }
.cat-card-icon-box svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.cat-card-label {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.cat-card.ed .cat-card-label { color: var(--ed-color); }
.cat-card.gest .cat-card-label { color: var(--gest-color); }
.cat-card.ist .cat-card-label { color: var(--ist-color); }
.cat-card-bottom { display: flex; align-items: flex-end; justify-content: space-between; }
.cat-card-count { display: flex; align-items: baseline; gap: 6px; }
.cat-card-total { font-size: 52px; font-weight: 800; letter-spacing: -1px; color: var(--ink); line-height: 1; }
.cat-card-sub { font-size: 12px; color: var(--muted); font-weight: 500; }
.cat-card-unread {
  font-size: 10px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}
.cat-card-unread:not(.zero) { background: var(--status-unread-bg); color: var(--status-unread); }
.cat-card-unread.zero { background: var(--status-read-bg); color: var(--status-read); }

/* HOME CONTENT ROW */
.home-content-row {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
}

/* COMMUNICATIONS CARD */
.com-card {
  background: var(--surface);
  border-radius: 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.com-card-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.com-card-hdr-left { display: flex; align-items: center; gap: 12px; }
.com-card-hdr-icon {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.com-card-hdr-icon svg { width: 18px; height: 18px; stroke: var(--ink); fill: none; stroke-width: 2; }
.com-card-hdr-title { font-size: 15px; font-weight: 600; color: var(--ink); line-height: 1.2; }
.com-card-hdr-sub { font-size: 12px; color: var(--muted); }

/* COMUNICATI LIST */
.com-list { display: flex; flex-direction: column; gap: 0; }
.com-row {
  background: var(--surface);
  padding: 16px 22px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  cursor: pointer;
  transition: background .15s;
  border-bottom: 1px solid var(--border);
}
.com-row:last-child { border-bottom: none; }
.com-row:hover { background: var(--surface2); }
.com-unread-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--status-unread);
  box-shadow: 0 0 0 4px rgba(239,68,68,0.15);
  flex-shrink: 0;
  margin-top: 6px;
}
.com-read-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 1px solid var(--border);
  flex-shrink: 0;
  margin-top: 6px;
}
.com-body { flex: 1; min-width: 0; }
.com-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 4px;
}
.tag-Editoriale { background: var(--ed-bg); color: var(--ed-color); }
.tag-Gestionale { background: var(--gest-bg); color: var(--gest-color); }
.tag-Istituzionale { background: var(--ist-bg); color: var(--ist-color); }
.com-meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
  flex-wrap: wrap;
}
.com-meta-sep { width: 3px; height: 3px; border-radius: 50%; background: var(--border); }
.com-title { font-size: 14px; font-weight: 500; color: var(--ink); margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.com-title.unread-title { font-weight: 600; }
.com-preview { font-size: 12px; color: var(--muted); line-height: 1.5; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }

/* Date block (categoria page) */
.com-row-date, .com-date-block { flex-shrink: 0; width: 44px; text-align: center; }
.com-day { font-weight: 800; font-size: 22px; color: var(--ink); line-height: 1; }
.com-month { font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 600; }
.com-author { font-size: 11px; color: var(--muted); }
.com-meta { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.com-pdf-badge { display: inline-flex; align-items: center; gap: 4px; background: #FEF2F2; color: #991B1B; font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 4px; }

.com-card-footer {
  padding: 12px 22px;
  border-top: 1px solid var(--border);
  background: rgba(248,250,252,0.5);
}
.com-card-footer a { font-size: 13px; font-weight: 500; color: var(--muted); text-decoration: none; transition: color .2s; cursor: pointer; }
.com-card-footer a:hover { color: var(--ink); }

/* Btn nuovo */
#btn-nuovo {
  display: none;
  align-items: center;
  gap: 6px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .2s;
}
#btn-nuovo:hover { background: var(--ink-soft); }

/* SIDEBAR */
.home-sidebar { display: flex; flex-direction: column; gap: 20px; }
.ql-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 2px;
  margin-bottom: 10px;
}
.ql-links-list { display: flex; flex-direction: column; gap: 8px; }
.ql-link {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  text-decoration: none;
  transition: all .2s;
  box-shadow: var(--shadow-sm);
}
.ql-link:hover { box-shadow: var(--shadow-card); transform: translateY(-1px); }
.ql-link-icon {
  width: 42px; height: 42px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.ql-link-icon img { width: 22px; height: 22px; object-fit: contain; }
.ql-link-name { font-size: 13px; font-weight: 600; color: var(--ink); line-height: 1.2; }
.ql-link-desc { font-size: 11px; color: var(--muted); }
.ql-tools-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ql-tools-grid-2 { grid-template-columns: repeat(3, 1fr); }
.ql-tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 8px 12px;
  text-decoration: none;
  transition: all .2s;
  aspect-ratio: 1;
  text-align: center;
}
.ql-tool:hover { border-color: rgba(14,75,139,0.3); background: var(--brand-light); box-shadow: var(--shadow-card); }
.ql-tool svg { width: 20px; height: 20px; stroke: var(--ink); fill: none; stroke-width: 2; }
.ql-tool-img { width: 28px; height: 28px; object-fit: contain; display: block; flex-shrink: 0; }
.ql-tool-name { font-size: 10px; font-weight: 700; color: var(--ink); line-height: 1.3; }
.ql-promo {
  background: var(--hero-gradient);
  border-radius: 20px;
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.ql-promo::before { content: ''; position: absolute; top: -30px; right: -30px; width: 100px; height: 100px; border-radius: 50%; background: rgba(14,75,139,0.5); filter: blur(30px); }
.ql-promo-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.15em; color: rgba(255,255,255,0.6); margin-bottom: 6px; position: relative; }
.ql-promo-text { font-size: 13px; font-weight: 500; color: rgba(255,255,255,0.85); line-height: 1.5; position: relative; }
.ql-promo-text span { color: var(--brand-accent); font-weight: 700; }

/* Legacy home sidebar */
.tools-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 8px; position: sticky; top: 84px; }
.tools-title { font-size: 11px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.tool-link { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--brand); background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; font-weight: 600; }
.tool-link:hover { background: var(--brand-light); }
.tool-icon { width: 18px; height: 18px; object-fit: contain; flex-shrink: 0; }

/* Section hdr (compat categoria) */
.section-hdr { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-title { font-size: 11px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--brand); display: flex; align-items: center; gap: 8px; }
.section-title::before { content: ''; width: 3px; height: 14px; background: var(--brand); border-radius: 2px; display: block; }

/* ---- CATEGORIA PAGE ---- */
.com-page { max-width: 900px; margin: 0 auto; padding: 28px; }
.com-page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.com-filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filter-input { border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; font-family: inherit; font-size: 13px; color: var(--text); background: #fff; outline: none; transition: border-color .2s; }
.filter-input:focus { border-color: var(--brand); }
.filter-select { border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; font-family: inherit; font-size: 13px; color: var(--text); background: #fff; outline: none; cursor: pointer; transition: border-color .2s; }
.filter-select:focus { border-color: var(--brand); }

/* ---- DETTAGLIO COMUNICATO ---- */
.com-detail { max-width: 760px; margin: 0 auto; padding: 28px; }
.com-detail-back { display: flex; align-items: center; gap: 6px; color: var(--brand); font-size: 13px; font-weight: 500; cursor: pointer; margin-bottom: 20px; background: none; border: none; font-family: inherit; }
.com-detail-back:hover { text-decoration: underline; }
.com-detail-card { background: #fff; border-radius: 20px; border: 1px solid var(--border); box-shadow: var(--shadow-card); overflow: hidden; }
.com-detail-header { background: var(--ink); padding: 28px 32px; }
.com-detail-tag { margin-bottom: 10px; }
.com-detail-title { font-size: 26px; font-weight: 800; color: #fff; line-height: 1.3; margin-bottom: 10px; }
.com-detail-meta { color: rgba(255,255,255,.5); font-size: 12px; }
.com-detail-body { padding: 32px; }
.com-detail-text { font-size: 15px; line-height: 1.8; color: var(--text); white-space: pre-wrap; }
.com-detail-pdf { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--border); }
.btn-pdf { display: inline-flex; align-items: center; gap: 8px; background: #FEF2F2; color: #991B1B; border: 1px solid #FECACA; border-radius: 8px; padding: 10px 16px; font-size: 13px; font-weight: 500; text-decoration: none; transition: all .2s; cursor: pointer; }
.btn-pdf:hover { background: #FEE2E2; }

/* ---- ADMIN / FORM ---- */
.admin-page { max-width: 860px; margin: 0 auto; padding: 28px; }
.admin-card { background: #fff; border-radius: 16px; border: 1px solid var(--border); box-shadow: var(--shadow-sm); padding: 28px 32px; margin-bottom: 20px; }
.admin-card-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field.full { grid-column: 1/-1; }
.form-label { font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); }
.form-input { border: 1px solid var(--border); border-radius: 10px; padding: 9px 13px; font-family: inherit; font-size: 14px; color: var(--text); background: var(--surface2); transition: border-color .2s, background .2s; outline: none; }
.form-input:focus { border-color: var(--brand); background: #fff; }
.form-select { border: 1px solid var(--border); border-radius: 10px; padding: 9px 13px; font-family: inherit; font-size: 14px; color: var(--text); background: var(--surface2); outline: none; cursor: pointer; transition: border-color .2s; }
.form-select:focus { border-color: var(--brand); }
.form-textarea { border: 1px solid var(--border); border-radius: 10px; padding: 9px 13px; font-family: inherit; font-size: 14px; color: var(--text); background: var(--surface2); transition: border-color .2s, background .2s; outline: none; resize: vertical; min-height: 200px; line-height: 1.7; }
.form-textarea:focus { border-color: var(--brand); background: #fff; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ---- AI ASSISTANT ---- */
.ai-box { background: linear-gradient(135deg, #EEF2FF, #F0FDFA); border: 1px solid #C7D2FE; border-radius: 12px; padding: 16px; margin-top: 8px; }
.ai-box-title { font-size: 12px; font-weight: 600; color: #4338CA; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.ai-prompt-row { display: flex; gap: 8px; }
.ai-prompt-input { flex: 1; border: 1px solid #C7D2FE; border-radius: 8px; padding: 8px 12px; font-family: inherit; font-size: 13px; background: #fff; outline: none; }
.ai-prompt-input:focus { border-color: #6366F1; }
.btn-ai { background: #4338CA; color: #fff; border: none; border-radius: 8px; padding: 8px 14px; font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; transition: background .2s; white-space: nowrap; }
.btn-ai:hover { background: #3730A3; }
.btn-ai:disabled { opacity: .5; cursor: not-allowed; }
.ai-hint { font-size: 11px; color: #6366F1; margin-top: 6px; }

/* PDF UPLOAD */
.pdf-drop { border: 2px dashed var(--border); border-radius: 10px; padding: 20px; text-align: center; cursor: pointer; transition: all .2s; }
.pdf-drop:hover, .pdf-drop.dragover { border-color: var(--brand); background: var(--brand-light); }
.pdf-drop-text { font-size: 13px; color: var(--muted); }
.pdf-drop-text strong { color: var(--brand); }
.pdf-preview { display: flex; align-items: center; gap: 10px; background: #FEF2F2; border: 1px solid #FECACA; border-radius: 8px; padding: 10px 14px; margin-top: 8px; }
.pdf-preview-name { flex: 1; font-size: 13px; color: #991B1B; font-weight: 500; }
.pdf-remove { background: none; border: none; color: #991B1B; cursor: pointer; font-size: 18px; line-height: 1; }

/* NOTIFICA EMAIL */
.notifica-box { background: var(--surface2); border-radius: 10px; padding: 16px; margin-top: 8px; }
.notifica-title { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 10px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; cursor: pointer; }
.checkbox-row input { width: 15px; height: 15px; cursor: pointer; accent-color: var(--brand); }
.checkbox-row label { font-size: 13px; color: var(--text); cursor: pointer; }
.recipients-input { width: 100%; border: 1px solid var(--border); border-radius: 7px; padding: 8px 12px; font-size: 12px; font-family: inherit; color: var(--text); background: #fff; outline: none; margin-top: 8px; }
.recipients-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---- BUTTONS ---- */
.btn { border: none; border-radius: 10px; padding: 10px 20px; font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: all .2s; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: #0a3d75; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-success { background: #059669; color: #fff; }
.btn-success:hover { background: #047857; }
.btn-danger { background: #DC2626; color: #fff; }
.btn-danger:hover { background: #B91C1C; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-nuovo-cat { display: none; }

/* ---- ADMIN TABS ---- */
/* Wrapper scrollabile su mobile: l'overflow X è sul parent così
   il margin-bottom:-2px delle tab non viene clippato.
   Safari iOS: max-width:100% + width:max-content/min-width:100%
   evitano che il flex container "sfori" causando scroll di pagina. */
.admin-tabs-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;          /* Firefox */
  margin-bottom: 24px;
  max-width: 100%;                /* Safari: limita il wrapper alla viewport */
}
.admin-tabs-wrap::-webkit-scrollbar { display: none; }  /* Chrome/Safari */
.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 0;
  border-bottom: 2px solid var(--border);
  /* Safari-safe: espande fino al contenuto ma non oltre il wrapper */
  width: -webkit-max-content;
  width: max-content;
  min-width: 100%;
}
.admin-tab { background: none; border: none; padding: 10px 18px; font-family: inherit; font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .2s; white-space: nowrap; flex-shrink: 0; }
.admin-tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ADMIN TABLES */
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th { text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); padding: 10px 12px; border-bottom: 2px solid var(--border); }
.admin-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--surface2); }

/* USERS TABLE */
.users-table { width: 100%; border-collapse: collapse; }
.users-table th { text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); padding: 10px 16px; border-bottom: 2px solid var(--border); }
.users-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
.users-table tr:last-child td { border-bottom: none; }
.users-table tr:hover td { background: var(--surface2); }

/* ROLE BADGES */
.role-badge { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; padding: 3px 8px; border-radius: 4px; }
.role-admin { background: #FEF3C7; color: #92400E; }
.role-editor { background: #DBEAFE; color: #1E40AF; }
.role-reader { background: #F3F4F6; color: #374151; }

/* PERM TAGS */
.perm-tag { display: inline-block; font-size: 10px; font-weight: 600; padding: 2px 6px; border-radius: 3px; margin: 1px; }
.perm-ed { background: var(--ed-bg); color: var(--ed-color); }
.perm-gest { background: var(--gest-bg); color: var(--gest-color); }
.perm-ist { background: var(--ist-bg); color: var(--ist-color); }

/* STATUS BADGES */
.badge-blocked { display: inline-block; background: #FEE2E2; color: #991B1B; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 4px; }
.badge-ok { display: inline-block; background: #D1FAE5; color: #065F46; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 4px; }

/* PAGINATION */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 16px; align-items: center; }
.pagination button { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 5px 12px; font-size: 12px; cursor: pointer; font-family: inherit; }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---- MODAL ---- */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(13,27,46,.7); z-index: 300; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal-box { background: #fff; border-radius: 16px; width: 500px; max-width: 100%; max-height: 90vh; overflow-y: auto; animation: slideUp .25s ease; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
.modal-head { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-head-title { font-size: 16px; font-weight: 500; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 24px; }
.modal-actions { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ---- TOAST ---- */
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--ink); color: #fff; border-left: 3px solid var(--brand-accent); padding: 12px 18px; border-radius: 8px; font-size: 13px; font-weight: 500; z-index: 400; opacity: 0; transform: translateY(8px); transition: all .3s; pointer-events: none; max-width: 320px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-left-color: #EF4444; }
.toast.success { border-left-color: #10B981; }

/* ---- SKELETON ---- */
.skeleton { background: linear-gradient(90deg, #e8eaed 25%, #f5f5f5 50%, #e8eaed 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; }
@keyframes shimmer { to { background-position: -200% 0 } }
.skel-row { height: 14px; margin-bottom: 8px; }

/* ---- EMPTY STATE ---- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state-icon { font-size: 40px; margin-bottom: 12px; opacity: .4; }
.empty-state-text { font-size: 14px; }

/* ---- BOZZA BADGE ---- */
.bozza-badge { background: #FEF3C7; color: #92400E; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 4px; letter-spacing: .5px; text-transform: uppercase; }

/* ---- STATS ---- */
.stats-summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.stat-kpi { background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.stat-kpi-value { font-family: 'DM Serif Display', serif; font-size: 28px; line-height: 1; color: var(--brand); margin-bottom: 4px; }
.stat-kpi-label { font-size: 11px; letter-spacing: .7px; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.stats-chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stats-chart-title { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .7px; text-transform: uppercase; margin-bottom: 8px; }
.stat-bar-row { display: grid; grid-template-columns: 170px 1fr 36px; gap: 8px; align-items: center; margin-bottom: 8px; }
.stat-bar-label { font-size: 12px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-bar-track { background: #E5E7EB; border-radius: 999px; height: 10px; overflow: hidden; }
.stat-bar-fill { background: linear-gradient(90deg, var(--brand), var(--brand-accent)); height: 100%; }
.stat-bar-value { font-size: 12px; color: var(--muted); text-align: right; }
.muted-small { font-size: 12px; color: var(--muted); }

/* ROLE BADGE — writer */
.role-writer { background: #FEF3C7; color: #92400E; }

/* STATS SUB-TABS */
.stats-subtabs-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  max-width: 100%;
  margin-bottom: 16px;
}
.stats-subtabs-wrap::-webkit-scrollbar { display: none; }
.stats-subtabs {
  display: flex;
  gap: 2px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0;
  padding: 0 16px;
  margin-bottom: 0;
  width: -webkit-max-content;
  width: max-content;
  min-width: 100%;
}
.stats-subtab {
  padding: 10px 18px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  transition: color .15s, border-color .15s;
  font-family: inherit;
  white-space: nowrap;
  flex-shrink: 0;
}
.stats-subtab:hover { color: var(--ink); }
.stats-subtab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.stats-cat-checks {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 0;
  font-size: 13px;
}
.stats-cat-checks label { display: flex; align-items: center; gap: 5px; cursor: pointer; }

/* TOOL ADMIN LIST */
.tool-admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.tool-admin-row:last-child { border-bottom: none; }

/* ADMIN TAB ICONS */
.admin-tab svg { vertical-align: -2px; margin-right: 4px; }

/* LOGIN SCREEN — enhanced */
.login-logo-wrap {
  width: 100px;
  height: 100px;
  background: #fff;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  padding: 10px;
}
.login-title {
  font-family: 'DM Serif Display', serif;
  font-size: 26px;
  color: #fff;
  margin-bottom: 4px;
  font-weight: 400;
}

/* Banner staging */
.staging-banner { background: #F59E0B; color: #fff; text-align: center; padding: 6px; font-size: 12px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; position: sticky; top: 0; z-index: 999; }

/* ---- THEME SWITCHER ---- */
.theme-btn { background: none; border: 2px solid transparent; border-radius: 50%; width: 28px; height: 28px; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 3px; transition: border-color .2s; }
.theme-btn:hover { border-color: #CBD5E1; }
.theme-btn.active { border-color: var(--brand); }

/* home-date-badge — usato dal tema C via applyThemeEnhancements */
.home-date-badge { display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.2); border-radius: 999px; padding: 4px 12px; font-size: 12px; font-weight: 500; color: rgba(255,255,255,0.85); margin-bottom: 12px; }

/* ================================================================
   TEMA B — Editorial Blue
   ================================================================ */
[data-theme="b"] {
  --brand: #1D4ED8; --cyan: #1D4ED8; --dark: #1E3A5F;
  --surface2: #F9FAFB; --border: #E5E7EB; --text: #111827; --muted: #6B7280;
}
[data-theme="b"] .topbar { border-bottom: none; border-top: 3px solid #1D4ED8; }
[data-theme="b"] .home-hero-card { background: linear-gradient(135deg, #1E3A5F 0%, #1a336e 60%, #1D4ED8 130%); }
[data-theme="b"] .admin-tab.active { color: #1D4ED8; border-bottom-color: #1D4ED8; }
[data-theme="b"] .pagination button.active { background: #1D4ED8; border-color: #1D4ED8; }
[data-theme="b"] .topbar-nav a.active { background: #1D4ED8; color: #fff; }
[data-theme="b"] .stat-bar-fill { background: linear-gradient(90deg, #1D4ED8, #60A5FA); }
[data-theme="b"] .section-title { color: #1D4ED8; }
[data-theme="b"] .section-title::before { background: #1D4ED8; }
[data-theme="b"] .topbar-role { color: #1D4ED8; }
[data-theme="b"] .com-unread-dot { background: #1D4ED8; }
[data-theme="b"] .toast { border-left-color: #1D4ED8; }
[data-theme="b"] .com-detail-back { color: #1D4ED8; }
[data-theme="b"] .stat-kpi-value { color: #1D4ED8; }

/* ================================================================
   TEMA A — Newsroom Dark
   ================================================================ */
[data-theme="a"] {
  --brand: #F59E0B; --cyan: #FBBF24; --dark: #0F172A;
  --bg: #0F172A; --surface: #1E293B; --surface2: #1E293B;
  --border: #334155; --text: #F1F5F9; --muted: #94A3B8;
  --ink: #F1F5F9; --ink-soft: #CBD5E1;
  --hero-gradient: linear-gradient(135deg, #1E293B 0%, #162032 60%, #0F172A 130%);
}
[data-theme="a"] body { background: #0F172A; color: #F1F5F9; }
[data-theme="a"] .topbar { background: rgba(30,41,59,0.9); border-bottom-color: #334155; }
[data-theme="a"] .topbar-nav a { color: #CBD5E1; }
[data-theme="a"] .topbar-nav a:hover { background: #334155; color: #F1F5F9; }
[data-theme="a"] .topbar-nav a.active { background: #F59E0B; color: #0F172A; }
[data-theme="a"] .topbar-brand-badge { background: #1E293B; border-color: #334155; color: #94A3B8; }
[data-theme="a"] .topbar-username { color: #F1F5F9; }
[data-theme="a"] .topbar-role { color: #FBBF24; }
[data-theme="a"] .topbar-avatar { background: linear-gradient(135deg, #F59E0B, #D97706); color: #0F172A; }
[data-theme="a"] .btn-logout { color: #94A3B8; }
[data-theme="a"] .topbar-status-dot { background: #F59E0B; box-shadow: 0 0 0 3px rgba(245,158,11,0.2); }
[data-theme="a"] .cat-card { background: #1E293B; border-color: #334155; }
[data-theme="a"] .cat-card-total { color: #F1F5F9; }
[data-theme="a"] .cat-card-label { color: #FBBF24 !important; }
[data-theme="a"] .cat-card-sub { color: #94A3B8; }
[data-theme="a"] .com-card { background: #1E293B; border-color: #334155; }
[data-theme="a"] .com-card-hdr { border-bottom-color: #334155; }
[data-theme="a"] .com-card-hdr-icon { background: #0F172A; border-color: #334155; }
[data-theme="a"] .com-card-hdr-icon svg { stroke: #94A3B8; }
[data-theme="a"] .com-card-hdr-title { color: #F1F5F9; }
[data-theme="a"] .com-card-footer { background: rgba(15,23,42,0.5); border-top-color: #334155; }
[data-theme="a"] .com-row { background: #1E293B; border-bottom-color: #334155; }
[data-theme="a"] .com-row:hover { background: #263348; }
[data-theme="a"] .com-title { color: #F1F5F9; }
[data-theme="a"] .com-unread-dot { background: #F59E0B; box-shadow: 0 0 0 4px rgba(245,158,11,0.15); }
[data-theme="a"] .com-read-dot { border-color: #334155; }
[data-theme="a"] .com-day { color: #FBBF24; }
[data-theme="a"] .admin-card { background: #1E293B; border-color: #334155; }
[data-theme="a"] .admin-card-title { border-bottom-color: #334155; color: #F1F5F9; }
[data-theme="a"] .admin-tabs { border-bottom-color: #334155; }
[data-theme="a"] .admin-tab { color: #94A3B8; }
[data-theme="a"] .admin-tab.active { color: #F59E0B; border-bottom-color: #F59E0B; }
[data-theme="a"] .admin-table th { color: #94A3B8; border-bottom-color: #334155; }
[data-theme="a"] .admin-table td { border-bottom-color: #334155; }
[data-theme="a"] .admin-table tr:hover td { background: #263348; }
[data-theme="a"] .users-table th { color: #94A3B8; border-bottom-color: #334155; }
[data-theme="a"] .users-table td { border-bottom-color: #334155; color: #F1F5F9; }
[data-theme="a"] .users-table tr:hover td { background: #263348; }
[data-theme="a"] .form-input { background: #0F172A; border-color: #334155; color: #F1F5F9; }
[data-theme="a"] .form-select { background: #0F172A; border-color: #334155; color: #F1F5F9; }
[data-theme="a"] .form-textarea { background: #0F172A; border-color: #334155; color: #F1F5F9; }
[data-theme="a"] .filter-input { background: #1E293B; border-color: #334155; color: #F1F5F9; }
[data-theme="a"] .filter-select { background: #1E293B; border-color: #334155; color: #F1F5F9; }
[data-theme="a"] .recipients-input { background: #0F172A; border-color: #334155; color: #F1F5F9; }
[data-theme="a"] .form-input:focus,[data-theme="a"] .form-select:focus,[data-theme="a"] .form-textarea:focus,[data-theme="a"] .filter-input:focus,[data-theme="a"] .recipients-input:focus { border-color: #F59E0B; }
[data-theme="a"] .btn-primary { background: #F59E0B; color: #0F172A; }
[data-theme="a"] .btn-primary:hover { background: #D97706; }
[data-theme="a"] .btn-secondary { background: #334155; color: #CBD5E1; border-color: #475569; }
[data-theme="a"] .pagination button { background: #334155; border-color: #475569; color: #CBD5E1; }
[data-theme="a"] .pagination button.active { background: #F59E0B; color: #0F172A; border-color: #F59E0B; }
[data-theme="a"] .modal-box { background: #1E293B; }
[data-theme="a"] .modal-head { background: #1E293B; border-bottom-color: #334155; }
[data-theme="a"] .modal-actions { border-top-color: #334155; }
[data-theme="a"] .modal-head-title { color: #F1F5F9; }
[data-theme="a"] .modal-body { color: #F1F5F9; }
[data-theme="a"] .com-detail-card { background: #1E293B; border-color: #334155; }
[data-theme="a"] .com-detail-header { background: #162032; }
[data-theme="a"] .com-detail-body { background: #1E293B; }
[data-theme="a"] .com-detail-text { color: #F1F5F9; }
[data-theme="a"] .com-detail-pdf { border-top-color: #334155; }
[data-theme="a"] .section-title { color: #F59E0B; }
[data-theme="a"] .section-title::before { background: #F59E0B; }
[data-theme="a"] .tools-panel { background: #1E293B; border-color: #334155; }
[data-theme="a"] .tool-link { background: #0F172A; border-color: #334155; color: #FBBF24; }
[data-theme="a"] .tool-link:hover { background: #263348; }
[data-theme="a"] .toast { background: #1E293B; border-left-color: #F59E0B; }
[data-theme="a"] .skeleton { background: linear-gradient(90deg, #334155 25%, #3D4F68 50%, #334155 75%); background-size: 200% 100%; }
[data-theme="a"] .stat-kpi { background: #1E293B; border-color: #334155; }
[data-theme="a"] .stat-kpi-value { color: #F59E0B; }
[data-theme="a"] .stat-bar-fill { background: linear-gradient(90deg, #F59E0B, #FBBF24); }
[data-theme="a"] .notifica-box { background: #0F172A; }
[data-theme="a"] .ai-box { background: linear-gradient(135deg, #1E293B, #162032); border-color: #334155; }
[data-theme="a"] .ai-box-title { color: #FBBF24; }
[data-theme="a"] .ai-prompt-input { background: #0F172A; border-color: #334155; color: #F1F5F9; }
[data-theme="a"] .btn-ai { background: #F59E0B; color: #0F172A; }
[data-theme="a"] .btn-ai:hover { background: #D97706; }
[data-theme="a"] .bozza-badge { background: #422006; color: #FCD34D; }
[data-theme="a"] .role-admin { background: #422006; color: #FCD34D; }
[data-theme="a"] .role-editor { background: #1E3A5F; color: #93C5FD; }
[data-theme="a"] .role-reader { background: #1E293B; color: #94A3B8; }
[data-theme="a"] .staging-banner { background: #F59E0B; }
[data-theme="a"] .theme-btn.active { border-color: #F59E0B; }
[data-theme="a"] .com-page .com-list { background: transparent; }
[data-theme="a"] .ql-link { background: #1E293B; border-color: #334155; }
[data-theme="a"] .ql-tool { background: #1E293B; border-color: #334155; }
[data-theme="a"] .ql-tool svg { stroke: #94A3B8; }
[data-theme="a"] .ql-tool-name { color: #94A3B8; }
[data-theme="a"] .ql-link-name { color: #F1F5F9; }
[data-theme="a"] .ql-section-title { color: #475569; }
[data-theme="a"] .com-card-hdr-sub { color: #475569; }
[data-theme="a"] .home-sidebar .ql-link:hover { background: #263348; }

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 1100px) {
  .home-content-row { grid-template-columns: 1fr; }
  .home-sidebar { flex-direction: row; flex-wrap: wrap; }
  .home-sidebar > div, .home-sidebar > .ql-promo { flex: 1 1 260px; min-width: 220px; }
}
@media (max-width: 900px) {
  .topbar { height: auto; padding: 14px 16px; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
  .topbar-nav { width: 100%; overflow-x: auto; padding-bottom: 2px; justify-content: center; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .topbar-status { display: none; }
  .brand-logo { height: 30px; }
  .home-main { padding: 16px; gap: 16px; }
  .home-hero-card { padding: 32px 28px; border-radius: 1.5rem; }
  .home-greeting { font-size: 30px; }
  .cards-grid { grid-template-columns: 1fr; gap: 12px; }
  .cat-card-total { font-size: 40px; }
  .home-content-row { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .stats-summary-grid { grid-template-columns: 1fr; }
  .stats-chart-grid { grid-template-columns: 1fr; }
  .stat-bar-row { grid-template-columns: 120px 1fr 32px; }
  .users-table { display: block; overflow-x: auto; white-space: nowrap; }
  .com-page, .com-detail, .admin-page { padding: 18px 16px; }
  .admin-card { padding: 20px 18px; }
  .com-detail-header, .com-detail-body { padding: 22px 18px; }
  .ai-prompt-row { flex-direction: column; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { justify-content: center; width: 100%; }
}
@media (max-width: 640px) {
  .brand-logo { height: 26px; }
  .topbar-username { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .com-row { padding: 14px 12px; gap: 12px; }
  .com-row { padding: 14px 12px; }
  .com-title { white-space: normal; }
  .com-page-header, .section-hdr { align-items: flex-start; }
  .filter-input { width: 100% !important; }
  .com-filters { flex-direction: column; align-items: stretch; }
  .home-hero-card { padding: 24px 20px; }
  .home-greeting { font-size: 24px; }
  .hero-subtitle { font-size: 14px; }
  /* Admin tab: font e padding ridotti su smartphone */
  .admin-tab { padding: 8px 10px; font-size: 11px; }
  .admin-tab svg { width: 13px; height: 13px; margin-right: 3px; }
}

/* ── Stato Sistema ─────────────────────────────────────────── */
.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.admin-section-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.sistema-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.sistema-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  position: relative;
}
.sistema-card-icon { font-size: 22px; margin-top: 2px; }
.sistema-card-body { flex: 1; min-width: 0; }
.sistema-card-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.sistema-card-value { font-size: 20px; font-weight: 700; color: var(--text); line-height: 1.2; }
.sistema-card-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.sistema-bar-wrap { height: 4px; background: rgba(0,0,0,.08); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.sistema-bar { height: 100%; border-radius: 2px; background: var(--brand); transition: width .4s; }
.sistema-status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: rgba(0,0,0,.15);
  flex-shrink: 0; margin-top: 4px;
}
.sistema-status-dot.sistema-ok  { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,.5); }
.sistema-status-dot.sistema-warn { background: #f59e0b; box-shadow: 0 0 6px rgba(245,158,11,.5); }
.sistema-status-dot.sistema-err  { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,.5); }
/* PM2 process rows */
.sistema-pm2-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.sistema-pm2-name { font-weight: 600; font-size: 13px; flex: 1; }
.sistema-pm2-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  font-weight: 600; text-transform: uppercase; letter-spacing: .3px;
}
.sistema-pm2-badge.online  { background: rgba(34,197,94,.13); color: #16a34a; border: 1px solid rgba(34,197,94,.3); }
.sistema-pm2-badge.stopped { background: rgba(239,68,68,.13); color: #dc2626; border: 1px solid rgba(239,68,68,.3); }
.sistema-pm2-badge.errored { background: rgba(239,68,68,.13); color: #dc2626; border: 1px solid rgba(239,68,68,.3); }
.sistema-pm2-meta { font-size: 12px; color: var(--muted); display: flex; gap: 16px; }
@media (max-width: 700px) {
  .sistema-grid-3 { grid-template-columns: 1fr; }
  .sistema-pm2-meta { flex-wrap: wrap; gap: 8px; }
}
/* Dark theme (tema A) overrides */
[data-theme="a"] .sistema-card { background: #1E293B; border-color: #334155; }
[data-theme="a"] .sistema-card-value { color: #F1F5F9; }
[data-theme="a"] .sistema-bar-wrap { background: rgba(255,255,255,.1); }
[data-theme="a"] .sistema-pm2-row { background: #1E293B; border-color: #334155; }
[data-theme="a"] .sistema-pm2-name { color: #F1F5F9; }
[data-theme="a"] .sistema-status-dot { background: rgba(255,255,255,.2); }

/* ── OpsY Chat Widget ──────────────────────────────────────── */

/* Launcher button */
#opsy-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  padding: 0;
  background: #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,.30);
  transition: transform .2s, box-shadow .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#opsy-launcher:hover { transform: scale(1.07); box-shadow: 0 6px 28px rgba(0,0,0,.38); }
#opsy-launcher img { width: 100%; height: 100%; object-fit: contain; display: block; }
#opsy-launcher.no-img { background: var(--brand); }
.opsy-launcher-emoji { font-size: 32px; line-height: 1; }

/* Chat panel */
#opsy-widget {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 9998;
  width: 380px;
  max-height: 580px;
  background: var(--surface, #fff);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,.22), 0 2px 8px rgba(0,0,0,.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity .22s ease, transform .22s ease;
}
#opsy-widget.opsy-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px) scale(.97);
}

/* Header */
#opsy-header {
  background: var(--brand);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#opsy-header img {
  width: 40px; height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}
#opsy-header-avatar-emoji {
  flex-shrink: 0;
}
.opsy-header-title { font-weight: 700; font-size: 15px; color: #fff; line-height: 1.2; }
.opsy-header-sub { font-size: 11px; color: rgba(255,255,255,.75); margin-top: 1px; }
#opsy-close {
  margin-left: auto;
  background: none;
  border: none;
  color: rgba(255,255,255,.8);
  font-size: 18px;
  cursor: pointer;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
#opsy-close:hover { color: #fff; background: rgba(255,255,255,.15); }

/* Messages area */
#opsy-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
#opsy-messages::-webkit-scrollbar { width: 4px; }
#opsy-messages::-webkit-scrollbar-track { background: transparent; }
#opsy-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Bubbles */
.opsy-bubble {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 100%;
}
.opsy-bubble.user { flex-direction: row-reverse; }
.opsy-bubble-avatar {
  width: 30px; height: 30px;
  object-fit: contain;
  flex-shrink: 0;
}
.opsy-bubble-emoji {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.opsy-bubble-text {
  background: var(--surface2, #F8FAFC);
  border: 1px solid var(--border);
  border-radius: 12px 12px 12px 2px;
  padding: 9px 13px;
  font-size: 13px;
  line-height: 1.55;
  max-width: 85%;
  color: var(--text);
  word-break: break-word;
}
.opsy-bubble.user .opsy-bubble-text {
  background: var(--brand);
  color: #fff;
  border-color: transparent;
  border-radius: 12px 12px 2px 12px;
}

/* Input area */
#opsy-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  background: var(--surface, #fff);
}
.opsy-input {
  width: 100%;
  box-sizing: border-box;
}
.opsy-btn-full {
  width: 100%;
}
.opsy-step-buttons {
  display: flex;
  gap: 8px;
}
.opsy-half-btn {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  padding: 8px 10px;
}
.opsy-step { display: flex; flex-direction: column; gap: 0; }

/* Loading dots animation */
.opsy-dots { display: inline-flex; gap: 3px; margin-left: 4px; vertical-align: middle; }
.opsy-dots span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: opsyDot 1.2s infinite ease-in-out;
  display: inline-block;
}
.opsy-bubble.user .opsy-dots span { background: rgba(255,255,255,.7); }
.opsy-dots span:nth-child(2) { animation-delay: .2s; }
.opsy-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes opsyDot {
  0%, 80%, 100% { transform: scale(.75); opacity: .5; }
  40%            { transform: scale(1.1); opacity: 1; }
}

/* Shake animation for validation */
@keyframes opsyShake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}

/* Ticket status badges */
.opsy-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .2px;
}
.opsy-badge.resolved        { background: #e8f5e9; color: #2e7d32; }
.opsy-badge.ticket_sent     { background: #e3f2fd; color: #1565c0; }
.opsy-badge.closed_no_ticket { background: #f5f5f5; color: #666; }
.opsy-badge.in_progress     { background: #fff8e1; color: #e65100; }

/* Admin section label */
.admin-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin-bottom: 12px;
  margin-top: 4px;
}

/* Responsive */
@media (max-width: 480px) {
  #opsy-widget {
    width: calc(100vw - 16px);
    right: 8px;
    bottom: 88px;
    max-height: 70vh;
  }
  #opsy-launcher {
    bottom: 16px;
    right: 16px;
  }
  /* Previene lo zoom automatico di iOS su focus degli input */
  #opsy-widget .form-input {
    font-size: 16px;
  }
}

/* Dark theme (tema A) support for OpsY */
[data-theme="a"] #opsy-widget { background: #1E293B; }
[data-theme="a"] #opsy-messages { background: #1E293B; }
[data-theme="a"] .opsy-bubble-text { background: #263347; border-color: #334155; color: #E2E8F0; }
[data-theme="a"] #opsy-input-area { background: #1E293B; border-color: #334155; }
[data-theme="a"] .opsy-badge.closed_no_ticket { background: #334155; color: #94A3B8; }

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  #opsy-widget, #opsy-launcher { transition: none; }
  .opsy-dots span { animation: none; opacity: 1; transform: none; }
  @keyframes opsyDot { }
}
