/* UI components. Colours come from the theme tokens in themes.css. */

/* ---------- Header ---------- */
.app-header {
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0 1rem;
    border-bottom: 1px solid var(--border);
}

.app-title {
    text-align: center;
}

.app-title h1 {
    font-size: clamp(1.1rem, 5.5vw, 1.5rem);
    font-weight: 700;
    line-height: 1.25;
    text-transform: var(--title-transform);
    letter-spacing: var(--title-spacing);
    background-image: linear-gradient(90deg, var(--accent-text), var(--accent-text-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    display: inline-block;
}

.app-title p {
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--muted);
}

.icon-btn {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    transition: background-color 0.15s, border-color 0.15s;
}
.icon-btn:hover {
    background: var(--surface);
    border-color: var(--border);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 48px;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    transition: transform 0.15s, filter 0.2s;
}
.btn:active:not(:disabled) {
    transform: scale(0.98);
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background-image: linear-gradient(90deg, var(--accent), var(--accent-2));
    color: var(--on-accent);
    box-shadow: var(--glow);
}
.btn-primary:hover:not(:disabled) {
    filter: brightness(1.1);
}

.btn-secondary {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}
.btn-secondary:hover:not(:disabled) {
    border-color: var(--accent-text);
}

.btn-ghost {
    min-height: 36px;
    padding: 0.375rem 0.625rem;
    background: transparent;
    color: var(--accent-text);
    font-size: 0.875rem;
    font-weight: 600;
}
.btn-ghost:hover:not(:disabled) {
    background: color-mix(in srgb, var(--accent-text) 14%, transparent);
}

.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}
.btn-danger[data-armed="true"] {
    background: var(--danger);
    color: var(--bg);
}

/* Copy / link button "done" state */
.btn[data-state="done"] {
    background: var(--success);
    color: var(--on-success);
    border-color: transparent;
    box-shadow: none;
}

/* ---------- Fields ---------- */
.field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    min-width: 0;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.field-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
}

.input {
    width: 100%;
    min-height: 48px;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--field);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder {
    color: var(--muted);
    opacity: 0.8;
}
.input:focus {
    outline: none;
    border-color: var(--ring);
    box-shadow: 0 0 0 2px var(--ring);
}
.input--surface {
    background: var(--surface);
}
.input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

select.input {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 2.5rem;
    cursor: pointer;
}
select.input option,
select.input optgroup {
    background: var(--surface);
    color: var(--text);
}

.select-wrap {
    position: relative;
}
.select-wrap::after {
    content: "";
    position: absolute;
    right: 1.1rem;
    top: 50%;
    width: 0.5rem;
    height: 0.5rem;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
}

textarea.input {
    resize: vertical;
    line-height: 1.5;
}
.mono {
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

/* ---------- Picker ---------- */
.picker {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.picker-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* ---------- Cards ---------- */
.card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    background: var(--surface);
    background: color-mix(in srgb, var(--surface) 72%, transparent);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
@media (min-width: 40rem) {
    .card {
        padding: 1.25rem;
    }
}

.card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}
.card-head h2 {
    font-size: 1.0625rem;
    font-weight: 700;
    line-height: 1.3;
}
.card-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.25rem;
    flex: none;
}

.fields {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* An empty issues slot would still add a flex gap inside the card. */
#formIssues:empty {
    display: none;
}

/* ---------- How to use ---------- */
.howto {
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent-text);
    border-radius: var(--radius);
    background: var(--field);
}
.howto[hidden] {
    display: none;
}
.howto summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 0.9rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--accent-text);
    cursor: pointer;
    list-style: none;
}
.howto summary::-webkit-details-marker {
    display: none;
}
.howto summary:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
    border-radius: var(--radius);
}
.howto summary [data-icon] svg {
    width: 1rem;
    height: 1rem;
    display: block;
}
.howto summary::after {
    content: "";
    margin-left: auto;
    width: 0.45rem;
    height: 0.45rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.15s;
}
.howto[open] summary::after {
    transform: rotate(-135deg);
}
.howto p {
    margin: 0;
    padding: 0 0.9rem 0.85rem;
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--muted);
    white-space: pre-line;
}

/* ---------- Output ---------- */
.output {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.output-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
}
.output-head h2 {
    font-size: 0.875rem;
    font-weight: 600;
}
.output-text {
    min-height: 160px;
    padding: 1rem;
    resize: none;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.18);
}
.output-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}
@media (min-width: 30rem) {
    .output-actions {
        grid-template-columns: 2fr 1fr;
    }
}

/* ---------- Callouts / notices ---------- */
.callout {
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: var(--radius);
    background: var(--field);
    font-size: 0.875rem;
}
.callout[data-level="error"] {
    border-left-color: var(--danger);
}
.callout[data-level="warning"] {
    border-left-color: var(--warning);
}
.callout[data-level="ok"] {
    border-left-color: var(--success);
}
.callout ul {
    margin-top: 0.375rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.callout li {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}
.callout li::before {
    content: "•";
    color: var(--muted);
}
.callout li[data-level="error"]::before {
    content: "✕";
    color: var(--danger);
}
.callout li[data-level="warning"]::before {
    content: "⚠";
    color: var(--warning);
}
.callout-title {
    font-weight: 700;
}

.notice-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}

#notices:empty {
    display: none;
}

/* ---------- Dialogs ---------- */
dialog {
    padding: 0;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}
dialog::backdrop {
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(2px);
}

dialog.modal {
    width: min(42rem, calc(100vw - 2rem));
    max-width: none;
    max-height: min(90dvh, 46rem);
    border-radius: var(--radius-lg);
}
dialog.modal[open] {
    display: flex;
    flex-direction: column;
    animation: pop-in 0.18s ease-out;
}

dialog.drawer {
    margin: 0;
    inset: 0 auto 0 0;
    width: min(22rem, 88vw);
    height: 100dvh;
    max-width: none;
    max-height: none;
    border-width: 0 1px 0 0;
    border-radius: 0;
}
dialog.drawer[open] {
    display: flex;
    flex-direction: column;
    animation: drawer-in 0.2s ease-out;
}

.modal-inner,
.drawer-inner {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding: 1.25rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.modal-header h2 {
    font-size: 1.125rem;
    font-weight: 700;
}

.modal-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.spacer {
    flex: 1;
}

@keyframes drawer-in {
    from { transform: translateX(-100%); }
    to { transform: none; }
}
@keyframes pop-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

/* ---------- Menu ---------- */
.menu-section {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}
.menu-heading {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}
.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    min-height: 44px;
    padding: 0.5rem 0.625rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    text-align: left;
    font-weight: 600;
    transition: background-color 0.15s, border-color 0.15s;
}
.menu-item:hover:not(:disabled) {
    background: var(--field);
    border-color: var(--border);
}
.menu-item:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.menu-item .icon {
    color: var(--accent-text);
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}
.theme-option {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    padding: 0.375rem;
    border: 2px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
}
.theme-option:hover {
    background: var(--field);
}
.theme-option[aria-pressed="true"] {
    border-color: var(--accent-text);
    background: color-mix(in srgb, var(--accent-text) 12%, transparent);
}
/* data-theme on this element scopes the theme tokens to the preview only */
.theme-preview {
    position: relative;
    display: block;
    height: 2.75rem;
    padding: 0.375rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background-color: var(--bg);
    background-image: var(--bg-image);
}
.theme-preview::before {
    content: "";
    display: block;
    height: 55%;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
}
.theme-preview::after {
    content: "";
    position: absolute;
    left: 0.375rem;
    right: 0.375rem;
    bottom: 0.375rem;
    height: 0.3rem;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* ---------- Help / About ---------- */
.syntax-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.syntax-table th,
.syntax-table td {
    padding: 0.5rem 0.5rem 0.5rem 0;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}
.syntax-table th {
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}
.prose {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    font-size: 0.9375rem;
}
.prose ul {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    padding-left: 1.1rem;
    list-style: disc;
}
.prose h3 {
    font-size: 0.9375rem;
    font-weight: 700;
}

/* ---------- Editor ---------- */
.editor-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.editor-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.5rem 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--field);
}
.editor-item-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.editor-item-text strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.editor-item-actions {
    display: flex;
    flex: none;
}
.editor-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.insert-bar {
    display: flex;
    align-items: center;
    gap: 0.125rem;
    font-size: 0.8125rem;
    color: var(--muted);
}
.insert-bar .btn-ghost {
    min-height: 30px;
    padding: 0.125rem 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
}
.preview-box {
    padding: 0.75rem 0.875rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
}
.preview-box h3 {
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.25rem;
}
.preview-box p {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    inset: auto auto 1.5rem 50%;
    transform: translateX(-50%);
    margin: 0;
    width: max-content;
    height: auto;
    max-width: calc(100vw - 2rem);
    padding: 0.625rem 1rem;
    border: 0;
    border-radius: 999px;
    background: var(--text);
    color: var(--bg);
    font-size: 0.875rem;
    font-weight: 600;
    box-shadow: var(--shadow);
    pointer-events: none;
    overflow: visible;
}
.toast:empty {
    display: none;
}
.toast[data-kind="error"] {
    background: var(--danger);
    color: #1a0505;
}

/* ---------- Small screens ---------- */
@media (max-width: 30rem) {
    .picker-row,
    .field-row {
        grid-template-columns: 1fr;
    }
    .card-head {
        flex-direction: column;
    }
    .card-actions {
        justify-content: flex-start;
    }
}
