:root {
  color-scheme: light;
  --color-canvas: #f7f7f8;
  --color-ink: #0b0d12;
  --color-muted: #5b6471;
  --color-line: #e5e7eb;
  --color-card: #ffffff;
  --color-brand-50: #eef2ff;
  --color-brand-500: #4f5fd8;
  --color-brand-600: #3d4ac0;
  --color-brand-700: #2f3a99;
  --header-h: 64px;
}

html,
body {
  background-color: var(--color-canvas);
  color: var(--color-ink);
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body {
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Hide default disclosure marker so we can use a custom chevron */
summary::-webkit-details-marker { display: none; }
summary { list-style: none; }

* {
  -webkit-tap-highlight-color: rgba(79, 95, 216, 0.18);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

input,
select,
textarea {
  background-color: #ffffff;
  color: var(--color-ink);
  color-scheme: light;
  /* Prevent iOS zoom on focus by ensuring base font-size ≥ 16px on small screens */
  font-size: 16px;
}
@media (min-width: 640px) {
  input,
  select,
  textarea {
    font-size: 0.875rem;
  }
}

input::placeholder,
textarea::placeholder { color: #9aa3b1; }

input:focus,
select:focus,
textarea:focus {
  background-color: #ffffff;
  color: var(--color-ink);
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(79, 95, 216, 0.35);
  outline-offset: 1px;
  border-color: var(--color-brand-500);
}

select option {
  background-color: #ffffff;
  color: var(--color-ink);
}

a:focus-visible {
  outline: 3px solid rgba(79, 95, 216, 0.35);
  outline-offset: 2px;
  border-radius: 4px;
}

[x-cloak] { display: none !important; }

.lp-shell { min-height: 100vh; }

/* ===== Mobile-first utilities ===== */

/* 44px minimum touch target on mobile (WCAG / Apple HIG). */
@media (max-width: 767px) {
  .lp-btn,
  button:not(.lp-btn-sm):not([class*="text-"]),
  .tap-target {
    min-height: 44px;
  }
  /* Slightly bigger tap area for inline link buttons in tables */
  td a,
  td button {
    padding-block: 0.35rem;
  }
}

/* Horizontal scroll wrapper for tables on mobile (with shadow hint). */
.lp-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 14px;
}
.lp-table-wrap > table {
  min-width: 640px;
}

/* Mobile bottom action bar (sticky CTA when long forms). */
.lp-mobile-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: 1rem -1rem -1rem -1rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--color-line);
}
@media (min-width: 768px) {
  .lp-mobile-actions {
    position: static;
    margin: 0;
    padding: 0;
    background: transparent;
    border-top: 0;
    backdrop-filter: none;
  }
}

/* Hide-on-mobile / show-on-mobile shortcuts */
.mobile-only { display: block; }
.desktop-only { display: none; }
@media (min-width: 768px) {
  .mobile-only { display: none; }
  .desktop-only { display: block; }
}

/* Global loading overlay (shown on slow form submissions) */
.lp-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1.25rem;
  background: rgba(247, 247, 248, 0.78);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  padding: 2rem;
  text-align: center;
}
.lp-overlay.is-visible { display: flex; }
.lp-spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid var(--color-line);
  border-top-color: var(--color-brand-600);
  border-right-color: var(--color-brand-600);
  animation: lp-spin 0.85s linear infinite;
}
.lp-overlay-text {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-ink);
  max-width: 22rem;
}
.lp-overlay-sub {
  font-size: 0.75rem;
  color: var(--color-muted);
  max-width: 28rem;
}
@keyframes lp-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Inline spinner for buttons / status pills */
.lp-spin-inline {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: lp-spin 0.7s linear infinite;
  vertical-align: -2px;
}

/* Disabled / loading state on buttons inside loader-bound forms */
form[data-loader].is-busy button[type="submit"],
form[data-loader].is-busy button:not([type]) {
  opacity: 0.7;
  pointer-events: none;
  cursor: progress;
}

/* Card */
.lp-card {
  background: var(--color-card);
  border: 1px solid var(--color-line);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.04);
}

/* Buttons — forte contrasto, padding generoso, focus ring */
.lp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  border-radius: 10px;
  border: 1.5px solid transparent;
  background: transparent;
  color: var(--color-ink);
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease,
    box-shadow 140ms ease, transform 80ms ease;
  white-space: nowrap;
}
.lp-btn:hover { transform: translateY(-1px); }
.lp-btn:active { transform: translateY(0); }
.lp-btn:focus-visible {
  outline: 3px solid rgba(79, 95, 216, 0.35);
  outline-offset: 2px;
}
.lp-btn:disabled,
.lp-btn[aria-disabled="true"] {
  opacity: 0.55;
  pointer-events: none;
  transform: none;
}

.lp-btn-primary {
  background: linear-gradient(180deg, var(--color-brand-500), var(--color-brand-600));
  color: #ffffff;
  border-color: var(--color-brand-700);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.15) inset,
    0 6px 16px rgba(61, 74, 192, 0.28);
}
.lp-btn-primary:hover {
  background: linear-gradient(180deg, var(--color-brand-600), var(--color-brand-700));
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.15) inset,
    0 8px 20px rgba(61, 74, 192, 0.4);
}

.lp-btn-ghost {
  background: #ffffff;
  border-color: #cbd2dc;
  color: var(--color-ink);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
.lp-btn-ghost:hover {
  background: var(--color-canvas);
  border-color: var(--color-brand-400, #94a4fb);
  color: var(--color-brand-700);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
}

.lp-btn-danger {
  background: #ffffff;
  border-color: #fecaca;
  color: #b91c1c;
  box-shadow: 0 1px 2px rgba(185, 28, 28, 0.08);
}
.lp-btn-danger:hover {
  background: #fef2f2;
  border-color: #f87171;
  color: #991b1b;
}

.lp-btn-success {
  background: linear-gradient(180deg, #10b981, #059669);
  color: #ffffff;
  border-color: #047857;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.15) inset,
    0 6px 16px rgba(5, 150, 105, 0.28);
}
.lp-btn-success:hover {
  background: linear-gradient(180deg, #059669, #047857);
}

.lp-btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  border-radius: 8px;
}
.lp-btn-lg {
  padding: 0.75rem 1.4rem;
  font-size: 0.95rem;
  border-radius: 12px;
}

/* Default styling per submit buttons che NON usano .lp-btn esplicito.
   Garantisce minima visibilità anche dove gli sviluppatori hanno usato
   solo classi Tailwind o nessuna classe. */
button[type="submit"]:not([class*="lp-btn"]):not([class*="bg-"]):not([class*="rounded"]),
input[type="submit"]:not([class*="lp-btn"]):not([class*="bg-"]) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 10px;
  background: var(--color-brand-600);
  color: #ffffff;
  border: 1px solid var(--color-brand-700);
  box-shadow: 0 4px 10px rgba(61, 74, 192, 0.25);
  cursor: pointer;
  transition: background 120ms ease;
}
button[type="submit"]:not([class*="lp-btn"]):not([class*="bg-"]):not([class*="rounded"]):hover {
  background: var(--color-brand-700);
}

/* Bottoni con classi Tailwind bg-* / rounded-* esistenti — dai un minimo di
   "tono pulsante" (font-weight + ombra) anche se non hanno .lp-btn. */
button[class*="bg-indigo-"],
button[class*="bg-violet-"],
button[class*="bg-emerald-"],
button[class*="bg-rose-"],
button[class*="bg-amber-"],
button[class*="bg-brand"] {
  font-weight: 600;
  letter-spacing: 0.005em;
}

/* Bottoni "ghost" Tailwind (border-slate-200 + hover) hanno spesso testo
   muted poco visibile: alziamo il contrasto del testo. */
button[class*="border-slate-"][class*="hover:bg-slate-50"],
button[class*="border-line"][class*="hover:bg-canvas"] {
  color: var(--color-ink);
  font-weight: 500;
}

/* Empty state container */
.lp-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem;
  border: 1.5px dashed var(--color-line);
  border-radius: 14px;
  background: #ffffff;
  text-align: center;
  color: var(--color-muted);
}
.lp-empty .lp-empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: var(--color-brand-50);
  color: var(--color-brand-600);
  margin-bottom: 0.75rem;
}
.lp-empty h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-ink);
  margin: 0 0 0.25rem 0;
}
.lp-empty p {
  font-size: 0.85rem;
  max-width: 28rem;
  margin: 0;
}

/* Skeleton loader */
.lp-skeleton {
  background: linear-gradient(90deg, #eef0f3 25%, #f7f7f8 50%, #eef0f3 75%);
  background-size: 200% 100%;
  border-radius: 8px;
  animation: lp-shimmer 1.4s linear infinite;
}
@keyframes lp-shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Flash toast — esistente, polished con icona */
.lp-toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  left: 1.25rem;
  z-index: 60;
  max-width: 28rem;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
}
@media (min-width: 640px) {
  .lp-toast { left: auto; }
}
.lp-toast-success { background: #059669; color: #ffffff; }
.lp-toast-error { background: #dc2626; color: #ffffff; }
.lp-toast-warn { background: #d97706; color: #ffffff; }
.lp-toast-info { background: var(--color-ink); color: #ffffff; }
.lp-toast-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.18);
}
.lp-toast-icon svg { width: 0.95rem; height: 0.95rem; }
.lp-toast-body { flex: 1 1 auto; line-height: 1.35; }
.lp-toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  flex-shrink: 0;
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.85);
  transition: background 0.15s ease, color 0.15s ease;
}
.lp-toast-close:hover { background: rgba(255, 255, 255, 0.16); color: #ffffff; }
.lp-toast-close:focus-visible { outline: 2px solid rgba(255, 255, 255, 0.7); outline-offset: 1px; }

/* Pretty pre-formatted text used for AI output */
.lp-text-pretty {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--color-ink);
}

.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }

textarea.lp-copy {
  min-height: 6rem;
  white-space: pre-wrap;
}

.tab-link.active {
  color: var(--color-brand-600);
  border-color: var(--color-brand-600);
  font-weight: 600;
}

/* Platform brand colors (subtle, pill style) */
.platform-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.platform-linkedin { background: #e8f1ff; color: #0a66c2; }
.platform-instagram { background: #fdf0fa; color: #c2299a; }
.platform-facebook { background: #eaf2ff; color: #1877f2; }
.platform-twitter, .platform-x { background: #eef0f3; color: #0f1419; }
.platform-tiktok { background: #f1f2f4; color: #111111; }
.platform-youtube { background: #fdecec; color: #ed1d24; }
.platform-google { background: #eaf3ff; color: #1a73e8; }
.platform-other { background: #eef2ff; color: #4f5fd8; }

/* Status pills */
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.status-draft { background: #f1f5f9; color: #475569; }
.status-pending_review { background: #fef3c7; color: #b45309; }
.status-approved { background: #dcfce7; color: #15803d; }
.status-rejected { background: #fee2e2; color: #b91c1c; }
.status-published { background: #ddd6fe; color: #6d28d9; }

/* PED export layout */
.ped-card {
  border: 1px solid var(--color-line);
  border-radius: 12px;
  background: #ffffff;
  padding: 1rem 1.1rem;
  display: flex;
  gap: 1rem;
}
.ped-card .ped-day { flex: 0 0 56px; }
.ped-card .ped-body { flex: 1; min-width: 0; }
.ped-card .ped-meta {
  font-size: 0.7rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.ped-card pre.ped-copy {
  font-family: inherit;
  white-space: pre-wrap;
  margin: 0.5rem 0;
  font-size: 0.92rem;
  line-height: 1.5;
}
.ped-card .ped-hashtags {
  color: #475569;
  font-size: 0.78rem;
  margin-top: 0.25rem;
}
.ped-card .ped-cta {
  font-size: 0.8rem;
  color: #1e293b;
  margin-top: 0.5rem;
}
.ped-card .ped-cta a { color: var(--color-brand-600); text-decoration: underline; }
.ped-card .ped-stories { margin-top: 0.5rem; font-size: 0.7rem; color: #94a3b8; display: flex; gap: 1rem; flex-wrap: wrap; }

/* Asset library */
.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
}
.asset-tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: #f1f5f9;
  border: 1px solid var(--color-line);
}
.asset-tile img,
.asset-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.asset-tile .asset-meta {
  position: absolute;
  inset: auto 0 0 0;
  background: linear-gradient(to top, rgba(11, 13, 18, 0.78), transparent);
  color: #ffffff;
  font-size: 0.68rem;
  padding: 0.5rem;
}
.asset-dropzone {
  border: 1.5px dashed #cbd5e1;
  border-radius: 12px;
  padding: 1.5rem;
  background: #fafbfc;
  text-align: center;
  color: var(--color-muted);
  font-size: 0.85rem;
  transition: all 120ms ease;
}
.asset-dropzone.is-dragover {
  border-color: var(--color-brand-500);
  background: var(--color-brand-50);
  color: var(--color-brand-700);
}

/* Calendar */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--color-line);
  border: 1px solid var(--color-line);
  border-radius: 14px;
  overflow: hidden;
}
.cal-headcell {
  background: var(--color-canvas);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  padding: 0.5rem 0.6rem;
  text-align: center;
}
.cal-cell {
  background: #ffffff;
  min-height: 120px;
  padding: 0.5rem 0.6rem;
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.cal-cell.muted { background: #fafafa; color: #94a3b8; }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--color-brand-500); }
.cal-day-num { font-weight: 600; color: var(--color-ink); }
.cal-cell.muted .cal-day-num { color: #cbd5e1; }
.cal-chip {
  display: block;
  background: var(--color-brand-50);
  color: var(--color-brand-700);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.68rem;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
}
.cal-chip:hover { background: #ddd9ff; }

/* Social previews */
.preview-card {
  background: #ffffff;
  border: 1px solid var(--color-line);
  border-radius: 14px;
  overflow: hidden;
  font-size: 0.85rem;
  max-width: 380px;
}
.preview-card .preview-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--color-line);
}
.preview-card .preview-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4f5fd8, #c2299a);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 600;
}
.preview-card .preview-body { padding: 0.75rem; }
.preview-card .preview-media {
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 0.75rem;
  aspect-ratio: 1;
}
.preview-card .preview-media img { width: 100%; height: 100%; object-fit: cover; }

/* Print */
@media print {
  body { background: #ffffff !important; }
  .no-print, aside, header, .lp-print-hide { display: none !important; }
  main { padding: 0 !important; }
  .ped-week { page-break-after: always; }
  .ped-page { page-break-after: always; }
  .ped-card { break-inside: avoid; }
}
