:root {
    --gold: #c9a84c;
    --gold-dark: #9b7a29;
    --ink: #1d2430;
    --muted: #667085;
    --line: #d9dee8;
    --line-soft: #edf0f5;
    --panel: #ffffff;
    --surface: #f5f7fb;
    --slot: #eef8f3;
    --slot-border: #88c9a8;
    --slot-hover: #dff1e8;
    --danger: #b42318;
    --shadow: 0 18px 45px rgba(29, 36, 48, 0.18);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--surface);
    color: var(--ink);
    font-family: 'Inter', sans-serif;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 24px;
    min-height: 76px;
    padding: 12px 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    width: 210px;
}

.brand img {
    display: block;
    max-width: 190px;
    max-height: 46px;
    object-fit: contain;
}

.toolbar {
    display: grid;
    grid-template-columns: minmax(260px, 460px) auto;
    align-items: end;
    gap: 12px;
    width: 100%;
}

label span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

select,
input {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    outline: none;
}

select:focus,
input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.18);
}

.week-controls {
    display: grid;
    grid-template-columns: 42px 72px 42px;
    gap: 6px;
}

.day-controls {
    display: none;
    grid-template-columns: 48px 1fr 48px;
    gap: 6px;
}

.week-controls button,
.day-controls button,
.btn-ghost,
.btn-primary,
.btn-move,
.btn-danger,
#close-modal {
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font-weight: 700;
}

.week-controls button:hover,
.day-controls button:hover,
.btn-ghost:hover,
#close-modal:hover {
    background: var(--surface);
}

.agenda-shell {
    width: min(1420px, calc(100vw - 32px));
    margin: 18px auto 28px;
}

.agenda-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 8px 0 16px;
}

.agenda-head h1 {
    margin: 0 0 4px;
    font-size: 24px;
    line-height: 1.1;
}

.agenda-head p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.agenda-head .drag-hint {
    margin-top: 5px;
    font-size: 12px;
}

.status-pill {
    min-width: 112px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-align: center;
}

.status-pill.ok {
    border-color: rgba(136, 201, 168, 0.7);
    color: #177245;
}

.status-pill.error {
    border-color: rgba(180, 35, 24, 0.35);
    color: var(--danger);
}

.calendar {
    display: grid;
    grid-template-columns: 72px 1fr;
    grid-template-rows: 58px auto;
    min-height: calc(100vh - 176px);
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.calendar-corner {
    grid-column: 1;
    grid-row: 1;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.day-head {
    grid-column: 2;
    grid-row: 1;
    display: grid;
    grid-template-columns: repeat(7, minmax(116px, 1fr));
    border-bottom: 1px solid var(--line);
}

.day-head div {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    padding: 0 12px;
    border-right: 1px solid var(--line-soft);
}

.day-head div:last-child {
    border-right: 0;
}

.day-name {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.day-date {
    margin-top: 3px;
    font-size: 18px;
    font-weight: 700;
}

.time-column {
    grid-column: 1;
    grid-row: 2;
    border-right: 1px solid var(--line);
    background: #fbfcfe;
}

.time-label {
    height: 76px;
    padding: 6px 10px 0 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-align: right;
    border-bottom: 1px solid var(--line-soft);
}

.week-grid {
    grid-column: 2;
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(7, minmax(116px, 1fr));
    position: relative;
}

.day-column {
    min-width: 0;
    border-right: 1px solid var(--line-soft);
}

.day-column:last-child {
    border-right: 0;
}

.hour-cell {
    height: 76px;
    border-bottom: 1px solid var(--line-soft);
    padding: 4px;
    overflow-y: auto;
}

.slot-btn {
    width: 100%;
    min-height: 30px;
    padding: 5px 8px;
    margin-bottom: 4px;
    border: 1px solid var(--slot-border);
    border-radius: 6px;
    background: var(--slot);
    color: #165b36;
    font-size: 12px;
    font-weight: 800;
    text-align: left;
    overflow: hidden;
}

.slot-btn:hover {
    background: var(--slot-hover);
    border-color: #58a87f;
}

.slot-btn:last-child {
    margin-bottom: 0;
}

.slot-btn span,
.slot-btn small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.slot-btn small {
    margin-top: 2px;
    font-size: 10px;
    font-weight: 700;
}

.slot-occupied {
    border-color: #f3a29a;
    background: #fff0ee;
    color: #b42318;
    cursor: grab;
}

.slot-occupied:active {
    cursor: grabbing;
}

.slot-occupied.dragging {
    opacity: 0.45;
}

.slot-btn.move-target {
    border-style: dashed;
    border-width: 2px;
    background: #fff9df;
    border-color: var(--gold);
}

.slot-btn.drag-over {
    background: #f4df9b;
    transform: scale(1.02);
}

.slot-occupied:hover {
    border-color: #f3a29a;
    background: #fff0ee;
}

.empty-state {
    grid-column: 1 / -1;
    align-self: start;
    margin: 72px auto;
    color: var(--muted);
    font-size: 14px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(29, 36, 48, 0.38);
}

.hidden {
    display: none !important;
}

.modal {
    width: min(460px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 18px 8px;
}

.modal h2 {
    margin: 0 0 4px;
    font-size: 18px;
}

.modal p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

#close-modal,
#close-occupied {
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    font-size: 22px;
    line-height: 1;
}

#interno-form {
    display: grid;
    gap: 14px;
    padding: 14px 18px 18px;
}

.form-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 4px;
}

.occupied-details .form-actions {
    grid-template-columns: 1fr 1fr 1fr;
}

.btn-move {
    border-color: var(--gold-dark);
    background: #fff9df;
    color: #5f4912;
}

.btn-move:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-primary {
    border-color: var(--gold-dark);
    background: var(--gold);
    color: #221806;
}

.btn-primary:hover {
    background: #d6b95e;
}

.btn-primary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-danger {
    border-color: #b42318;
    background: #b42318;
    color: #fff;
}

.btn-danger:hover {
    background: #971b12;
}

.btn-danger:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.occupied-details {
    padding: 12px 18px 18px;
}

.occupied-details dl {
    display: grid;
    gap: 10px;
    margin: 0 0 16px;
}

.occupied-details div {
    padding: 10px 12px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #fbfcfe;
}

.occupied-details dt {
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.occupied-details dd {
    margin: 0;
    color: var(--ink);
    font-size: 14px;
    font-weight: 700;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 60;
    max-width: min(420px, calc(100vw - 36px));
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--ink);
    color: #fff;
    box-shadow: var(--shadow);
    font-size: 14px;
}

.toast.error {
    background: var(--danger);
}

@media (max-width: 860px) {
    .topbar {
        position: static;
        display: block;
        padding: 14px;
    }

    .brand {
        width: 100%;
        margin-bottom: 12px;
    }

    .toolbar {
        grid-template-columns: 1fr;
    }

    .week-controls {
        display: none;
    }

    .day-controls {
        display: grid;
    }

    .agenda-shell {
        width: calc(100vw - 20px);
        margin-top: 10px;
    }

    .agenda-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .calendar {
        grid-template-columns: 56px minmax(0, 1fr);
        overflow: hidden;
        min-height: auto;
    }

    .day-head,
    .week-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .day-head div {
        align-items: center;
        text-align: center;
    }

    .agenda-head .drag-hint {
        display: none;
    }

    .status-pill {
        width: 100%;
    }

    .modal-backdrop {
        align-items: flex-end;
        padding: 0;
    }

    .modal {
        max-height: 92vh;
        overflow-y: auto;
        border-radius: 16px 16px 0 0;
    }

    .form-actions,
    .occupied-details .form-actions {
        grid-template-columns: 1fr;
    }

    .time-label,
    .hour-cell {
        height: 72px;
    }
}
