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

body {
    font-family: 'Microsoft JhengHei', sans-serif;
    background: linear-gradient(135deg, #667eea 50%, #764ba2 100%);
    /* Keeping original gradient as it has specific stop */
    padding: 20px;
    line-height: 1.6;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

h1 {
    text-align: center;
    color: var(--text-main);
    margin-bottom: 30px;
}

h2 {
    color: var(--text-secondary);
    margin-bottom: 15px;
    font-size: 1.3em;
}

/* =========================================
   2. Subject Stats
   ========================================= */
.subject-stats {
    background: var(--bg-light);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 30px;
}

#subjectStatsContainer {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 10px;
}

/* Scrollbar Styling */
#subjectStatsContainer::-webkit-scrollbar {
    width: 8px;
}

#subjectStatsContainer::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#subjectStatsContainer::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

#subjectStatsContainer::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.subject-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    transition: var(--transition-normal);
    margin-bottom: 10px;
    width: 100%;
}

.subject-header {
    padding: 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--accent-blue);
    color: white;
    user-select: none;
}

.subject-header:hover {
    background: #2980b9;
}

.subject-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.subject-name {
    font-weight: bold;
    font-size: 1.1em;
}

.subject-count {
    background: rgba(255, 255, 255, 0.3);
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 0.9em;
}

.toggle-icon {
    transition: transform 0.3s;
    font-size: 1.2em;
}

.toggle-icon.expanded {
    transform: rotate(180deg);
}

.subject-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background: var(--bg-light);
}

.subject-content.show {
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
}

.subject-records {
    padding: 10px;
}

/* Content Scrollbar */
.subject-content::-webkit-scrollbar {
    width: 6px;
}

.subject-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.subject-content::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.subject-content::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.subject-record-item {
    padding: 8px;
    margin-bottom: 5px;
    background: var(--bg-light);
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.subject-record-item:hover {
    background: #ecf0f1;
}

/* =========================================
   3. Input Section
   ========================================= */
.input-section {
    background: var(--bg-light);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 30px;
}

.input-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 2fr;
    gap: 10px;
    align-items: center;
}

input[type="text"],
select {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    width: 100%;
}

input[type="text"]:focus,
select:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

/* Datalist Styling */
input[list] {
    position: relative;
}

input[list]::-webkit-calendar-picker-indicator {
    opacity: 100;
    cursor: pointer;
}

input[list]:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

/* =========================================
   4. Type Section
   ========================================= */
.type-section {
    margin-bottom: 20px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
}

.type-header {
    padding: 15px 20px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--text-main);
    color: white;
    user-select: none;
}

.type-header:hover {
    background: #1a252f;
}

.type-header.common {
    background: #27ae60;
}

.type-header.common:hover {
    background: #219a52;
}

.type-header.professional {
    background: var(--accent-red);
}

.type-header.professional:hover {
    background: #c0392b;
}

.type-name {
    font-weight: bold;
    font-size: 1.2em;
}

.type-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 15px;
    border-radius: 20px;
}

.type-toggle {
    font-size: 1.2em;
    transition: transform 0.3s;
}

.type-toggle.expanded {
    transform: rotate(180deg);
}

.type-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background: var(--bg-light);
    padding: 0;
}

.type-content.show {
    max-height: 2000px;
    padding: 20px;
    transition: max-height 0.3s ease-in;
}

.type-subjects-grid {
    display: flex;
    flex-direction: column;
    padding: 15px;
    width: 100%;
}

/* =========================================
   5. Buttons & Controls
   ========================================= */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: var(--transition-normal);
}

.btn-add {
    background-color: #27ae60;
    color: white;
}

.btn-add:hover {
    background-color: #219a52;
}

.btn-delete {
    background-color: var(--accent-red);
    color: white;
    padding: 5px 15px;
    font-size: 14px;
}

.btn-delete:hover {
    background-color: #c0392b;
}

/* Danger Zone */
.danger-zone {
    margin-top: 40px;
    padding: 20px;
    background-color: #ffe6e6;
    border: 2px dashed var(--accent-red);
    border-radius: 8px;
    text-align: center;
}

.danger-zone h3 {
    color: #c0392b;
    margin-bottom: 10px;
    font-size: 1.1em;
}

.danger-zone p {
    color: #7f1e1e;
    margin-bottom: 15px;
    font-size: 0.9em;
}

.btn-clear {
    background-color: #c0392b;
    color: white;
    position: relative;
}

.btn-clear:hover {
    background-color: #a93226;
    box-shadow: 0 2px 10px rgba(231, 76, 60, 0.3);
}

.danger-confirm {
    margin-bottom: 15px;
}

.danger-confirm input[type="checkbox"] {
    margin-right: 10px;
    transform: scale(1.2);
}

.danger-confirm label {
    color: #c0392b;
    font-weight: bold;
}

/* =========================================
   6. Filter & Display
   ========================================= */
.filter-section {
    background: #ecf0f1;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.filter-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

.display-section {
    margin-top: 20px;
}

.record-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.record-table th {
    background-color: var(--accent-blue);
    color: white;
    padding: 12px;
    text-align: left;
    font-weight: bold;
}

.record-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #ecf0f1;
}

.record-table tr:hover {
    background-color: var(--bg-light);
}

.record-table tr:nth-child(even) {
    background-color: #f5f7fa;
}

.no-records,
.no-subject-stats {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 18px;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    padding: 15px;
}

.pagination button {
    padding: 8px 12px;
    border: 1px solid #ddd;
    background: white;
    color: #333;
    border-radius: 5px;
    cursor: pointer;
    transition: var(--transition-normal);
}

.pagination button:hover:not(:disabled) {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination .page-btn {
    min-width: 40px;
}

.pagination .page-btn.active {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

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

/* =========================================
   7. Media Queries
   ========================================= */
@media (max-width: 1024px) {
    .input-grid {
        grid-template-columns: 1fr 1fr;
    }
}

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