@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: radial-gradient(circle at top left, #1e293b, var(--bg-color));
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-size: 16px;
}

/* Glassmorphism utilities */
.glass {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    margin-bottom: 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(to right, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links a {
    color: var(--text-primary);
    text-decoration: none;
    margin-left: 1.5rem;
    font-weight: 500;
    transition: color 0.3s ease;
}

.nav-links a:hover {
    color: var(--accent);
}

/* Main Container */
.container {
    max-width: 1600px; /* Allargata per ospitare meglio tutte le colonne */
    margin: 0 auto;
    padding: 0 1rem;
    width: 100%;
    flex: 1;
}

/* Larghezza speciale solo per i report */
.container-wide {
    max-width: 95%;
    margin: 0 auto;
    padding: 0 1rem;
    width: 100%;
    flex: 1;
}

/* Dashboard Cards */
.balances-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.balance-card {
    padding: 1.5rem;
    text-align: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.balance-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
}

.balance-title {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.balance-amount {
    font-size: 1.875rem;
    font-weight: 700;
}

.balance-amount.positive {
    color: var(--success);
}
.balance-amount.negative {
    color: var(--danger);
}

/* Table styling */
.table-container {
    overflow-x: auto;
    margin-bottom: 3rem;
    width: 100%;
    -webkit-overflow-scrolling: touch; /* Smooth scroll on mobile */
    border-radius: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.6rem 0.3rem; /* Spazio molto ridotto per avvicinare scritte e cifre */
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    white-space: nowrap;
}

tbody tr {
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.amount-in {
    color: var(--success);
    font-weight: 600;
}

.amount-out {
    color: var(--danger);
    font-weight: 600;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(to right, var(--accent), #4f46e5);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(59, 130, 246, 0.39);
}

.btn-primary:hover {
    background: linear-gradient(to right, #2563eb, #4338ca);
    transform: translateY(-2px);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.875rem;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white !important;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

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

/* Searchable Select Styles (Global) */
.searchable-select {
    position: relative;
    width: 100%;
}
.search-input {
    width: 100%;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: white;
    font-size: 0.8rem;
    cursor: pointer;
}
.search-input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.1);
}
.options-container {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 9999;
    display: none;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}
.option-item {
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
    color: var(--text-muted);
}
.option-item:hover {
    background: var(--primary);
    color: white;
}
.option-item.selected {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary);
}

.inline-save-btn {
    display: none;
    padding: 4px 8px;
    background: var(--success);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.row-modified .inline-save-btn {
    display: inline-block;
}
.form-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 2rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

/* Reports Specific */
.ce-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

@media (max-width: 1200px) {
    .ce-grid {
        grid-template-columns: 1fr;
    }
}

.ce-grid h3 {
    width: fit-content;
    min-width: 380px;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
}

.ce-grid table {
    font-size: 0.95rem;
    width: 380px;
    table-layout: fixed;
    margin-bottom: 2rem;
    border-collapse: collapse;
}

.ce-grid th, .ce-grid td {
    padding: 0.4rem 0.5rem;
    overflow: hidden;
}

.ce-grid td:first-child, .ce-grid th:first-child {
    width: 280px;
    word-wrap: break-word;
    white-space: normal;
}

.ce-grid td:nth-child(n+2), .ce-grid th:nth-child(n+2) {
    text-align: right;
    width: 100px;
    white-space: nowrap;
    font-weight: 600;
}

.tab-btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.5rem 0;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s;
    white-space: nowrap;
}

.tab-btn:hover { color: white; }
.tab-btn.active-tab {
    border-bottom: 2px solid var(--accent);
    color: white;
    font-weight: 600;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.form-control::placeholder {
    color: rgba(255, 255, 255, 0.7) !important;
}

.form-control, .form-select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    transition: all 0.3s ease;
    font-size: 1rem;
}

.form-control:focus, .form-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Flashes */
.flashes {
    list-style: none;
    margin-bottom: 1.5rem;
}

.flash {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.flash.success {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.flash.danger {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Toolbar and Layout Improvements */
.toolbar {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-bottom: 2rem;
    position: relative;
    z-index: 50;
}

.toolbar-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.toolbar-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
}

.filter-group {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.action-group {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.toolbar .form-control, .toolbar .form-select {
    height: 42px;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    background: rgba(15, 23, 42, 0.4);
}

.toolbar .btn {
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 1.25rem;
    font-size: 0.9rem;
}

/* Badge System */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
}

/* Specific sector colors if not dynamic */
.badge-sector {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Table Enhancements */
.table-container.glass {
    padding: 1.5rem;
}

.balance-card .balance-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: 1rem;
    font-size: 0.8rem;
    border-top: 1px solid var(--border-color);
    padding-top: 0.75rem;
}

.balance-info div span {
    display: block;
    color: var(--text-secondary);
    font-size: 0.7rem;
    text-transform: uppercase;
}

@media (max-width: 768px) {
    .toolbar-top, .toolbar-bottom {
        flex-direction: column;
        align-items: stretch;
    }
}

/* TomSelect Custom Dark Theme overrides */
/* Strip styles from the wrapper to avoid "double box" effect */
.ts-wrapper.form-select, .toolbar .ts-wrapper.form-select {
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
    height: auto !important;
    box-shadow: none !important;
}

/* The actual control box */
.ts-control {
    background: rgba(15, 23, 42, 0.6) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    color: var(--text-primary) !important;
    padding: 0.5rem 1rem !important;
    font-family: inherit !important;
    font-size: 1rem !important;
    box-shadow: none !important;
    min-height: 42px !important;
    display: flex !important;
    align-items: center !important;
    flex-wrap: wrap !important;
    gap: 4px !important;
    transition: all 0.3s ease !important;
    cursor: pointer !important;
}
.toolbar .ts-control {
    padding: 4px 1rem !important;
    min-height: 42px !important;
    height: auto !important;
    font-size: 0.9rem !important;
}

/* Focus state */
.ts-wrapper.focus .ts-control {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2) !important;
    background: rgba(15, 23, 42, 0.8) !important;
}

/* Text color and items */
.ts-control .item {
    background: var(--accent) !important;
    color: white !important;
    border-radius: 4px !important;
    padding: 2px 8px !important;
    margin: 2px !important;
    font-size: 0.85em !important;
    border: none !important;
}
.ts-control > input {
    color: var(--text-primary) !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Dropdown styling */
.ts-dropdown {
    background: #1e293b !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    color: var(--text-primary) !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5) !important;
    margin-top: 6px !important;
    overflow: hidden !important;
}

/* Search Input inside Dropdown */
.dropdown-input-wrap {
    padding: 10px 10px 6px 10px !important;
    background: #1e293b !important;
}
.dropdown-input {
    background: rgba(15, 23, 42, 0.8) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    color: white !important;
    border-radius: 6px !important;
    padding: 8px 12px !important;
    width: 100% !important;
    font-size: 0.9rem !important;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2) !important;
    transition: border-color 0.2s ease !important;
}
.dropdown-input:focus {
    outline: none !important;
    border-color: var(--accent) !important;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2), 0 0 0 2px rgba(59, 130, 246, 0.2) !important;
}

/* Options */
.ts-dropdown .option {
    padding: 10px 14px !important;
    color: var(--text-secondary) !important;
    transition: all 0.2s !important;
    cursor: pointer !important;
    font-size: 0.9rem !important;
}
.ts-dropdown .option:hover, .ts-dropdown .option.active {
    background: var(--accent) !important;
    color: white !important;
}
.ts-dropdown .option.selected {
    background: rgba(59, 130, 246, 0.15) !important;
    color: var(--accent) !important;
    font-weight: 600 !important;
}

/* Arrow styling */
.ts-wrapper.single .ts-control:after {
    border-color: var(--text-secondary) transparent transparent transparent !important;
    border-width: 5px 4px 0 4px !important;
    right: 14px !important;
}
.ts-wrapper.single.dropdown-active .ts-control:after {
    border-color: transparent transparent var(--text-secondary) transparent !important;
    border-width: 0 4px 5px 4px !important;
}
