/* Roster.Ui application components: page structure, stats, data rows, forms, modal.
   Used by the organizer console. Tokens only (css/tokens.css); sizes from the mockups in docs/design. */

/* ---------- Page structure ---------- */
.ds-page {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    width: 100%;
    max-width: 1200px;
}

.ds-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-3) var(--space-4);
}

.ds-page-heading {
    flex: 1 1 280px;
    min-width: 0;
}

.ds-page-title {
    margin: 0;
    font: var(--text-h2);
    font-weight: 800;
    letter-spacing: var(--tracking-h2);
}

.ds-page-desc {
    margin: var(--space-1) 0 0;
    color: var(--color-ink-2);
    font: var(--text-body);
}

.ds-page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.ds-section-title {
    margin: 0;
    font: var(--text-body-l);
    font-weight: 800;
}

@media (min-width: 1024px) {
    .ds-page-title {
        font: var(--text-h1);
        letter-spacing: var(--tracking-h1);
    }
}

/* ---------- Stats ---------- */
.ds-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
    margin: 0;
    padding: 0;
    list-style: none;
}

.ds-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-4);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-l);
    background: var(--color-surface);
}

.ds-stat__value {
    font: var(--text-h2);
    font-weight: 800;
}

.ds-stat__label {
    color: var(--color-ink-2);
    font: var(--text-small);
}

.ds-stat__label--ok { color: var(--color-success); font-weight: 700; }
.ds-stat__label--wait { color: var(--color-warning); font-weight: 700; }
.ds-stat__label--no { color: var(--color-danger); font-weight: 700; }

@media (min-width: 1024px) {
    .ds-stats {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .ds-stat {
        padding: var(--space-5);
    }

    .ds-stat__value {
        font: var(--text-h1);
        font-weight: 800;
        letter-spacing: var(--tracking-h1);
    }
}

/* ---------- Panels ---------- */
.ds-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-l);
    background: var(--color-surface);
}

.ds-panels {
    display: grid;
    gap: var(--space-3);
}

@media (min-width: 1024px) {
    .ds-panels--2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .ds-panel {
        padding: var(--space-5);
    }
}

.ds-todo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--color-line);
}

.ds-todo > i {
    font-size: 1.25rem;
    color: var(--color-warning);
}

.ds-todo > span {
    flex: 1;
    min-width: 0;
}

/* ---------- Data rows ----------
   A list of rows. On phones every row is a card; from 1024 px the rows line up in columns
   (set --ds-row-columns on the list) under a header row. */
.ds-rows {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.ds-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-3);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-m);
    background: var(--color-surface);
}

.ds-row--muted {
    opacity: .6;
}

.ds-row--head {
    display: none;
}

.ds-row__main {
    display: flex;
    flex: 1 1 160px;
    flex-direction: column;
    min-width: 0;
}

.ds-row__title {
    font: var(--text-body);
    font-weight: 700;
    overflow-wrap: anywhere;
}

.ds-row__sub {
    color: var(--color-ink-2);
    font: var(--text-small);
    overflow-wrap: anywhere;
}

.ds-row__cell {
    color: var(--color-ink-2);
    font: var(--text-small);
}

.ds-row__cell--wide {
    flex-basis: 100%;
}

.ds-row__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-inline-start: auto;
}

@media (min-width: 1024px) {
    .ds-rows {
        gap: 0;
        overflow: hidden;
        border: 1px solid var(--color-line);
        border-radius: var(--radius-l);
        background: var(--color-surface);
    }

    .ds-row {
        display: grid;
        grid-template-columns: var(--ds-row-columns, 1fr);
        gap: var(--space-4);
        padding: var(--space-3) var(--space-4);
        border: 0;
        border-top: 1px solid var(--color-line);
        border-radius: 0;
    }

    .ds-row:first-child {
        border-top: 0;
    }

    .ds-row--head {
        display: grid;
        padding-block: var(--space-3);
        background: var(--color-surface-2);
        color: var(--color-ink-2);
        font: var(--text-small);
        font-weight: 700;
    }

    .ds-row__main {
        flex: initial;
    }

    .ds-row__cell--wide {
        flex-basis: auto;
    }

    .ds-row__actions {
        margin-inline-start: 0;
        justify-content: flex-end;
    }
}

/* ---------- Status with icon and word (never color alone) ---------- */
.ds-status {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font: var(--text-small);
    font-weight: 700;
}

.ds-status--ok { color: var(--color-success); }
.ds-status--wait { color: var(--color-warning); }
.ds-status--no { color: var(--color-danger); }
.ds-status--off { color: var(--color-ink-2); }

/* ---------- Forms ---------- */
.ds-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.ds-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.ds-select {
    display: block;
    width: 100%;
    min-height: var(--ds-control-m);
    padding: 0 var(--space-4);
    border: 1.5px solid var(--color-line-strong);
    border-radius: var(--radius-m);
    background-color: var(--color-surface);
    color: var(--color-ink);
    font: var(--text-body);
    font-weight: 600;
}

.ds-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    min-height: var(--target-min);
    font: var(--text-body);
}

.ds-switch input {
    appearance: none;
    flex: none;
    width: 48px;
    height: 28px;
    margin: 0;
    padding: 3px;
    border: 1.5px solid var(--color-line-strong);
    border-radius: var(--radius-pill);
    background: var(--color-surface-2);
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-standard);
}

.ds-switch input::before {
    content: "";
    display: block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--color-ink-2);
    transition: transform var(--dur-fast) var(--ease-standard);
}

.ds-switch input:checked {
    border-color: var(--color-on-lime);
    background: var(--color-lime);
}

.ds-switch input:checked::before {
    background: var(--color-on-lime);
    transform: translateX(20px);
}

.ds-stepper {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
}

.ds-stepper__value {
    min-width: 48px;
    font: var(--text-h2);
    font-weight: 800;
    text-align: center;
}

/* ---------- Modal (bottom sheet on phones, dialog from 640 px) ---------- */
.ds-modal {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: var(--z-dialog);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    max-height: 92dvh;
    overflow-y: auto;
    padding: var(--space-3) var(--space-5) max(var(--space-6), env(safe-area-inset-bottom));
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    background: var(--color-surface);
    color: var(--color-ink);
    box-shadow: var(--shadow-overlay);
    animation: ds-sheet-in var(--dur-slow) var(--ease-standard);
}

.ds-modal:focus {
    outline: none;
}

.ds-modal__title {
    margin: 0;
    font: var(--text-h3);
    font-weight: 800;
}

.ds-modal__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-3);
}

@media (min-width: 640px) {
    .ds-modal {
        inset: 50% auto auto 50%;
        width: min(480px, calc(100vw - var(--space-8)));
        padding: var(--space-6);
        border-radius: var(--radius-xl);
        transform: translate(-50%, -50%);
        animation: none;
    }
}

@media (max-width: 639px) {
    .ds-modal__actions > .ds-btn {
        flex: 1 1 auto;
    }
}

/* ---------- Action bar floating on phones ---------- */
.ds-fab {
    position: fixed;
    right: var(--space-5);
    bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
    z-index: var(--z-sticky);
    box-shadow: var(--shadow-lift);
}

@media (min-width: 1024px) {
    .ds-fab {
        display: none;
    }
}

.ds-link-field {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-1) var(--space-1) var(--space-4);
    border: 1.5px solid var(--color-line-strong);
    border-radius: var(--radius-m);
    background: var(--color-surface);
}

.ds-link-field > span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    font: var(--text-body);
    white-space: nowrap;
    text-overflow: ellipsis;
}

@media print {
    .ds-modal,
    .ds-scrim {
        display: none;
    }
}

/* A QR code must keep a fixed dark-on-white contrast in every theme or phones cannot scan it.
   This is the one place where the colors do not follow the active theme (see docs/design/open-questions.md). */
.ds-qr {
    display: inline-block;
    padding: var(--space-3);
    border-radius: var(--radius-m);
    background: #FFFFFF;
    color: #2B2D42;
    line-height: 0;
}

.ds-qr svg {
    width: min(240px, 60vw);
    height: auto;
}
