/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #1b98b9;
    --primary-dark: #29405d;
    --secondary-color: #764ba2;
    --accent-color: #48bb78;
    --danger-color: #f56565;
    --warning-color: #ed8936;
    --bg-color: #e3e3e3;
    --card-bg: #ffffff;
    --text-primary: #2d3748;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
    --border-radius: 8px;
    --transition: all 0.3s ease;
}

:focus {
  outline: none;
}
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-focus-ring-color: transparent;
}
html, body {
  touch-action: manipulation;  /* evita doppio tap zoom */
  -ms-touch-action: manipulation; /* vecchio IE/Edge */
}
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-user-select: none; /* Safari */
    -moz-user-select: none;    /* Firefox */
    -ms-user-select: none;     /* IE/Edge */
    user-select: none;         /* Standard */
}
.selectable {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1rem;
}

.logo h1 {
    /* color: var(--primary-color);
    font-size: 1.8rem;
    font-weight: 700; */
    text-indent:-999px;
    overflow:hidden;
    width: 3rem;
    height: 3rem;
    background: url('./images/bookbuddy.png') no-repeat center center;
    background-size:cover;
    border-radius:.5rem;
}

h1 {}

.nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.lang-btn, .user-btn {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
}

.lang-btn:hover, .user-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.user-menu {
    position: relative;
}

.dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    min-width: 150px;
    z-index: 200;
    display: none;
}

.dropdown.show {
    display: block;
}

.dropdown a {
    display: block;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--text-primary);
    transition: var(--transition);
}

.dropdown a:hover {
    background: var(--bg-color);
}

/* Main Content */
.main {
    padding: 2rem 0;
    min-height: calc(100vh - 100px);
}

/* Auth Screen */
.auth-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}

.auth-card {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.auth-card h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--primary-color);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 1rem;
}

.form-group label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.form-group input {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.auth-switch {
    text-align: center;
    margin-top: 1rem;
}

.auth-switch a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.forgot-password-link {
    text-align: center;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.forgot-password-link a {
    color: var(--text-muted);
    text-decoration: none;
    transition: var(--transition);
}

.forgot-password-link a:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

/* Password Reset Modal */
.reset-step {
    text-align: center;
}

.reset-step p {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.success-message {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.success-message h4 {
    color: #155724;
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
}

.success-message p {
    color: #155724;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    display: inline-block;
    text-align: center;
    /* text-transform: uppercase; */
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: .5rem;
}
.btn-secondary.selected {
    background-color: #cfd4e8!important;
}
.btn-secondary:hover {
    background: var(--border-color);
}




/* Dashboard */
.dashboard {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/*.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-card h3 {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    
    font-size:.8rem;height:3rem;
    display:flex;align-items:center;
    justify-content:center

}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-text {
    font-size: .8rem;
    color: var(--text-muted);
}*/

/* Search Section */
.search-section {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.search-bar {
    display: flex;
    gap: 0.5rem;
}

.search-bar input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Shelves Section */
.shelves-section {
    /* background: var(--card-bg); */
    /* padding: 1rem; */
    /* border-radius: var(--border-radius); */
    /* box-shadow: var(--shadow); */
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.shelves-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
}

.shelf-card {
    background: var(--card-bg);
    border: 1px solid #bec3c9;
    border-radius: var(--border-radius);
    overflow: hidden;
    transition: var(--transition);
    position: relative;
}

.shelf-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.shelf-content {
    cursor: pointer;
}

.shelf-actions {
    padding: 0.75rem;
    border-top: 1px solid var(--border-color);
    /* background: var(--bg-color); */
    display: flex;
    /* justify-content: flex-end; */
    gap: 0.5rem;
}

.btn-danger {
    background: var(--danger-color);
    color: white;

}

.btn-danger:hover {
    background: #e53e3e;
    transform: translateY(-1px);
}

.delete-icon {
    font-size: 1rem;
}

/* OCR Data Section in Edit Modal */
.ocr-data-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    /* border-top: 1px solid var(--border-color); */
}

.raw-text-area {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.75rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--text-secondary);
    resize: vertical;
    min-height: 80px;
}

.raw-text-area:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-help {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.25rem;
    display: block;
}

.shelf-stats {
    position:absolute;
    top:11rem;
    left: .75rem;
    background-color:#000;
    color:#fff;
    border-radius:.3rem;
    display:inline-block;
    padding:.2rem .5rem;
    font-size:.7rem;
}
.book-counter:empty, .pic-counter:empty {
    display:none;
}
.shelf-image {
    width: 100%;
    object-fit: cover;
    aspect-ratio:1.75
}

.shelf-info {
    padding: 1rem;
}

.shelf-name {
    font-weight: 600;
    margin-bottom: 0.5rem;
}


/* .shelf-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--text-muted);
} */


/* Books List */
.books-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.books-list > * {
  order: 1;
}

.books-list > .selected {
  order: 0;
}
.book-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    transition: var(--transition);
    cursor: pointer;
}
.book-item.selected {
     background: var(--border-color);
     border-color: var(--text-primary);
}

/*.book-item:hover {
    background: #f1f5f9;
    border-color: var(--primary-color);
}*/

.book-info {
    flex: 1;
}

.book-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.book-author {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.book-position {
    color: var(--primary-color);
    font-size: 0.8rem;
    cursor: pointer;
    margin-top: 0.25rem;
    transition: var(--transition);
}

.book-position:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.book-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    flex: 0 1 20%;
    justify-content: flex-end;
}

.confidence-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    display:flex;
    align-items:center;
    justify-content:center;
}

.confidence-high {
    background: #c6f6d5;
    color: #22543d;
}

.confidence-medium {
    background: #fefcbf;
    color: #744210;
}

.confidence-low {
    background: #fed7d7;
    color: #742a2a;
}
.confidence-badge.verified {
    background: #4cad01;
    color: #ffffff;
}
/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#addShelfModalTitle,
#shelfModalTitle {
    flex: 0 0 calc(100% - 2.5rem);
}
.modal-close.icon-cancel::before {
    margin:0!important;
}

/* Edit book modal should appear above shelf modal */
#editBookModal {
    z-index: 1100;
    background: rgba(0, 0, 0, 0.7);
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    /* max-height: 90vh; */
    /* overflow-y: auto; */
}

.modal-large {
    max-width: 900px;
}

.modal-header {
    display: flex;
    /* justify-content: space-between; */
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: .5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    /* float: right; */
    /* background: red; */
    flex: 0 0 2rem;
}

.modal-body {
    padding: 1.5rem;
    max-height:80vh;
    overflow-y:auto;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}
.form-actions button {
     flex:0 0 calc(50% - .5rem);
}

/* File Upload */
.file-preview {
    margin-top: 1rem;
}

.file-preview img {
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius);
}

/* OCR Progress */
.ocr-progress {
    text-align: center;
    margin-bottom: 2rem;
}

.progress-bar {
    width: 100%;
    height: 10px;
    background: var(--border-color);
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    width: 0%;
    transition: width 0.3s ease;
}

/* Shelf Detail */
.shelf-detail {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

.shelf-image-container {
    position: relative;
}

.shelf-image-container img {
    width: 100%;
    height: auto;
    border-radius: var(--border-radius);
}

.highlight-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.books-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.book-count {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Search Results */
.search-results {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

/* Loading States */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    color: white;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Fullscreen Image Viewer */
.image-viewer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    display: flex;
    flex-direction: column;
}

.viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: rgba(0, 0, 0, 0.8);
    color: white;
}

.viewer-header h3 {
    margin: 0;
    font-size: 1.25rem;
}

.viewer-close {
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.viewer-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.viewer-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.viewer-content {
    position: relative;
    transform-origin: center center;
    transition: transform 0.1s ease-out;
    cursor: grab;
}

.viewer-content:active {
    cursor: grabbing;
}

.viewer-content img {
    max-width: 100vw;
    max-height: 100vh;
    display: block;
    user-select: none;
    pointer-events: none;
}

.viewer-canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.viewer-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.8);
}

.viewer-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    min-width: 50px;
}

.viewer-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

.viewer-btn:active {
    transform: scale(0.95);
}

/* Responsive adjustments for mobile */
@media (max-width: 768px) {
    .viewer-header {
        padding: 0.75rem 1rem;
    }
    
    .viewer-header h3 {
        font-size: 1rem;
    }
    
    .viewer-close {
        width: 40px;
        height: 40px;
        font-size: 1.5rem;
    }
    
    .viewer-controls {
        padding: 0.75rem;
        gap: 0.75rem;
    }
    
    .viewer-btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: .5rem;
    left: .5rem;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: #2d2a2a;
    /* border: 1px solid var(--border-color); */
    border-radius: var(--border-radius);
    padding: .5rem 1rem;
    box-shadow: var(--shadow-lg);
    max-width: 300px;
    animation: slideIn 0.3s ease;
    font-size: .9rem;
    color: #fff;
}

.toast.success {
    border-left: 4px solid var(--accent-color);
}

.toast.error {
    border-left: 4px solid var(--danger-color);
}

.toast.warning {
    border-left: 4px solid var(--warning-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-muted);
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* Responsive Design */
@media (max-width: 768px) {
    body,html {
        font-size:4vw;
    }
    .container {
        padding: 0 1rem;
    }
    
    .header-content {
        /* flex-direction: column; */
        gap: 1rem;
    }
    
    .shelves-grid {
        grid-template-columns: 1fr;
    }
    
    .shelf-detail {
        grid-template-columns: 1fr;
    }
    .stat-card .stat-text {
        font-size:.7rem
    }
    .stat-card h3 {
        font-size:.7rem
    }
    .modal-content {
        width: 95%;
        margin: 20px;
    }
    
    .search-bar {
        /* flex-direction: column; */
    }
    
    .form-actions {
        flex-direction: row;
        justify-content: space-between;
    }
}

@media (max-width: 480px) {
    .main {
        padding: 1rem 0;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .auth-card {
        padding: 1.5rem;
    }
}
