/* ============================================================
   TrafficHub — Autopilot design system
   Shared stylesheet for the 3 Autopilot pages:
     /autopilot, /autopilot/rules/*, /autopilot/history
   Global file, so EVERY class is namespaced `ap-` and every token
   `--ap-` to guarantee nothing leaks into Dashboard / Campaigns.
   Palette reused verbatim from MainLayout / Home / NavMenu (dark, cyan).
   ============================================================ */

:root {
    /* ---- Surfaces & core palette (from the existing app) ---- */
    --ap-bg:            #0f0f1a; /* page background      */
    --ap-surface:       #16213e; /* card / panel surface */
    --ap-surface-2:     #1a1a2e; /* deeper surface       */
    --ap-accent:        #00d4ff; /* cyan accent          */
    --ap-accent-hover:  #33ddff;
    --ap-accent-ink:    #0b1020; /* text on cyan         */
    --ap-text:          #ffffff;
    --ap-text-dim:      #c7cdd9;
    --ap-muted:         #8a90a2;

    /* ---- Semantic (state) colors + dim backing ---- */
    --ap-success:       #22c55e;
    --ap-success-dim:   #0f2f22;
    --ap-warning:       #f0b429; /* money-gated / pending / observing */
    --ap-warning-dim:   #2a2410;
    --ap-danger:        #ff5c5c;
    --ap-danger-dim:    #2a1414;
    --ap-info:          #38bdf8;
    --ap-info-dim:      #0e2740;

    /* ---- Lines ---- */
    --ap-border:        rgba(255, 255, 255, .08);
    --ap-border-strong: rgba(255, 255, 255, .16);

    /* ---- Shape & motion ---- */
    --ap-radius:        .75rem;
    --ap-radius-sm:     .5rem;
    --ap-radius-pill:   999px;
    --ap-gap:           1.5rem;
    --ap-pad:           1.5rem;
    --ap-ease:          150ms cubic-bezier(.2, .6, .2, 1);
}

/* ============================================================
   Page shell
   ============================================================ */
.ap-page {
    /* tabular figures for every metric / budget / percent / count */
    font-variant-numeric: tabular-nums;
    color: var(--ap-text);
    max-width: 1100px;
}

.ap-page__header { margin-bottom: var(--ap-gap); }
.ap-page__header h1 { margin: 0; font-size: 1.75rem; font-weight: 600; letter-spacing: .01em; }
.ap-page__sub { color: var(--ap-muted); font-size: .95rem; margin: .35rem 0 0; }

/* utility: opt-in tabular figures for callers that need it locally */
.ap-num { font-variant-numeric: tabular-nums; }

/* ============================================================
   Kill switch — the hero control
   ============================================================ */
.ap-killswitch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.25rem;
    flex-wrap: wrap;
    padding: 1.75rem 2rem;
    border-radius: var(--ap-radius);
    border: 1px solid var(--ap-border-strong);
    margin-bottom: var(--ap-gap);
    transition: box-shadow var(--ap-ease), border-color var(--ap-ease), background var(--ap-ease);
}

.ap-killswitch__info { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.ap-killswitch__text { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.ap-killswitch__title { font-size: 1.2rem; font-weight: 600; letter-spacing: .01em; }
.ap-killswitch__meta { color: var(--ap-text-dim); font-size: .9rem; }
.ap-killswitch__meta .ap-sep { color: var(--ap-muted); margin: 0 .45rem; }

/* ON — calm, success-tinted, soft glow */
.ap-killswitch.is-on {
    background: linear-gradient(180deg, rgba(34, 197, 94, .10), rgba(34, 197, 94, .03)), var(--ap-surface);
    border-color: rgba(34, 197, 94, .45);
    box-shadow: 0 0 0 1px rgba(34, 197, 94, .15), 0 12px 34px -14px rgba(34, 197, 94, .5);
}

/* OFF — danger-tinted, muted */
.ap-killswitch.is-off {
    background: linear-gradient(180deg, rgba(255, 92, 92, .10), rgba(255, 92, 92, .03)), var(--ap-surface);
    border-color: rgba(255, 92, 92, .4);
}

/* status dot */
.ap-dot { width: .7rem; height: .7rem; border-radius: 50%; flex: 0 0 auto; }
.ap-dot--on {
    background: var(--ap-success);
    box-shadow: 0 0 0 4px rgba(34, 197, 94, .18);
    animation: ap-pulse 2.4s ease-in-out infinite;
}
.ap-dot--off {
    background: var(--ap-danger);
    box-shadow: 0 0 0 4px rgba(255, 92, 92, .15);
}

@keyframes ap-pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(34, 197, 94, .18); }
    50%      { box-shadow: 0 0 0 8px rgba(34, 197, 94, .05); }
}

/* ============================================================
   Dimmed group (autopilot off => de-emphasize the rest)
   ============================================================ */
.ap-dimmed {
    opacity: .42;
    filter: saturate(.65);
    pointer-events: none;
    transition: opacity var(--ap-ease), filter var(--ap-ease);
}

/* ============================================================
   Sections
   ============================================================ */
.ap-section { margin-bottom: 2rem; }
.ap-section__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .9rem;
}
.ap-section__head h2 { margin: 0; font-size: 1.15rem; font-weight: 600; }
.ap-count { color: var(--ap-muted); font-weight: 500; }

/* ============================================================
   Cards
   ============================================================ */
.ap-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 1.1rem 1.25rem;
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-radius-sm);
    margin-bottom: .6rem;
    transition: transform var(--ap-ease), border-color var(--ap-ease), box-shadow var(--ap-ease);
}
.ap-card:hover {
    transform: translateY(-1px);
    border-color: var(--ap-border-strong);
    box-shadow: 0 12px 26px -20px rgba(0, 0, 0, .85);
}
.ap-card__body { min-width: 0; display: flex; flex-direction: column; gap: .35rem; }
.ap-card__title { font-weight: 600; }
.ap-card__meta { color: var(--ap-muted); font-size: .85rem; line-height: 1.4; }

/* ============================================================
   Pending-approval tray (amber, money-gated, elevated)
   ============================================================ */
.ap-tray {
    background: linear-gradient(180deg, rgba(240, 180, 41, .09), rgba(240, 180, 41, .02)), var(--ap-surface);
    border: 1px solid rgba(240, 180, 41, .38);
    border-radius: var(--ap-radius);
    padding: 1.25rem 1.35rem 1.1rem;
    margin-bottom: 2rem;
    box-shadow: 0 12px 30px -20px rgba(240, 180, 41, .5);
}
.ap-tray__head { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.ap-tray__head h2 { margin: 0; font-size: 1.1rem; font-weight: 600; color: var(--ap-warning); }
.ap-tray__note { color: var(--ap-text-dim); font-size: .88rem; margin: .4rem 0 1rem; }
.ap-card--pending { background: rgba(240, 180, 41, .05); border-color: rgba(240, 180, 41, .28); }
.ap-card--pending:hover { border-color: rgba(240, 180, 41, .5); }

/* ============================================================
   Rows (recent executions — compact list)
   ============================================================ */
.ap-row {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .7rem .35rem;
    border-bottom: 1px solid var(--ap-border);
}
.ap-row:last-child { border-bottom: 0; }
.ap-row__when { color: var(--ap-muted); font-size: .82rem; white-space: nowrap; }
.ap-row__what {
    color: var(--ap-text-dim);
    font-size: .9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================
   Badges — semantic status system
   ============================================================ */
.ap-badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .2rem .6rem;
    border-radius: var(--ap-radius-pill);
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .02em;
    white-space: nowrap;
    border: 1px solid transparent;
}
.ap-badge--success { background: var(--ap-success-dim); color: #7ee2a8; border-color: rgba(34, 197, 94, .35); }
.ap-badge--warning { background: var(--ap-warning-dim); color: #f4cd6b; border-color: rgba(240, 180, 41, .35); }
.ap-badge--danger  { background: var(--ap-danger-dim);  color: #ff9a9a; border-color: rgba(255, 92, 92, .35); }
.ap-badge--info    { background: var(--ap-info-dim);    color: #8ed6f7; border-color: rgba(56, 189, 248, .35); }
.ap-badge--neutral { background: rgba(255, 255, 255, .06); color: var(--ap-text-dim); border-color: var(--ap-border); }

/* ============================================================
   Alerts / banners (Edit page: active-rule warning)
   ============================================================ */
.ap-alert {
    display: flex;
    gap: .65rem;
    align-items: flex-start;
    padding: 1rem 1.15rem;
    border-radius: var(--ap-radius-sm);
    margin-bottom: 1.5rem;
    font-size: .9rem;
    line-height: 1.6;
    color: var(--ap-text-dim);
}
.ap-alert::before { flex: 0 0 auto; font-size: 1.05rem; line-height: 1.5; }
.ap-alert--warning {
    background: var(--ap-warning-dim);
    border: 1px solid rgba(240, 180, 41, .4);
}
.ap-alert--warning::before { content: "⚠"; color: var(--ap-warning); }
.ap-alert strong { color: var(--ap-warning); }

/* ============================================================
   Buttons — primary (cyan) / danger / ghost
   ============================================================ */
.ap-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .55rem 1.05rem;
    border-radius: .45rem;
    font-size: .9rem;
    font-weight: 600;
    line-height: 1;
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: transform var(--ap-ease), background var(--ap-ease), border-color var(--ap-ease), color var(--ap-ease), box-shadow var(--ap-ease);
}
.ap-btn:active { transform: translateY(1px); }
.ap-btn:focus-visible { outline: 2px solid var(--ap-accent); outline-offset: 2px; }
.ap-btn:disabled { opacity: .5; cursor: not-allowed; }

.ap-btn--primary { background: var(--ap-accent); color: var(--ap-accent-ink); }
.ap-btn--primary:hover { background: var(--ap-accent-hover); box-shadow: 0 6px 18px -8px rgba(0, 212, 255, .6); }

.ap-btn--danger { background: transparent; color: #ff9a9a; border-color: rgba(255, 92, 92, .5); }
.ap-btn--danger:hover { background: var(--ap-danger); color: #fff; border-color: var(--ap-danger); }

.ap-btn--ghost { background: transparent; color: var(--ap-text-dim); border-color: var(--ap-border-strong); }
.ap-btn--ghost:hover { background: rgba(255, 255, 255, .06); color: var(--ap-text); }

.ap-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ============================================================
   Links
   ============================================================ */
.ap-link { color: var(--ap-accent); text-decoration: none; font-size: .9rem; font-weight: 500; }
.ap-link:hover { text-decoration: underline; }

/* ============================================================
   Filter chips (History page)
   ============================================================ */
.ap-chip-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1.75rem; }
.ap-chip {
    background: transparent;
    color: var(--ap-muted);
    border: 1px solid var(--ap-border-strong);
    padding: .4rem .95rem;
    border-radius: var(--ap-radius-pill);
    font-size: .85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--ap-ease), border-color var(--ap-ease), color var(--ap-ease);
}
.ap-chip:hover { color: var(--ap-text); border-color: var(--ap-accent); }
.ap-chip:focus-visible { outline: 2px solid var(--ap-accent); outline-offset: 2px; }
.ap-chip.is-active { background: var(--ap-accent); color: var(--ap-accent-ink); border-color: var(--ap-accent); }

/* ============================================================
   Execution entries (History page) — each execution renders as
   its OWN .ap-card (see comment in History.razor: never wrap the
   whole list in a single card, or it lifts together on hover).
   ============================================================ */
.ap-card--exec { align-items: flex-start; }
.ap-card--simulated { border-style: dashed; opacity: .88; }

.ap-exec-head { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.ap-exec-when { color: var(--ap-muted); font-size: .82rem; white-space: nowrap; }
.ap-exec-rule { color: var(--ap-muted); font-size: .8rem; }

.ap-exec-reason { color: var(--ap-text-dim); font-size: .92rem; margin: 0; line-height: 1.5; }
.ap-exec-reason em { color: var(--ap-text); font-style: normal; font-weight: 600; }
.ap-exec-blocked { color: #f4cd6b; font-size: .85rem; margin: 0; }
.ap-exec-failure { color: #ff9a9a; font-size: .85rem; margin: 0; }

.ap-exec-ai {
    background: var(--ap-info-dim);
    border-left: 3px solid var(--ap-info);
    padding: .7rem .9rem;
    border-radius: 0 var(--ap-radius-sm) var(--ap-radius-sm) 0;
    margin-top: .15rem;
}
.ap-exec-ai__label { color: var(--ap-info); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.ap-exec-ai p { color: var(--ap-text-dim); margin: .3rem 0 0; font-size: .88rem; line-height: 1.55; }

/* ============================================================
   Form controls — shared by the rule wizard (New) and the future
   rule edit page (Task 29), both built on top of RuleForm.razor.
   ============================================================ */
.ap-form-section { margin-bottom: 1.75rem; }
.ap-form-section h3 { margin: 0 0 .3rem; font-size: 1.05rem; font-weight: 600; }
.ap-form-section__head { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; margin: 0 0 .75rem; }
.ap-form-section__head h3 { margin: 0; }

.ap-field { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1.15rem; max-width: 28rem; }
.ap-label { color: var(--ap-text-dim); font-size: .85rem; font-weight: 500; }

.ap-hint { color: var(--ap-muted); font-size: .85rem; line-height: 1.55; margin: 0; }
.ap-hint--inline { display: inline; }
.ap-hint--small { font-size: .78rem; }

.ap-input, .ap-select, .ap-textarea {
    padding: .6rem .75rem;
    border-radius: var(--ap-radius-sm);
    border: 1px solid var(--ap-border-strong);
    background: var(--ap-surface-2);
    color: var(--ap-text);
    font-size: .92rem;
    font-family: inherit;
    line-height: 1.3;
    transition: border-color var(--ap-ease), box-shadow var(--ap-ease);
}
.ap-input::placeholder { color: var(--ap-muted); }
.ap-input:focus, .ap-select:focus, .ap-textarea:focus {
    outline: none;
    border-color: var(--ap-accent);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, .18);
}
.ap-input--number { width: 8rem; }

/* checkbox row (AI comment toggle) */
.ap-checkbox-field {
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    margin: 1.25rem 0 .5rem;
    cursor: pointer;
}
.ap-checkbox-field input[type="checkbox"] {
    margin-top: .2rem;
    accent-color: var(--ap-accent);
    width: 1.05rem;
    height: 1.05rem;
    flex: 0 0 auto;
}
.ap-checkbox-field span { color: var(--ap-text-dim); font-size: .9rem; line-height: 1.5; }

/* condition editor row */
.ap-condition {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
    align-items: center;
    padding: .8rem .9rem;
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-radius-sm);
    margin-bottom: .55rem;
}
.ap-condition__remove {
    margin-left: auto;
    width: 1.9rem;
    height: 1.9rem;
    flex: 0 0 auto;
    border-radius: 50%;
    border: 1px solid var(--ap-border-strong);
    background: transparent;
    color: var(--ap-muted);
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    transition: color var(--ap-ease), border-color var(--ap-ease), background var(--ap-ease);
}
.ap-condition__remove:hover { color: #ff9a9a; border-color: rgba(255, 92, 92, .5); background: var(--ap-danger-dim); }
.ap-condition__remove:focus-visible { outline: 2px solid var(--ap-accent); outline-offset: 2px; }

/* inline validation — never color alone: icon + explicit text + bordered panel */
.ap-condition-error {
    display: flex;
    gap: .5rem;
    align-items: flex-start;
    color: #ff9a9a;
    background: var(--ap-danger-dim);
    border: 1px solid rgba(255, 92, 92, .35);
    border-radius: var(--ap-radius-sm);
    padding: .65rem .85rem;
    font-size: .85rem;
    line-height: 1.5;
    margin: -.15rem 0 .8rem;
}
.ap-condition-error::before { content: "⚠"; flex: 0 0 auto; }

/* mode picker (Shadow/Active radio cards) */
.ap-radio-card {
    display: flex;
    gap: .8rem;
    align-items: flex-start;
    padding: 1rem 1.1rem;
    border: 1px solid var(--ap-border-strong);
    border-radius: var(--ap-radius-sm);
    margin-bottom: .7rem;
    cursor: pointer;
    transition: border-color var(--ap-ease), background var(--ap-ease);
}
.ap-radio-card:hover { border-color: var(--ap-accent); }
.ap-radio-card:has(input:focus-visible) { outline: 2px solid var(--ap-accent); outline-offset: 2px; }
.ap-radio-card.is-selected { border-color: var(--ap-accent); background: rgba(0, 212, 255, .07); }
.ap-radio-card input[type="radio"] { margin-top: .25rem; accent-color: var(--ap-accent); width: 1.05rem; height: 1.05rem; flex: 0 0 auto; }
.ap-radio-card__body { display: flex; flex-direction: column; gap: .25rem; }
.ap-radio-card__title { font-weight: 600; color: var(--ap-text); }
.ap-radio-card__desc { color: var(--ap-muted); font-size: .85rem; line-height: 1.55; }

/* clickable card variant (template picker) */
.ap-card--clickable { cursor: pointer; }
.ap-card--clickable:hover { border-color: var(--ap-accent); }
.ap-card--clickable:focus-visible { outline: 2px solid var(--ap-accent); outline-offset: 2px; }
.ap-card__cta { color: var(--ap-accent); font-weight: 600; font-size: .85rem; white-space: nowrap; }

/* Template cards / "Começar do zero" render as <button> (not <div>) so keyboard and screen-reader
   users can reach them — a plain @onclick div is invisible to Tab and has no accessible role.
   Reset native button chrome so the result stays pixel-identical to the old div-based card. */
button.ap-card--clickable {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    color: inherit;
    font: inherit;
    text-align: left;
}
button.ap-card--clickable::-moz-focus-inner { border: 0; padding: 0; }

/* wizard step indicator */
.ap-steps { display: flex; gap: 1rem; list-style: none; padding: 0; margin: 0 0 1.75rem; }
.ap-steps li {
    flex: 1;
    padding-bottom: .6rem;
    border-bottom: 2px solid var(--ap-border-strong);
    color: var(--ap-muted);
    font-size: .85rem;
    font-weight: 500;
}
.ap-steps li.is-current { color: var(--ap-accent); border-color: var(--ap-accent); }
.ap-steps li.is-done { color: var(--ap-success); border-color: var(--ap-success); }

.ap-nav-buttons { display: flex; gap: .6rem; margin-top: 1.75rem; }

/* ============================================================
   Empty states (inviting, not bare text)
   ============================================================ */
.ap-empty {
    text-align: center;
    padding: 2.4rem 1.5rem;
    background: var(--ap-surface);
    border: 1px dashed var(--ap-border-strong);
    border-radius: var(--ap-radius-sm);
    color: var(--ap-text-dim);
}
.ap-empty--sm { padding: 1.5rem; }
.ap-empty__title { font-weight: 600; font-size: 1.02rem; color: var(--ap-text); margin-bottom: .45rem; }
.ap-empty__body {
    color: var(--ap-muted);
    font-size: .9rem;
    max-width: 48ch;
    margin: 0 auto 1.15rem;
    line-height: 1.55;
}
.ap-empty--sm .ap-empty__body { margin-bottom: 0; }

/* ============================================================
   Loading — shimmering skeletons
   ============================================================ */
.ap-skeleton {
    position: relative;
    overflow: hidden;
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-radius-sm);
    margin-bottom: .6rem;
}
.ap-skeleton--hero { height: 104px; border-radius: var(--ap-radius); margin-bottom: var(--ap-gap); }
.ap-skeleton--row { height: 68px; }
.ap-skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .05), transparent);
    animation: ap-shimmer 1.3s infinite;
}
@keyframes ap-shimmer { 100% { transform: translateX(100%); } }

/* ============================================================
   Entrance animation — subtle staggered fade-in
   ============================================================ */
@keyframes ap-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ap-fade { animation: ap-fade-in .4s ease both; }
.ap-delay-1 { animation-delay: .04s; }
.ap-delay-2 { animation-delay: .10s; }
.ap-delay-3 { animation-delay: .16s; }
.ap-delay-4 { animation-delay: .22s; }

@media (prefers-reduced-motion: reduce) {
    .ap-fade, .ap-dot--on, .ap-skeleton::after { animation: none; }
    .ap-fade { opacity: 1; transform: none; }
}

/* ============================================================
   Responsive — reflow at narrow widths
   ============================================================ */
@media (max-width: 640px) {
    .ap-killswitch { padding: 1.35rem 1.25rem; }
    .ap-killswitch, .ap-card { align-items: stretch; }
    .ap-killswitch > .ap-btn { width: 100%; }
    .ap-actions { width: 100%; }
    .ap-actions .ap-btn { flex: 1 1 auto; }
    .ap-row { flex-wrap: wrap; gap: .5rem .85rem; }
    .ap-row__what { white-space: normal; }

    .ap-field { max-width: none; }
    .ap-condition { flex-direction: column; align-items: stretch; }
    .ap-condition select, .ap-condition input { width: 100%; }
    .ap-condition__remove { margin-left: 0; align-self: flex-end; }
    .ap-nav-buttons { flex-direction: column-reverse; }
    .ap-nav-buttons .ap-btn { width: 100%; }

    .ap-chip-row { gap: .4rem; }
    .ap-exec-head { gap: .5rem; }
}
