/* VsD Magical Items - Table-Based Layout */

/* ===== MAIN TABLE STYLING ===== */
.magical-items-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.magical-items-table th {
    background: #2c2c2c; /* Dark grey header background to match existing tables */
    color: white;
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.9em;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    position: sticky;
    top: 0;
    z-index: 10;
}

.magical-items-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease;
}

.magical-items-table th.sortable:hover {
    background: #1a1a1a; /* Darker grey on hover */
}

.magical-items-table th.sorted-asc::after {
    content: ' ↑';
    font-weight: bold;
}

.magical-items-table th.sorted-desc::after {
    content: ' ↓';
    font-weight: bold;
}

.magical-items-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #e9ecef;
    vertical-align: top;
    font-size: 0.9em;
}

.magical-items-table tr:hover {
    background-color: #f8f9fa;
}

.magical-items-table tr.equipped {
    background-color: #e8f5e8;
}

.magical-items-table tr.cursed {
    background-color: #ffebee;
    border-left: 4px solid #e74c3c;
}

.magical-items-table tr.item-of-power {
    background-color: #fff3e0;
    border-left: 4px solid #ff9800;
}

/* ===== COLUMN SPECIFIC STYLING ===== */
.item-name-cell {
    font-weight: 600;
    color: #2c3e50;
    min-width: 180px;
}

.item-type-cell {
    color: #6c757d;
    font-style: italic;
    min-width: 100px;
}

.item-description-cell {
    max-width: 300px;
    line-height: 1.4;
    color: #495057;
}

.item-description-truncated {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-status-cell {
    min-width: 100px;
    text-align: center;
}

.item-attunement-cell {
    min-width: 120px;
    text-align: center;
}

.item-actions-cell {
    min-width: 150px;
    text-align: center;
}

/* ===== STATUS BADGES ===== */
.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

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

.status-attuned {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

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

.status-power-item {
    background-color: #ffeaa7;
    color: #b7791f;
    border: 1px solid #fdd835;
}

/* ===== ATTUNEMENT INDICATORS ===== */
.attunement-required {
    color: #dc3545;
    font-weight: 500;
}

.attunement-optional {
    color: #6c757d;
}

.attunement-none {
    color: #28a745;
}

/* ===== ACTION BUTTONS ===== */
.table-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 2px;
    text-decoration: none;
    display: inline-block;
}

.table-btn-primary {
    background-color: #007bff;
    color: white;
}

.table-btn-primary:hover {
    background-color: #0056b3;
    transform: translateY(-1px);
}

.table-btn-secondary {
    background-color: #6c757d;
    color: white;
}

.table-btn-secondary:hover {
    background-color: #545b62;
    transform: translateY(-1px);
}

.table-btn-success {
    background-color: #28a745;
    color: white;
}

.table-btn-success:hover {
    background-color: #1e7e34;
    transform: translateY(-1px);
}

.table-btn-warning {
    background-color: #ffc107;
    color: #212529;
}

.table-btn-warning:hover {
    background-color: #e0a800;
    transform: translateY(-1px);
}

.table-btn-danger {
    background-color: #dc3545;
    color: white;
}

.table-btn-danger:hover {
    background-color: #c82333;
    transform: translateY(-1px);
}

.table-btn-info {
    background-color: #17a2b8;
    color: white;
}

.table-btn-info:hover {
    background-color: #138496;
    transform: translateY(-1px);
}

.table-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* ===== PROGRESS BARS IN TABLES ===== */
.table-progress-container {
    width: 100%;
    height: 16px;
    background-color: #e9ecef;
    border-radius: 8px;
    overflow: hidden;
    margin: 4px 0;
}

.table-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #28a745, #20c997);
    border-radius: 8px;
    transition: width 0.3s ease;
    position: relative;
}

.table-progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.7em;
    font-weight: 600;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.table-progress-affinity {
    background: linear-gradient(90deg, #9C27B0, #E91E63);
}

.table-progress-usage {
    background: linear-gradient(90deg, #FF9800, #F57C00);
}

/* ===== EXPANDABLE ROWS ===== */
.expandable-row {
    cursor: pointer;
}

.expandable-row td:first-child::before {
    content: '▶ ';
    color: #6c757d;
    font-size: 0.8em;
    margin-right: 8px;
}

.expandable-row.expanded td:first-child::before {
    content: '▼ ';
}

.detail-row {
    display: none;
    background-color: #f8f9fa;
}

.detail-row.expanded {
    display: table-row;
}

.detail-content {
    padding: 20px;
    border-left: 4px solid #007bff;
    background: white;
    margin: 8px;
    border-radius: 4px;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    .magical-items-table {
        font-size: 0.8em;
    }
    
    .magical-items-table th,
    .magical-items-table td {
        padding: 8px 12px;
    }
    
    .item-description-cell {
        max-width: 200px;
    }
    
    .table-btn {
        padding: 4px 8px;
        font-size: 0.7em;
    }
}

@media (max-width: 576px) {
    .magical-items-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .magical-items-table thead,
    .magical-items-table tbody,
    .magical-items-table th,
    .magical-items-table td,
    .magical-items-table tr {
        display: block;
    }
    
    .magical-items-table thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    .magical-items-table tr {
        border: 1px solid #ccc;
        margin-bottom: 10px;
        padding: 10px;
        border-radius: 8px;
        background: white;
    }
    
    .magical-items-table td {
        border: none;
        position: relative;
        padding-left: 50% !important;
        white-space: normal;
        text-align: left;
    }
    
    .magical-items-table td:before {
        content: attr(data-label) ": ";
        position: absolute;
        left: 6px;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        font-weight: 600;
        color: #2c3e50;
    }
}

/* ===== EMPTY STATE ===== */
.table-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #6c757d;
}

.table-empty-state h4 {
    margin-bottom: 10px;
    color: #495057;
}

.table-empty-state p {
    margin-bottom: 20px;
    line-height: 1.5;
}

/* ===== LOADING STATE ===== */
.table-loading {
    text-align: center;
    padding: 40px 20px;
}

.table-loading-spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== FILTER AND SEARCH ===== */
.table-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.table-search {
    flex: 1;
    max-width: 300px;
    margin-right: 15px;
}

.table-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
}

.table-filters {
    display: flex;
    gap: 10px;
}

.table-filter-select {
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
    background: white;
}

/* ===== SPECIAL CONTENT CELLS ===== */
.spells-list-cell {
    max-width: 250px;
}

.spell-item-compact {
    display: inline-block;
    background: #e3f2fd;
    color: #1565c0;
    padding: 2px 6px;
    margin: 2px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 500;
}

.material-indicator {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: 500;
    margin-left: 8px;
}

.material-runesilver {
    background-color: #e8f5e9;
    color: #2e7d32;
}

.material-shadowsilk {
    background-color: #f3e5f5;
    color: #7b1fa2;
}

.material-wyrdwood {
    background-color: #fff3e0;
    color: #ef6c00;
}

/* ===== CREATE ITEM FORM STYLING ===== */
.create-item-form {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.form-section {
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid #e9ecef;
}

.form-section:last-of-type {
    border-bottom: none;
    margin-bottom: 24px;
}

.form-section h5 {
    color: #2c2c2c;
    font-size: 1.2em;
    font-weight: 600;
    margin: 0 0 16px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid #2c2c2c;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-weight: 600;
    color: #495057;
    margin-bottom: 6px;
    font-size: 0.9em;
}

.form-control {
    padding: 10px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: #2c2c2c;
    box-shadow: 0 0 0 2px rgba(44, 44, 44, 0.1);
}

.form-control::placeholder {
    color: #6c757d;
    font-style: italic;
}

/* Template buttons styling */
.template-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.load-template {
    background: #f8f9fa;
    border: 1px solid #ced4da;
    color: #495057;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85em;
}

.load-template:hover {
    background: #2c2c2c;
    color: white;
    border-color: #2c2c2c;
}

/* Bonus grid styling */
.bonus-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
}

/* Spell effects styling */
.spell-effects-help {
    background: #e3f2fd;
    border: 1px solid #bbdefb;
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 16px;
}

.spell-effects-help p {
    margin: 0;
    color: #1565c0;
    font-size: 0.9em;
}

.spell-effect {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 16px;
    margin-bottom: 16px;
}

.spell-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #dee2e6;
}

.spell-header h6 {
    margin: 0;
    color: #2c2c2c;
    font-weight: 600;
}

.remove-spell {
    background: #dc3545;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 0.75em;
    cursor: pointer;
}

.remove-spell:hover {
    background: #c82333;
}

/* Spell selection section */
.spell-selection-section {
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 12px;
}

.grimoire-spell-group {
    transition: opacity 0.2s ease;
}

.spell-search-container {
    position: relative;
    margin-top: 8px;
}

.spell-search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
}

.spell-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ced4da;
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.spell-search-results-list {
    padding: 0;
}

.spell-search-result,
.lore-search-result {
    padding: 12px;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.spell-search-result:hover,
.lore-search-result:hover {
    background: #f8f9fa;
}

.spell-search-result:last-child,
.lore-search-result:last-child {
    border-bottom: none;
}

.spell-result-header,
.lore-result-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.spell-result-name,
.lore-result-name {
    font-weight: 600;
    color: #2c3e50;
}

.spell-result-weave {
    background: #e9ecef;
    color: #495057;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.8em;
    font-weight: 500;
}

.spell-result-access,
.lore-result-access {
    margin-left: auto;
    font-size: 0.9em;
}

.spell-search-result.accessible .spell-result-access,
.lore-search-result.accessible .lore-result-access {
    color: #28a745;
}

.spell-search-result.restricted .spell-result-access,
.lore-search-result.restricted .lore-result-access {
    color: #ffc107;
}

.spell-result-lore,
.lore-result-description {
    color: #6c757d;
    font-size: 0.85em;
    margin-bottom: 2px;
}

.spell-result-details,
.lore-result-spells {
    color: #6c757d;
    font-size: 0.8em;
}

.search-no-results {
    padding: 12px;
    text-align: center;
    color: #6c757d;
    font-style: italic;
}

/* Spell details section */
.spell-details-section {
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 12px;
}

.spell-lore-info {
    background: #e8f5e8;
    border: 1px solid #c3e6c3;
    border-radius: 4px;
    padding: 8px 12px;
    margin-top: 12px;
}

.spell-lore-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
}

.lore-name {
    font-weight: 600;
    color: #155724;
}

.lore-stat {
    color: #6c757d;
    font-style: italic;
}

.access-indicator.accessible {
    color: #28a745;
    font-weight: 500;
}

.access-indicator.restricted {
    color: #ffc107;
    font-weight: 500;
}

/* Autocomplete styling */
.spell-autocomplete-container {
    position: relative;
}

.spell-autocomplete-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
}

.spell-autocomplete-input:focus {
    border-color: #80bdff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    outline: 0;
}

.spell-autocomplete-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ced4da;
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.spell-autocomplete-list {
    padding: 0;
}

.spell-autocomplete-result {
    padding: 12px;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.spell-autocomplete-result:hover {
    background: #f8f9fa;
}

.spell-autocomplete-result:last-child {
    border-bottom: none;
}

.autocomplete-result-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.autocomplete-spell-name {
    font-weight: 600;
    color: #2c3e50;
    flex: 1;
}

.autocomplete-spell-weave {
    background: #e9ecef;
    color: #495057;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.8em;
    font-weight: 500;
}

.autocomplete-access-icon {
    font-size: 0.9em;
}

.spell-autocomplete-result.accessible .autocomplete-access-icon {
    color: #28a745;
}

.spell-autocomplete-result.restricted .autocomplete-access-icon {
    color: #ffc107;
}

.spell-autocomplete-result.restricted {
    opacity: 0.8;
}

.autocomplete-result-lore {
    color: #6c757d;
    font-size: 0.85em;
    margin-bottom: 2px;
}

.autocomplete-result-details {
    color: #6c757d;
    font-size: 0.8em;
}

.autocomplete-no-results {
    padding: 12px;
    text-align: center;
    color: #6c757d;
    font-style: italic;
}

.autocomplete-more-results {
    padding: 8px 12px;
    text-align: center;
    color: #6c757d;
    font-size: 0.85em;
    font-style: italic;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
}

/* Weave filter styling */
.spell-weave-filter {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
    background: white;
}

.spell-weave-filter:focus {
    border-color: #80bdff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    outline: 0;
}

/* Enhanced form row spacing for new layout */
.spell-selection-section .form-row {
    margin-bottom: 12px;
}

.spell-selection-section .form-row:last-child {
    margin-bottom: 0;
}

/* Global search result styling */
.spell-global-search-result {
    padding: 12px;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.spell-global-search-result:hover {
    background: #f8f9fa;
}

.spell-global-search-result:last-child {
    border-bottom: none;
}

/* Confirm spell button styling */
.confirm-spell {
    background: #28a745;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.9em;
    cursor: pointer;
    transition: background-color 0.2s ease;
    margin-bottom: 8px;
}

.confirm-spell:hover:not(:disabled) {
    background: #218838;
}

.confirm-spell:disabled {
    background: #6c757d;
    cursor: not-allowed;
    opacity: 0.6;
}

.confirm-spell + .form-text {
    color: #6c757d;
    font-size: 0.8em;
    font-style: italic;
}

/* Responsive adjustments for autocomplete */
@media (max-width: 768px) {
    .spell-autocomplete-results {
        max-height: 200px;
    }

    .autocomplete-result-header {
        flex-wrap: wrap;
        gap: 4px;
    }

    .autocomplete-spell-name {
        flex: 1 1 100%;
        margin-bottom: 4px;
    }
}

/* Form actions styling */
.form-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    padding-top: 24px;
    border-top: 1px solid #e9ecef;
}

.form-actions .btn {
    padding: 12px 24px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-size: 0.9em;
}

.form-actions .btn-primary {
    background: #2c2c2c;
    color: white;
}

.form-actions .btn-primary:hover {
    background: #1a1a1a;
}

.form-actions .btn-secondary {
    background: #6c757d;
    color: white;
}

.form-actions .btn-secondary:hover {
    background: #545b62;
}

/* Preview and validation styling */
.item-preview {
    background: #e8f5e8;
    border: 1px solid #c3e6c3;
    border-radius: 6px;
    padding: 16px;
    margin-top: 16px;
}

.item-preview h5 {
    color: #155724;
    margin: 0 0 12px 0;
    font-weight: 600;
}

.validation-messages {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 6px;
    padding: 16px;
    margin-top: 16px;
}

.validation-messages h6 {
    color: #721c24;
    margin: 0 0 8px 0;
    font-weight: 600;
}

.validation-messages ul {
    margin: 0;
    padding-left: 20px;
    color: #721c24;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    .magical-items-table {
        display: none;
    }

    .table-mobile-cards {
        display: block;
    }

    .mobile-item-card {
        background: white;
        border: 1px solid #e9ecef;
        border-radius: 8px;
        margin-bottom: 16px;
        padding: 16px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .mobile-item-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 12px;
        padding-bottom: 8px;
        border-bottom: 1px solid #e9ecef;
    }

    .mobile-item-name {
        font-weight: 600;
        color: #2c3e50;
        font-size: 1.1em;
        margin: 0;
    }

    .mobile-item-type {
        color: #6c757d;
        font-style: italic;
        font-size: 0.9em;
    }

    .mobile-item-content {
        margin-bottom: 12px;
    }

    .mobile-item-description {
        color: #495057;
        line-height: 1.4;
        margin-bottom: 8px;
    }

    .mobile-item-details {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 12px;
    }

    .mobile-item-actions {
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
    }

    /* Responsive form styling */
    .create-item-form {
        padding: 16px;
        margin: 0 8px;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .bonus-grid {
        grid-template-columns: 1fr 1fr;
    }

    .template-buttons {
        flex-direction: column;
    }

    .form-actions {
        flex-direction: column;
    }
}
