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

:root {
    --bg: #ffffff;
    --bg2: #f5f5f3;
    --bg3: #ebebea;
    --text: #111111;
    --text2: #555550;
    --text3: #99998f;
    --border: rgba(0, 0, 0, 0.11);
    --border2: rgba(0, 0, 0, 0.20);
    --radius: 8px;
    --radius-lg: 12px;
}

@media(prefers-color-scheme:dark) {
    :root {
        --bg: #1c1c1e;
        --bg2: #2c2c2e;
        --bg3: #3a3a3c;
        --text: #f0f0f0;
        --text2: #aaaaaa;
        --text3: #666666;
        --border: rgba(255, 255, 255, 0.10);
        --border2: rgba(255, 255, 255, 0.20);
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5
}

.app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 0 48px
}

/* Header */
.header {
    padding: 16px 16px 0
}

.header h1 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px
}

.nav {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    border-bottom: 0.5px solid var(--border);
    padding-bottom: 12px
}

.nav-btn {
    padding: 6px 16px;
    border-radius: var(--radius);
    border: 0.5px solid var(--border2);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    transition: background .15s
}

.nav-btn:hover {
    background: var(--bg2)
}

.nav-btn.active {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text)
}

/* Pages */
.page {
    display: none;
    padding: 14px 16px
}

.page.active {
    display: block
}

.section-title {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 14px
}

.hint {
    font-size: 12px;
    color: var(--text3);
    margin-top: 8px
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px
}

.date-nav {
    display: flex;
    align-items: center;
    gap: 8px
}

.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    border: 0.5px solid var(--border2);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center
}

.icon-btn:hover {
    background: var(--bg2)
}

.date-range {
    font-size: 15px;
    font-weight: 500;
    min-width: 160px;
    text-align: center
}

.today-btn {
    padding: 5px 12px;
    border-radius: var(--radius);
    border: 0.5px solid var(--border2);
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    font-size: 13px
}

.today-btn:hover {
    background: var(--bg2)
}

.view-toggle {
    display: flex;
    border: 0.5px solid var(--border2);
    border-radius: var(--radius);
    overflow: hidden
}

.vt-btn {
    padding: 5px 14px;
    border: none;
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    font-size: 13px
}

.vt-btn.active {
    background: var(--text);
    color: var(--bg)
}

/* Legend */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text2)
}

.legend-dot {
    width: 11px;
    height: 11px;
    border-radius: 3px;
    flex-shrink: 0
}

/* Timeline */
.timeline-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg)
}

.timeline {
    border-collapse: collapse;
    width: 100%;
    table-layout: auto
}

.timeline th,
.timeline td {
    border: 0.5px solid var(--border);
    padding: 0;
    vertical-align: middle
}

.corner-cell {
    background: var(--bg2);
    font-size: 12px;
    font-weight: 500;
    color: var(--text2);
    padding: 4px 8px;
    min-width: 72px;
    max-width: 90px;
    position: sticky;
    left: 0;
    z-index: 3;
    text-align: center
}

.day-head {
    background: var(--bg2);
    font-size: 12px;
    font-weight: 400;
    color: var(--text2);
    text-align: center;
    padding: 5px 2px;
    white-space: nowrap
}

.day-head.today {
    color: #1d4ed8;
    background: #dbeafe
}

.hour-head {
    background: var(--bg3);
    font-size: 10px;
    font-weight: 400;
    color: var(--text3);
    text-align: center;
    padding: 3px 1px;
    min-width: 30px
}

.car-label {
    background: var(--bg2);
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    padding: 0 8px;
    min-width: 72px;
    max-width: 90px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: sticky;
    left: 0;
    z-index: 2;
    height: 34px
}

/* Slots */
.slot-empty {
    width: 100%;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 11px;
    color: var(--text3);
    transition: background .1s;
    user-select: none
}

.slot-empty:hover {
    background: #dbeafe;
    color: #1d4ed8
}

.booked {
    width: 100%;
    height: 34px;
    display: flex;
    align-items: center;
    padding: 0 4px;
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
    user-select: none
}

.booked-single {
    border-radius: 4px;
    margin: 0 1px
}

.booked-start {
    border-radius: 4px 0 0 4px;
    margin-left: 1px
}

.booked-end {
    border-radius: 0 4px 4px 0;
    margin-right: 1px
}

.booked-mid {
    border-radius: 0
}

/* Management cards */
.mgmt-card {
    background: var(--bg);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 11px 14px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px
}

.mgmt-left {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0
}

.car-icon {
    font-size: 20px
}

.del-btn {
    padding: 4px 12px;
    border-radius: var(--radius);
    border: 0.5px solid var(--border2);
    background: transparent;
    color: #b91c1c;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap
}

.del-btn:hover {
    background: #fee2e2
}

/* Add row */
.add-row {
    display: flex;
    gap: 8px;
    margin-top: 12px
}

.add-row input {
    flex: 1;
    padding: 9px 12px;
    border-radius: var(--radius);
    border: 0.5px solid var(--border2);
    background: var(--bg);
    color: var(--text);
    font-size: 14px
}

.add-row input:focus {
    outline: none;
    border-color: #2563eb
}

.add-row button {
    padding: 9px 18px;
    border-radius: var(--radius);
    border: none;
    background: var(--text);
    color: var(--bg);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap
}

.add-row button:hover {
    opacity: .85
}

/* Reservation list */
.res-card {
    background: var(--bg);
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 8px;
    display: flex;
    gap: 10px;
    align-items: flex-start
}

.res-card-past {
    opacity: 0.5;
}

.res-today-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    background: #2563eb;
    color: #fff;
    vertical-align: middle;
    margin-right: 3px;
}

.past-details {
    margin-top: 16px;
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.past-summary {
    padding: 10px 14px;
    background: var(--bg2);
    font-size: 13px;
    color: var(--text2);
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.past-summary::-webkit-details-marker {
    display: none;
}

.past-details[open] .past-summary {
    border-bottom: 0.5px solid var(--border);
}

.past-body {
    padding: 12px;
}

.res-info {
    flex: 1;
    min-width: 0
}

.res-name {
    font-size: 14px;
    font-weight: 500
}

.muted {
    font-weight: 400;
    color: var(--text2)
}

.res-meta {
    font-size: 12px;
    color: var(--text2);
    margin-top: 2px
}

.del-res-btn {
    padding: 4px 10px;
    border-radius: var(--radius);
    border: 0.5px solid var(--border2);
    background: transparent;
    color: #b91c1c;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0
}

.del-res-btn:hover {
    background: #fee2e2
}

.no-data {
    color: var(--text3);
    font-size: 14px;
    padding: 16px 0
}

/* Modal */
.modal-bg {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 16px
}

.modal-bg.open {
    display: flex
}

.modal {
    background: var(--bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    max-width: 380px;
    width: 100%;
    border: 0.5px solid var(--border)
}

.modal h3 {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 16px
}

.form-row {
    margin-bottom: 12px
}

.form-row.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px
}

.form-row label {
    display: block;
    font-size: 13px;
    color: var(--text2);
    margin-bottom: 4px
}

.form-row select,
.form-row input[type="date"],
.form-row input[type="text"] {
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--radius);
    border: 0.5px solid var(--border2);
    background: var(--bg);
    color: var(--text);
    font-size: 14px
}

.form-row select:focus,
.form-row input:focus {
    outline: none;
    border-color: #2563eb
}

.modal-btns {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px
}

.cancel-btn {
    padding: 8px 18px;
    border-radius: var(--radius);
    border: 0.5px solid var(--border2);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 14px
}

.primary-btn {
    padding: 8px 20px;
    border-radius: var(--radius);
    border: none;
    background: var(--text);
    color: var(--bg);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500
}

.primary-btn:hover {
    opacity: .85
}

/* Drag handles & ghost */
.booked {
    position: relative;
    cursor: grab;
}

.booked:active {
    cursor: grabbing;
}

.booked-label {
    pointer-events: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 8px;
    cursor: col-resize;
    background: rgba(255, 255, 255, 0.35);
    border-radius: 0 3px 3px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.8);
    flex-shrink: 0;
    user-select: none;
}

.resize-handle::after {
    content: '⋮';
}

.resize-handle:hover {
    background: rgba(255, 255, 255, 0.55);
}

.drag-ghost {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    transform: translate(-50%, -110%);
    opacity: 0.92;
}

.res-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.edit-res-btn {
    padding: 4px 12px;
    border-radius: var(--radius);
    border: 0.5px solid var(--border2);
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.edit-res-btn:hover {
    background: var(--bg2);
    color: var(--text);
}

.del-res-btn {
    padding: 4px 10px;
    border-radius: var(--radius);
    border: 0.5px solid var(--border2);
    background: transparent;
    color: #b91c1c;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.del-res-btn:hover {
    background: #fee2e2;
}

.res-group {
    margin-bottom: 20px;
}

.res-group-date {
    font-size: 13px;
    font-weight: 500;
    color: var(--text2);
    padding: 4px 0 8px;
    border-bottom: 0.5px solid var(--border);
    margin-bottom: 8px;
}

.modal-delete-row {
    display: flex;
    justify-content: center;
    margin-top: 10px;
    padding-top: 12px;
    border-top: 0.5px solid var(--border);
}

.danger-btn {
    padding: 8px 20px;
    border-radius: var(--radius);
    border: 0.5px solid #fca5a5;
    background: transparent;
    color: #b91c1c;
    cursor: pointer;
    font-size: 13px;
    width: 100%;
}

.danger-btn:hover {
    background: #fee2e2;
}

/* Zoom control */
.zoom-ctrl {
    display: flex;
    align-items: center;
    gap: 6px
}

.zoom-label {
    font-size: 15px;
    line-height: 1
}

.zoom-ctrl input[type=range] {
    width: 90px;
    accent-color: var(--text);
    cursor: pointer
}

.zoom-val {
    font-size: 12px;
    color: var(--text3);
    min-width: 34px
}

/* Card holders grid */
.card-holders-wrap {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 0 16px 24px;
}

@media(max-width:480px) {
    .card-holders-wrap {
        grid-template-columns: 1fr;
    }
}

/* ETC panel */
.etc-panel {
    margin-top: 20px;
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.etc-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg2);
    border-bottom: 0.5px solid var(--border);
}

.etc-icon {
    font-size: 18px;
    line-height: 1;
}

.etc-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.etc-body {
    padding: 12px 14px;
}

.etc-current {
    margin-bottom: 12px;
}

.etc-badge {
    display: inline-block;
    padding: 5px 16px;
    border-radius: 20px;
    font-size: 15px;
    font-weight: 600;
    background: var(--bg3);
    color: var(--text2);
    transition: background .2s, color .2s;
}

.etc-members {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.etc-member-btn {
    padding: 5px 14px;
    border-radius: 20px;
    border: 0.5px solid var(--border2);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background .15s, color .15s, border-color .15s;
}

.etc-member-btn:hover {
    background: var(--bg2);
}

.etc-member-btn.active {
    font-weight: 600;
}

.etc-clear {
    color: #b91c1c;
    border-color: #fca5a5;
}

.etc-clear:hover {
    background: #fee2e2;
}

.etc-clear.hidden {
    display: none;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #111;
    color: #fff;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    z-index: 200;
    opacity: 0;
    transition: opacity .3s;
    pointer-events: none;
    white-space: nowrap
}

.toast.show {
    opacity: 1
}

@media(max-width:600px) {
    .header h1 {
        font-size: 17px
    }

    .corner-cell,
    .car-label {
        min-width: 58px;
        max-width: 70px;
        font-size: 11px
    }

    .date-range {
        min-width: 120px;
        font-size: 13px
    }
}