/* File: frontend/html/css/tables.css */
/* Styling specifico per tabelle e interazioni */

.table-container {
    background: white;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 1rem;
    position: relative;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: #2c3e50;
}

th, td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #e1e8ed;
    position: relative;
}

th {
    font-weight: 500;
    color: white;
    background: #2c3e50;
}

/* Sortable header styling */
.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease;
    position: relative;
}

.sortable:hover {
    background: #34495e;
}

.sortable.active {
    background: #34495e;
}

.sort-arrows {
    float: right;
    margin-left: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.sort-arrow {
    font-size: 0.7rem;
    color: #95a5a6;
    cursor: pointer;
    transition: color 0.2s ease;
    line-height: 1;
}

.sort-arrow:hover {
    color: white;
}

.sort-arrow.active {
    color: #3498db;
    font-weight: bold;
}

/* Specific column widths */
.date-cell {
    width: 12%;
}

.description-cell {
    width: 25%;
}

.category-cell {
    width: 20%;
}

.amount-cell {
    width: 12%;
}

.credit-cell {
    width: 15%;
}

.account-cell {
    width: 16%;
}

/* Account badges - MINIMALE CON BORDO COLORATO */
.account-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    text-align: center;
    min-width: 70px;
    background-color: white;
    border: 2px solid;
}

.account-badge-marco {
    border-color: #3498db;
    color: #3498db;
}

.account-badge-cointestato {
    border-color: #27ae60;
    color: #27ae60;
}

/* Amount styling based on transaction type */
.amount-expense {
    color: #e74c3c;
    font-weight: 500;
}

.amount-income {
    color: #27ae60;
    font-weight: 500;
}

/* Alternating row colors */
tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

tbody tr:nth-child(odd) {
    background-color: white;
}

/* Row hover effect */
tbody tr:hover {
    background-color: #e3f2fd !important;
    cursor: pointer;
}

/* Selected rows */
tbody tr.selected {
    background-color: #bbdefb !important;
    border: 2px solid #2196f3;
}

/* Editing rows - different styling */
tbody tr.editing-row {
    background-color: #fff3e0 !important;
    border: 2px solid #ff9800;
}

tbody tr.editing-row:hover {
    background-color: #fff3e0 !important;
    cursor: default;
}

/* Row actions container */
.row-actions {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    gap: 4px;
    align-items: center;
    z-index: 10;
}

tbody tr:hover .row-actions {
    display: flex;
}

/* Always show actions for editing rows */
tbody tr.editing-row .row-actions {
    display: flex;
}

/* Editing cell constraints */
tbody tr.editing-row td {
    overflow: visible;
    position: relative;
}

/* Badge handling during editing */
.editing-row .account-cell .account-badge {
    display: none;
}

.editing-row .account-cell .inline-edit-select {
    display: block;
}

/* Base input styling for editing */
.inline-edit-input,
.inline-edit-select {
    border: 1px solid #2196f3;
    border-radius: 4px;
    padding: 0.3rem;
    font-size: 0.85rem;
    background: white;
    box-sizing: border-box;
}

.inline-edit-input:focus,
.inline-edit-select:focus {
    outline: none;
    border-color: #1976d2;
    box-shadow: 0 0 0 1px rgba(33, 150, 243, 0.2);
}

/* Column-specific input widths during editing */
tbody tr.editing-row .date-cell .inline-edit-input {
    width: calc(100% - 5px);
}

tbody tr.editing-row .description-cell .inline-edit-input {
    width: calc(100% - 5px);
}

tbody tr.editing-row .category-cell .inline-edit-input {
    width: calc(100% - 5px);
}

tbody tr.editing-row .amount-cell .inline-edit-input {
    width: calc(100% - 5px);
}

tbody tr.editing-row .credit-cell .inline-edit-select {
    width: calc(100% - 5px);
}

/* Special handling for the last cell (account) which contains row actions */
tbody tr.editing-row .account-cell {
    padding-right: 45px;
}

tbody tr.editing-row .account-cell .inline-edit-select {
    width: calc(100% - 40px);
}

/* Responsive per tabelle */
@media (max-width: 768px) {
    th, td {
        padding: 0.5rem;
        font-size: 0.9rem;
    }

    .account-badge {
        font-size: 0.75rem;
        padding: 0.2rem 0.6rem;
        min-width: 60px;
    }

    /* Hide sort arrows on mobile */
    .sort-arrows {
        display: none;
    }
}
