/* ── Reset & base ── */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: Arial, sans-serif;
    font-size: 14px;
    background: #f4f4f4;
    color: #222;
    overflow-x: auto;
}

/* ── Navbar ── */
.navbar {
    background: #1F3A5F;
    color: white;
    padding: 0 1.2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 48px;
}

.nav-brand {
    font-size: 1.1rem;
    font-weight: bold;
    letter-spacing: 0.03em;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.nav-user { font-weight: bold; }
.nav-role { color: #a0b8d0; font-size: 0.85rem; }

.nav-links a {
    color: #a0d0ff;
    text-decoration: none;
    font-size: 0.9rem;
}

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

/* ── Filter bar divider ── */
.filter-divider {
    display: inline-block;
    width: 1px;
    height: 30px;
    background: #2E4A6B;
    margin: 0 6px;
    vertical-align: middle;
    flex-shrink: 0;
}

/* ── Main content ── */
.main-content {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 48px);
    overflow-x: auto;
}

/* ── Page layout (inside main-content) ── */
.page-layout {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 0.8rem 1.2rem 0 1.2rem;
    overflow: hidden;
}

/* ── Filter bar ── */
.filter-bar {
    display: flex;
    gap: 0.5rem 0.6rem;
    align-items: center;
    background: #dce6f0;
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.filter-bar label {
    font-weight: bold;
    font-size: 0.85rem;
    color: #1F3A5F;
    white-space: nowrap;
}

.filter-bar input,
.filter-bar select {
    padding: 4px 8px;
    border: 1px solid #aaa;
    border-radius: 4px;
    font-size: 0.85rem;
}

.filter-bar button {
    padding: 4px 10px;
    background: #666;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    white-space: nowrap;
}

.filter-bar button:hover { background: #444; }

/* Filter groups keep label and input together */
.filter-group {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-shrink: 0;
}

.filter-group.email-buttons {
    gap: 0.4rem;
}

/* Responsive adjustments for filter bar */
@media (max-width: 1400px) {
    .filter-bar {
        gap: 0.4rem 0.5rem;
    }
    .filter-bar label {
        font-size: 0.8rem;
    }
    .filter-bar input,
    .filter-bar select {
        font-size: 0.8rem;
        padding: 3px 6px;
    }
    .filter-bar button {
        font-size: 0.75rem;
        padding: 4px 8px;
    }
    #filterName {
        width: 100px !important;
    }
    #filterId {
        width: 70px !important;
    }
}

@media (max-width: 1200px) {
    .filter-divider {
        display: none;
    }
    .filter-bar {
        gap: 0.3rem 0.4rem;
    }
}

@media (max-width: 900px) {
    .filter-bar label {
        font-size: 0.75rem;
    }
    .filter-bar input,
    .filter-bar select {
        font-size: 0.75rem;
        padding: 2px 4px;
    }
    .filter-bar button {
        font-size: 0.7rem;
        padding: 3px 6px;
    }
}

/* ── Table wrapper — scrolls ── */
.table-wrapper {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
    background: white;
}

/* ── Honors table ── */
.honors-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.honors-table thead th {
    background: #1F3A5F;
    color: white;
    padding: 7px 10px;
    text-align: left;
    font-size: 0.85rem;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sortable columns */
.honors-table thead th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.honors-table thead th.sortable:hover {
    background: #2a4a7f;
}

.honors-table thead th.sortable.sorted {
    background: #2a4a7f;
}

.honors-table thead th .sort-indicator {
    font-size: 0.7rem;
    margin-left: 3px;
    opacity: 0.9;
}

.honors-table td {
    padding: 5px 10px;
    border-bottom: 1px solid #e8e8e8;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Checkbox column */
.honors-table th.checkbox-col,
.honors-table td.checkbox-col {
    width: 32px;
    overflow: visible;
}

/* Column resize handle */
.honors-table th {
    position: relative;
}

.col-resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
    z-index: 2;
    border-right: 2px solid transparent;
    transition: border-color 0.15s;
}

.col-resizer:hover,
.col-resizer.resizing {
    border-right: 2px solid #a0b8d0;
}

.col-resizer:hover,
.col-resizer.resizing {
    background: rgba(255, 255, 255, 0.25);
}

.honors-table tr:hover td { background: #f0f5fa; }

/* Skill honor rows — green left border */
.honors-table tr.skill-honor td:first-child {
    border-left: 4px solid #2e7d32;
}

/* Zebra striping */
.honors-table tbody tr:nth-child(even) td {
    background: #f0f5fa;
}

.honors-table tbody tr:nth-child(even):hover td {
    background: #e0ecf8;
}

/* Name cell — clickable */
td.name-cell {
    cursor: pointer;
    color: #1F3A5F;
    min-width: 180px;
}

td.name-cell:hover {
    text-decoration: underline;
    background: #e8f0fa !important;
}

td.name-cell.unassigned {
    color: #aaa;
    font-style: italic;
}

/* Status badge */
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.78rem;
    font-weight: bold;
}

.status-unassigned   { background: #e0e0e0; color: #555; }
.status-assigned     { background: #fff9c4; color: #795500; }
.status-reserved     { background: #e8d5f5; color: #5c007a; }
.status-emailsent    { background: #bbdefb; color: #0d47a1; }
.status-accepting    { background: #ffe0b2; color: #bf360c; }
.status-accepted     { background: #c8e6c9; color: #1b5e20; }
.status-modification { background: #ffccbc; color: #bf360c; }
.status-bounced      { background: #ffcdd2; color: #b71c1c; }
.status-open     { background: #4e92d1a6; color: #cdf0f0; }

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

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

.modal {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.2);
    width: 580px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    background: #1F3A5F;
    color: white;
    padding: 0.7rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    flex-shrink: 0;
}

.modal-header button {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    display: flex;
    gap: 0.8rem;
    padding: 0.8rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.modal-left {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    min-width: 0;
}

.modal-right {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 160px;
    flex-shrink: 0;
}

#familySearch {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    flex-shrink: 0;
}

#familyList {
    height: 220px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
}

#familyList div {
    padding: 5px 8px;
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 1px solid #f0f0f0;
}

#familyList div:hover,
#familyList div.selected { background: #1F3A5F; color: white; }

#memberList {
    display: block;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-top: 0.5rem;
}

#memberList div {
    padding: 5px 8px;
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 1px solid #f0f0f0;
}

#memberList div:hover { background: #e8f0fa; }

/* Assignment buttons */
.assign-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
}

.assign-btn {
    padding: 8px;
    border: 2px solid #1F3A5F;
    background: white;
    color: #1F3A5F;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.85rem;
    transition: all 0.15s;
}

.assign-btn:hover {
    background: #1F3A5F;
    color: white;
}

.assign-btn.full-width { grid-column: span 2; }
.assign-btn:disabled { opacity: 0.3; cursor: default; }

/* Unassign button */
.btn-unassign {
    padding: 6px;
    background: #fff;
    border: 1px solid #cc0000;
    color: #cc0000;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    margin-top: auto;
}

.btn-unassign:hover { background: #ffeeee; }

/* ── Status popup ── */
.status-popup {
    position: absolute;
    right: 0;
    top: 100%;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 50;
    min-width: 120px;
}

.status-popup div {
    padding: 7px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    white-space: nowrap;
}

.status-popup div:hover {
    background: #1F3A5F;
    color: white;
}

.status-popup div:last-child {
    border-top: 1px solid #eee;
    color: #888;
}

/* ── Email Status Selector ── */
.email-status-info {
    font-size: 0.8rem;
    color: #666;
    font-style: italic;
    margin-left: 5px;
}

#emailStatusSelect {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

/* Send/Preview email buttons */
#btnSendAll:disabled,
#btnSendChecked:disabled,
#btnPreviewChecked:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#btnSendAll:not(:disabled),
#btnSendChecked:not(:disabled) {
    background-color: #4CAF50;
    color: white;
    border: none;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

#btnSendAll:not(:disabled):hover,
#btnSendChecked:not(:disabled):hover {
    background-color: #45a049;
}

#btnPreviewChecked:not(:disabled) {
    background-color: #2196F3;
    color: white;
    border: none;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

#btnPreviewChecked:not(:disabled):hover {
    background-color: #1976D2;
}

@media (max-width: 1400px) {
    #btnSendAll:not(:disabled),
    #btnSendChecked:not(:disabled),
    #btnPreviewChecked:not(:disabled) {
        padding: 4px 8px;
        font-size: 0.75rem;
    }
}

@media (max-width: 900px) {
    #btnSendAll:not(:disabled),
    #btnSendChecked:not(:disabled),
    #btnPreviewChecked:not(:disabled) {
        padding: 3px 6px;
        font-size: 0.7rem;
    }
}

/* ── Email Preview Modal ── */
#previewModalOverlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

#previewModalOverlay.active {
    display: flex;
}

.preview-modal {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.preview-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    background: #1F3A5F;
    color: white;
    border-radius: 8px 8px 0 0;
}

.preview-modal .modal-header button {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0 5px;
}

.preview-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.preview-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.preview-nav button {
    padding: 8px 16px;
    border: 1px solid #ccc;
    background: #f5f5f5;
    border-radius: 4px;
    cursor: pointer;
}

.preview-nav button:not(:disabled):hover {
    background: #e0e0e0;
}

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

#previewCounter {
    font-weight: bold;
    color: #333;
}

.preview-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.preview-field {
    display: flex;
    gap: 10px;
}

.preview-field label {
    font-weight: bold;
    color: #555;
    min-width: 100px;
}

.preview-field span {
    color: #333;
    word-break: break-word;
}

.preview-message-container {
    margin-top: 15px;
}

.preview-message-container label {
    display: block;
    font-weight: bold;
    color: #555;
    margin-bottom: 10px;
}

.preview-message {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 20px;
    background: #fafafa;
    max-height: 400px;
    overflow-y: auto;
    line-height: 1.6;
}

.preview-modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    text-align: right;
}

.preview-modal-footer button {
    padding: 10px 25px;
    background: #1F3A5F;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.preview-modal-footer button:hover {
    background: #2a4a7f;
}

/* Responsive preview modal */
@media (max-width: 900px) {
    .preview-modal {
        width: 95%;
        max-height: 95vh;
    }
    
    .preview-modal-body {
        padding: 15px;
    }
    
    .preview-field {
        flex-direction: column;
        gap: 3px;
    }
    
    .preview-field label {
        min-width: auto;
    }
    
    .preview-message {
        max-height: 300px;
        padding: 15px;
    }
    
    .preview-nav button {
        padding: 6px 12px;
        font-size: 0.85rem;
    }
}

/* Status cell needs overflow visible for popup to show */
.honors-table td.status-cell {
    overflow: visible;
}