/* ========================================
   Reset and Base Styles
======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Church-appropriate color palette */
    --primary-color: #2c5282;
    --primary-dark: #1a365d;
    --secondary-color: #4a5568;
    --accent-color: #48bb78;
    --danger-color: #f56565;
    --warning-color: #ed8936;
    
    --bg-color: #f7fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --text-light: #a0aec0;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 15px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 16px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ========================================
   Header
======================================== */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 40px 30px;
    border-radius: var(--radius-lg);
    margin-bottom: 30px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.header-icon {
    font-size: 2.5rem;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0;
}

.subtitle {
    margin-top: 10px;
    font-size: 1.1rem;
    opacity: 0.9;
}

/* ========================================
   Status Cards
======================================== */
.status-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.status-card {
    background: var(--card-bg);
    padding: 25px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.status-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.status-card i {
    font-size: 2.5rem;
    color: var(--primary-color);
}

.status-card:nth-child(1) i {
    color: var(--warning-color);
}

.status-card:nth-child(2) i {
    color: var(--accent-color);
}

.status-card:nth-child(3) i {
    color: var(--primary-color);
}

.status-info h3 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.status-info p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* ========================================
   Form Section
======================================== */
.form-section {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    margin-bottom: 30px;
}

.form-section h2 {
    color: var(--primary-color);
    margin-bottom: 25px;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

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

.form-group label {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-group label i {
    color: var(--primary-color);
}

.form-group input,
.form-group select {
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    background-color: white;
    width: 100%;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(44, 82, 130, 0.1);
}

.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 45px;
}

.form-actions {
    display: flex;
    gap: 15px;
    margin-top: 25px;
}

/* ========================================
   Buttons
======================================== */
.btn {
    padding: 12px 25px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    font-family: inherit;
}

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

.btn-primary:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-secondary:hover {
    background-color: #2d3748;
    transform: translateY(-1px);
}

.btn-success {
    background-color: var(--accent-color);
    color: white;
    padding: 8px 15px;
    font-size: 0.9rem;
}

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

.btn-danger {
    background-color: var(--danger-color);
    color: white;
    padding: 8px 15px;
    font-size: 0.9rem;
}

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

.btn-edit {
    background-color: #4299e1;
    color: white;
    padding: 8px 15px;
    font-size: 0.9rem;
}

.btn-edit:hover {
    background-color: #3182ce;
}

/* ========================================
   Filter Section
======================================== */
.filter-section {
    background: var(--card-bg);
    padding: 25px 30px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    margin-bottom: 30px;
}

.filter-section h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-subsection {
    margin-bottom: 20px;
}

.filter-subsection:last-child {
    margin-bottom: 0;
}

.filter-subsection h3 {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.filter-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: center;
    justify-content: space-between;
}

.filter-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.key-filter-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 10px 20px;
    border: 2px solid var(--border-color);
    background: white;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.filter-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.filter-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.key-filter-btn {
    padding: 8px 16px;
    border: 2px solid var(--border-color);
    background: white;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
    white-space: nowrap;
}

.key-filter-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    transform: translateY(-1px);
}

.key-filter-btn.active {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.search-group {
    position: relative;
    flex: 1;
    min-width: 250px;
    max-width: 400px;
}

.search-group input {
    width: 100%;
    padding: 10px 15px 10px 40px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.search-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.search-group i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
}

/* ========================================
   Table Section
======================================== */
.table-section {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    margin-bottom: 30px;
}

.table-section h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

thead {
    background-color: var(--primary-color);
    color: white;
}

thead th {
    padding: 15px 12px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s;
}

tbody tr:hover {
    background-color: #f7fafc;
}

tbody td {
    padding: 15px 12px;
    vertical-align: middle;
}

.status-badge {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-out {
    background-color: #fed7d7;
    color: #c53030;
}

.status-returned {
    background-color: #c6f6d5;
    color: #276749;
}

.key-status-badge {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}

.key-status-badge i {
    margin-right: 5px;
}

.key-status-badge.in-use {
    background-color: #bee3f8;
    color: #2c5282;
}

.key-status-badge.keysafe {
    background-color: #feebc8;
    color: #c05621;
}

.key-status-badge.spare {
    background-color: #e9d8fd;
    color: #553c9a;
}

/* ========================================
   Tooltip Styling
======================================== */
.tooltip-wrapper {
    position: relative;
    display: inline-block;
    margin-left: 5px;
}

.tooltip-icon {
    cursor: help;
    color: var(--primary-color);
    transition: color 0.2s;
    font-size: 0.9em;
}

.tooltip-icon:hover {
    color: var(--primary-dark);
}

.tooltip-text {
    visibility: hidden;
    opacity: 0;
    width: 350px;
    background-color: var(--primary-dark);
    color: white;
    text-align: left;
    border-radius: var(--radius-sm);
    padding: 15px;
    position: absolute;
    z-index: 1000;
    bottom: 125%;
    left: 50%;
    margin-left: -175px;
    transition: opacity 0.3s, visibility 0.3s;
    box-shadow: var(--shadow-lg);
    font-size: 0.9rem;
    line-height: 1.5;
}

.tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: var(--primary-dark) transparent transparent transparent;
}

.tooltip-wrapper:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Mobile adjustment */
@media (max-width: 768px) {
    .tooltip-text {
        width: 280px;
        margin-left: -140px;
        font-size: 0.85rem;
    }
}

.action-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.no-records {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
    display: none;
}

.no-records i {
    font-size: 4rem;
    margin-bottom: 15px;
    opacity: 0.5;
}

.no-records p {
    font-size: 1.2rem;
}

/* ========================================
   Loading Overlay
======================================== */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    justify-content: center;
    align-items: center;
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   Responsive Design
======================================== */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .header {
        padding: 30px 20px;
    }
    
    .header h1 {
        font-size: 1.8rem;
    }
    
    .header-icon {
        font-size: 2rem;
    }
    
    .status-cards {
        grid-template-columns: 1fr;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .form-section,
    .filter-section,
    .table-section {
        padding: 20px;
    }
    
    .filter-subsection {
        margin-bottom: 20px;
    }
    
    .filter-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filter-group {
        width: 100%;
    }
    
    .filter-btn {
        flex: 1;
        justify-content: center;
    }
    
    .key-filter-btn {
        flex: 1;
        font-size: 0.85rem;
        padding: 8px 12px;
    }
    
    .search-group {
        max-width: 100%;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
    
    table {
        font-size: 0.85rem;
    }
    
    thead th,
    tbody td {
        padding: 10px 8px;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .action-buttons .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.5rem;
    }
    
    .status-info h3 {
        font-size: 1.5rem;
    }
    
    /* Make table scrollable on small screens */
    .table-container {
        margin: 0 -20px;
        padding: 0 20px;
    }
}
