/* Lovely London Route System - Global Styles */

:root {
    --primary: #1a1a2e;
    --secondary: #c9a961;
    --bg-light: #f5f5f5;
    --text-dark: #333;
    --border: #e0e0e0;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text-dark);
    background: var(--bg-light);
}

/* Header & Navigation */
.app-header {
    background: var(--primary);
    color: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.app-nav {
    display: flex;
    gap: 2rem;
    list-style: none;
    margin: 1rem 0 0 0;
}

.app-nav a {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.app-nav a:hover,
.app-nav a.active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Cards */
.card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: var(--secondary);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn:hover {
    background: #b89850;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(201, 169, 97, 0.3);
}

.btn-primary {
    background: var(--primary);
}

.btn-primary:hover {
    background: #252a42;
}

.btn-secondary {
    background: white;
    color: var(--primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-light);
}

.btn-danger {
    background: var(--error);
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Form Elements */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-dark);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--secondary);
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
    font-family: inherit;
}

/* Grid */
.grid {
    display: grid;
    gap: 1.5rem;
}

.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: white;
    border-radius: 12px;
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #999;
}

.modal-close:hover {
    color: var(--text-dark);
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.5rem;
}

.tab {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 1rem;
    color: #666;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--primary);
}

.tab.active {
    color: var(--secondary);
    border-bottom-color: var(--secondary);
    font-weight: 600;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Alerts */
.alert {
    padding: 1rem 1.5rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border-left: 4px solid var(--success);
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid var(--error);
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border-left: 4px solid var(--warning);
}

/* Loading */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Badge */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 12px;
    background: var(--bg-light);
    color: var(--text-dark);
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-region {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
}

/* Table */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    text-align: left;
    padding: 0.75rem;
    background: var(--bg-light);
    font-weight: 600;
    border-bottom: 2px solid var(--border);
    vertical-align: middle;
}

.table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.table tr:hover {
    background: #fafafa;
}

/* Drag and Drop */
.draggable-item {
    background: white;
    padding: 1rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: move;
    transition: all 0.2s;
}

.draggable-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.draggable-item.sortable-ghost {
    opacity: 0.4;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mt-3 {
    margin-top: 1.5rem;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mb-3 {
    margin-bottom: 1.5rem;
}

.flex {
    display: flex;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gap-1 {
    gap: 0.5rem;
}

.gap-2 {
    gap: 1rem;
}

.gap-3 {
    gap: 1.5rem;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .grid-cols-2,
    .grid-cols-3 {
        grid-template-columns: 1fr;
    }

    .app-nav {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* --- Card Unificado (ADICIONE ISTO) --- */
.route-card {
    display: grid;
    /* Grid de 4 colunas: Handle | Visual | Conteúdo (Fluido) | Ações */
    grid-template-columns: 24px 40px 1fr auto;
    gap: 12px;
    align-items: center;
    background: white;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 8px;
    transition: all 0.2s;
    height: 72px;
    /* Altura fixa para uniformidade visual */
}

.route-card:hover {
    border-color: #b0b0b0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

/* Cores por Tipo */
.route-card.type-point {
    border-left: 4px solid var(--primary);
}

.route-card.type-text {
    border-left: 4px solid var(--secondary);
    background: #fafafa;
}

.route-card.type-note {
    border-left: 4px solid var(--warning);
    background: #fffdf5;
}

/* Coluna 2: Visual (Thumb ou Icon) */
.card-visual {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    flex-shrink: 0;
}

.item-thumbnail {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
}

.item-icon-wrapper {
    color: #666;
}

/* Coluna 3: Conteúdo e Truncamento */
.card-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    /* CRÍTICO para o texto não estourar */
}

.card-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.card-subtitle {
    font-size: 0.8rem;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Coluna 4: Ações */
.card-actions {
    display: flex;
    gap: 4px;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.route-card:hover .card-actions {
    opacity: 1;
}

.btn-icon-small {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: #666;
    border-radius: 4px;
}

.btn-icon-small:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--primary);
}

.btn-icon-small.text-danger:hover {
    color: var(--error);
    background: rgba(255, 0, 0, 0.05);
}

/* --- Estilos do Drag & Drop --- */

/* Área de arraste (os 3 pontinhos ou linhas) */
.card-handle {
    cursor: grab;
    color: #9ca3af;
    /* Cinza suave */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 4px;
}

.card-handle:hover {
    color: var(--primary);
    background-color: rgba(0, 0, 0, 0.05);
}

.card-handle:active {
    cursor: grabbing;
}

/* Estado visual enquanto arrasta */
.sortable-ghost {
    background-color: #f3f4f6;
    border: 2px dashed #cbd5e1;
    opacity: 0.5;
}

.sortable-drag {
    opacity: 1;
    background: white;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    transform: scale(1.02);
    /* Leve aumento para dar sensação de "pegar" */
}

/* Utility to hide map wrapper */
.hidden-map {
    display: none !important;
}

.hidden-panel {
    display: none !important;
}

/* === Toggle Switch (iOS style) === */
.toggle-switch-container {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 12px;
    background: var(--surface-2);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.toggle-switch-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    user-select: none;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked+.toggle-slider {
    background-color: #10b981;
    /* Green quando ativo */
}

.toggle-switch input:checked+.toggle-slider:before {
    transform: translateX(20px);
}

.toggle-switch:hover .toggle-slider {
    opacity: 0.9;
}

/* --- ESTILOS DE PREVIEW (A4 Simulation) --- */

.preview-background {
    background-color: #525659;
    /* Cor de fundo cinza escuro estilo Acrobat Reader */
    /* Faz o preview ocupar todo o espaço restante do .main-content */
    flex-grow: 1;
    height: 100%;
    padding: 40px;
    display: flex;
    justify-content: center;
    overflow-y: auto;
    /* A rolagem acontece aqui dentro */
}

.a4-page {
    background: white;
    width: 210mm;
    /* Largura exata A4 */
    min-height: 297mm;
    /* Altura mínima A4 */
    padding: 20mm;
    /* Margens de impressão padrão */
    margin: 0 auto 30px auto;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    /* Sombra para dar profundidade */
    position: relative;
    color: #000;
    /* Texto sempre preto para impressão */
}

/* Header do Roteiro (Dentro da folha) */
.itinerary-header {
    text-align: center;
    border-bottom: 2px solid var(--secondary);
    padding-bottom: 20px;
    margin-bottom: 30px;
}

.itinerary-title {
    font-size: 24pt;
    font-family: "Georgia", serif;
    /* Fonte mais editorial */
    color: var(--primary);
    margin-bottom: 10px;
}

.itinerary-meta {
    color: #666;
    font-size: 11pt;
}

/* Seções do Roteiro */
.preview-section {
    margin-bottom: 30px;
    break-inside: avoid;
    /* Tenta não quebrar a seção no meio da página */
}

.preview-section-title {
    font-size: 16pt;
    color: var(--secondary);
    border-bottom: 1px solid #eee;
    margin-bottom: 15px;
    padding-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Itens do Roteiro */
.preview-item {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    page-break-inside: avoid;
    /* Evita quebrar um item ao meio na impressão */
}

.preview-time {
    font-weight: bold;
    color: var(--secondary);
    min-width: 60px;
    font-size: 10pt;
}

.preview-content {
    flex: 1;
}

.preview-item-title {
    font-weight: bold;
    font-size: 12pt;
    margin-bottom: 4px;
}

.preview-item-desc {
    font-size: 10pt;
    color: #444;
    line-height: 1.5;
}

.preview-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-radius: 4px;
    margin-top: 10px;
    margin-bottom: 10px;
}

/* Notas Especiais */
.preview-note {
    background: #fffdf5;
    border-left: 3px solid var(--warning);
    padding: 10px 15px;
    margin-top: 5px;
    font-size: 0.9em;
    font-style: italic;
}

/* --- MEDIA QUERY DE IMPRESSÃO (O Mágico) --- */
@media print {

    /* Esconde tudo que não é o papel */
    body * {
        visibility: hidden;
    }

    /* Esconde Sidebar, Header do Site, Botões */
    .sidebar,
    .app-header,
    .preview-toolbar,
    .no-print {
        display: none !important;
    }

    /* Mostra apenas a folha A4 */
    .a4-page,
    .a4-page * {
        visibility: visible;
    }

    .preview-background {
        background: white;
        padding: 0;
        height: auto;
        overflow: visible;
    }

    .a4-page {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        margin: 0;
        padding: 0;
        /* O driver de impressão controla a margem física */
        box-shadow: none;
        min-height: auto;
    }

    /* Garante cores de fundo (crucial para badges e notas) */
    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}