/*
 * saidify site-specific layer.
 * Brand tokens (--gleif-*, --color-*, --font-*) come from tokens.css, which
 * loads before this file. No hardcoded hexes here — reference tokens or use
 * color-mix for tints. FLAG: marks values the brand deck does not cover.
 */

:root {
    /* FLAG: component spec — brand deck does not define a radius scale */
    --radius: 4px;
    --radius-lg: 8px;

    /* FLAG: brand deck has no mono stack */
    --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;

    /* FLAG: surface layering — brand deck gives --color-bg/surface only;
       we derive deeper surfaces from cyprus mixed with white */
    --color-surface-2: color-mix(in srgb, var(--gleif-cyprus) 6%, var(--color-bg));
    --color-surface-3: color-mix(in srgb, var(--gleif-cyprus) 12%, var(--color-bg));
    --color-border: color-mix(in srgb, var(--gleif-cyprus) 18%, var(--color-bg));
    --color-hover: color-mix(in srgb, var(--gleif-jade) 10%, var(--color-bg));

    /* State colors — map to brand where possible, FLAG where not */
    --color-success: var(--gleif-jade);        /* FLAG: no success token; jade reads as affirmative */
    --color-warning: var(--gleif-honey);
    --color-error: var(--gleif-lava);
    --color-info: var(--gleif-azure);

    /* FLAG: no shadow scale in brand; use cyprus-tinted translucency */
    --shadow-sm: 0 2px 8px color-mix(in srgb, var(--gleif-cyprus) 12%, transparent);
    --shadow-md: 0 4px 16px color-mix(in srgb, var(--gleif-cyprus) 18%, transparent);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: var(--line-height-body);
}

/* Header */
header {
    background: var(--color-surface);
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

header .logo {
    width: 40px;
    height: 40px;
}

header h1 {
    font-size: var(--font-size-h3);
    color: var(--color-accent-deep);
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.1em;
    line-height: var(--line-height-heading);
}

header .subtitle {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    margin-left: 0.5rem;
    padding-left: 1rem;
    border-left: 1px solid var(--color-border);
}

.header-btn {
    margin-left: auto;
    padding: 0.4rem 0.9rem;
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font: inherit;
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.header-btn:hover,
.header-btn:focus-visible {
    background: var(--color-hover);
    border-color: var(--color-accent-mid);
    outline: none;
}

.header-btn[aria-expanded="true"] {
    background: var(--color-accent-mid);
    border-color: var(--color-accent-mid);
    color: var(--color-text-inverse);
}

/* Main */
main {
    flex: 1;
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
}

/* Footer */
footer {
    background: var(--color-surface);
    padding: 0.75rem 2rem;
    border-top: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    flex-shrink: 0;
}

footer code {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--color-accent-deep);
}

/* Form */
.saidify-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: var(--color-surface);
    padding: 1.25rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

.form-label {
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
    font-size: var(--font-size-sm);
}

.drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 1rem;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface-2);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.drag-over {
    border-color: var(--color-accent-mid);
    background: var(--color-hover);
    outline: none;
}

.drop-text {
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.drop-text code {
    font-family: var(--font-mono);
    color: var(--color-accent-deep);
}

.drop-hint {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.json-input {
    width: 100%;
    min-height: 220px;
    padding: 0.75rem 1rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    line-height: 1.5;
    resize: vertical;
    tab-size: 2;
}

.json-input:focus {
    outline: none;
    border-color: var(--color-accent-mid);
}

.upload-error {
    color: var(--color-error);
    font-size: var(--font-size-sm);
}

.upload-error:empty {
    display: none;
}

.json-input::placeholder {
    color: var(--color-text-muted);
    opacity: 0.6;
}

.form-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
}

.control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.label-select {
    padding: 0.4rem 0.6rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    cursor: pointer;
}

.label-select:focus {
    outline: none;
    border-color: var(--color-accent-mid);
}

.checkbox-control {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.checkbox-control input[type="checkbox"] {
    accent-color: var(--color-accent-mid);
    cursor: pointer;
}

.primary-btn {
    margin-left: auto;
    padding: 0.5rem 1.5rem;
    background: var(--color-accent-mid);
    color: var(--color-text-inverse);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: var(--font-weight-medium);
    font-size: var(--font-size-body);
    transition: background 0.2s;
}

.primary-btn:hover {
    background: var(--color-accent-deep);
}

.primary-btn:disabled {
    background: var(--color-text-muted);
    cursor: not-allowed;
}

/* Result */
.result-section {
    min-height: 8rem;
}

.result-placeholder {
    padding: 2rem;
    text-align: center;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    background: var(--color-surface-2);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-lg);
}

.result-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--color-surface-2);
    border-bottom: 1px solid var(--color-border);
}

.result-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex: 1;
}

.badge {
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-sm);
    background: var(--color-bg);
}

.badge code {
    font-family: var(--font-mono);
    color: var(--color-accent-deep);
}

.said-value {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--color-accent-deep);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.copy-btn {
    padding: 0.35rem 0.75rem;
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: var(--font-size-sm);
    transition: all 0.2s;
    flex-shrink: 0;
}

.copy-btn:hover {
    background: var(--color-accent-mid);
    border-color: var(--color-accent-mid);
    color: var(--color-text-inverse);
}

.copy-btn.copied {
    background: var(--color-success);
    border-color: var(--color-success);
    color: var(--color-text-inverse);
}

.result-output {
    margin: 0;
    padding: 1rem;
    background: var(--color-bg);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    line-height: 1.5;
    white-space: pre;
}

.result-output code {
    font-family: inherit;
    color: var(--color-text);
}

/* Error — saturated brand fill, white text (brand rule 5) */
.error-card {
    background: var(--gleif-lava);
    color: var(--color-text-inverse);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-lg);
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
}

/* HTMX loading indicator */
.htmx-request .primary-btn {
    opacity: 0.7;
    pointer-events: none;
}

/* Spec drawer */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: color-mix(in srgb, var(--gleif-cyprus) 45%, transparent);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 90;
}

.drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: min(640px, 100vw);
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.22s ease;
    z-index: 100;
}

.drawer.open {
    transform: translateX(0);
}

/* Vertical pull-out tab on the left edge of the drawer */
.drawer-tab {
    position: absolute;
    top: 50%;
    left: -1.75rem;
    transform: translateY(-50%);
    width: 1.75rem;
    height: 5.5rem;
    padding: 0;
    background: var(--color-accent-deep);
    color: var(--color-text-inverse);
    border: none;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    cursor: pointer;
    font: inherit;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    box-shadow: -2px 2px 8px color-mix(in srgb, var(--gleif-cyprus) 22%, transparent);
    transition: background 0.15s ease;
}

.drawer-tab:hover,
.drawer-tab:focus-visible {
    background: var(--color-accent-mid);
    outline: none;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-2);
    flex-shrink: 0;
}

.drawer-titles {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 0;
}

.drawer-eyebrow {
    font-size: 0.6875rem;
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.drawer-title {
    font-size: var(--font-size-h3);
    color: var(--color-accent-deep);
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-heading);
}

.drawer-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
}

.drawer-close:hover {
    color: var(--color-text);
    background: var(--color-hover);
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1.5rem 2rem;
    color: var(--color-text);
}

/* Prose layer for the rendered spec markdown.
   FLAG: heading sizes below h4 and body spacing not in brand deck;
   derived for legibility within brand color tokens. */
.prose h1,
.prose h2,
.prose h3,
.prose h4 {
    color: var(--color-accent-deep);
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-heading);
    margin: 1.5rem 0 0.5rem;
}

.prose > h1:first-child,
.prose > h2:first-child { margin-top: 0; }

.prose h1 { font-size: var(--font-size-h2); }
.prose h2 { font-size: var(--font-size-h3); }
.prose h3 { font-size: var(--font-size-h4); }
.prose h4 { font-size: 1rem; }

.prose p {
    line-height: var(--line-height-body);
    margin: 0 0 0.75rem;
}

.prose ul,
.prose ol {
    margin: 0.5rem 0 0.75rem 1.5rem;
    line-height: var(--line-height-body);
}

.prose li { margin-bottom: 0.25rem; }

.prose a {
    color: var(--color-accent-mid);
    text-decoration: underline;
}

.prose a:hover { color: var(--color-accent-deep); }

.prose code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--color-surface-2);
    padding: 0.05rem 0.3rem;
    border-radius: var(--radius);
    color: var(--color-accent-deep);
}

.prose pre {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.75rem 0.9rem;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.5;
    margin: 0.75rem 0;
}

.prose pre code {
    background: none;
    padding: 0;
    color: var(--color-text);
    font-size: inherit;
}

.prose table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0 1rem;
    font-size: var(--font-size-sm);
}

.prose th,
.prose td {
    border: 1px solid var(--color-border);
    padding: 0.375rem 0.625rem;
    text-align: left;
    vertical-align: top;
}

.prose th {
    background: color-mix(in srgb, var(--color-accent-mid) 14%, var(--color-surface));
    color: var(--color-accent-deep);
    font-weight: var(--font-weight-semibold);
}

.prose tr:nth-child(even) td {
    background: var(--color-surface-2);
}

.prose blockquote {
    border-left: 3px solid var(--color-accent-mid);
    padding-left: 1rem;
    margin: 0.75rem 0;
    color: var(--color-text-muted);
}

.prose hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 1.5rem 0;
}

/* Walkthrough modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: color-mix(in srgb, var(--gleif-cyprus) 45%, transparent);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 110;
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -48%);
    width: min(720px, calc(100vw - 2rem));
    max-height: min(90vh, 780px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 120;
}

.modal.open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-2);
    flex-shrink: 0;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1.5rem;
}

.modal-footer {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface-2);
    flex-shrink: 0;
}

.modal-footer .secondary-btn,
.modal-footer .primary-btn {
    flex-shrink: 0;
}

.secondary-btn {
    padding: 0.4rem 0.9rem;
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font: inherit;
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.secondary-btn:hover:not(:disabled),
.secondary-btn:focus-visible:not(:disabled) {
    background: var(--color-hover);
    border-color: var(--color-accent-mid);
    outline: none;
}

.secondary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Step content — only one visible at a time; JS flips aria-hidden */
.wt-step[aria-hidden="true"] {
    display: none;
}

.wt-step-head {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    margin-bottom: 0.5rem;
}

.wt-step-num {
    font-size: 0.6875rem;
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.wt-step-title {
    font-size: var(--font-size-h4);
    color: var(--color-accent-deep);
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-heading);
}

.wt-hint {
    font-size: var(--font-size-sm);
    line-height: var(--line-height-body);
    color: var(--color-text);
    margin-bottom: 0.75rem;
}

.wt-code {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.75rem 0.9rem;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.55;
    margin-bottom: 0.5rem;
    /* Allow wrapping for long serialized strings so the SAID stays visible */
    white-space: pre-wrap;
    word-break: break-all;
}

.wt-code mark {
    background: color-mix(in srgb, var(--color-warning) 55%, transparent);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

.wt-caption {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    font-style: italic;
}

.wt-dots {
    display: flex;
    gap: 0.4rem;
    flex: 1;
    justify-content: center;
}

.wt-dot {
    width: 0.625rem;
    height: 0.625rem;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.wt-dot:hover,
.wt-dot:focus-visible {
    border-color: var(--color-accent-mid);
    outline: none;
}

.wt-dot.active {
    background: var(--color-accent-mid);
    border-color: var(--color-accent-mid);
    transform: scale(1.15);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-surface);
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

/* Responsive */
@media (max-width: 700px) {
    main {
        padding: 1rem;
    }

    header {
        padding: 1rem;
    }

    .form-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .primary-btn {
        margin-left: 0;
    }

    .result-header {
        flex-wrap: wrap;
    }
}
