/* ===== Design tokens ===== */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --accent: #0d9488;       /* teal — saving/positive */
  --accent-light: #ecfdf5;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --warn: #d97706;
  --warn-light: #fffbeb;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --card: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 4px 12px rgba(15, 23, 42, .08);
  --font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
.ea-boot { padding: 3rem; text-align: center; color: var(--muted); }
a { color: var(--primary); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

/* ===== Buttons (always explicit background) ===== */
.ea-btn { display: inline-flex; align-items: center; gap: .5rem; font-family: inherit; font-size: .9rem; font-weight: 600;
  padding: .6rem 1rem; border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer; transition: background .15s, box-shadow .15s; }
.ea-btn:disabled { opacity: .6; cursor: not-allowed; }
.ea-btn-primary { background: var(--primary); color: #fff; }
.ea-btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.ea-btn-secondary { background: #f1f5f9; color: var(--text); border-color: var(--border); }
.ea-btn-secondary:hover:not(:disabled) { background: #e2e8f0; }
.ea-btn-danger { background: var(--danger); color: #fff; }
.ea-btn-ghost { background: #f8fafc; color: var(--muted); border-color: var(--border); }
.ea-btn-block { width: 100%; justify-content: center; }
.ea-btn svg { width: 18px; height: 18px; }

/* ===== Fields ===== */
.ea-field { margin-bottom: 1rem; }
.ea-field label { display: block; font-size: .8rem; font-weight: 600; color: var(--text); margin-bottom: .35rem; }
.ea-input, .ea-select { width: 100%; font-family: inherit; font-size: .9rem; padding: .6rem .75rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: #fff; color: var(--text); }
.ea-input:focus, .ea-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.ea-input[aria-invalid="true"] { border-color: var(--danger); }
.ea-error { color: var(--danger); font-size: .8rem; margin-top: .35rem; }

/* ===== Login ===== */
.ea-login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(1200px 600px at 50% -10%, #dbeafe, var(--bg)); }
.ea-login-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem; }
.ea-login-brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.15rem; margin-bottom: .25rem; }
.ea-login-brand .ea-logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--primary), var(--accent)); display: grid; place-items: center; color: #fff; }
.ea-login-sub { color: var(--muted); font-size: .85rem; margin: 0 0 1.5rem; }

/* ===== App shell ===== */
.ea-shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.ea-sidebar { background: var(--card); border-right: 1px solid var(--border); padding: 1.25rem 1rem; display: flex; flex-direction: column; }
.ea-sidebar-brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; margin: 0 .25rem 1.5rem; }
.ea-logo { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, var(--primary), var(--accent)); display: grid; place-items: center; color: #fff; flex: none; }
.ea-nav { display: flex; flex-direction: column; gap: .15rem; }
.ea-nav a { display: flex; align-items: center; gap: .65rem; padding: .6rem .7rem; border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font-size: .9rem; font-weight: 500; }
.ea-nav a:hover { background: #f8fafc; color: var(--text); }
.ea-nav a.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.ea-nav a svg { width: 18px; height: 18px; }
.ea-sidebar-foot { margin-top: auto; font-size: .8rem; color: var(--muted); padding: .5rem .25rem 0; }
.ea-main { display: flex; flex-direction: column; min-width: 0; }
.ea-topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.75rem; background: var(--card); border-bottom: 1px solid var(--border); }
.ea-topbar h1 { font-size: 1.15rem; margin: 0; }
.ea-topbar .sub { color: var(--muted); font-size: .82rem; }
.ea-user { display: flex; align-items: center; gap: .6rem; }
.ea-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: .8rem; }
.ea-content { padding: 1.75rem; overflow: auto; }

/* ===== KPI ===== */
.ea-kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.ea-kpi { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow-sm); }
.ea-kpi-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.ea-kpi-value { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: .35rem 0 .1rem; }
.ea-kpi-hint { font-size: .78rem; color: var(--muted); }
.ea-kpi-hint.good { color: var(--accent); }

/* ===== Card ===== */
.ea-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 1.5rem; }
.ea-card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); }
.ea-card-head h2 { font-size: 1rem; margin: 0; }
.ea-card-head .sub { font-size: .8rem; color: var(--muted); }
.ea-card-body { padding: 1.25rem; }

/* ===== Toolbar + table ===== */
.ea-toolbar { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.ea-search { position: relative; flex: 1; min-width: 200px; }
.ea-search svg { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.ea-search input { width: 100%; padding: .55rem .75rem .55rem 2.3rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: inherit; font-size: .88rem; }
.ea-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.ea-table th, .ea-table td { text-align: left; padding: .8rem 1.25rem; border-bottom: 1px solid var(--border); }
.ea-table th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); cursor: pointer; user-select: none; white-space: nowrap; }
.ea-table th .arr { color: var(--primary); }
.ea-table tbody tr:hover { background: #f8fafc; }
.ea-table td.ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Badges ===== */
.ea-badge { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.ea-role-admin { background: #ede9fe; color: #6d28d9; }
.ea-role-category_manager { background: #dbeafe; color: #1d4ed8; }
.ea-role-approver { background: #dcfce7; color: #166534; }
.ea-role-viewer { background: #f1f5f9; color: #475569; }
.ea-status-active { background: var(--accent-light); color: #0f766e; }
.ea-status-disabled { background: #f1f5f9; color: #64748b; }

/* ===== Empty state ===== */
.ea-empty-state { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 2.5rem 1.5rem; text-align: center; }
.ea-empty-state-icon { width: 48px; height: 48px; margin: 0 auto .75rem; color: var(--muted); }
.ea-empty-state-title { font-size: 1rem; font-weight: 600; margin: 0 0 .375rem; }
.ea-empty-state-desc { font-size: .875rem; color: var(--muted); margin: 0 0 1rem; }

/* ===== Modal ===== */
.ea-modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; padding: 1rem; z-index: 50; }
.ea-modal { background: #fff; border-radius: var(--radius); box-shadow: 0 20px 50px rgba(15,23,42,.25); width: 100%; max-width: 440px; }
.ea-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); }
.ea-modal-head h3 { margin: 0; font-size: 1.05rem; }
.ea-modal-close { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; width: 30px; height: 30px; cursor: pointer; color: var(--muted); font-size: 1.1rem; line-height: 1; }
.ea-modal-body { padding: 1.25rem; }
.ea-modal-foot { display: flex; justify-content: flex-end; gap: .6rem; padding: 1rem 1.25rem; border-top: 1px solid var(--border); }

/* ===== Toast ===== */
#toast-root { position: fixed; bottom: 1.25rem; right: 1.25rem; display: flex; flex-direction: column; gap: .6rem; z-index: 60; }
.ea-toast { background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: .8rem 1rem; min-width: 260px; font-size: .88rem; animation: slidein .2s ease; }
.ea-toast.success { border-left-color: var(--accent); }
.ea-toast.error { border-left-color: var(--danger); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== Skeleton ===== */
.ea-skel { background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 37%, #eef2f7 63%); background-size: 400% 100%; animation: shimmer 1.3s infinite; border-radius: 6px; height: 14px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.ea-chart-wrap { position: relative; height: 280px; }
.ea-pill { display:inline-block; font-size:.7rem; font-weight:600; color: var(--warn); background: var(--warn-light); padding:.15rem .5rem; border-radius:999px; }

@media (max-width: 820px) {
  .ea-shell { grid-template-columns: 1fr; }
  .ea-sidebar { flex-direction: row; align-items: center; overflow-x: auto; }
  .ea-nav { flex-direction: row; }
  .ea-sidebar-foot { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ===== Guida / testi descrittivi ===== */
.ea-help { background: #fff; border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: var(--radius-sm); padding: .85rem 1.1rem; margin-bottom: 1.25rem; color: var(--muted); font-size: .9rem; line-height: 1.55; }
.ea-help strong { color: var(--text); }
.ea-section-intro { font-size: .85rem; color: var(--muted); margin: -.25rem 0 1.1rem; max-width: 72ch; line-height: 1.55; }
.ea-callout { display: flex; gap: .7rem; align-items: flex-start; background: var(--primary-light); border: 1px solid #dbeafe; border-radius: var(--radius-sm); padding: .8rem 1rem; font-size: .85rem; color: #1e3a8a; margin-bottom: 1rem; line-height: 1.5; }
.ea-callout svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }

/* ===== Alert / opportunità ===== */
.ea-alert { display: flex; gap: .85rem; align-items: center; border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1.5rem; font-size: .92rem; border: 1px solid; }
.ea-alert-ic { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.ea-alert-ic svg { width: 20px; height: 20px; }
.ea-alert.good { background: var(--accent-light); border-color: #a7f3d0; color: #065f46; }
.ea-alert.good .ea-alert-ic { background: #10b981; color: #fff; }
.ea-alert.warn { background: var(--warn-light); border-color: #fde68a; color: #92400e; }
.ea-alert.warn .ea-alert-ic { background: var(--warn); color: #fff; }
.ea-alert.neutral { background: #f8fafc; border-color: var(--border); color: var(--muted); }
.ea-alert.neutral .ea-alert-ic { background: #94a3b8; color: #fff; }

/* ===== Sotto-tab Configuratore ===== */
.ea-tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; overflow-x: auto; }
.ea-tab { background: #f8fafc; border: 1px solid var(--border); border-bottom: none; border-radius: 8px 8px 0 0; padding: .6rem 1rem; font-family: inherit; font-size: .88rem; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; margin-bottom: -1px; display: inline-flex; align-items: center; gap: .4rem; }
.ea-tab:hover { color: var(--text); }
.ea-tab.active { background: #fff; color: var(--primary-dark); border-bottom-color: #fff; }
.ea-tab svg { width: 15px; height: 15px; }
