/* ========================================
   Ciclismoplus - AI Booking Optimizer
   Styles
   ======================================== */

/* === CSS Variables === */
:root {
    /* Brand Colors */
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;

    /* Decision Colors */
    --success: #16a34a;
    --success-light: #22c55e;
    --success-bg: #dcfce7;
    --warning: #ea580c;
    --warning-light: #f97316;
    --warning-bg: #ffedd5;
    --danger: #dc2626;
    --danger-light: #ef4444;
    --danger-bg: #fee2e2;

    /* Neutral Colors */
    --bg-dark: #1e293b;
    --bg-light: #f8fafc;
    --bg-white: #ffffff;
    --text-dark: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --border: #e2e8f0;
    --border-dark: #cbd5e1;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

    /* Layout */
    --sidebar-width: 280px;
    --ai-panel-width: 380px;
    --header-height: 64px;
    --footer-height: 48px;
}

/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

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

/* === Utility Classes === */
.hidden {
    display: none !important;
}

/* === Auth Gate === */
.auth-gate {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.auth-modal {
    background: var(--bg-white);
    padding: var(--spacing-xl);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 360px;
    text-align: center;
}

.auth-logo {
    margin-bottom: var(--spacing-lg);
}

.auth-logo .logo-icon {
    font-size: 48px;
    display: block;
    margin-bottom: var(--spacing-sm);
}

.auth-logo h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: var(--spacing-xs);
}

.auth-logo p {
    color: var(--text-muted);
    font-size: 14px;
}

#auth-form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

#auth-form input {
    padding: var(--spacing-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 16px;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#auth-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.error-message {
    color: var(--danger);
    font-size: 13px;
    min-height: 20px;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-white);
    color: var(--text-dark);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-light);
    border-color: var(--border-dark);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    color: var(--text-dark);
    background: rgba(0, 0, 0, 0.05);
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.btn-icon:hover {
    background: var(--bg-light);
}

/* === App Layout === */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* === Header === */
.header {
    height: var(--header-height);
    background: var(--bg-dark);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-lg);
    flex-shrink: 0;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.header-brand .logo-icon {
    font-size: 32px;
}

.header-text h1 {
    font-size: 20px;
    font-weight: 700;
    line-height: 1.2;
}

.header-subtitle {
    font-size: 12px;
    color: var(--text-light);
}

.header-actions {
    display: flex;
    gap: var(--spacing-sm);
}

.header-actions .btn {
    color: white;
    border-color: rgba(255, 255, 255, 0.2);
}

.header-actions .btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* === Main Content === */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge {
    background: var(--primary);
    color: white;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.booking-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
}

/* === Booking Card === */
.booking-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.booking-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.booking-card.active {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.05);
}

.booking-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-sm);
}

.booking-id {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    background: rgba(37, 99, 235, 0.1);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
}

.booking-status {
    font-size: 11px;
    color: var(--text-muted);
}

.booking-name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
}

.booking-details {
    font-size: 12px;
    color: var(--text-muted);
}

.booking-details span {
    display: block;
    margin-bottom: 2px;
}

/* === Calendar Section === */
.calendar-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-light);
    overflow: hidden;
}

.section-header {
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.section-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.calendar-nav {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.cal-month-label {
    font-size: 14px;
    font-weight: 600;
    min-width: 120px;
    text-align: center;
}

.calendar-container {
    flex: 1;
    padding: var(--spacing-lg);
    overflow-y: auto;
}

/* === Calendar Grid === */
.calendar-grid {
    background: var(--bg-white);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    overflow: hidden;
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    background: var(--bg-light);
    border-bottom: 1px solid var(--border);
}

.calendar-weekday {
    padding: var(--spacing-sm);
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.calendar-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}

.calendar-day {
    aspect-ratio: 1;
    padding: var(--spacing-xs);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 13px;
    position: relative;
}

.calendar-day:nth-child(7n) {
    border-right: none;
}

.calendar-day.other-month {
    color: var(--text-light);
    background: var(--bg-light);
}

.calendar-day.today {
    background: rgba(37, 99, 235, 0.1);
}

.calendar-day.today .day-number {
    background: var(--primary);
    color: white;
    border-radius: var(--radius-full);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.calendar-day.highlighted {
    background: rgba(37, 99, 235, 0.15);
}

.calendar-day .event-dot {
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: var(--radius-full);
    margin-top: 2px;
}

/* Event titles in calendar cells */
.calendar-day.has-events {
    align-items: flex-start;
    padding: var(--spacing-xs);
}

.calendar-day .event-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    margin-top: 2px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--border-dark) transparent;
}

.calendar-day .event-list::-webkit-scrollbar {
    width: 4px;
}

.calendar-day .event-list::-webkit-scrollbar-track {
    background: transparent;
}

.calendar-day .event-list::-webkit-scrollbar-thumb {
    background: var(--border-dark);
    border-radius: 2px;
}

.calendar-day .event-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.calendar-day .event-title {
    display: block;
    font-size: 9px;
    line-height: 1.2;
    padding: 1px 3px;
    background: var(--primary);
    color: white;
    border-radius: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
    flex-shrink: 0;
}

/* Event type colors */
.calendar-day .event-title.event-pickup {
    background: #fbbf24;
    color: #000;
}

.calendar-day .event-title.event-dropoff {
    background: #22c55e;
    color: #000;
}

.calendar-day .event-title.event-cancelled {
    background: #ef4444;
    color: #fff;
}

.calendar-day .event-title.event-swap {
    background: #3b82f6;
    color: #fff;
}

.calendar-day .event-title.event-other {
    background: #f472b6;
    color: #000;
}

/* === AI Panel === */
.ai-panel {
    width: var(--ai-panel-width);
    background: var(--bg-white);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.ai-suggestion {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-lg);
}

.ai-placeholder {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--text-muted);
}

.placeholder-icon {
    font-size: 48px;
    display: block;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

/* === AI Result === */
.ai-result {
    border-radius: var(--radius-md);
    overflow: hidden;
}

.ai-result-header {
    padding: var(--spacing-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-result.decision-ACCETTA .ai-result-header {
    background: var(--success-bg);
    border-left: 4px solid var(--success);
}

.ai-result.decision-SPOSTA .ai-result-header {
    background: var(--warning-bg);
    border-left: 4px solid var(--warning);
}

.ai-result.decision-DECLINA .ai-result-header {
    background: var(--danger-bg);
    border-left: 4px solid var(--danger);
}

.decision-label {
    font-size: 18px;
    font-weight: 700;
}

.decision-ACCETTA .decision-label { color: var(--success); }
.decision-SPOSTA .decision-label { color: var(--warning); }
.decision-DECLINA .decision-label { color: var(--danger); }

.confidence-badge {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: rgba(0, 0, 0, 0.1);
}

.ai-result-body {
    padding: var(--spacing-md);
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.ai-section {
    margin-bottom: var(--spacing-md);
}

.ai-section:last-child {
    margin-bottom: 0;
}

.ai-section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--spacing-xs);
}

.ai-section-content {
    font-size: 13px;
    color: var(--text-dark);
}

.bike-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    background: var(--bg-white);
    padding: var(--spacing-sm);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.bike-code {
    font-weight: 600;
    color: var(--primary);
}

.cost-breakdown {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-xs);
}

.cost-item {
    display: flex;
    justify-content: space-between;
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--bg-white);
    border-radius: var(--radius-sm);
    font-size: 12px;
}

.cost-item.total {
    grid-column: 1 / -1;
    font-weight: 600;
    background: var(--success-bg);
    color: var(--success);
}

/* === Footer === */
.footer {
    height: var(--footer-height);
    background: var(--bg-dark);
    color: var(--text-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
}

.footer strong {
    color: white;
}

/* === Loading States === */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
    gap: var(--spacing-md);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.spinner-small {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: var(--text-muted);
    font-size: 13px;
}

.pulse {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* AI Loading State */
.ai-loading {
    text-align: center;
    padding: var(--spacing-xl);
}

.ai-loading .spinner {
    margin: 0 auto var(--spacing-md);
}

.ai-loading-text {
    color: var(--text-muted);
    font-size: 14px;
}

.ai-loading-subtext {
    color: var(--text-light);
    font-size: 12px;
    margin-top: var(--spacing-xs);
}

/* === Responsive === */
@media (max-width: 1200px) {
    :root {
        --ai-panel-width: 320px;
    }
}

@media (max-width: 992px) {
    .main-content {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .booking-list {
        display: flex;
        overflow-x: auto;
        padding: var(--spacing-sm);
    }

    .booking-card {
        min-width: 200px;
        margin-bottom: 0;
        margin-right: var(--spacing-sm);
    }

    .ai-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
        max-height: 300px;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 0 var(--spacing-md);
    }

    .header-text h1 {
        font-size: 16px;
    }

    .header-subtitle {
        display: none;
    }

    .btn span:not(.btn-icon) {
        display: none;
    }
}
