* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    background: #f5f5f5;
    color: #333;
}

/* ── Header ─────────────────────────────────────────── */
.header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: #fff;
    border-bottom: 1px solid #ddd;
    position: sticky;
    top: 0;
    z-index: 10;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
}

.header input[type="date"] {
    padding: 5px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
}

.btn {
    padding: 6px 14px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}

.btn-primary { background: #3498db; color: #fff; }
.btn-primary:hover { background: #2980b9; }
.btn-secondary { background: #ecf0f1; color: #333; }
.btn-secondary:hover { background: #dde1e3; }
.btn-danger { background: #e74c3c; color: #fff; }
.btn-danger:hover { background: #c0392b; }
.btn-warning { background: #f39c12; color: #fff; }
.btn-warning:hover { background: #d68910; }

.pending-badge {
    display: inline-block;
    background: #fff;
    color: #f39c12;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 6px;
    margin-left: 4px;
    min-width: 18px;
    text-align: center;
}

.version-label {
    font-size: 11px;
    color: #aaa;
    margin-left: 4px;
}

.nav-btn {
    background: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 16px;
}
.nav-btn:hover { background: #eee; }

/* ── Layout ─────────────────────────────────────────── */
.layout {
    display: flex;
    height: calc(100vh - 50px);
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
    width: 200px;
    background: #fff;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-section {
    padding: 10px;
    border-bottom: 1px solid #eee;
}

.customer-search {
    width: 100%;
    padding: 5px 8px;
    margin-top: 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
    box-sizing: border-box;
}

.btn-personal-toggle {
    width: 100%;
    margin-top: 6px;
    font-size: 12px;
    padding: 4px 8px;
}

.btn-personal-toggle.active {
    background: #3498db;
    color: #fff;
}

.customer-row.is-personal .customer-item {
    opacity: 0.75;
    font-style: italic;
}

.sidebar-section h3 {
    font-size: 12px;
    text-transform: uppercase;
    color: #999;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.customer-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.customer-item {
    padding: 6px 10px;
    background: #ecf0f1;
    border-radius: 4px;
    margin-bottom: 4px;
    cursor: grab;
    user-select: none;
    font-size: 13px;
    border: 1px solid transparent;
}

.customer-item:hover { border-color: #3498db; }
.customer-item:active { cursor: grabbing; }
.customer-item.dragging { opacity: 0.5; }

/* ── Calendar ─────────────────────────────────────────── */
.calendar-wrapper {
    flex: 1;
    overflow: auto;
}

.calendar {
    display: flex;
    min-width: max-content;
}

.time-gutter {
    width: 60px;
    flex-shrink: 0;
}

.time-gutter-header {
    height: 36px;
    border-bottom: 1px solid #ddd;
    background: #fff;
}

.time-label {
    height: 60px;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 4px 8px 0 0;
    font-size: 11px;
    color: #999;
    border-bottom: 1px solid #f0f0f0;
    background: #fff;
}

.room-columns {
    display: flex;
    flex: 1;
}

.room-col {
    min-width: 160px;
    border-right: 1px solid #e0e0e0;
    flex: 1;
}

.room-col-header {
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    border-bottom: 1px solid #ddd;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 5;
    gap: 6px;
}

.room-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.room-body {
    position: relative;
}

.time-cell {
    height: 60px;
    border-bottom: 1px solid #f0f0f0;
    background: #fafafa;
    transition: background 0.1s;
}

.time-cell:nth-child(even) { background: #fff; }
.time-cell.drag-over { background: rgba(52, 152, 219, 0.15) !important; }

/* ── Booking blocks ─────────────────────────────────── */
.booking-block {
    position: absolute;
    left: 2px;
    right: 2px;
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 12px;
    overflow: hidden;
    cursor: pointer;
    color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    z-index: 2;
    line-height: 1.3;
}

.booking-block:hover { filter: brightness(0.9); }

/* During a booking drag, let pointer events fall through to time cells */
.calendar.is-dragging-booking .booking-block { pointer-events: none; }

.booking-block .booking-time {
    font-size: 10px;
    opacity: 0.85;
}

.booking-block .booking-customer {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.booking-block .booking-notes {
    font-size: 10px;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.booking-block.is-series {
    border-left: 3px solid rgba(255,255,255,0.5);
}

.booking-block .booking-resize-handle {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 8px;
    cursor: ns-resize;
    background: linear-gradient(to bottom, transparent, rgba(255,255,255,0.35));
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
    opacity: 0;
    transition: opacity 0.12s;
    touch-action: none;
}
.booking-block:hover .booking-resize-handle { opacity: 1; }
.booking-block.is-resizing { cursor: ns-resize; filter: brightness(0.92); }
.booking-block.is-resizing .booking-resize-handle { opacity: 1; }

.booking-block.is-pending {
    opacity: 0.65;
    border: 2px dashed rgba(255,255,255,0.7);
    background-image: repeating-linear-gradient(
        45deg,
        rgba(0,0,0,0.12) 0px,
        rgba(0,0,0,0.12) 4px,
        transparent 4px,
        transparent 10px
    ) !important;
}

/* ── Modal ──────────────────────────────────────────── */
dialog {
    border: none;
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    min-width: 360px;
    max-width: 480px;
    width: 100%;
}

dialog::backdrop {
    background: rgba(0,0,0,0.4);
}

.modal-header {
    padding: 16px 20px 12px;
    border-bottom: 1px solid #eee;
    font-size: 16px;
    font-weight: 600;
}

.modal-body {
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 12px;
    font-weight: 500;
    color: #666;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 7px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
}

/* Färgväljare utan grå ram — hela knappen blir den valda färgen */
.form-group input[type="color"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding: 0;
    border: none;
    width: 56px;
    height: 32px;
    border-radius: 4px;
    cursor: pointer;
    background: none;
}
.form-group input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.form-group input[type="color"]::-webkit-color-swatch {
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: 4px;
}
.form-group input[type="color"]::-moz-color-swatch {
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: 4px;
}

.form-row {
    display: flex;
    gap: 10px;
}

.form-row .form-group { flex: 1; }

.modal-footer {
    padding: 12px 20px 16px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    border-top: 1px solid #eee;
}

.modal-footer-left {
    flex: 1;
}

/* ── Error / Empty states ────────────────────────────── */
.error-message {
    padding: 20px;
    color: #e74c3c;
    text-align: center;
}

.empty-state {
    padding: 40px;
    text-align: center;
    color: #aaa;
}

/* ── Upprepnings-UI ──────────────────────────────────── */
.form-label-small {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: #666;
    margin-bottom: 6px;
}

.weekday-picker {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.weekday-picker label {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 13px;
    cursor: pointer;
    padding: 3px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.weekday-picker label:has(input:checked) {
    background: #3498db;
    color: #fff;
    border-color: #3498db;
}

.approval-section {
    margin-top: 12px;
    padding: 10px 12px;
    background: #fff8e6;
    border: 1px solid #f39c12;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.approval-label {
    font-size: 13px;
    color: #a36000;
    font-weight: 500;
}

.approval-actions {
    display: flex;
    gap: 8px;
}

.series-action-label {
    font-size: 12px;
    color: #888;
    margin-bottom: 6px;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

/* ── Print toggle label ──────────────────────────────── */
.print-toggle-label {
    font-size: 12px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    white-space: nowrap;
}

/* ── Print header (rubrik) ───────────────────────────── */
.print-header {
    display: none;          /* dold i webbläsaren alltid */
    padding: 4px 16px 8px;
    border-bottom: 1px solid #ccc;
    margin-bottom: 4px;
}

.print-header h2 {
    font-size: 15px;
    margin: 0;
}

.print-version {
    font-size: 11px;
    color: #888;
}

.print-footer {
    display: none;
}

@media print {
    .print-footer {
        display: block !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        text-align: center;
        font-size: 9px;
        color: #777;
        padding: 10px 0;
        border-top: 1px solid #eee;
        background: #fff;
        z-index: 9999;
        height: 30px;
    }
}

@media print {
    .print-only {
        display: block !important;
    }
}

/* ── Tabell-vy för utskrift ─────────────────────────── */
.print-table-view { display: none; }
.print-table-view table {
    width: 100%; border-collapse: collapse; font-size: 12px;
}
.print-table-view th, .print-table-view td {
    border-bottom: 1px solid #ddd; padding: 6px 8px; text-align: left; vertical-align: top;
}
.print-table-view th {
    background: #f4f4f4; font-weight: 700; font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.3px;
}
.print-table-view .group-header td {
    background: #fafbfc; font-weight: 700; padding-top: 10px;
}
.print-table-view .room-color-dot {
    display: inline-block; width: 10px; height: 10px; border-radius: 50%;
    margin-right: 6px; vertical-align: middle;
}
.print-table-view h2 {
    font-size: 16px; margin-bottom: 12px;
}

/* ── Print ───────────────────────────────────────────── */
@media print {
    .no-print { display: none !important; }

    /* Rubrik visas bara om body har klassen show-print-header */
    body.show-print-header .print-header {
        display: block !important;
    }

    /* Tabellutskrift: göm kalendern, visa tabellen */
    body.print-as-table .layout { display: none !important; }
    body.print-as-table .print-table-view {
        display: block !important;
        padding: 12px 16px 50px;
    }

    body, html {
        height: auto !important;
        overflow: visible !important;
        background: #fff;
    }

    /* Lägg layout i block-läge så höjdklippning försvinner */
    .layout {
        display: block !important;
        height: auto !important;
        overflow: visible !important;
        padding-bottom: 40px; /* Plats för fixed footer */
    }

    .sidebar { display: none !important; }

    .calendar-wrapper {
        overflow: visible !important;
        height: auto !important;
    }

    .calendar {
        display: flex !important;
        min-width: 0 !important;
        width: 100% !important;
    }

    .room-columns {
        flex: 1 !important;
        min-width: 0 !important;
    }

    .room-col {
        min-width: 0 !important;
        flex: 1 !important;
    }

    .time-gutter { flex-shrink: 0; }

    .booking-block {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        color: #fff !important;
    }
}

/* ── Customer row (sidebar) ──────────────────────────── */
.customer-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.customer-row .customer-item {
    flex: 1;
    margin-bottom: 0;
}

/* ── Edit button ─────────────────────────────────────── */
.edit-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #bbb;
    font-size: 14px;
    padding: 2px 5px;
    border-radius: 3px;
    line-height: 1;
    flex-shrink: 0;
}

.edit-btn:hover {
    background: #e8e8e8;
    color: #333;
}

/* ── Audit dialog ────────────────────────────────────── */
.audit-dialog {
    min-width: 620px;
    max-width: 860px;
    width: 90vw;
}

.audit-dialog .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dialog-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: #aaa;
    padding: 0 4px;
    line-height: 1;
}

.dialog-close-btn:hover { color: #333; }

.audit-tabs {
    display: flex;
    border-bottom: 1px solid #eee;
    padding: 0 20px;
    gap: 4px;
}

.audit-tab {
    padding: 8px 14px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    color: #666;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.audit-tab:hover { color: #333; }
.audit-tab.active { color: #3498db; border-bottom-color: #3498db; font-weight: 500; }

.audit-body {
    max-height: 440px;
    overflow-y: auto;
    padding: 6px 0;
}

.audit-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 20px;
    border-bottom: 1px solid #f5f5f5;
    font-size: 13px;
}

.audit-row:last-child { border-bottom: none; }

.audit-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 3px;
    white-space: nowrap;
    flex-shrink: 0;
}

.audit-row.audit-create  .audit-badge { background: #d4edda; color: #1e7e34; }
.audit-row.audit-update  .audit-badge { background: #cce5ff; color: #004085; }
.audit-row.audit-delete  .audit-badge { background: #f8d7da; color: #721c24; }
.audit-row.audit-restore .audit-badge { background: #fff3cd; color: #856404; }

.audit-type {
    color: #999;
    font-size: 12px;
    min-width: 56px;
    flex-shrink: 0;
}

.audit-desc {
    flex: 1;
    color: #444;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.audit-time {
    color: #bbb;
    font-size: 11px;
    white-space: nowrap;
    flex-shrink: 0;
}

.audit-diff {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-left: auto;
    padding: 4px 8px;
    background: #f9f9f9;
    border-left: 2px solid #cce5ff;
    border-radius: 3px;
    flex-shrink: 0;
    max-width: 380px;
}

.audit-diff-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
}

.audit-diff-label {
    color: #999;
    min-width: 70px;
    flex-shrink: 0;
}

.audit-diff-before {
    color: #c0392b;
    text-decoration: line-through;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
}

.audit-diff-arrow { color: #aaa; flex-shrink: 0; }

.move-from { color: #c0392b; }
.move-to   { color: #27ae60; font-weight: 500; }

/* ── Undo toast ──────────────────────────────────────── */
.undo-toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: #2c3e50;
    color: #fff;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 13px;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.undo-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.undo-toast.undo-toast-error {
    background: #c0392b;
    max-width: 420px;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
}

.toast-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.75;
    flex-shrink: 0;
    padding: 0 2px;
}
.toast-close:hover { opacity: 1; }

#moveDialogText { font-size: 14px; line-height: 1.8; }

.audit-diff-after {
    color: #27ae60;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
}

/* ── View page specific ──────────────────────────────── */
.view-date {
    font-size: 14px;
    color: #555;
    text-transform: capitalize;
}

.refresh-indicator {
    font-size: 14px;
    color: #3498db;
    min-width: 14px;
}
