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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #000;
    color: #e0e0e0;
    height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 33.333%;
    min-width: 320px;
    background: #0a0a1a;
    color: #fff;
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.logo {
    text-align: center;
    padding: 15px 0;
    border-bottom: 2px solid rgba(255,255,255,0.1);
    margin-bottom: 20px;
    flex-shrink: 0;
}

.logo img {
    max-width: 100%;
    height: auto;
    max-height: 120px;
}

.clock {
    text-align: center;
    font-size: 2.5em;
    font-weight: bold;
    padding: 15px 0;
    font-family: 'Courier New', monospace;
    flex-shrink: 0;
}

.calendar {
    flex: 1;
    margin-top: 10px;
    min-height: 0;
}

.cal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    font-size: 1.1em;
    font-weight: bold;
}

.cal-header button {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background 0.2s;
}

.cal-header button:hover {
    background: rgba(255,255,255,0.3);
}

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    text-align: center;
}

.cal-grid .day-name {
    font-size: 0.8em;
    padding: 6px 0;
    opacity: 0.7;
    font-weight: 600;
}

.cal-grid .day {
    padding: 8px 0;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.95em;
}

.cal-grid .day:hover {
    background: rgba(255,255,255,0.2);
}

.cal-grid .day.selected {
    background: #ff6f00;
    font-weight: bold;
}

.cal-grid .day.other-month {
    opacity: 0.35;
}

.cal-grid .day.today {
    border: 2px solid rgba(255,255,255,0.6);
}

.main {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    gap: 15px;
}

.main-header h2 {
    font-size: 1.4em;
    color: #ffab00;
    flex-shrink: 0;
}

.header-buttons {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.table-wrapper {
    flex: 1;
    overflow-y: auto;
    background: #1a1a2e;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #3a3a5a;
}

th {
    border-right: 1px solid #3a3a5a;
}

th:last-child {
    border-right: none;
}

td {
    border-right: 1px solid #2e2e4e;
    border-bottom: 1px solid #2e2e4e;
}

td:last-child {
    border-right: none;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:nth-child(even) td {
    background: #16162e;
}

thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

th {
    background: #0d0d2b;
    color: #ffab00;
    padding: 12px 10px;
    text-align: left;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 1px;
}

td {
    padding: 10px;
    font-size: 0.95em;
    cursor: pointer;
    transition: background 0.15s;
    color: #e0e0e0;
}

td:hover {
    background: #2a2a3e;
}

td.empty {
    color: #666;
    font-style: italic;
}

td .clave-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-weight: bold;
    font-size: 0.9em;
    letter-spacing: 1px;
}

.clave-R { background: #00c853; color: #000; }
.clave-E { background: #2979ff; color: #fff; }
.clave-A { background: #ff1744; color: #fff; }
.clave-M { background: #ffd600; color: #000; }

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-primary {
    background: #1a237e;
    color: #fff;
}

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

.btn-secondary {
    background: #757575;
    color: #fff;
}

.btn-secondary:hover {
    background: #616161;
}

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

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

.btn-email {
    display: inline-block;
    padding: 10px 16px;
    background: #00c853;
    color: #000;
    font-size: 0.9em;
    font-weight: 700;
    border: 2px solid #00e676;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.btn-email:hover {
    background: #00e676;
}

.alert-success {
    background: #1b5e20;
    color: #a5d6a7;
    padding: 12px;
    border-radius: 6px;
    font-weight: 600;
}

.alert-error {
    background: #b71c1c;
    color: #ef9a9a;
    padding: 12px;
    border-radius: 6px;
    font-weight: 600;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: #1a1a2e;
    border-radius: 12px;
    padding: 30px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
    border: 1px solid #333;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 18px;
    font-size: 28px;
    cursor: pointer;
    color: #999;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #fff;
}

.modal-content h2 {
    margin-bottom: 20px;
    color: #ffab00;
}

.form-row {
    display: flex;
    gap: 15px;
    margin-bottom: 12px;
}

.form-group {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.85em;
    font-weight: 600;
    color: #aaa;
    margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 8px 10px;
    border: 1px solid #444;
    border-radius: 6px;
    font-size: 0.95em;
    font-family: inherit;
    transition: border-color 0.2s;
    background: #0d0d2b;
    color: #e0e0e0;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #ffab00;
    box-shadow: 0 0 0 2px rgba(255,171,0,0.15);
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: flex-end;
}

.btn-coches-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 9px 14px;
    background: #2e7d32;
    color: #fff;
    font-size: 0.85em;
    font-weight: 700;
    text-decoration: none;
    border-radius: 8px;
    white-space: nowrap;
    transition: background 0.2s;
}

.btn-coches-link:hover {
    background: #388e3c;
    color: #fff;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.topbar-logo {
    height: 36px;
    width: auto;
}

.coches-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #0a0a1a;
    color: #ffab00;
    padding: 15px 25px;
    border-bottom: 2px solid #1a1a3e;
    flex-shrink: 0;
}

.coches-topbar h1 {
    font-size: 1.3em;
    font-weight: 700;
}

.btn-back-coches {
    color: #aaa;
    text-decoration: none;
    font-size: 0.95em;
    padding: 7px 14px;
    border: 1px solid #444;
    border-radius: 6px;
    transition: all 0.2s;
}

.btn-back-coches:hover {
    color: #fff;
    border-color: #ffab00;
}

.coches-body {
    flex: 1;
    padding: 20px 25px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #000;
}

.coches-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    gap: 15px;
    flex-shrink: 0;
}

.coches-filter {
    display: flex;
    align-items: center;
    gap: 8px;
}

.coches-filter label {
    color: #aaa;
    font-size: 0.85em;
    font-weight: 600;
}

.coches-filter select {
    padding: 7px 12px;
    border: 1px solid #444;
    border-radius: 6px;
    font-size: 0.9em;
    background: #0d0d2b;
    color: #e0e0e0;
}

.btn-add-coche {
    background: #00c853;
    color: #000;
    font-weight: 700;
    border: 2px solid #00e676;
}

.btn-add-coche:hover {
    background: #00e676;
}

.coche-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 0.8em;
    font-weight: 700;
}

.badge-ok { background: #00c853; color: #000; }
.badge-warn { background: #ff6f00; color: #fff; }
.badge-err { background: #c62828; color: #fff; }

.acciones-cell {
    white-space: nowrap;
}

.btn-sm {
    padding: 4px 8px;
    border: 1px solid #555;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    margin: 0 2px;
    transition: all 0.2s;
    background: transparent;
}

.btn-sm:hover { transform: scale(1.15); }
.btn-sm:disabled { opacity: 0.25; cursor: not-allowed; transform: none; }

.btn-sm-edit { color: #42a5f5; border-color: #42a5f5; }
.btn-sm-edit:hover:not(:disabled) { background: rgba(66,165,245,0.15); }
.btn-sm-assign { color: #ffa726; border-color: #ffa726; }
.btn-sm-assign:hover:not(:disabled) { background: rgba(255,167,38,0.15); }
.btn-sm-return { color: #66bb6a; border-color: #66bb6a; }
.btn-sm-return:hover:not(:disabled) { background: rgba(102,187,106,0.15); }
.btn-sm-del { color: #ef5350; border-color: #ef5350; }
.btn-sm-del:hover:not(:disabled) { background: rgba(239,83,80,0.15); }
.btn-sm-print { color: #ab47bc; border-color: #ab47bc; }
.btn-sm-print:hover { background: rgba(171,71,188,0.15); }

#cochesTable td {
    padding: 8px 10px;
    vertical-align: middle;
}

/* Scroll hint gradient for table overflow */
.table-wrapper {
    position: relative;
}
.table-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 30px;
    background: linear-gradient(to right, transparent, rgba(0,0,0,0.6));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    border-radius: 0 10px 10px 0;
}
.table-wrapper.is-overflowing::after {
    opacity: 1;
}

/* ===== RESPONSIVE ===== */

/* Tablets and below */
@media (max-width: 1024px) {
    .sidebar {
        min-width: 260px;
    }
    .clock {
        font-size: 2em;
    }
    .main-header h2 {
        font-size: 1.1em;
    }
    .header-buttons {
        gap: 6px;
    }
    .btn {
        padding: 8px 14px;
        font-size: 0.85em;
    }
    .btn-email {
        padding: 8px 12px;
        font-size: 0.8em;
    }
    .btn-coches-link {
        padding: 7px 10px;
        font-size: 0.8em;
    }
}

/* Mobile landscape / small tablets */
@media (max-width: 768px) {
    body {
        overflow: auto;
        height: auto;
    }

    .container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .sidebar {
        width: 100%;
        min-width: unset;
        max-height: none;
        padding: 12px;
        overflow-y: visible;
    }

    .logo {
        padding: 10px 0;
        margin-bottom: 10px;
    }
    .logo img {
        max-height: 80px;
    }

    .clock {
        font-size: 1.6em;
        padding: 8px 0;
    }

    .calendar {
        margin-top: 5px;
        max-height: 340px;
        overflow-y: auto;
    }

    .cal-header {
        font-size: 0.95em;
        padding: 6px 0;
    }
    .cal-header button {
        padding: 6px 10px;
        font-size: 0.9em;
    }

    .cal-grid .day-name {
        font-size: 0.7em;
        padding: 4px 0;
    }
    .cal-grid .day {
        padding: 5px 0;
        font-size: 0.85em;
    }

    .main {
        padding: 12px;
        overflow: visible;
    }

    .main-header {
        flex-wrap: wrap;
        gap: 10px;
    }
    .main-header h2 {
        width: 100%;
        text-align: center;
    }
    .header-buttons {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #citasTable {
        min-width: 650px;
    }

    th {
        padding: 8px 6px;
        font-size: 0.75em;
    }
    td {
        padding: 8px 6px;
        font-size: 0.85em;
    }

    td .clave-badge {
        padding: 3px 8px;
        font-size: 0.8em;
    }

    .modal-content {
        width: 95%;
        padding: 20px 16px;
        margin: 10px;
        max-height: 85vh;
    }
    .modal-content h2 {
        font-size: 1.2em;
        margin-bottom: 15px;
    }

    .form-row {
        flex-direction: column;
        gap: 8px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 10px 10px;
        font-size: 16px;
    }

    .form-actions {
        flex-wrap: wrap;
        gap: 8px;
    }
    .form-actions .btn {
        flex: 1;
        min-width: 80px;
        text-align: center;
    }

    /* Coches page responsive */
    .coches-topbar {
        flex-wrap: wrap;
        gap: 10px;
        padding: 12px 16px;
    }
    .coches-topbar h1 {
        font-size: 1em;
        order: 3;
        width: 100%;
        text-align: center;
    }
    .topbar-left {
        gap: 10px;
    }
    .topbar-logo {
        height: 28px;
    }

    .coches-body {
        padding: 12px 16px;
        overflow: visible;
    }

    .coches-toolbar {
        flex-wrap: wrap;
        gap: 10px;
    }
    .coches-toolbar .btn {
        flex: 1;
        min-width: 120px;
        text-align: center;
    }
    .coches-filter {
        width: 100%;
        justify-content: center;
    }
    .coches-filter select {
        flex: 1;
        max-width: 200px;
    }

    #cochesTable {
        min-width: 900px;
    }

    #cochesTable td {
        padding: 6px 6px;
        font-size: 0.8em;
    }

    .btn-sm {
        padding: 3px 6px;
        font-size: 0.75em;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .sidebar {
        padding: 8px;
    }
    .clock {
        font-size: 1.3em;
    }
    .cal-header {
        font-size: 0.85em;
    }
    .cal-grid .day {
        font-size: 0.75em;
        padding: 4px 0;
    }
    .cal-grid .day-name {
        font-size: 0.65em;
    }
    .main {
        padding: 8px;
    }
    .main-header h2 {
        font-size: 1em;
    }
    .btn {
        padding: 7px 10px;
        font-size: 0.8em;
    }
    .btn-email {
        padding: 6px 10px;
        font-size: 0.75em;
    }
    .modal-content {
        padding: 16px 12px;
    }
    .coches-topbar {
        padding: 10px 12px;
    }
    .coches-body {
        padding: 10px 12px;
    }
    .coches-toolbar .btn {
        font-size: 0.8em;
        padding: 8px 10px;
    }
    .btn-sm {
        padding: 2px 5px;
        font-size: 0.7em;
    }
}

/* Hide scrollbar for table wrapper on mobile */
@media (max-width: 768px) {
    .table-wrapper::-webkit-scrollbar {
        height: 6px;
    }
    .table-wrapper::-webkit-scrollbar-thumb {
        background: #444;
        border-radius: 3px;
    }
}
