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

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

/* Header Styles */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
}

.header h1 {
    font-size: 28px;
    margin-bottom: 10px;
}

.header p {
    opacity: 0.9;
    font-size: 14px;
}

/* Navigation */
.nav {
    padding: 20px 30px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
}

.nav a {
    color: #667eea;
    text-decoration: none;
    font-weight: 600;
}

.nav a:hover {
    text-decoration: underline;
}

/* Content */
.content {
    padding: 30px;
}

/* Controls for index page */
.controls {
    padding: 20px 30px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.control-group label {
    font-size: 12px;
    color: #666;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Form Elements */
input,
select,
button {
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.3s;
}

input:focus,
select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Form Groups for add/edit pages */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #333;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.3s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

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

/* Tables */
.table-container {
    padding: 30px;
    overflow-x: auto;
}

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

th {
    background: #f8f9fa;
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: #333;
    border-bottom: 2px solid #e0e0e0;
    position: sticky;
    top: 0;
    cursor: pointer;
    user-select: none;
    transition: background 0.3s;
}

th:hover {
    background: #e9ecef;
}

th.sortable::after {
    content: " ↕";
    opacity: 0.3;
    font-size: 12px;
}

th.sorted-asc::after {
    content: " ↑";
    opacity: 1;
}

th.sorted-desc::after {
    content: " ↓";
    opacity: 1;
}

td {
    padding: 12px;
    border-bottom: 1px solid #f0f0f0;
    color: #555;
}

tr:hover {
    background: #f8f9fa;
}

/* Collapsible Row Styles */
.main-row {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.main-row:hover {
    background: #f0f4ff !important;
}

.main-row.expanded {
    background: #e3f2fd;
}

.expand-cell {
    text-align: center;
    padding: 8px !important;
    width: 50px;
}

.expand-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.expand-btn:hover {
    background: #e0e7ff;
}

.expand-icon {
    font-size: 12px;
    color: #667eea;
    transition: transform 0.2s ease;
    display: inline-block;
}

.expand-icon.rotated {
    transform: rotate(180deg);
}

/* Detail row styles */
.detail-row {
    display: none;
    background: #f8fffe;
}

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

.detail-content {
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s ease;
    text-align: left;
}

.detail-row.expanded .detail-content {
    padding: 20px;
    max-height: 1000px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
    background: white;
    border-radius: 8px;
    padding: 20px;
    border: 1px solid #e1e8ed;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
    text-align: left;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.detail-label {
    font-weight: 600;
    color: #444;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #e1e8ed;
    padding-bottom: 4px;
}

.detail-value {
    color: #666;
    line-height: 1.5;
    min-height: 20px;
}

.detail-value:empty::before {
    content: "—";
    color: #ccc;
}

/* Responsive adjustments for collapsible rows */
@media (max-width: 480px) {
    .detail-row td {
        padding: 0 !important;
    }

    .detail-content {
        margin: 0 -15px;
    }

    .detail-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 20px 15px;
        margin: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .expand-btn {
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
    }

    .main-row {
        min-height: 48px;
    }

    .main-row td {
        padding: 12px 8px;
    }
}

/* Pagination */
.pagination {
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
}

.pagination-info {
    color: #666;
    font-size: 14px;
}

.pagination-controls {
    display: flex;
    gap: 10px;
}

.pagination-controls button {
    padding: 8px 16px;
    font-size: 13px;
}

/* States */
.loading,
.error,
.empty {
    padding: 60px;
    text-align: center;
    color: #666;
}

.error {
    color: #dc3545;
    background: #fff5f5;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #666;
}

.success {
    background: #d4edda;
    color: #155724;
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 20px;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

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

/* Search Box */
.search-box {
    flex: 1;
    min-width: 200px;
    max-width: 400px;
}

/* Badge */
.badge {
    background: #667eea;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 8px;
}

/* Section States */
.login-section,
.add-section,
.edit-section {
    display: none;
}

.login-section.active,
.add-section.active,
.edit-section.active {
    display: block;
}

/* User Info */
.user-info {
    background: #e8f5e8;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-info span {
    color: #2d5a2d;
    font-weight: 600;
}

.logout-btn {
    background: #dc3545;
    font-size: 12px;
    padding: 6px 12px;
}

.logout-btn:hover {
    background: #c82333;
}

/* Button Group */
.button-group {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

.delete-btn {
    background: #dc3545;
}

.delete-btn:hover {
    background: #c82333;
    box-shadow: 0 5px 15px rgba(220, 53, 69, 0.3);
}

/* Checkbox Styling */
.form-group input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
    vertical-align: middle;
}

.form-group label.checkbox-label {
    display: flex;
    align-items: center;
    margin-bottom: 0;
    cursor: pointer;
}

.checkbox-group label {
    display: flex !important;
    align-items: center;
    margin: 8px 0 !important;
    cursor: pointer;
    font-weight: normal;
}

.checkbox-group input[type="checkbox"] {
    margin-right: 8px;
    margin-top: 0;
}

/* Radio Button Styling */
.radio-group {
    width: 100%;
}

.radio-group label {
    display: flex !important;
    align-items: center;
    margin: 8px 0 !important;
    cursor: pointer;
    font-weight: normal;
    width: 100%;
    max-width: 100%;
}

.radio-group input[type="radio"] {
    width: auto;
    margin-right: 8px;
    margin-top: 0;
    flex-shrink: 0;
}

/* Debug Section */
.debug-section {
    border-top: 1px solid #e0e0e0;
}

.debug-toggle {
    padding: 15px 30px;
    background: #f8f9fa;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: #666;
    transition: background 0.3s;
}

.debug-toggle:hover {
    background: #e9ecef;
}

.debug-arrow {
    font-size: 12px;
    transition: transform 0.3s;
}

.debug-arrow.rotated {
    transform: rotate(180deg);
}

.debug-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.debug-content.open {
    max-height: 500px;
}

.debug-info {
    padding: 20px 30px;
    background: #f1f3f5;
    font-family: "Courier New", monospace;
    font-size: 12px;
    color: #495057;
    line-height: 1.6;
}

.debug-info strong {
    color: #212529;
}

/* Mobile Responsive Styles */
@media (max-width: 480px) {
    /* Container for smaller screens */
    .container {
        max-width: 800px;
    }

    /* Table responsiveness */
    .table-container {
        padding: 15px;
        overflow-x: visible;
    }

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tr {
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        margin-bottom: 15px;
        padding: 15px;
        background: white;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    tr:hover {
        background: white;
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        transition: all 0.2s ease;
    }

    td {
        border: none;
        position: relative;
        padding: 8px 0;
        border-bottom: 1px solid #f0f0f0;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        min-height: 35px;
    }

    td:last-child {
        border-bottom: none;
    }

    td:before {
        content: attr(data-label);
        font-weight: 600;
        color: #333;
        text-transform: capitalize;
        flex-shrink: 0;
        margin-right: 15px;
        font-size: 13px;
    }

    td > * {
        flex: 1;
        text-align: right;
        word-break: break-word;
    }

    /* Controls responsiveness */
    .controls {
        flex-direction: column;
        gap: 10px;
        padding: 15px;
    }

    .control-group {
        width: 100%;
    }

    .search-box {
        min-width: unset;
        max-width: unset;
    }

    /* Pagination responsiveness */
    .pagination {
        flex-direction: column;
        gap: 15px;
        text-align: center;
        padding: 15px;
    }

    .pagination-controls {
        justify-content: center;
    }

    /* Form responsiveness */
    .form-row {
        grid-template-columns: 1fr;
    }

    .button-group {
        flex-direction: column;
    }

    /* Debug section responsiveness */
    .debug-toggle {
        padding: 15px;
    }

    .debug-info {
        padding: 15px;
        font-size: 10px;
        word-break: break-all;
    }
}

