/**
 * CORE - Sistema Gestionale DKR
 * Stylesheet principale - Design pulito e minimale
 */

/* ============================================
   IMPORT FONTS
   ============================================ */
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;700&family=Oswald:wght@400;600;700&display=swap');

/* ============================================
   VARIABILI CSS
   ============================================ */
:root {
    /* Colori principali */
    --primary: #1974AB;
    --primary-dark: #145a87;
    --primary-light: #2589c9;

    /* Colori secondari */
    --secondary: #666666;
    --secondary-light: #999999;

    /* Colori stato (non utilizzati direttamente) */
    --success: #999999;
    --warning: #cccccc;
    --danger: #dddddd;
    --info: #999999;

    /* Colori neutri */
    --gray-50: #fafafa;
    --gray-100: #f2f2f2;
    --gray-200: #eeeeee;
    --gray-300: #dddddd;
    --gray-400: #cccccc;
    --gray-500: #999999;
    --gray-600: #666666;
    --gray-700: #444444;
    --gray-800: #333333;
    --gray-900: #222222;

    /* Background e testo */
    --bg-body: #f2f2f2;
    --bg-card: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;

    /* Bordi e ombre */
    --border-color: #dddddd;
    --border-color-light: #eeeeee;
    --border-radius: 3px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);

    /* Spaziature */
    --spacing-xs: 0.5rem;
    --spacing-sm: 0.75rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;

    /* Layout */
    --sidebar-width: 260px;
    --header-height: 72px;

    /* Transizioni */
    --transition: all 0.2s ease;
}

/* ============================================
   RESET E BASE
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Open Sans', sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Oswald', sans-serif;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-md);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--primary-dark);
}

img {
    max-width: 100%;
    height: auto;
}

/* ============================================
   LAYOUT PRINCIPALE
   ============================================ */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 1000;
    transition: var(--transition);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    font-family: 'Oswald', sans-serif;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 1px;
    line-height: 1;
    cursor: pointer;
    transition: var(--transition);
}

.sidebar-logo:hover {
    color: var(--primary-dark);
}

.sidebar-nav {
    padding: var(--spacing-md) 0;
}

.nav-item {
    padding: 0;
    margin: 0 var(--spacing-md) var(--spacing-xs);
}

.nav-link {
    display: flex;
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-md);
    color: var(--text-secondary);
    border-radius: var(--border-radius);
    transition: var(--transition);
    font-weight: 400;
}

.nav-link:hover {
    background: var(--gray-100);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--primary);
    color: white;
}

.nav-link.active:hover {
    background: var(--primary-dark);
    color: white;
}

.nav-icon {
    margin-right: var(--spacing-sm);
    width: 20px;
    height: 20px;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 0 var(--spacing-xl);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-title {
    font-family: 'Oswald', sans-serif;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 1px;
    line-height: 1;
    margin: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.user-name {
    font-size: 0.875rem;
    color: var(--text-primary);
    font-weight: 600;
}

/* Content Area */
.content-area {
    flex: 1;
    padding: var(--spacing-xl);
}

/* ============================================
   COMPONENTI
   ============================================ */

/* Card */
.card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    margin-bottom: var(--spacing-lg);
}

.card-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-family: 'Oswald', sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0;
}

.card-body {
    padding: var(--spacing-lg);
    overflow: hidden;
}

.card-body[style*="padding: 0"] {
    padding: 0;
}

.card-footer {
    padding: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    background: var(--gray-50);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1.5;
    border-radius: var(--border-radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    gap: var(--spacing-xs);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: white;
}

.btn-secondary {
    background: #bbbbbb;
    color: white;
    border-color: #bbbbbb;
}

.btn-secondary:hover:not(:disabled) {
    background: #999999;
    border-color: #999999;
    color: white;
}

.btn-success {
    background: #999999;
    color: white;
    border-color: #999999;
}

.btn-success:hover:not(:disabled) {
    background: #666666;
    border-color: #666666;
}

.btn-danger {
    background: #999999;
    color: white;
    border-color: #999999;
}

.btn-danger:hover:not(:disabled) {
    background: #666666;
    border-color: #666666;
}

.btn-sm {
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* Forms */
.form-group {
    margin-bottom: var(--spacing-lg);
}

.form-label {
    display: block;
    margin-bottom: var(--spacing-xs);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.form-label.required::after {
    content: ' *';
    color: #999999;
}

.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(25, 116, 171, 0.1);
}

.form-control:disabled {
    background: var(--gray-100);
    cursor: not-allowed;
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

select.form-control {
    cursor: pointer;
}

.form-text {
    display: block;
    margin-top: var(--spacing-xs);
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.form-error {
    color: #999999;
}

/* Form field widths for short inputs */
.form-control-short {
    max-width: 200px;
}

.form-control-medium {
    max-width: 350px;
}

.form-control-price {
    max-width: 150px;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-md);
}

.form-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: var(--spacing-md);
}

@media (max-width: 768px) {
    .form-grid-2,
    .form-grid-3 {
        grid-template-columns: 1fr;
    }

    .form-control-short,
    .form-control-medium,
    .form-control-price {
        max-width: 100%;
    }
}

/* Table */
.table-responsive {
    overflow-x: auto;
    margin: 0;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin: 0;
}

.table thead {
    background: transparent;
}

.table th {
    padding: 15px;
    text-align: left;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.table th:first-child {
    padding-left: 25px;
}

.table th:last-child {
    padding-right: 25px;
}

.table td {
    padding: 15px;
    border-bottom: 1px solid var(--border-color-light);
    font-size: 0.875rem;
    white-space: nowrap;
}

.table td:first-child {
    padding-left: 25px;
}

.table td:last-child {
    padding-right: 25px;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    border-radius: 3px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-primary {
    background: #999999;
    color: #333333;
}

.badge-success {
    background: #999999;
    color: #333333;
}

.badge-warning {
    background: #cccccc;
    color: #666666;
}

.badge-danger {
    background: #dddddd;
    color: #999999;
}

.badge-secondary {
    background: #cccccc;
    color: #666666;
}

/* Alert */
.alert {
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing-lg);
    border: 1px solid transparent;
}

.alert-success {
    background: #f2f2f2;
    border-color: #dddddd;
    color: #333333;
}

.alert-danger {
    background: #f2f2f2;
    border-color: #dddddd;
    color: #333333;
}

.alert-warning {
    background: #f2f2f2;
    border-color: #dddddd;
    color: #333333;
}

.alert-info {
    background: #f2f2f2;
    border-color: #dddddd;
    color: #333333;
}

/* Stats Card */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
}

.stat-card {
    background: var(--bg-card);
    padding: var(--spacing-md);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary);
}

.stat-card.success {
    border-left-color: #999999;
}

.stat-card.warning {
    border-left-color: #cccccc;
}

.stat-card.danger {
    border-left-color: #dddddd;
}

.stat-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-family: 'Oswald', sans-serif;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: var(--spacing-2xl);
}

.empty-state-icon {
    font-size: 3rem;
    color: var(--gray-400);
    margin-bottom: var(--spacing-md);
}

.empty-state-title {
    font-family: 'Oswald', sans-serif;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-xs);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.empty-state-text {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-lg);
}

/* Loading */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: #999999; }
.text-danger { color: #999999; }
.text-warning { color: #cccccc; }

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-normal { font-weight: 400; }

.mt-0 { margin-top: 0; }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }

.mb-0 { margin-bottom: 0; }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }

.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }

/* ============================================
   LOGIN PAGE
   ============================================ */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
}

.login-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    padding: var(--spacing-2xl);
    width: 100%;
    max-width: 420px;
}

.login-logo {
    text-align: center;
    margin-bottom: var(--spacing-xl);
}

.login-logo h1 {
    font-family: 'Oswald', sans-serif;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: var(--spacing-xs);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.login-logo p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ============================================
   CLIENT SELECTOR (Multi-select replacement)
   ============================================ */
.client-selector-wrapper {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-card);
    max-height: 350px;
    overflow-y: auto;
}

.client-search-box {
    padding: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 10;
}

.client-search-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.client-search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(25, 116, 171, 0.1);
}

.client-list {
    padding: var(--spacing-xs);
}

.client-checkbox-item {
    display: flex;
    align-items: center;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2px;
}

.client-checkbox-item:hover {
    background: var(--gray-100);
}

.client-checkbox-item input[type="checkbox"] {
    margin: 0;
    margin-right: var(--spacing-sm);
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.client-checkbox-label {
    flex: 1;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-primary);
    user-select: none;
}

.client-checkbox-item.selected {
    background: rgba(25, 116, 171, 0.08);
}

.client-checkbox-item.selected .client-checkbox-label {
    font-weight: 600;
    color: var(--primary);
}

.client-selected-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
    min-width: 20px;
}

.client-primary-badge {
    display: inline-flex;
    align-items: center;
    background: var(--primary-light);
    color: white;
    font-size: 0.625rem;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    margin-left: var(--spacing-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.client-no-results {
    padding: var(--spacing-lg);
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Card header subtitle */
.card-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    /* Sidebar mobile */
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .app-header {
        padding: 0 var(--spacing-md);
    }

    .content-area {
        padding: var(--spacing-md);
    }

    /* Tabelle responsive */
    .table-responsive {
        margin: 0;
    }

    .table thead {
        display: none;
    }

    .table tr {
        display: block;
        margin-bottom: var(--spacing-md);
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius);
        background: var(--bg-card);
    }

    .table td {
        display: flex;
        justify-content: space-between;
        padding: var(--spacing-sm) var(--spacing-md);
        border-bottom: 1px solid var(--border-color-light);
    }

    .table td:last-child {
        border-bottom: none;
    }

    .table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 0.8125rem;
        text-transform: uppercase;
    }

    /* Stats grid */
    .stats-grid {
        grid-template-columns: 1fr;
    }

    /* Buttons */
    .btn {
        width: 100%;
        justify-content: center;
    }

    /* User info */
    .user-name {
        display: none;
    }
}

@media (max-width: 480px) {
    .header-title {
        font-size: 1rem;
    }

    .login-card {
        padding: var(--spacing-lg);
    }
}
