:root {
    --tms-bg: #e8eff3;
    --tms-panel: rgba(244, 247, 250, 0.94);
    --tms-panel-border: #9ab0c3;
    --tms-primary: #005e66;
    --tms-primary-soft: #0a7f89;
    --tms-primary-ink: #13345d;
    --tms-accent: #dbe8f4;
    --tms-danger: #be3b3b;
    --tms-danger-dark: #9f2e2e;
    --tms-text: #15324a;
    --tms-muted: #5e7285;
    --tms-line: #c4d3df;
    --tms-shadow: 0 20px 45px rgba(19, 52, 93, 0.14);
    --tms-radius-lg: 22px;
    --tms-radius-md: 16px;
    --tms-radius-sm: 12px;
    --tms-focus: 0 0 0 3px rgba(10, 127, 137, 0.2);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    font-family: "Segoe UI", "Trebuchet MS", sans-serif;
    color: var(--tms-text);
    background:
        radial-gradient(circle at top left, rgba(0, 94, 102, 0.16), transparent 30%),
        linear-gradient(180deg, #f6fbff 0%, var(--tms-bg) 100%);
}

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

.carrier-app {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px 22px 24px;
    gap: 18px;
}

.app-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 20px;
    align-items: center;
    padding: 24px 28px;
    border-radius: var(--tms-radius-lg);
    background: linear-gradient(135deg, #005e66 0%, #0f7e84 100%);
    color: #f4fbfd;
    box-shadow: var(--tms-shadow);
}

.app-header__brand {
    display: flex;
    align-items: center;
    gap: 24px;
    min-width: 0;
}

.app-header__logo {
    width: clamp(180px, 22vw, 280px);
    height: clamp(68px, 9vw, 104px);
    flex-shrink: 0;
    background-image: url("/static/piccini-logo.png");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

.app-header h1 {
    margin: 0;
    font-size: clamp(1.9rem, 2.7vw, 2.8rem);
    line-height: 1.04;
}

.app-header__eyebrow {
    margin: 0 0 10px;
    font-size: 0.78rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    opacity: 0.82;
}

.app-header__subtitle {
    margin: 12px 0 0;
    max-width: 820px;
    font-size: 1rem;
    line-height: 1.55;
    color: rgba(244, 251, 253, 0.82);
}

.app-header__meta {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    margin-left: auto;
}

.meta-pill {
    min-width: 120px;
    padding: 12px 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
}

.meta-pill__label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.82;
}

.meta-pill strong {
    font-size: 1.3rem;
}

.app-main {
    min-height: 0;
    flex: 1;
    display: flex;
}

.board {
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--tms-panel);
    border: 2px solid var(--tms-panel-border);
    border-radius: 18px;
    box-shadow: var(--tms-shadow);
    overflow: hidden;
}

.board__scroll {
    min-height: 0;
    flex: 1;
    padding: 14px 10px 14px 14px;
    overflow: auto;
    scrollbar-gutter: stable both-edges;
}

.board__scroll::-webkit-scrollbar {
    width: 14px;
    height: 14px;
}

.board__scroll::-webkit-scrollbar-thumb {
    border: 3px solid transparent;
    border-radius: 999px;
    background: rgba(19, 52, 93, 0.42);
    background-clip: padding-box;
}

.board__scroll::-webkit-scrollbar-track {
    background: rgba(219, 232, 244, 0.55);
}

.tables-grid {
    display: grid;
    gap: 18px;
}

.appointment-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 168px;
    gap: 16px;
    padding: 20px;
    border-radius: 18px;
    border: 1px solid rgba(154, 176, 195, 0.7);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(232, 239, 243, 0.85));
    box-shadow: 0 14px 28px rgba(19, 52, 93, 0.08);
}

.appointment-card__head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 12px;
}

.appointment-card__title {
    margin: 0;
    font-size: 1.2rem;
    color: var(--tms-primary-ink);
}

.appointment-card__subtitle {
    margin: 4px 0 0;
    color: var(--tms-muted);
    font-size: 0.92rem;
}

.appointment-card__badge {
    flex-shrink: 0;
    padding: 8px 12px;
    border-radius: 999px;
    background: var(--tms-accent);
    color: var(--tms-primary-ink);
    font-weight: 700;
    font-size: 0.84rem;
}

.appointment-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    overflow: visible;
    border-radius: 16px;
    border: 1px solid rgba(154, 176, 195, 0.65);
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 12px 26px rgba(19, 52, 93, 0.08);
}

.appointment-table th {
    padding: 12px 14px;
    text-align: left;
    background: linear-gradient(180deg, #0a6871 0%, #005e66 100%);
    color: #f4fbfd;
    font-size: 0.9rem;
    letter-spacing: 0.02em;
}

.appointment-table th:first-child {
    border-top-left-radius: 16px;
}

.appointment-table th:last-child {
    border-top-right-radius: 16px;
}

.table-header-cell {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.table-info {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.table-info__button {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.56);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    color: #f4fbfd;
    font-size: 0.86rem;
    font-weight: 700;
    cursor: help;
    transition:
        background-color 0.18s ease,
        border-color 0.18s ease,
        transform 0.18s ease,
        box-shadow 0.18s ease;
}

.table-info__button:hover,
.table-info__button:focus-visible {
    background: rgba(255, 255, 255, 0.28);
    border-color: rgba(255, 255, 255, 0.7);
    transform: translateY(-1px);
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18);
}

.table-info__panel {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    z-index: 30;
    top: calc(100% + 10px);
    left: 0;
    width: max-content;
    min-width: 320px;
    max-width: min(620px, calc(100vw - 80px));
    padding: 14px 16px;
    border-radius: 16px;
    background: rgba(38, 55, 74, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
    box-shadow: 0 18px 30px rgba(15, 25, 45, 0.28);
    line-height: 1.45;
    white-space: normal;
    text-align: left;
    transition: opacity 0.15s ease;
}

.table-info:hover .table-info__panel,
.table-info:focus-within .table-info__panel {
    visibility: visible;
    opacity: 1;
}

.table-info__title {
    display: block;
    margin-bottom: 8px;
    font-size: 0.76rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.76);
}

.table-info__list {
    margin: 0;
    padding-left: 18px;
    font-size: 0.92rem;
}

.table-info__list li + li {
    margin-top: 6px;
}

.table-info__empty {
    margin: 0;
}

.appointment-table td {
    padding: 14px;
    vertical-align: middle;
    border-top: 1px solid rgba(196, 211, 223, 0.8);
    background: rgba(255, 255, 255, 0.78);
}

.appointment-table tbody tr:last-child td:first-child {
    border-bottom-left-radius: 16px;
}

.appointment-table tbody tr:last-child td:last-child {
    border-bottom-right-radius: 16px;
}

.appointment-table tbody tr:first-child td {
    border-top: 0;
}

.appointment-table tbody tr:hover td {
    background: rgba(219, 232, 244, 0.44);
}

.td-ordine {
    white-space: pre-line;
    line-height: 1.45;
}

.td-fascia-oraria {
    min-width: 220px;
    max-width: 220px;
    font-weight: 600;
    color: var(--tms-primary-ink);
}

.select-cell {
    width: 110px;
    text-align: center;
}

.appointment-card__actions {
    display: flex;
    align-items: center;
    justify-content: center;
}

.cancel-button,
#confirm-button {
    border: 1px solid transparent;
    border-radius: 18px;
    cursor: pointer;
    transition:
        transform 0.18s ease,
        border-color 0.18s ease,
        box-shadow 0.18s ease,
        background-color 0.18s ease;
    box-shadow: 0 12px 24px rgba(19, 52, 93, 0.16);
}

.cancel-button {
    width: 100%;
    min-height: 88px;
    padding: 12px 10px;
    white-space: pre-line;
    background: linear-gradient(180deg, var(--tms-danger) 0%, var(--tms-danger-dark) 100%);
    border-color: rgba(122, 28, 28, 0.6);
    color: #fff;
    font-weight: 700;
    line-height: 1.2;
}

.cancel-button:hover,
#confirm-button:hover {
    transform: translateY(-1px);
}

.cancel-button:hover {
    background: linear-gradient(180deg, #cf4848 0%, #ad3030 100%);
    border-color: rgba(122, 28, 28, 0.82);
    box-shadow: 0 16px 28px rgba(159, 46, 46, 0.28);
}

.cancel-button:focus-visible,
#confirm-button:focus-visible,
input[type="radio"]:focus-visible {
    outline: none;
    box-shadow: var(--tms-focus);
}

#confirm-button {
    min-width: 200px;
    padding: 14px 20px;
    background: linear-gradient(180deg, var(--tms-primary-soft) 0%, var(--tms-primary) 100%);
    border-color: rgba(0, 73, 80, 0.62);
    color: #fff;
    font-size: 0.96rem;
    font-weight: 700;
}

#confirm-button:hover {
    background: linear-gradient(180deg, #13909a 0%, #006b73 100%);
    border-color: rgba(0, 73, 80, 0.84);
    box-shadow: 0 16px 28px rgba(0, 94, 102, 0.26);
}

#confirm-button[disabled] {
    cursor: not-allowed;
    opacity: 0.65;
    transform: none;
}

#empty-message {
    height: 100%;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-state__panel {
    max-width: 520px;
    padding: 34px 30px;
    border-radius: 24px;
    border: 1px dashed var(--tms-panel-border);
    background: rgba(255, 255, 255, 0.65);
    text-align: center;
}

.empty-state__panel h3 {
    margin: 0 0 12px;
    font-size: 1.7rem;
    color: var(--tms-primary-ink);
}

.empty-state__panel p {
    margin: 0;
    color: var(--tms-muted);
    line-height: 1.6;
}

input[type="radio"] {
    width: 24px;
    height: 24px;
    cursor: pointer;
    accent-color: var(--tms-primary-soft);
}

.swal2-popup.tms-swal {
    width: min(580px, calc(100vw - 28px));
    max-width: 580px;
    max-height: calc(100vh - 20px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 28px;
    border: 1px solid rgba(154, 176, 195, 0.65);
    box-shadow: 0 24px 50px rgba(19, 52, 93, 0.2);
}

.swal2-popup.tms-swal .swal2-title {
    color: var(--tms-primary-ink);
    font-size: clamp(1.65rem, 3.6vw, 2.1rem);
    line-height: 1.05;
}

.swal2-popup.tms-swal .swal2-html-container {
    flex: 1 1 auto;
    min-height: 0;
    margin-top: 0.2rem;
    color: var(--tms-text);
    max-height: calc(100vh - 230px);
    overflow-x: hidden;
    overflow-y: auto;
    padding-right: 6px;
}

.swal2-popup.tms-swal .swal2-confirm {
    background: linear-gradient(180deg, var(--tms-primary-soft) 0%, var(--tms-primary) 100%);
    border-radius: 14px;
    padding: 0.8rem 1.4rem;
}

.swal2-popup.tms-swal .swal2-actions {
    flex-shrink: 0;
    margin: 0.65rem 0 0;
    padding-bottom: 0.75rem;
}

.swal2-popup.tms-swal .swal2-icon {
    margin-top: 0.45rem;
    margin-bottom: 0.2rem;
}

.swal2-popup.tms-swal .swal2-title {
    margin-top: 0;
}

.swal-result {
    text-align: left;
}

.swal-result__section + .swal-result__section {
    margin-top: 18px;
}

.swal-result__label {
    display: block;
    margin-bottom: 6px;
    font-weight: 700;
    color: var(--tms-primary-ink);
}

.swal-result__list {
    max-height: min(220px, 26vh);
    overflow-y: auto;
    overflow-x: hidden;
    margin: 0;
    padding: 10px 12px;
    list-style: none;
    border-radius: 16px;
    border: 1px solid rgba(154, 176, 195, 0.7);
    background: rgba(232, 239, 243, 0.72);
}

.swal-result__list li + li {
    margin-top: 8px;
}

.swal-result__list--appointments {
    display: grid;
    gap: 10px;
}

.swal-result__list--appointments li + li {
    margin-top: 0;
}

.swal-appointment {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(154, 176, 195, 0.6);
}

.swal-appointment__ref {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 10px;
    border-radius: 999px;
    background: rgba(0, 94, 102, 0.12);
    color: var(--tms-primary-ink);
    font-weight: 700;
}

.swal-appointment__meta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 26px;
    padding: 0 10px;
    border-radius: 999px;
    background: rgba(219, 232, 244, 0.85);
    color: var(--tms-text);
    font-size: 0.98rem;
    white-space: nowrap;
}

.swal-appointment__meta--combined {
    flex: 1;
    justify-content: center;
    flex-wrap: nowrap;
    min-width: 0;
}

.swal-appointment__meta-label {
    font-size: 0.74rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--tms-muted);
}

.swal-appointment__meta-separator {
    font-size: 0.85rem;
    color: var(--tms-muted);
}

@media (max-width: 560px) {
    .swal-appointment {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .swal-appointment__meta--combined {
        justify-content: center;
        width: 100%;
        font-size: 0.92rem;
    }
}

.swal-result__hint {
    margin: 0;
    color: var(--tms-muted);
    line-height: 1.5;
}

.swal-result__warning {
    padding: 12px 14px;
    border-radius: 16px;
    background: rgba(253, 246, 228, 0.9);
    border: 1px solid rgba(230, 186, 92, 0.45);
    color: #7a5710;
}

@media (max-width: 920px) {
    html,
    body {
        overflow: auto;
    }

    .carrier-app {
        height: auto;
        min-height: 100%;
    }

    .app-main,
    .board,
    .board__scroll {
        min-height: auto;
    }

    .appointment-card {
        grid-template-columns: 1fr;
    }

    .appointment-card__actions {
        min-height: 76px;
    }

    #confirm-button {
        width: 100%;
    }
}

@media (max-width: 700px) {
    .carrier-app {
        padding: 12px;
    }

    .app-header {
        padding: 20px;
    }

    .app-header__brand {
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
    }

    .app-header__logo {
        width: min(240px, 62vw);
        height: 84px;
    }

    .app-header__meta {
        width: 100%;
        justify-content: flex-start;
        margin-left: 0;
    }

    .board__scroll {
        padding-left: 14px;
        padding-right: 14px;
    }

    .appointment-card {
        padding: 14px;
    }

    .appointment-card__head {
        flex-direction: column;
        align-items: flex-start;
    }

    .appointment-table {
        display: block;
        overflow-x: auto;
    }

    .table-info__panel {
        left: 0;
        width: min(420px, calc(100vw - 56px));
        min-width: 0;
        max-width: min(420px, calc(100vw - 56px));
    }

    .swal2-popup.tms-swal {
        width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
        max-height: calc(100vh - 12px);
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .swal2-popup.tms-swal .swal2-html-container {
        max-height: calc(100vh - 195px);
        padding-right: 4px;
    }

    .swal-result__list {
        max-height: min(150px, 18vh);
    }

    .swal2-popup.tms-swal .swal2-icon {
        margin-top: 0.3rem;
    }
}
