/* ============================================
   MARTI SISTEMI - Shared Styles
   Centralized CSS for the warehouse application
   ============================================ */

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS Variables */
:root {
    --primary-color: #34495e;
    --secondary-color: #5dade2;
    --accent-color: #5dade2;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --background-color: #f5f5f5;
    --card-background: #ffffff;
    --text-color: #333333;
    --text-muted: #6c757d;
    --border-color: #d0d0d0;
    --navbar-bg: #34495e;
}

/* Base */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.5;
    font-size: 0.85rem;
}

/* Navigation */
nav {
    background: linear-gradient(135deg, #34495e 0%, #4a5f7f 100%);
    color: #ffffff;
    padding: 0.5rem 2rem;
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}

nav .nav-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

nav .logo-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

nav .logo-container img {
    height: 40px;
    width: auto;
}

nav h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: #ffffff;
}

nav h1 span {
    color: #ffffff;
}

nav .hamburger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    flex-direction: column;
    gap: 5px;
}

nav .hamburger span {
    display: block;
    width: 24px;
    height: 3px;
    background: #fff;
    border-radius: 2px;
    transition: transform 0.3s, opacity 0.3s;
}

nav ul {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    justify-content: flex-end;
}

nav a {
    color: #ffffff;
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    white-space: nowrap;
    transition: all 0.3s;
    font-weight: 500;
}

nav a:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    transform: translateY(-2px);
}

/* Main container */
.container {
    max-width: 1400px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.page-header h1 {
    font-size: 1.2rem;
    margin: 0;
}

/* Cards */
.card {
    background: var(--card-background);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.card h2 {
    margin-bottom: 0.75rem;
    color: #34495e;
    border-bottom: 2px solid #5dade2;
    padding-bottom: 0.4rem;
    font-size: 1rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label:not(.form-check-label) {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.8rem;
}

.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
    font-family: inherit;
}

/* Filter bar */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    align-items: end;
}

.filter-bar .form-group {
    margin-bottom: 0;
}

.filter-bar .form-group:first-child {
    flex: 2;
}

.filter-bar .form-group:nth-child(2) {
    flex: 1;
}

.form-group input:not([type="checkbox"]):not([type="radio"]):focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #5dade2;
    box-shadow: 0 0 0 3px rgba(93, 173, 226, 0.15);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    border: none;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.3s;
    text-align: center;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

.btn-outline-primary {
    background: transparent;
    color: #5dade2;
    border: 1px solid #5dade2;
}

.btn-outline-primary:hover {
    background-color: #5dade2;
    color: white;
}

.btn-primary {
    background-color: #5dade2;
    color: white;
}

.btn-primary:hover {
    background-color: #3498db;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(93, 173, 226, 0.3);
}

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

.btn-success:hover {
    background-color: #229954;
}

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

.btn-danger:hover {
    background-color: #c0392b;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

/* Messages */
.messages {
    margin-bottom: 1.5rem;
}

.alert {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.alert-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Grid */
.grid {
    display: grid;
    gap: 1.5rem;
}

.grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.grid-3 {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

/* Table */
table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
}

th, td {
    padding: 0.4rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

thead {
    background: linear-gradient(135deg, #34495e 0%, #4a5f7f 100%);
}

th {
    background: transparent;
    color: white;
    font-weight: 600;
}

tr:hover {
    background-color: #f8f9fa;
}

/* Compact table variant */
.table-compact {
    margin-bottom: 0;
}

.table-compact thead {
    background: linear-gradient(135deg, #34495e 0%, #4a5f7f 100%);
}

.table-compact th {
    background: transparent;
    color: white;
    padding: 0.25rem 0.4rem;
    font-size: 0.8rem;
}

.table-compact td {
    padding: 0.25rem 0.4rem;
    font-size: 0.8rem;
}

.table-compact .btn-sm {
    padding: 0.15rem 0.35rem;
    font-size: 0.7rem;
}

.table-compact .badge {
    padding: 0.15rem 0.5rem;
    font-size: 0.7rem;
}

/* Status Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    color: white;
    white-space: nowrap;
}

.badge-da-iniziare { background: #f39c12; }
.badge-in-corso { background: #5dade2; }
.badge-completato { background: #27ae60; }
.badge-annullato { background: #999; }

.badge-aperta { background: #d4edda; color: #155724; }
.badge-in_corso { background: #d1ecf1; color: #0c5460; }
.badge-completata { background: #cce5ff; color: #004085; }
.badge-chiusa { background: #d6d8db; color: #383d41; }

.badge-success { background: #d4edda; color: #155724; }
.badge-secondary { background: #d6d8db; color: #383d41; }
.badge-info { background: #5dade2; }

.text-muted-block { display: block; margin-top: 0.25rem; color: var(--text-muted); }

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 0;
    border: 1px solid #888;
    border-radius: 8px;
    width: 90%;
    max-width: 700px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.modal-header {
    padding: 15px 20px;
    background-color: var(--secondary-color);
    color: white;
    border-radius: 8px 8px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
}

.modal-body {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 15px 20px;
    background-color: #f8f9fa;
    border-radius: 0 0 8px 8px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal .close {
    color: white;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    background: none;
    border: none;
    line-height: 1;
}

.modal .close:hover {
    color: #f0f0f0;
}

.modal-header-danger {
    background-color: var(--danger-color);
}

/* Narrow variant for confirmation dialogs */
.modal-confirm .modal-content {
    max-width: 420px;
    margin: 15% auto;
}

/* Checkboxes / radio buttons */
.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-left: 0;
}

.form-check-input {
    position: static;
    margin: 0;
    flex-shrink: 0;
}

.form-check-label {
    margin: 0;
    cursor: pointer;
}

/* Detail link (looks like form-control but is a link) */
.detail-link {
    display: block;
    background: #f8f9fa;
    color: #495057;
    text-decoration: none;
    cursor: pointer;
}

.detail-link:hover {
    border-color: #80bdff;
    box-shadow: 0 0 0 0.1rem rgba(0,123,255,.25);
}

.detail-table .valign-top {
    vertical-align: top;
}

/* Grand total row in product tables */
.table-total-row td {
    background: #f0f4f8;
    border-top: 2px solid #34495e;
    font-size: 0.9rem;
}

/* Hours input group */
.hours-input-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.hours-input {
    width: 80px;
}

/* Quantity controls */
.qty-controls {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.qty-value {
    min-width: 40px;
    text-align: center;
}

/* Product thumbnail */
.product-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
}

.product-thumb-placeholder {
    width: 40px;
    height: 40px;
    background: #ddd;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

/* Search results hidden */
.search-results-hidden {
    margin-top: 1rem;
    display: none;
}

/* Search result items */
.search-result-item {
    border: 1px solid #ddd;
    padding: 0.75rem;
    border-radius: 4px;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.search-result-item img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
}

.search-result-item .search-result-placeholder {
    width: 60px;
    height: 60px;
    background: #ddd;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-result-item .search-result-info {
    flex: 1;
}

/* Address Cards */
.address-card {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    position: relative;
    transition: box-shadow 0.2s;
}

.address-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.address-card.is-default {
    border-left: 4px solid var(--success-color);
}

.address-card:not(.is-default) {
    border-left: 4px solid #ddd;
}

.address-card .address-label {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.address-card .address-text {
    color: #666;
    font-size: 0.85rem;
    line-height: 1.4;
    margin: 0;
}

.address-card .badge-default {
    background-color: var(--success-color);
    color: white;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.address-card .address-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

/* Mobile visibility helpers */
.show-mobile {
    display: none;
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
    .show-mobile {
        display: block;
    }
}

/* Mobile card layout */
.mobile-card {
    display: block;
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    text-decoration: none;
    color: var(--text-color);
    transition: box-shadow 0.2s;
}

.mobile-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.mobile-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.mobile-card-code {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.8rem;
}

.mobile-card-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.35rem;
}

.mobile-card-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    padding: 0.1rem 0;
    color: var(--text-muted);
}

.mobile-card-label {
    font-weight: 500;
    color: var(--text-color);
}

/* Responsive */
@media (max-width: 768px) {
    nav .hamburger {
        display: flex;
    }

    nav .nav-links {
        display: none;
        width: 100%;
        flex-direction: column;
        gap: 0.25rem;
        text-align: center;
    }

    nav.nav-open .nav-links {
        display: flex;
    }

    nav .nav-content {
        flex-wrap: wrap;
    }
    
    .container {
        padding: 0 0.5rem;
    }
    
    table {
        font-size: 0.9rem;
    }
    
    th, td {
        padding: 0.5rem;
    }
}

/* Tablet optimized (iPad) */
@media (min-width: 768px) and (max-width: 1024px) {
    .container {
        max-width: 95%;
    }
    
    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Dashboard stat cards */
.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
}

.card h3 {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

/* Card header / body compact */
.card-header {
    padding: 0.4rem 0.75rem;
    background: linear-gradient(135deg, #34495e 0%, #4a5f7f 100%);
    color: white;
}

.card-header h5 {
    margin: 0;
    font-size: 0.9rem;
    color: white;
}

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

.card-body {
    padding: 0.75rem;
}

/* Detail page header bar */
.detail-title {
    background: linear-gradient(135deg, #34495e 0%, #4a5f7f 100%);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.detail-title h2 {
    margin: 0;
    font-size: 1.1rem;
    color: white;
    border: none;
    padding: 0;
}

.detail-title .btn {
    margin-left: auto;
}

/* Detail table (inline edit forms) */
.detail-table {
    margin-bottom: 0;
}

.detail-table th {
    background: linear-gradient(135deg, #34495e 0%, #4a5f7f 100%);
    color: white;
    width: 25%;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    vertical-align: middle;
    border-bottom: 1px solid rgba(255,255,255,0.2);
}

.detail-table td {
    padding: 0.25rem 0.4rem;
    vertical-align: middle;
}

.detail-table .form-control {
    width: 100%;
    padding: 0.35rem 0.65rem;
    font-size: 0.85rem;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    transition: all 0.15s ease-in-out;
}

.detail-table .form-control:focus {
    border-color: #80bdff;
    box-shadow: 0 0 0 0.1rem rgba(0,123,255,.25);
    outline: none;
}

/* Section header (flex row with title + action) */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.section-header h3 {
    margin: 0;
}

/* Intervento card (sidebar-colored list item) */
.intervento-card {
    padding: 0.6rem;
    margin-bottom: 0.5rem;
    background: #f8f9fa;
    border-radius: 4px;
    border-left: 4px solid #999;
}

.intervento-card.status-da-iniziare { border-left-color: #f39c12; }
.intervento-card.status-in-corso { border-left-color: #5dade2; }
.intervento-card.status-completato { border-left-color: #27ae60; }

.intervento-card.unassigned {
    background: #fff3cd;
    border-left-color: #f39c12;
}

.intervento-card .intervento-row {
    display: flex;
    justify-content: space-between;
    align-items: start;
}

.intervento-card .intervento-row > div:first-child {
    flex: 1;
}

.intervento-card a.intervento-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.intervento-card .intervento-meta {
    font-size: 0.8rem;
    color: #666;
    margin-top: 0.15rem;
}

.intervento-card .intervento-date {
    font-size: 0.75rem;
    color: #999;
    margin-top: 0.15rem;
}

/* Scroll container */
.scroll-container {
    max-height: 300px;
    overflow-y: auto;
}

/* Product grid card */
.product-card {
    border: 1px solid #ddd;
    padding: 0.75rem;
    border-radius: 8px;
}

.product-card .product-image {
    text-align: center;
    margin-bottom: 0.75rem;
}

.product-card .product-image img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 4px;
}

.product-card .product-image-placeholder {
    width: 100%;
    height: 150px;
    background: #f0f0f0;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
}

.product-card .product-code {
    color: var(--secondary-color);
    font-weight: 600;
}

.product-card h3 {
    font-size: 0.95rem;
    margin: 0.3rem 0;
}

.product-card .product-category {
    font-size: 0.8rem;
    color: #666;
}

.product-card .product-price {
    font-size: 1rem;
    font-weight: bold;
    color: var(--success-color);
    margin: 0.3rem 0;
}

.product-card .product-stock {
    font-size: 0.8rem;
    color: #666;
}

.product-card .btn {
    width: 100%;
    margin-top: 0.5rem;
}

/* Pagination */
.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.pagination-nav {
    display: flex;
    gap: 0.5rem;
}

.page-number {
    padding: 0.35rem 0.75rem;
    background: #f8f9fa;
    border-radius: 4px;
    color: #333;
}

/* Empty state */
.empty-state {
    padding: 1.5rem 0;
}

/* Inline form */
.form-inline {
    display: inline;
}

/* Full width button */
.btn-block {
    width: 100%;
}

/* Utility classes */
.text-center { text-align: center; }
.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; }
.text-muted { color: #6c757d; }
.color-primary { color: var(--primary-color); }
.color-secondary { color: var(--secondary-color); }
.color-success { color: var(--success-color); }
.color-warning { color: var(--warning-color); }
.color-danger { color: var(--danger-color); }
