/* Design tokens and base element styles, per req02_0005 section 2.
   Feature-agnostic: lives in common/ so any feature stylesheet can rely on
   these custom properties without importing another feature's CSS. Feature
   stylesheets must define no raw colour, spacing or radius values of their
   own - they reference these tokens. */

:root {
    /* Brand */
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-primary-active: #1e40af;
    --color-primary-soft: #eff6ff;
    --color-primary-ring: rgba(37, 99, 235, 0.16);

    /* Backgrounds */
    --color-page: #f6f8fb;
    --color-surface: #ffffff;
    --color-surface-secondary: #f8fafc;
    --color-surface-hover: #f1f5f9;
    --color-overlay: rgba(15, 23, 42, 0.48);

    /* Text */
    --color-text-primary: #0f172a;
    --color-text-secondary: #64748b;
    --color-text-muted: #94a3b8;
    --color-text-disabled: #cbd5e1;
    --color-text-on-primary: #ffffff;

    /* Borders */
    --color-border: #e2e8f0;
    --color-border-strong: #cbd5e1;
    --color-border-focus: #2563eb;

    /* Semantic states */
    --color-success: #16a34a;
    --color-success-soft: #f0fdf4;
    --color-warning: #d97706;
    --color-warning-soft: #fffbeb;
    --color-danger: #dc2626;
    --color-danger-hover: #b91c1c;
    --color-danger-soft: #fef2f2;
    --color-recording: #ef4444;
    --color-recording-soft: #fef2f2;

    /* Typography */
    --font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-page-title: clamp(1.5rem, 3vw, 1.875rem);

    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    --line-height-tight: 1.2;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.65;

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    /* Dimensions.
       Tightened against req02_0005 section 2, which was drawn for a roomier
       screen than this one turned out to be: controls, avatars and the
       composer were reading as oversized once the page was assembled. The
       token names are unchanged, so anything referring to them scales with
       this one edit. */
    --page-max-width: 60rem;
    --control-height: 2.25rem;
    --button-height: 2.25rem;
    --icon-button-size: 2rem;
    --avatar-size: 2rem;
    --composer-textarea-min-height: 5.5rem;
    --attachment-card-width: 9.5rem;
    --attachment-card-height: 6rem;
    --map-height: 20rem;

    /* Border radii - also pulled in, since large radii read as large
       elements even when the box itself is small. */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 0.875rem;
    --radius-pill: 999px;

    /* Shadows */
    --shadow-xs:
        0 1px 2px rgba(15, 23, 42, 0.04);

    --shadow-sm:
        0 1px 3px rgba(15, 23, 42, 0.06),
        0 1px 2px rgba(15, 23, 42, 0.04);

    --shadow-md:
        0 8px 24px rgba(15, 23, 42, 0.07);

    --shadow-focus:
        0 0 0 4px var(--color-primary-ring);

    /* Motion */
    --transition-fast: 120ms ease;
    --transition-normal: 180ms ease;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    background: var(--color-page);
    color: var(--color-text-primary);
    font-family: var(--font-family);
}

body {
    margin: 0;
    min-width: 20rem;
    background: var(--color-page);
    font-size: var(--font-size-md);
    line-height: var(--line-height-normal);
}

button,
input,
textarea,
select {
    color: inherit;
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled,
input:disabled,
textarea:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

/* ---------------------------------------------------------------------------
   Shared surface (req02_0005 section 4)
   --------------------------------------------------------------------------- */

.surface-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
}

.surface-card--interactive {
    transition:
        border-color var(--transition-normal),
        box-shadow var(--transition-normal),
        transform var(--transition-normal);
}

.surface-card--interactive:hover {
    border-color: var(--color-border-strong);
    box-shadow: var(--shadow-md);
}

/* ---------------------------------------------------------------------------
   Buttons (req02_0005 section 6)
   --------------------------------------------------------------------------- */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--button-height);
    padding-inline: var(--space-4);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    line-height: 1;
    text-decoration: none;
    transition:
        background-color var(--transition-fast),
        border-color var(--transition-fast),
        color var(--transition-fast),
        box-shadow var(--transition-fast),
        transform var(--transition-fast);
}

.button:active:not(:disabled) {
    transform: translateY(1px);
}

.button--primary {
    background: var(--color-primary);
    color: var(--color-text-on-primary);
    box-shadow: var(--shadow-xs);
}

.button--primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.button--primary:active:not(:disabled) {
    background: var(--color-primary-active);
}

.button--secondary {
    background: var(--color-surface);
    border-color: var(--color-border);
    color: var(--color-text-primary);
}

.button--secondary:hover:not(:disabled) {
    background: var(--color-surface-hover);
    border-color: var(--color-border-strong);
}

.icon-button {
    display: inline-grid;
    width: var(--icon-button-size);
    height: var(--icon-button-size);
    padding: 0;
    place-items: center;
    background: transparent;
    border: 0;
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    text-decoration: none;
    transition:
        background-color var(--transition-fast),
        color var(--transition-fast);
}

.icon-button:hover:not(:disabled) {
    background: var(--color-primary-soft);
    color: var(--color-primary);
}

.icon-button--danger:hover:not(:disabled) {
    background: var(--color-danger-soft);
    color: var(--color-danger);
}

.icon-button svg {
    display: block;
}

/* ---------------------------------------------------------------------------
   Form primitives (req02_0005 section 13)
   --------------------------------------------------------------------------- */

.form-field {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: var(--space-1);
}

.form-field__label {
    color: var(--color-text-secondary);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
}

.form-control {
    width: 100%;
    height: var(--control-height);
    padding: 0 var(--space-3);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-primary);
    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast);
}

.form-control::placeholder {
    color: var(--color-text-muted);
}

.form-control:hover {
    border-color: var(--color-border-strong);
}

.form-control:focus {
    border-color: var(--color-border-focus);
    outline: none;
    box-shadow: var(--shadow-focus);
}

.form-message {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    margin: 0;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
}

.form-message:empty {
    display: none;
}

.form-message--error {
    background: var(--color-danger-soft);
    color: var(--color-danger);
}

.form-message--success {
    background: var(--color-success-soft);
    color: var(--color-success);
}

/* ---------------------------------------------------------------------------
   Loading states (req02_0005 section 19)
   --------------------------------------------------------------------------- */

.skeleton {
    overflow: hidden;
    background:
        linear-gradient(
            90deg,
            var(--color-surface-secondary) 25%,
            var(--color-surface-hover) 50%,
            var(--color-surface-secondary) 75%
        );
    background-size: 200% 100%;
    border-radius: var(--radius-sm);
    animation: skeleton-loading 1.4s infinite;
}

@keyframes skeleton-loading {
    from {
        background-position: 200% 0;
    }

    to {
        background-position: -200% 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .skeleton {
        animation: none;
    }
}

/* ---------------------------------------------------------------------------
   Toasts (req02_0005 section 18)
   --------------------------------------------------------------------------- */

.toast-region {
    position: fixed;
    z-index: 1000;
    top: var(--space-5);
    right: var(--space-5);
    display: flex;
    width: min(24rem, calc(100vw - 2 * var(--space-4)));
    flex-direction: column;
    gap: var(--space-3);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    pointer-events: auto;
}

.toast--success {
    border-left: 0.25rem solid var(--color-success);
}

.toast--error {
    border-left: 0.25rem solid var(--color-danger);
}

@media (max-width: 48rem) {
    .toast-region {
        top: var(--space-4);
        right: var(--space-4);
        left: var(--space-4);
        width: auto;
    }
}
