* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Montserrat", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: linear-gradient(135deg, #f0f4f8 0%, #e1e8f0 100%);
    color: #1f2933;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    line-height: 1.6;
}

.container {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

.app-card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
    padding: 32px 32px 36px;
    position: relative;
    overflow: hidden;
    border: 1px solid #dde5f0;
}

.header-section {
    text-align: center;
    margin-bottom: 24px;
    padding-bottom: 18px;
    border-bottom: 1px solid #e1e8f0;
}

.logo-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    margin-bottom: 8px;
}

.logo {
    width: 156px;
    background: linear-gradient(135deg, #1e3a5f 0%, #2c5282 100%);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 32px;
    font-weight: bold;
    box-shadow: 0 8px 20px rgba(30, 58, 95, 0.28);
    transform: rotate(4deg);
    transition: transform 0.3s ease;
}

.logo:hover {
    transform: rotate(0deg) scale(1.02);
}

.logo-image {
    width: 135px;
    height: 80px;
    object-fit: contain;
    filter: brightness(0) invert(1);
}

.title-container h1 {
    font-size: 2.2rem;
    margin-bottom: 4px;
    color: #1e3a5f;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 1rem;
    color: #4a5568;
    font-weight: 400;
}

.accent-line {
    height: 4px;
    background: linear-gradient(to right, #1e3a5f, #2c5282, #4c7cb3);
    width: 90px;
    border-radius: 999px;
    margin: 14px auto 0;
}

.camera-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 8px;
}

#webcam-container {
    width: 100%;
    max-width: 720px;
    height: 380px;
    background: #f7fafc;
    border-radius: 10px;
    display: flex;
    align-items: stretch;
    justify-content: center;
    margin-bottom: 18px;
    overflow: hidden;
    position: relative;
    border: 1px solid #cbd5e0;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.03);
}

.camera-frame {
    flex: 1;
    height: 100%;
    display: flex;
    align-items: stretch;
    justify-content: center;
    position: relative;
}

.camera-placeholder {
    border: none;
    background: transparent;
    text-align: left;
    color: #4a5568;
    padding: 20px 24px;
    cursor: pointer;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    transition: background 0.2s ease, transform 0.1s ease;
}

.camera-placeholder:hover {
    background: #edf2f7;
    transform: translateY(-1px);
}

.camera-placeholder-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1e3a5f;
}

#webcam-status {
    font-size: 0.95rem;
    color: #4a5568;
}

.webcam-video,
#capture-canvas,
#captured-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
    display: none;
}

.camera-loading {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(248, 250, 252, 0.8);
    text-align: center;
    color: #2c5282;
    z-index: 5;
    align-items: center;
    justify-content: center;
}

.camera-loading .spinner {
    margin-bottom: 10px;
}

/* Status */
.status-container {
    text-align: center;
    margin: 10px 0 18px;
    padding: 14px 16px;
    border-radius: 8px;
    background: #f7fafc;
    font-size: 0.95rem;
    color: #4a5568;
    border-left: 4px solid #2c5282;
    width: 100%;
    max-width: 720px;
}

/* Botones */
.controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
    max-width: 720px;
}

button {
    font-family: inherit;
}

.btn-primary,
.btn-secondary,
.btn-ghost {
    padding: 12px 24px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.95rem;
    min-width: 170px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px rgba(15, 23, 42, 0.08);
}

.btn-primary {
    background: linear-gradient(to right, #1e3a5f, #2c5282);
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 10px rgba(15, 23, 42, 0.18);
}

.btn-secondary {
    background: #ffffff;
    border: 1px solid #cbd5e0;
    color: #1e3a5f;
}

.btn-secondary:hover:not(:disabled) {
    background: #edf2f7;
}

.btn-ghost {
    background: transparent;
    border: 1px dashed #cbd5e0;
    color: #4a5568;
    box-shadow: none;
}

.btn-ghost:hover:not(:disabled) {
    background: #f7fafc;
}

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-ghost:disabled {
    background: #a0aec0;
    color: #e2e8f0;
    cursor: not-allowed;
    box-shadow: none;
    border-color: transparent;
}

/* Modales genéricos */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.65);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 16px;
    overflow-y: auto;
    /* importante para pantallas bajas */
}

.modal-content {
    background: white;
    padding: 26px 26px 22px;
    border-radius: 12px;
    width: 100%;
    max-width: 780px;
    box-shadow: 0 15px 40px rgba(15, 23, 42, 0.22);
    animation: modalAppear 0.35s ease;
    border-top: 5px solid #2c5282;
    max-height: calc(100vh - 32px);
    /* nunca sobresale de la pantalla */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* scroll suave en móvil */
}

@keyframes modalAppear {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(-14px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e1e8f0;
}

.modal-title {
    font-size: 1.4rem;
    color: #1e3a5f;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: #4a5568;
    cursor: pointer;
    padding: 4px;
    min-width: auto;
    box-shadow: none;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.modal-close:hover {
    background: #f7fafc;
    color: #1e3a5f;
}

.modal-body {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: 24px;
    margin-bottom: 16px;
}

.modal-body-single {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-option {
    width: 100%;
    text-align: left;
    border-radius: 10px;
    border: 1px solid #d2d6e0;
    padding: 14px 16px;
    background: #f8fafc;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-option:hover {
    background: #edf2ff;
    border-color: #2c5282;
}

.modal-option--active {
    border-color: #2c5282;
    background: #edf2ff;
}

.modal-option-title {
    font-size: 0.98rem;
    font-weight: 600;
    color: #1e3a5f;
    margin-bottom: 4px;
}

.modal-option-desc {
    font-size: 0.85rem;
    color: #4a5568;
}

.modal-photo-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.photo-preview {
    width: 100%;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(15, 23, 42, 0.18);
}

.modal-info {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-result {
    font-size: 1.2rem;
    color: #1e3a5f;
    font-weight: 600;
}

.modal-confidence {
    font-size: 0.95rem;
    color: #4a5568;
}

.high-confidence {
    color: #1e3a5f;
    font-weight: 700;
}

.pet-info {
    background: #f7fafc;
    border-radius: 8px;
    padding: 18px;
    border-left: 4px solid #2c5282;
}

.pet-info h3 {
    margin-bottom: 10px;
    color: #1e3a5f;
    font-size: 1.05rem;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    padding: 7px 0;
    border-bottom: 1px solid #e1e8f0;
    font-size: 0.9rem;
}

.info-label {
    font-weight: 600;
    color: #4a5568;
}

.info-value {
    color: #1e3a5f;
    font-weight: 500;
    text-align: right;
}

.class-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.class-1 {
    background: #e6f2ff;
    color: #1e3a5f;
}

.class-2 {
    background: #d6e4ff;
    color: #2c5282;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}

.modal-action {
    padding: 10px 22px;
    background: linear-gradient(to right, #1e3a5f, #2c5282);
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.95rem;
    box-shadow: 0 4px 6px rgba(15, 23, 42, 0.16);
}

.modal-action:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 10px rgba(15, 23, 42, 0.22);
}

/* Overlay global loader */
.global-loader {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    z-index: 1500;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.global-loader-card {
    background: white;
    padding: 16px 18px;
    border-radius: 10px;
    min-width: 210px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 15px 40px rgba(15, 23, 42, 0.3);
}

.global-loader-card p {
    margin-top: 6px;
    font-size: 0.9rem;
    color: #1e3a5f;
}

/* Spinner genérico */
.spinner {
    border: 4px solid rgba(44, 82, 130, 0.25);
    border-radius: 50%;
    border-top: 4px solid #2c5282;
    width: 30px;
    height: 30px;
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Decoración */
.wave-decoration {
    position: absolute;
    bottom: -20px;
    right: -20px;
    width: 150px;
    height: 150px;
    opacity: 0.06;
    background: #1e3a5f;
    border-radius: 50%;
    z-index: -1;
}

/* ===== Responsivo fuerte para móvil ===== */

@media (max-width: 992px) {
    #webcam-container {
        height: 340px;
    }

    .modal-body {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    body {
        align-items: flex-start;
        padding: 16px 10px;
    }

    .container {
        padding: 10px;
    }

    .app-card {
        padding: 20px 14px 20px;
    }

    .title-container h1 {
        font-size: 1.7rem;
    }

    #webcam-container {
        height: 300px;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-primary,
    .btn-secondary,
    .btn-ghost {
        width: 100%;
        min-width: 0;
        font-size: 0.9rem;
        padding: 11px 18px;
    }

    .modal {
        align-items: flex-start;
        /* el modal arranca desde arriba en pantallas chicas */
        padding: 10px;
    }

    .modal-content {
        padding: 18px 14px 16px;
        border-radius: 10px;
        max-height: calc(100vh - 20px);
    }

    .modal-title {
        font-size: 1.25rem;
    }

    .modal-option {
        padding: 12px 12px;
    }

    .modal-option-title {
        font-size: 0.95rem;
    }

    .modal-option-desc {
        font-size: 0.82rem;
    }

    .status-container {
        font-size: 0.9rem;
        padding: 12px 12px;
    }
}

@media (max-width: 576px) {
    #webcam-container {
        height: 260px;
    }

    .title-container h1 {
        font-size: 1.55rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .modal-result {
        font-size: 1.05rem;
    }

    .modal-confidence {
        font-size: 0.88rem;
    }

    .info-item {
        font-size: 0.85rem;
    }
}

@media (max-width: 420px) {
    #webcam-container {
        height: 230px;
    }

    .title-container h1 {
        font-size: 1.45rem;
    }

    .app-card {
        padding: 18px 10px 18px;
    }
}

/* ===== Toast global (más compacto en móvil) ===== */

.toast-container {
    position: fixed;
    bottom: 1.1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    pointer-events: none;
}

.toast {
    display: none;
    background: #1a202c;
    color: #f7fafc;
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    font-size: 0.8rem;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
    max-width: 360px;
    width: 92vw;
    text-align: center;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.22s ease-out, transform 0.22s ease-out;
    border: 1px solid rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(8px);
}

.toast--visible {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

/* variantes por tipo */
.toast--error {
    background: linear-gradient(135deg, #c53030, #9b2c2c);
}

.toast--info {
    background: linear-gradient(135deg, #2b6cb0, #2c5282);
}

@media (min-width: 768px) {
    .toast-container {
        bottom: 1.6rem;
    }

    .toast {
        font-size: 0.85rem;
        width: auto;
        max-width: 400px;
        padding: 0.6rem 1rem;
    }
}