/* Styles for the data table */
#logo-animation-container {
    -webkit-touch-callout: none; /* Prevents the long-press context menu on iOS Chrome/Safari */
    -webkit-user-select: none;   /* Prevents text or image selection during the hold */
    user-select: none;
    touch-action: manipulation;  /* Allows scrolling while disabling double-tap zoom interference */
}

#table-container {
    overflow: auto; /* Enable scrolling in both directions for the container */
    max-height: 70vh; /* Limit the height to create a scrollable area */
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.5rem;
    background-color: var(--text-light);
    box-shadow: var(--card-shadow);
}

.data-table th, .data-table td {
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    text-align: left;
    font-size: 80%;
}

.data-table thead {
    position: sticky;
    top: 0;
    z-index: 20;
    background-color: #eef2f7; /* Light blue-gray */
}

/* Sticky First Column for Data Table */
.data-table th:first-child,
.data-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 10; /* Above regular cells, below header */
    background-color: var(--text-light); /* Match table background */
}

.data-table th {
    font-weight: 600;
    position: relative;
}

/* Ensure the top-left corner cell stays on top of both sticky row and sticky column */
.data-table thead th:first-child {
    z-index: 30;
    background-color: #eef2f7;
}

.data-table th.sortable::after {
    content: ' \2195'; /* Up-down arrow */
    opacity: 0.3;
    position: absolute;
    right: 5px;
}

.data-table th.sorted-asc::after {
    content: ' \25B2'; /* Up arrow */
    opacity: 1;
}

.data-table th.sorted-desc::after {
    content: ' \25BC'; /* Down arrow */
    opacity: 1;
}

/* Filter Dropdown Styles */
.filter-container {
    position: relative;
    width: 100%;
}

.filter-btn {
    width: 100%;
    padding: 6px;
    text-align: left;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.filter-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #ccc;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    z-index: 100;
    min-width: 220px;
    padding: 10px;
    border-radius: 4px;
}

.filter-menu.show {
    display: block;
}

/* Generic Dropdown Styles */
.dropdown-container {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    background-color: #fff;
    min-width: 150px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    z-index: 1000;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-menu a {
    display: block;
    padding: 10px 15px;
    text-decoration: none;
    color: #333;
    font-size: 0.9rem;
}

.dropdown-menu a:hover {
    background-color: #f8f9fa;
}

.dropdown-item-submenu {
    position: relative;
}

.dropdown-submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: 0;
    background-color: #fff;
    min-width: 160px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    z-index: 1001;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.dropdown-item-submenu:hover > .dropdown-submenu {
    display: block;
}

/* Mobile optimization: stack the submenu instead of showing it to the side */
@media (max-width: 600px) {
    .dropdown-submenu {
        position: static;
        box-shadow: none;
        border: none;
        padding-left: 20px;
    }
}

.filter-controls, .filter-actions, .visibility-controls {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.filter-actions {
    margin-top: 8px;
    justify-content: flex-end;
}

.filter-search {
    padding: 0 0 8px 0;
}

.filter-search-input {
    width: 100%;
    padding: 5px;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 0.9rem;
    box-sizing: border-box;
}

.filter-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #eee;
    padding: 5px;
    background: #fafafa;
}

.filter-list label {
    display: block;
    cursor: pointer;
    padding: 2px 0;
    font-weight: normal;
}

.btn-small, .btn-primary-small {
    padding: 4px 8px;
    font-size: 0.8rem;
    cursor: pointer;
    border-radius: 3px;
    border: 1px solid #ccc;
    background: #f0f0f0;
}

.btn-primary-small {
    background-color: var(--primary-blue);
    color: white;
    border: none;
}

/* Tab Styles */
.tab-nav {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 1rem;
    background-color: #fff;
    overflow-x: auto; /* Handle overflow on small screens */
}

.tab-btn {
    padding: 1rem 1.5rem;
    border: none;
    background: none;
    cursor: pointer;
    font-family: var(--font-heading);
    font-weight: 600;
    color: #666;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}

.tab-btn:hover:not(:disabled) {
    color: var(--primary-blue);
    background-color: #f8f9fa;
}

.tab-btn.active {
    color: var(--primary-blue);
    border-bottom-color: var(--primary-blue);
}

.tab-btn:disabled {
    color: #666; /* Keep label color consistent with inactive state */
    cursor: default;
}

.tab-btn:disabled .close-tab-x {
    pointer-events: none;
    opacity: 0.3; /* Visually disable the 'x' without affecting the label */
}

.close-tab-x {
    font-size: 1.2em;
    line-height: 0.8;
    border-radius: 50%;
    padding: 0 4px;
    color: #888;
}

.close-tab-x:hover {
    color: #d00;
    background-color: #eee;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

#tab-records {
    position: relative;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 0.25rem;
    position: relative; /* For positioning the record count */
}

.card-header h2 {
    margin-bottom: 0;
}

#record-count,
.add-record-btn {
    font-size: 80%;
    font-weight: 600;
    font-family: inherit;
}

.refresh-btn-inline {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    padding: 2px 8px;
    font-size: 1rem;
    line-height: 1;
    color: var(--primary-blue);
}

.refresh-btn-inline {
    /* Ensure it aligns nicely with other buttons if needed */
    height: fit-content;
}

.refresh-btn-floating {
    /* Keep floating style for Records tab if it doesn't have a card header title */
    position: absolute;
    top: 5px;
    left: 5px;
    z-index: 25; /* Above sticky headers */
}

.refresh-btn-inline:hover, .refresh-btn-floating:hover {
    background-color: #f8f9fa;
}

/* Spinner Styles */
#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    border-radius: 8px; /* Match card radius */
}

.spinner {
    border: 5px solid #f3f3f3; /* Light grey */
    border-top: 5px solid var(--primary-blue); /* Blue */
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

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

.tab-view-container {
    position: relative;
    min-height: 200px;
}

/* Column Visibility Styles */
.column-visibility-control {
    position: relative;
}

.visibility-btn {
    width: 100%;
    height: 100%;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--primary-blue);
}

.visibility-btn.filtered {
    font-weight: bold;
    color: var(--primary-gold);
}

.visibility-menu {
    display: none;
    position: absolute;
    background: white;
    border: 1px solid #ccc;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    z-index: 101; /* Above filter menus */
    min-width: 220px;
    padding: 10px;
    border-radius: 4px;
    left: 5px;
    top: 95%;
}

.visibility-menu.show {
    display: block;
}

.visibility-list {
    max-height: 250px;
    overflow-y: auto;
    padding-top: 10px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 5px;
}

.visibility-list label {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 3px;
    background-color: #f9f9f9;
    border: 1px solid #eee;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: normal;
}

.visibility-actions {
    justify-content: flex-end;
    margin-top: 10px;
}

.visibility-controls {
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.column-header-btn {
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    font: inherit;
    font-weight: 600;
    color: inherit;
    padding: 4px 8px;
    cursor: pointer;
    display: inline-block;
    transition: background-color 0.2s, border-color 0.2s;
}

.column-header-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
    border-color: var(--border-color);
}

.record-action-btn {
    background: none;
    border: 1px solid var(--primary-blue);
    color: var(--primary-blue);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    line-height: 1;
    padding: 0;
    transition: all 0.2s ease;
}

.record-action-btn.error-icon {
    font-size: 16px; /* Reduced size to ensure the emoji fits within the 24px bounding circle */
    padding-bottom: 4px; /* Nudge the icon up slightly to center it visually */
}

.record-action-btn:hover {
    background-color: var(--primary-blue);
    color: white;
}

.record-specific-action.disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
    text-decoration: none;
    color: #333;
}

.action-menu-dropdown a:hover {
    background-color: #f8f9fa;
}

/* Edit Table Styles */
.edit-table {
    width: 100%;
    margin-top: 1.5rem;
    border-collapse: collapse;
}

.edit-table th, .edit-table td {
    border: 1px solid var(--border-color);
    padding: 8px;
    vertical-align: top;
}

.data-table td.missing-column {
    background-color: #f0f0f0;
}

.cell-error {
    color: #d32f2f; /* Darker red for accessibility */
    white-space: nowrap;
}

.edit-table th {
    background-color: #eef2f7;
    font-weight: 600;
    width: 25%;
}

.edit-table td:nth-child(2) {
    background-color: #f8f9fa;
    width: 37.5%;
}

.edit-table input[type="text"] {
    width: 100%;
}

/* Requests Table Styles */
#requests-table-container {
    overflow: auto;
    max-height: 70vh;
}

.requests-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 80%;
}

.requests-table th, .requests-table td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
    vertical-align: top;
}

.requests-table thead th {
    position: sticky;
    top: 0;
    z-index: 20;
    background-color: #eef2f7;
    font-weight: 600;
}

/* Sticky First Column for Requests Table */
.requests-table th:first-child,
.requests-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 10;
    background-color: #fff; /* Assuming white background for requests table */
}

.requests-table thead th:first-child {
    z-index: 30;
    background-color: #eef2f7;
}

.requests-table del {
    color: #dc3545; /* red */
}

.requests-table ins {
    color: #28a745; /* green */
    text-decoration: none;
    background-color: #e9f5ec;
}

.requests-table .action-select {
    padding: 4px;
    border-radius: 3px;
    border: 1px solid var(--border-color);
}

/* Record Type List Styles */
.record-type-container {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    max-height: 300px;
    overflow-y: auto;
    background-color: #fff;
}

.record-type-container label {
    display: block;
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    font-weight: normal;
}

.record-type-container label:last-child {
    border-bottom: none;
}

.record-type-container label:hover {
    background-color: #f8f9fa;
}

.record-type-container input[type="radio"] {
    margin-right: 0.75rem;
}

/* Prevent wrapping on specific input groups */
.input-group.no-wrap {
    flex-wrap: nowrap;
}

.admin-bar-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.zoom-controls span {
    font-weight: 600;
    min-width: 45px; /* prevent layout shift */
    text-align: center;
}

/* Header layout to align title and admin controls */
header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 8px 16px;
    font-size: 16px;
    gap: 20px;
}

.shaking {
    animation: shakePattern 0.15s infinite;
}

@keyframes shakePattern {
    0% { transform: translate(0, 0); }
    10% { transform: translate(3px, -4px); }
    20% { transform: translate(-2px, 5px); }
    30% { transform: translate(5px, -3px); }
    40% { transform: translate(-4px, 4px); }
    50% { transform: translate(2px, -6px); }
    60% { transform: translate(-5px, 3px); }
    70% { transform: translate(4px, -2px); }
    80% { transform: translate(-3px, 5px); }
    90% { transform: translate(1px, -4px); }
    100% { transform: translate(0, 0); }
}

.header-controls {
    grid-column: 3;
    display: flex;
    align-items: center;
    gap: 15px;
    justify-self: end;
}

#view-selector-container {
    grid-column: 2;
    justify-self: center;
}

/* Auth Dropdown Styles */
.auth-dropdown-container {
    position: relative;
    display: inline-block;
}

.auth-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 5px);
    right: 0;
    background-color: #fff;
    min-width: 160px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    z-index: 1000;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.auth-dropdown-menu.show {
    display: block;
}

.auth-dropdown-menu a {
    display: block;
    padding: 10px 15px;
    text-decoration: none;
    color: #333;
    font-size: 0.9rem;
    white-space: nowrap;
}

.auth-dropdown-menu a:hover {
    background-color: #f8f9fa;
}

/* Align sub-menus to the left in the right-aligned auth dropdown to prevent screen overflow */
.auth-dropdown-menu .dropdown-submenu {
    left: auto;
    right: 100%;
}

/* Auth Button Styles (within Nav Bar) */
#auth-button {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.9rem;
    background-color: #fff;
    color: #666;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 6px 16px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

#auth-button:hover {
    color: var(--primary-blue);
    background-color: #f8f9fa;
}

#auth-button.auth-signed-in {
    background-color: #fff;
    color: #666;
}

/* View Selector Styles */
.view-dropdown-container {
    position: relative;
    display: inline-block;
}

.view-selector-btn {
    font-size: 0.9rem;
    padding: 6px 16px;
    border-radius: 20px;
    white-space: nowrap;
}

.view-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    background-color: #fff;
    min-width: 180px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    z-index: 1000;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.view-dropdown-menu.show {
    display: block;
}

.view-dropdown-menu a {
    display: block;
    padding: 10px 15px;
    text-decoration: none;
    color: #333;
    font-size: 0.9rem;
}

.view-dropdown-menu a:hover {
    background-color: #f8f9fa;
}

/* Find Bar Styles */
.table-find-bar {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 0;
    padding: 0;
    background-color: transparent;
    border: none;
}

.find-input {
    padding: 2px 8px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 0.8rem;
    width: 150px;
    box-sizing: border-box;
}

.global-find-bar {
    background-color: #f8f9fa;
    border-bottom: 1px solid var(--border-color);
    padding: 8px 1rem;
    display: flex;
    justify-content: flex-end;
}

.find-count {
    font-size: 0.9rem;
    color: #666;
    min-width: 70px;
    text-align: center;
}

mark.table-match {
    background-color: #ffeb3b;
    color: #000;
}

mark.table-match.active {
    background-color: #ff9800;
    color: #fff;
    box-shadow: 0 0 0 2px #f44336;
}

/* Smaller Zoom Slider */
.zoom-controls input[type="range"] {
    width: 80px;
    cursor: pointer;
    margin: 0;
}

/* Global Menu Bar Styles */
#main-nav-bar {
    display: flex;
    background-color: var(--text-light);
    border-bottom: 1px solid var(--border-color);
    padding: 0 1rem;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.menu-item {
    position: relative;
}

.menu-btn {
    background: none;
    border: none;
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-family: var(--font-heading);
    font-weight: 600;
    color: #666;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.menu-btn:hover {
    color: var(--primary-blue);
    background-color: #f8f9fa;
}

.menu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background-color: #fff;
    min-width: 200px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1001;
    border: 1px solid var(--border-color);
    border-radius: 0 0 4px 4px;
}

.menu-dropdown.show {
    display: block;
}

.menu-dropdown a {
    display: block;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: #333;
    font-size: 0.9rem;
    border-bottom: 1px solid #f0f0f0;
}

.menu-dropdown a:last-child {
    border-bottom: none;
}

.menu-dropdown a:hover {
    background-color: #f8f9fa;
    color: var(--primary-blue);
}
