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

:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --danger: #dc3545;
    --danger-dark: #b02a37;
    --success: #28a745;
    --warning: #ffc107;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-500: #6c757d;
    --gray-700: #495057;
    --gray-900: #212529;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    line-height: 1.5;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 24px 0;
    box-shadow: var(--shadow);
}

header .header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 700;
}

header .subtitle {
    opacity: 0.85;
    font-size: 0.95rem;
    margin-top: 4px;
}

.header-logo {
    height: 70px;
    width: auto;
    display: block;
}

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

.header-nav a {
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s;
}

.header-sep {
    width: 1px;
    height: 20px;
    background: rgba(255,255,255,0.3);
    margin: 0 4px;
}

.header-user {
    color: rgba(255,255,255,0.8);
    font-size: 0.85rem;
    font-weight: 500;
}

.header-logout {
    font-size: 0.82rem !important;
    padding: 4px 12px !important;
    opacity: 0.7;
}

.header-logout:hover {
    opacity: 1;
}

.header-nav a:hover {
    color: white;
    background: rgba(255,255,255,0.15);
}

.header-nav a.active {
    color: white;
    background: rgba(255,255,255,0.25);
}

/* Main */
main {
    padding: 24px 0 40px;
}

/* Forms */
.search-form {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

.search-form h2 {
    font-size: 1.3rem;
    margin-bottom: 20px;
    color: var(--gray-700);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 4px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15);
}

/* Marketplace disabilitati nella select */
.form-group select option.mp-disabled,
.form-group select option:disabled {
    color: #adb5bd;
    font-style: italic;
    background: #f8f9fa;
}

.form-actions {
    display: flex;
    gap: 12px;
}

/* Buttons */
.btn {
    padding: 10px 24px;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

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

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

.btn-danger:hover:not(:disabled) {
    background: var(--danger-dark);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--gray-300);
}

/* Progress */
.progress-section {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

.progress-section h3 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: var(--gray-700);
}

.progress-bar {
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.5s ease;
    width: 0%;
}

.progress-fill.completed {
    background: var(--success);
}

.progress-fill.error {
    background: var(--danger);
}

.progress-fill.indeterminate {
    width: 30% !important;
    animation: indeterminate 1.5s infinite ease-in-out;
}

@keyframes indeterminate {
    0% { margin-left: 0; }
    50% { margin-left: 70%; }
    100% { margin-left: 0; }
}

.progress-info {
    font-size: 0.9rem;
    color: var(--gray-500);
    margin-bottom: 16px;
}

.progress-stats {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}

.stat {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    display: block;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--gray-900);
}

.stat-value.stat-warning {
    color: #e67e00;
}

/* Results */
.results-section {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.results-header h2 {
    font-size: 1.3rem;
    color: var(--gray-700);
}

.results-header h2 span {
    font-size: 0.9rem;
    color: var(--gray-500);
    font-weight: 400;
}

.results-table-wrapper {
    overflow-x: auto;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.results-table th {
    background: var(--gray-100);
    padding: 10px 12px;
    text-align: left;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-500);
    border-bottom: 2px solid var(--gray-300);
    white-space: nowrap;
}

.results-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-200);
    vertical-align: middle;
}

.results-table tr:hover td {
    background: var(--gray-100);
}

.results-table .thumbnail {
    width: 80px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
    background: var(--gray-200);
}

.results-table .no-image {
    width: 80px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-200);
    border-radius: 4px;
    color: var(--gray-500);
    font-size: 0.7rem;
}

.results-table .marca-modello {
    font-weight: 600;
}

.results-table .versione {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.8rem;
    color: var(--gray-500);
}

.results-table .prezzo {
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
}

.results-table a.link-annuncio {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.85rem;
}

.results-table a.link-annuncio:hover {
    text-decoration: underline;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 20px;
}

.pagination button {
    padding: 6px 14px;
    border: 1px solid var(--gray-300);
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}

.pagination button:hover {
    background: var(--gray-100);
}

.pagination button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Console Debug */
.console-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    max-height: 50vh;
    transition: max-height 0.3s ease;
}

.console-panel.collapsed {
    max-height: 32px;
}

.console-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: #2d2d2d;
    cursor: pointer;
    user-select: none;
    min-height: 32px;
    flex-shrink: 0;
    border-top: 2px solid #007acc;
}

.console-header span {
    font-weight: 600;
    color: #cccccc;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.console-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.console-controls button {
    background: none;
    border: 1px solid #555;
    color: #ccc;
    width: 22px;
    height: 22px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.console-controls button:hover {
    background: #444;
    color: white;
}

.console-badge {
    background: #007acc;
    color: white;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.console-badge.has-errors {
    background: #f44747;
}

.console-body {
    overflow-y: auto;
    padding: 8px 12px;
    flex: 1;
    min-height: 0;
}

.console-panel:not(.collapsed) .console-body {
    min-height: 120px;
    max-height: calc(50vh - 32px);
}

.console-line {
    padding: 2px 0;
    border-bottom: 1px solid #2a2a2a;
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.4;
}

.console-line .time {
    color: #6a9955;
    margin-right: 8px;
}

.console-line.log { color: #d4d4d4; }
.console-line.info { color: #4fc1ff; }
.console-line.warn { color: #cca700; background: rgba(204,167,0,0.05); }
.console-line.error { color: #f44747; background: rgba(244,71,71,0.08); }
.console-line.success { color: #4ec9b0; }
.console-line.request { color: #9cdcfe; }
.console-line.response { color: #ce9178; }

.console-line .json-key { color: #9cdcfe; }
.console-line .json-str { color: #ce9178; }
.console-line .json-num { color: #b5cea8; }
.console-line .json-bool { color: #569cd6; }
.console-line .json-null { color: #569cd6; }

/* Demo Banner */
.demo-banner {
    background: linear-gradient(135deg, #ff6b35, #f7c948);
    color: #1a1a2e;
    padding: 10px 20px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    position: relative;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
}

.demo-banner .demo-banner-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.demo-banner .demo-tag {
    background: rgba(0,0,0,0.15);
    padding: 2px 10px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.demo-banner .demo-timer {
    background: rgba(0,0,0,0.12);
    padding: 3px 12px;
    border-radius: 6px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9rem;
    white-space: nowrap;
}

.demo-banner .demo-timer.warning {
    background: rgba(220, 53, 69, 0.25);
    color: #8b0000;
}

.demo-banner .demo-info-text {
    font-weight: 400;
    font-size: 0.82rem;
}

.demo-banner .demo-sep {
    width: 1px;
    height: 16px;
    background: rgba(0,0,0,0.2);
}

/* Demo Overlay (tempo scaduto) */
.demo-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.demo-overlay-content {
    background: white;
    border-radius: 16px;
    padding: 48px;
    max-width: 520px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: demoOverlayIn 0.3s ease;
}

@keyframes demoOverlayIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.demo-overlay-content .demo-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    display: block;
}

.demo-overlay-content h2 {
    font-size: 1.5rem;
    color: var(--gray-900);
    margin-bottom: 12px;
}

.demo-overlay-content .demo-message {
    color: var(--gray-700);
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 24px;
}

.demo-overlay-content .demo-price {
    background: linear-gradient(135deg, #1a73e8, #1557b0);
    color: white;
    padding: 16px 24px;
    border-radius: 12px;
    margin-bottom: 24px;
}

.demo-overlay-content .demo-price .price-label {
    font-size: 0.8rem;
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.demo-overlay-content .demo-price .price-value {
    font-size: 2rem;
    font-weight: 800;
    display: block;
    margin-top: 4px;
}

.demo-overlay-content .demo-price .price-period {
    font-size: 0.9rem;
    opacity: 0.8;
}

.demo-overlay-content .demo-note {
    background: var(--gray-100);
    padding: 14px 18px;
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--gray-700);
    margin-bottom: 20px;
    font-style: italic;
}

.demo-overlay-content .demo-contacts {
    text-align: left;
    font-size: 0.85rem;
    color: var(--gray-700);
    line-height: 1.8;
    border-top: 1px solid var(--gray-200);
    padding-top: 16px;
}

.demo-overlay-content .demo-contacts strong {
    color: var(--gray-900);
}

.demo-overlay-content .demo-contacts .contact-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.demo-overlay-content .demo-contacts .contact-label {
    color: var(--gray-500);
    min-width: 70px;
    font-size: 0.8rem;
}

/* Welcome Dialog (post-login, chiudibile) */
.welcome-dialog-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 90000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(3px);
    animation: welcomeFadeIn 0.25s ease;
}

@keyframes welcomeFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.welcome-dialog {
    background: white;
    border-radius: 16px;
    padding: 40px 44px;
    max-width: 500px;
    width: 92%;
    text-align: center;
    box-shadow: 0 24px 80px rgba(0,0,0,0.25);
    animation: demoOverlayIn 0.3s ease;
    position: relative;
}

.welcome-dialog .welcome-close {
    position: absolute;
    top: 14px;
    right: 18px;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gray-500);
    cursor: pointer;
    line-height: 1;
    padding: 4px;
    transition: color 0.2s;
}

.welcome-dialog .welcome-close:hover {
    color: var(--gray-900);
}

.welcome-dialog .welcome-badge {
    display: inline-block;
    background: linear-gradient(135deg, #ff6b35, #f7c948);
    color: #1a1a2e;
    padding: 4px 16px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 16px;
}

.welcome-dialog h2 {
    font-size: 1.4rem;
    color: var(--gray-900);
    margin-bottom: 8px;
}

.welcome-dialog .welcome-subtitle {
    font-size: 0.9rem;
    color: var(--gray-500);
    margin-bottom: 24px;
}

.welcome-dialog .welcome-limits {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    justify-content: center;
}

.welcome-dialog .welcome-limit-card {
    flex: 1;
    background: var(--gray-100);
    border-radius: 10px;
    padding: 14px 12px;
    text-align: center;
}

.welcome-dialog .welcome-limit-card .limit-icon {
    font-size: 1.5rem;
    display: block;
    margin-bottom: 4px;
}

.welcome-dialog .welcome-limit-card .limit-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--gray-900);
    display: block;
}

.welcome-dialog .welcome-limit-card .limit-label {
    font-size: 0.72rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.welcome-dialog .welcome-cta {
    background: linear-gradient(135deg, #1a73e8, #1557b0);
    color: white;
    padding: 14px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.welcome-dialog .welcome-cta .cta-price {
    font-size: 1.6rem;
    font-weight: 800;
}

.welcome-dialog .welcome-cta .cta-period {
    font-size: 0.85rem;
    opacity: 0.8;
}

.welcome-dialog .welcome-cta .cta-text {
    font-size: 0.8rem;
    opacity: 0.85;
    text-align: left;
}

.welcome-dialog .welcome-note {
    background: #fffbeb;
    border: 1px solid #fde68a;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.82rem;
    color: #92400e;
    margin-bottom: 16px;
    font-style: italic;
}

.welcome-dialog .welcome-contacts {
    text-align: left;
    font-size: 0.82rem;
    color: var(--gray-700);
    line-height: 1.7;
    border-top: 1px solid var(--gray-200);
    padding-top: 14px;
}

.welcome-dialog .welcome-contacts strong {
    color: var(--gray-900);
}

.welcome-dialog .welcome-contacts .contact-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.welcome-dialog .welcome-contacts .contact-label {
    color: var(--gray-500);
    min-width: 60px;
    font-size: 0.78rem;
}

.welcome-dialog .welcome-btn-continue {
    margin-top: 20px;
    padding: 10px 32px;
    background: var(--gray-200);
    color: var(--gray-700);
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.welcome-dialog .welcome-btn-continue:hover {
    background: var(--gray-300);
}

/* Expiry Banner (registered, ultimi 10 giorni) */
.expiry-banner {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #1a1a2e;
    padding: 8px 20px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    position: relative;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.expiry-banner .expiry-banner-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
}

.expiry-banner .expiry-icon {
    font-size: 1.1rem;
}

.expiry-banner .expiry-days {
    background: rgba(0,0,0,0.15);
    padding: 2px 12px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.85rem;
    white-space: nowrap;
}

.expiry-banner .expiry-days.critical {
    background: rgba(220, 53, 69, 0.3);
    color: #7f1d1d;
}

.expiry-banner .expiry-text {
    font-weight: 400;
    font-size: 0.82rem;
}

.expiry-banner .expiry-contact {
    font-weight: 400;
    font-size: 0.8rem;
    opacity: 0.85;
}

/* Footer con spazio per console */
body:has(.console-panel) footer {
    padding-bottom: 180px;
}

footer {
    padding: 20px 0;
    text-align: center;
    color: var(--gray-500);
    font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr 1fr;
    }
    .progress-stats {
        gap: 16px;
    }
    .results-table {
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    header h1 {
        font-size: 1.4rem;
    }
    .header-logo {
        height: 36px;
    }
}
