/* GENIAC UI — design tokens and components shared by the console and the
   client portal, in plain CSS so no build step is needed. Design source:
   docs/ui-redesign/uxpilot-ui-guidelines.md. Layout-specific rules
   stay in static/console/console.css and static/portal/portal.css. */

:root {
    /* Palette from the UX Pilot redesign (docs/ui-redesign/): an electric blue
       accent on slate neutrals. The --gen-* names (originally «blu GEN») are
       kept so every component follows; --gen-900 is now the action blue. */
    --gen-50: #eff6ff; --gen-100: #dbeafe; --gen-200: #bfdbfe; --gen-300: #93c5fd;
    --gen-500: #3b82f6; --gen-600: #2563eb; --gen-700: #1d4ed8; --gen-800: #1d4ed8;
    --gen-900: #2563eb; --gen-950: #0f172a;
    /* Green, for success/ok only */
    --iac-50: #ecfdf5; --iac-100: #d1fae5; --iac-400: #34d399; --iac-500: #10b981;
    --iac-600: #059669; --iac-700: #047857; --iac-800: #065f46;
    /* Amber */
    --ambra-50: #fffbeb; --ambra-100: #fef3c7; --ambra-800: #b45309;
    /* Slate neutrals */
    --ink-50: #f8fafc; --ink-100: #f1f5f9; --ink-200: #e2e8f0; --ink-300: #cbd5e1;
    --ink-400: #94a3b8; --ink-500: #64748b; --ink-600: #475569; --ink-700: #334155;
    --ink-800: #1e293b; --ink-900: #0f172a;

    /* Semantic tokens. Templates' inline styles reference these names, so they
       are kept stable: --ok/--warn/--red/--info are the readable *text*
       colours, --*-soft their backgrounds, --*-dot the vivid accent. */
    --bg: #f8fafc;
    --card: #ffffff;
    --line: var(--ink-200);
    --line2: var(--ink-200);
    --ink: var(--ink-900);
    --ink2: var(--ink-700);
    --muted: var(--ink-500);
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --accent-soft: #eff6ff;
    --accent-light: #dbeafe;
    --accent-ring: #bfdbfe;
    --sidebar: #0f172a;
    --ok: #047857;   --ok-soft: #ecfdf5;   --ok-dot: #10b981;   --ok-line: #a7f3d0;
    --warn: #b45309; --warn-soft: #fffbeb; --warn-dot: #f59e0b; --warn-line: #fde68a;
    --red: #b91c1c;  --red-soft: #fef2f2;  --red-dot: #ef4444;  --red-line: #fecaca;
    --info: #1d4ed8; --info-soft: #eff6ff; --info-dot: #3b82f6; --info-line: #bfdbfe;

    --radius-card: 16px;
    --radius-ctl: 12px;
    --ctl-height: 44px;
    --shadow: 0 1px 2px 0 rgba(15, 23, 42, .05);
    --shadow-lift: 0 10px 15px -3px rgba(15, 23, 42, .08), 0 4px 6px -4px rgba(15, 23, 42, .08);
    --shadow-primary: 0 10px 15px -3px rgba(37, 99, 235, .2), 0 4px 6px -4px rgba(37, 99, 235, .2);
    --ring: 0 0 0 4px rgba(37, 99, 235, .1);
    --font-sans: 'Inter', ui-sans-serif, system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-sans); -webkit-font-smoothing: antialiased; }

.console-root, .portal-root { min-height: 100vh; background: var(--bg); color: var(--ink); font-family: var(--font-sans); font-size: 14px; line-height: 1.5; }
.console-root *, .console-root *::before, .console-root *::after,
.portal-root *, .portal-root *::before, .portal-root *::after { box-sizing: border-box; }
/* :where() keeps these resets at zero specificity so component classes
   (buttons, nav links, headings) always win over them. */
:where(.console-root, .portal-root) a { color: var(--gen-600); text-decoration: none; }
:where(.console-root, .portal-root) a:hover { color: var(--gen-900); text-decoration: underline; text-underline-offset: 2px; }
.console-root :focus-visible, .portal-root :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:where(.console-root, .portal-root) :where(h1, h2, h3, p) { margin: 0; }

.mono { font-family: var(--font-mono); }
.tnum { font-variant-numeric: tabular-nums; }
/* Components set their own display (flex/grid), which would otherwise beat
   the browser's built-in [hidden] rule; JS toggles .hidden on such elements
   (e.g. the AI proposal card in static/console/ai_proposal.js). */
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.icon { width: 16px; height: 16px; flex-shrink: 0; display: inline-block; vertical-align: -3px; }
.icon--sm { width: 14px; height: 14px; }
.icon--lg { width: 20px; height: 20px; }

/* --- Headings -------------------------------------------------------- */
.console-eyebrow, .portal-eyebrow {
    font: 400 14px/1.3 var(--font-sans); color: var(--ink-400); margin-bottom: 4px;
}
.console-h1 { font-size: 30px; font-weight: 700; letter-spacing: -.025em; line-height: 1.15; }
@media (max-width: 639px) { .console-h1 { font-size: 24px; } }
.portal-h1 { font-size: 32px; font-weight: 800; letter-spacing: -.025em; line-height: 1.15; }
.portal-sub { margin-top: 8px; color: var(--ink2); font-size: 15px; }

/* --- Card ------------------------------------------------------------ */
.console-card, .portal-card {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-card);
    box-shadow: var(--shadow); overflow: hidden;
}
.card-header {
    display: flex; align-items: center; gap: 10px; padding: 16px 24px;
    border-bottom: 1px solid var(--line); font-size: 15px; font-weight: 700;
}
.card-header .icon { color: var(--gen-500); }
.card-header .count { font: 500 11px var(--font-mono); color: var(--muted); }

/* --- Buttons --------------------------------------------------------- */
.console-btn, a.console-btn, .portal-btn, a.portal-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: var(--ctl-height); padding: 0 16px; border-radius: var(--radius-ctl);
    font: 500 14px/1 var(--font-sans); white-space: nowrap; cursor: pointer; user-select: none;
    background: #fff; color: var(--ink2); border: 1px solid var(--line2); box-shadow: none;
    transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s, transform .1s;
    text-decoration: none;
}
.console-btn:hover, a.console-btn:hover, .portal-btn:hover, a.portal-btn:hover {
    background: var(--ink-50); border-color: var(--line2); color: var(--ink); text-decoration: none;
}
.console-btn:active, .portal-btn:active { transform: scale(.98); }
.console-btn--primary, a.console-btn--primary, .portal-btn--primary, a.portal-btn--primary {
    padding: 0 20px; background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: var(--shadow-primary);
}
.console-btn--primary:hover, a.console-btn--primary:hover, .portal-btn--primary:hover, a.portal-btn--primary:hover {
    background: var(--accent-dark); border-color: var(--accent-dark); color: #fff;
}
.console-btn--success, .portal-btn--success { background: var(--iac-600); border-color: var(--iac-600); color: #fff; }
.console-btn--success:hover, .portal-btn--success:hover { background: var(--iac-700); border-color: var(--iac-700); color: #fff; }
.console-btn--danger, a.console-btn--danger, .portal-btn--danger {
    background: var(--red-soft); border-color: var(--red-line); color: var(--red); box-shadow: none;
}
.console-btn--danger:hover, a.console-btn--danger:hover, .portal-btn--danger:hover {
    background: var(--red); border-color: var(--red); color: #fff;
}
.console-btn--ghost, a.console-btn--ghost, .portal-btn--ghost, a.portal-btn--ghost {
    background: transparent; border-color: transparent; box-shadow: none; color: var(--ink2);
}
.console-btn--ghost:hover, a.console-btn--ghost:hover, .portal-btn--ghost:hover, a.portal-btn--ghost:hover {
    background: var(--ink-100); border-color: transparent; color: var(--ink);
}
.console-btn--sm, .portal-btn--sm { height: 36px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.console-btn--sm.console-btn--primary, .portal-btn--sm.portal-btn--primary { padding: 0 14px; }
.console-btn.is-busy, .portal-btn.is-busy { opacity: .6; cursor: progress; }
.console-btn:disabled, .portal-btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- Status pills ---------------------------------------------------- */
.status-pill {
    display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px 0 8px;
    border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
    background: var(--ink-100); color: var(--ink2);
}
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-400); flex-shrink: 0; }
.status-pill--ok { background: var(--ok-soft); color: var(--ok); }
.status-pill--ok::before { background: var(--ok-dot); }
.status-pill--warn { background: var(--warn-soft); color: var(--warn); }
.status-pill--warn::before { background: var(--warn-dot); }
.status-pill--red, .status-pill--late { background: var(--red-soft); color: var(--red); }
.status-pill--red::before, .status-pill--late::before { background: var(--red-dot); }
.status-pill--info { background: var(--info-soft); color: var(--info); }
.status-pill--info::before { background: var(--info-dot); }
.status-pill--muted { background: var(--ink-100); color: var(--ink2); }

.anomaly-badge, .badge-mandatory {
    display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 6px; border-radius: 6px;
    font: 600 11px/1 var(--font-mono); background: var(--red-soft); color: var(--red); white-space: nowrap;
}
.badge-mandatory { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }

/* --- Avatar ---------------------------------------------------------- */
.avatar {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 28px; height: 28px; border-radius: 50%; font: 600 11px/1 var(--font-sans);
    background: var(--gen-100); color: var(--gen-800);
}
.avatar--sm { width: 22px; height: 22px; font-size: 9px; }
.avatar--lg { width: 34px; height: 34px; font-size: 12px; }
.avatar--ok { background: var(--iac-100); color: var(--iac-800); }
.avatar--ambra { background: var(--ambra-100); color: var(--ambra-800); }

.avatar-tile {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 36px; height: 36px; border-radius: 12px; border: 1px solid transparent;
    font: 700 12px/1 var(--font-sans); letter-spacing: .02em;
    background: var(--accent-soft); color: var(--accent);
}
.avatar-tile--1 { background: #eef2ff; color: #4f46e5; }
.avatar-tile--2 { background: #fffbeb; color: #d97706; }
.avatar-tile--3 { background: #ecfdf5; color: #059669; }
.avatar-tile--sm { width: 30px; height: 30px; border-radius: 10px; font-size: 11px; }
.avatar-tile--lg { width: 80px; height: 80px; border-radius: 16px; font-size: 24px; border-color: var(--accent-light); box-shadow: var(--shadow); }
@media (max-width: 639px) { .avatar-tile--lg { width: 60px; height: 60px; border-radius: 16px; font-size: 20px; } }

/* Small uppercase label next to a title (e.g. «Persona fisica»). */
.type-badge {
    display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px;
    border: 1px solid rgba(37, 99, 235, .1); background: var(--accent-light); color: var(--accent);
    font: 700 10.5px/1 var(--font-sans); letter-spacing: .08em; text-transform: uppercase; white-space: nowrap;
}
.type-badge--muted { border-color: var(--line); background: var(--ink-100); color: var(--ink2); }

/* Square icon-only button (row actions, header tools). */
.icon-btn, a.icon-btn {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 32px; height: 32px; border: 1px solid transparent; border-radius: 8px;
    background: transparent; color: var(--ink-400); cursor: pointer; text-decoration: none;
    transition: background-color .15s, color .15s, border-color .15s;
}
.icon-btn:hover, a.icon-btn:hover { background: var(--ink-100); color: var(--ink); text-decoration: none; }
.icon-btn--danger:hover, a.icon-btn--danger:hover { background: var(--red-soft); color: var(--red); }
.icon-btn--outline { border-color: var(--line2); background: #fff; box-shadow: var(--shadow); }

/* --- Icon tile (KPI, list items) -------------------------------------- */
.icon-tile {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 36px; height: 36px; border-radius: var(--radius-ctl); background: var(--accent-light); color: var(--accent);
}
.icon-tile .icon { width: 18px; height: 18px; }
.icon-tile--ok { background: var(--iac-50); color: var(--iac-700); }
.icon-tile--warn { background: var(--warn-soft); color: var(--warn); }
.icon-tile--red { background: var(--red-soft); color: var(--red); }
.icon-tile--info { background: var(--info-soft); color: var(--info); }
.icon-tile--ambra { background: var(--ambra-50); color: var(--ambra-800); }
.icon-tile--muted { background: var(--ink-100); color: var(--ink-500); }

/* --- Segmented tabs (filters) ---------------------------------------- */
.seg-tabs {
    display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px; padding: 4px;
    border: 1px solid var(--line); border-radius: var(--radius-ctl); background: #fff; box-shadow: var(--shadow);
}
.seg-tab, a.seg-tab {
    display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 16px; border-radius: 8px;
    border: 1px solid transparent; font-size: 14px; font-weight: 500; color: var(--ink-500); text-decoration: none;
    transition: color .15s, background-color .15s;
}
.seg-tab:hover, a.seg-tab:hover { color: var(--ink); background: var(--ink-50); text-decoration: none; }
.seg-tab.active, a.seg-tab.active { background: var(--accent); color: #fff; font-weight: 500; }
.seg-tab .count {
    display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px;
    border-radius: 6px; background: rgba(136, 143, 161, .16); font: 600 11px var(--font-sans); color: var(--ink2);
}
.seg-tab.active .count { background: rgba(255, 255, 255, .2); color: #fff; }
.seg-tab .count--red { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--red-soft); color: var(--red); }

/* --- Alerts / Django messages ----------------------------------------- */
.console-messages, .portal-messages { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.console-message, .portal-message {
    display: flex; align-items: flex-start; gap: 10px; padding: 12px 10px 12px 14px;
    border-radius: 12px; border: 1px solid var(--info-line); font-size: 14px;
    background: var(--info-soft); color: var(--info);
}
.console-message > .icon, .portal-message > .icon { width: 18px; height: 18px; margin-top: 1px; }
.console-message .message-text, .portal-message .message-text { flex: 1; }
.console-message--error, .portal-message--error { background: var(--red-soft); color: var(--red); border-color: var(--red-line); }
.console-message--success, .portal-message--success { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.console-message--warning, .portal-message--warning { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.console-message--info, .portal-message--info { background: var(--info-soft); color: var(--info); border-color: var(--info-line); }
.console-message form { margin: 0; }
.message-dismiss {
    display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px;
    border: 0; border-radius: 6px; background: transparent; color: inherit; cursor: pointer;
}
.message-dismiss:hover { background: rgba(0, 0, 0, .06); }

/* --- Form controls ---------------------------------------------------- */
.console-root input[type=text], .console-root input[type=number], .console-root input[type=email],
.console-root input[type=date], .console-root input[type=datetime-local], .console-root input[type=password],
.console-root input[type=search], .console-root input[type=tel], .console-root input[type=url],
.console-root input[type=file], .console-root select, .console-root textarea,
.portal-root input[type=text], .portal-root input[type=email], .portal-root input[type=password],
.portal-root input[type=file], .portal-root select, .portal-root textarea {
    min-height: var(--ctl-height); padding: 9px 14px; border-radius: var(--radius-ctl);
    border: 1px solid var(--line2); background: #fff; color: var(--ink);
    font: 14px/1.4 var(--font-sans); max-width: 100%; box-shadow: var(--shadow);
    transition: border-color .15s, box-shadow .15s;
}
.console-root input:hover, .console-root select:hover, .console-root textarea:hover,
.portal-root input:hover, .portal-root select:hover, .portal-root textarea:hover { border-color: var(--ink-400); }
.console-root input:focus, .console-root select:focus, .console-root textarea:focus,
.portal-root input:focus, .portal-root select:focus, .portal-root textarea:focus {
    outline: none; border-color: var(--accent); box-shadow: var(--ring);
}
.console-root input[type=file], .portal-root input[type=file] { padding: 6px 8px; font-size: 13px; }
.console-root input[type=checkbox], .portal-root input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--gen-900); }
.console-root input::placeholder, .console-root textarea::placeholder,
.portal-root input::placeholder, .portal-root textarea::placeholder { color: var(--ink-500); }
.console-root input:disabled, .portal-root input:disabled { background: var(--ink-50); color: var(--muted); }

/* Custom dropdown arrow, replacing the native control so selects match the
   rest of the UI instead of looking like an unstyled OS widget. */
.console-root select, .portal-root select {
    appearance: none; -webkit-appearance: none; -moz-appearance: none; padding-right: 34px; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23646b7c' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; background-size: 12px 12px;
}
.console-root select::-ms-expand, .portal-root select::-ms-expand { display: none; }

.errors, .errorlist { color: var(--red); font-size: 12.5px; }
.errorlist { list-style: none; margin: 4px 0 0; padding: 0; }

/* --- Empty state ------------------------------------------------------ */
.empty-state { padding: 48px 24px; text-align: center; }
.empty-state .icon-tile { width: 48px; height: 48px; border-radius: 16px; background: var(--ink-100); color: var(--ink-500); }
.empty-state .icon-tile .icon { width: 24px; height: 24px; }
.empty-state-title { margin-top: 14px; font-weight: 600; color: var(--ink); }
.empty-state-text { margin-top: 4px; font-size: 14px; color: var(--muted); }
.empty-state .console-btn, .empty-state .portal-btn { margin-top: 18px; }

/* --- Back link -------------------------------------------------------- */
.console-back-link, a.console-back-link, .portal-back-link, a.portal-back-link {
    display: inline-flex; align-items: center; gap: 6px; margin-bottom: 16px;
    font-size: 13.5px; font-weight: 600; color: var(--ink2);
}
.console-back-link:hover, .portal-back-link:hover { color: var(--gen-900); }

/* Compact notes/description fields with an «Espandi» toggle (see ui.js). */
.console-root textarea.textarea-compact { min-height: 0; height: 40px; resize: none; }
.console-root textarea.textarea-compact.is-expanded { height: 180px; resize: vertical; }
.textarea-toggle { align-self: flex-start; margin-top: 4px; padding: 0; border: 0; background: none; font: 600 12px var(--font-sans); color: var(--accent); cursor: pointer; }
.textarea-toggle:hover { text-decoration: underline; }
.textarea-toggle:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 4px; }
