/* ── WebWatch shared component layer ──
   Canonical buttons, form controls, and field scaffolding for every page.
   Loaded in base.html right after global.css. Page stylesheets may extend
   these components but must not redefine them. */

/* ── Buttons ──
   One vocabulary: .ww-btn (primary, filled indigo), .ww-btn-ghost (neutral
   surface), .ww-btn-danger (destructive), .ww-mini-btn (compact row action).
   States: hover, focus-visible, active, disabled, loading. */

.ww-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    padding: 12px 18px;
    border-radius: 12px;
    border: 1px solid transparent;

    background: linear-gradient(135deg, #4f46e5, #4338ca);
    color: #ffffff;

    font-family: inherit;
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1.2;
    letter-spacing: 0.2px;
    text-decoration: none;
    white-space: nowrap;

    cursor: pointer;
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.25);
    transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1),
                filter 0.18s ease,
                background 0.18s ease,
                border-color 0.18s ease,
                box-shadow 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.ww-btn svg {
    flex-shrink: 0;
}

.ww-btn:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(79, 70, 229, 0.32);
}

.ww-btn:active {
    transform: translateY(0);
    filter: brightness(0.97);
}

.ww-btn:focus-visible {
    outline: 2px solid rgba(6, 182, 212, 0.65);
    outline-offset: 3px;
}

.ww-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    filter: none;
    box-shadow: none;
}

/* Alias kept so existing markup (.ww-btn-primary) stays valid. */
.ww-btn.ww-btn-primary {
    background: linear-gradient(135deg, #4f46e5, #4338ca);
    color: #fff;
}

.ww-btn.ww-btn-ghost {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
    box-shadow: 0 4px 12px rgba(16, 24, 40, 0.06);
}

.ww-btn.ww-btn-ghost:hover {
    background: var(--glass-hover);
    border-color: var(--brand);
    filter: none;
}

.ww-btn.ww-btn-danger {
    background: var(--surface);
    border-color: rgba(239, 68, 68, 0.35);
    color: var(--red-deep);
    box-shadow: none;
}

.ww-btn.ww-btn-danger:hover {
    background: rgba(239, 68, 68, 0.08);
    border-color: var(--red);
    filter: none;
}

/* Busy state: spinner replaces intent ambiguity while a form submits. */
.ww-btn-loading {
    position: relative;
    pointer-events: none;
}

.ww-btn-loading::after {
    content: "";
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-right-color: transparent;
    animation: ww-btn-spin 0.7s linear infinite;
}

@keyframes ww-btn-spin {
    to { transform: rotate(360deg); }
}

/* Compact row action: pause/test/delete on hooks, status page rows. */
.ww-mini-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;

    padding: 7px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);

    background: var(--surface);
    color: var(--text);

    font-family: inherit;
    font-weight: 700;
    font-size: 0.82rem;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;

    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ww-mini-btn:hover {
    background: var(--glass-hover);
    border-color: var(--brand);
}

.ww-mini-btn:focus-visible {
    outline: 2px solid rgba(6, 182, 212, 0.65);
    outline-offset: 2px;
}

.ww-mini-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.ww-mini-btn.danger {
    color: var(--red-deep);
}

.ww-mini-btn.danger:hover {
    background: rgba(239, 68, 68, 0.10);
    border-color: rgba(239, 68, 68, 0.4);
}

/* ── Form controls ──
   .ww-input covers text, url, email, number, select, and textarea. */

.ww-input {
    appearance: none;
    width: 100%;
    padding: 11px 14px;

    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text);

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    outline: none;

    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.ww-input::placeholder {
    color: var(--muted);
    opacity: 0.75;
}

.ww-input:hover {
    border-color: color-mix(in srgb, var(--brand) 35%, var(--border));
}

.ww-input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15);
}

.ww-input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

textarea.ww-input {
    resize: vertical;
    min-height: 96px;
    line-height: 1.5;
}

select.ww-input {
    padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    cursor: pointer;
}

/* number spinners look off against the rounded style; hide, keep keyboard */
input[type="number"].ww-input::-webkit-outer-spin-button,
input[type="number"].ww-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"].ww-input {
    -moz-appearance: textfield;
}

/* ── Field scaffolding: label + control + hint ── */

.ww-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 14px 16px;
}

.ww-field-full {
    grid-column: 1 / -1;
}

.ww-field label {
    display: block;
    margin-bottom: 6px;

    font-size: 0.78rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ww-field .hint {
    margin: 6px 0 0;
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--muted);
}

.ww-fieldset {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    margin: 0;
}

.ww-fieldset legend {
    padding: 0 6px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ww-check-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 8px;
}

.ww-check {
    display: flex;
    align-items: center;
    gap: 9px;

    padding: 6px 8px;
    border-radius: 8px;

    font-size: 0.92rem;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s ease;
}

.ww-check:hover {
    background: var(--glass-hover);
}

.ww-check input[type="checkbox"] {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    accent-color: var(--brand);
    cursor: pointer;
}

.ww-check span {
    overflow-wrap: anywhere;
}

/* ── Key-value rows (cert details, incident summaries, ack receipt) ── */

.ww-kvlist {
    display: grid;
    gap: 8px;
    font-size: 0.92rem;
}

.ww-kvrow {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.ww-kvrow > .k {
    color: var(--muted);
    flex-shrink: 0;
}

.ww-kvrow > .v {
    text-align: right;
    overflow-wrap: anywhere;
    min-width: 0;
    color: var(--text);
}

/* ── Inline code / embed snippet with copy affordance ── */

.ww-snippet {
    display: flex;
    align-items: center;
    gap: 8px;

    margin-top: 8px;
    padding: 9px 12px;

    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
}

.ww-snippet code {
    flex: 1 1 auto;
    min-width: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.78rem;
    color: var(--text);
    overflow-wrap: anywhere;
}

.ww-copy-chip {
    appearance: none;
    flex-shrink: 0;

    display: inline-flex;
    align-items: center;
    gap: 5px;

    padding: 5px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);

    background: var(--surface);
    color: var(--muted);

    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 700;

    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.ww-copy-chip:hover {
    color: var(--text);
    border-color: var(--brand);
}

.ww-copy-chip:focus-visible {
    outline: 2px solid rgba(6, 182, 212, 0.65);
    outline-offset: 2px;
}

.ww-copy-chip.copied {
    color: var(--green-deep);
    border-color: var(--green);
}

/* ── Dark mode ── */

@media (prefers-color-scheme: dark) {
    .ww-btn.ww-btn-ghost {
        box-shadow: none;
    }

    .ww-input {
        background: rgba(255, 255, 255, 0.05);
    }

    select.ww-input {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23b8bdc9' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    }

    select.ww-input option {
        background: #131a2e;
        color: var(--text);
    }

    .ww-snippet {
        background: rgba(255, 255, 255, 0.04);
    }
}

/* ── Reduced motion ── */

@media (prefers-reduced-motion: reduce) {
    .ww-btn,
    .ww-mini-btn,
    .ww-input,
    .ww-check,
    .ww-copy-chip {
        transition: none;
    }

    .ww-btn:hover {
        transform: none;
    }

    .ww-btn-loading::after {
        animation-duration: 1.5s;
    }
}

@media (max-width: 640px) {
    .ww-form-grid {
        grid-template-columns: 1fr;
    }
}
