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

body {
    font-family: 'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-family: 'Alfa Slab One', cursive;
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 2.5rem;
    letter-spacing: 1px;
}

header p {
    color: #7f8c8d;
    font-size: 0.95rem;
}

/* Main Container */
main {
    max-width: 1400px;
    margin: 0 auto;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Loading State */
#loading-state {
    text-align: center;
    padding: 60px 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#loading-state p {
    font-size: 1.2rem;
    color: #555;
    margin-bottom: 20px;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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

/* Error State */
#error-state {
    text-align: center;
    padding: 40px 20px;
    background: #fee;
    border: 2px solid #e74c3c;
    border-radius: 8px;
    margin-bottom: 20px;
}

.error-message {
    color: #c0392b;
    font-size: 1.1rem;
    margin-bottom: 20px;
}

#retry-btn {
    background-color: #e74c3c;
    color: white;
    border: none;
    padding: 10px 24px;
    font-size: 1rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

#retry-btn:hover {
    background-color: #c0392b;
}

/* Search Controls */
#search-controls {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

#search-controls label {
    font-weight: 600;
    color: #2c3e50;
}

#search-input {
    flex: 1;
    min-width: 250px;
    padding: 10px 15px;
    border: 2px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

#search-input:focus {
    outline: none;
    border-color: #3498db;
}

#result-count {
    color: #7f8c8d;
    font-size: 0.95rem;
    font-weight: 500;
}

/* Pagination Controls */
.pagination-controls {
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}

.page-size-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-size-selector label {
    font-weight: 600;
    color: #2c3e50;
}

#page-size-select {
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 4px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

#page-size-select:focus {
    outline: none;
    border-color: #3498db;
}

.page-navigation {
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-navigation button {
    background-color: #3498db;
    color: white;
    border: none;
    padding: 8px 16px;
    font-size: 0.9rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s, opacity 0.2s;
}

.page-navigation button:hover:not(:disabled) {
    background-color: #2980b9;
}

.page-navigation button:disabled {
    background-color: #bdc3c7;
    cursor: not-allowed;
    opacity: 0.6;
}

#page-info,
#page-info-bottom {
    font-weight: 600;
    color: #2c3e50;
    min-width: 100px;
    text-align: center;
}

#item-range {
    color: #7f8c8d;
    font-size: 0.9rem;
}

/* Table Container */
#table-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    overflow-x: auto;
    margin-bottom: 20px;
}

/* Table Styles */
#emoji-table {
    width: 100%;
    border-collapse: collapse;
}

#emoji-table thead {
    background-color: #34495e;
    color: white;
    position: sticky;
    top: 0;
    z-index: 10;
}

#emoji-table th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #2c3e50;
}

/* Sortable header styles */
#emoji-table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: background-color 0.2s;
}

#emoji-table th.sortable:hover {
    background-color: #2c3e50;
}

#emoji-table th.sortable:focus {
    outline: 2px solid #3498db;
    outline-offset: -2px;
}

/* Sort indicators */
.sort-indicator {
    margin-left: 8px;
    font-size: 0.8em;
    opacity: 0;
    transition: opacity 0.2s;
}

#emoji-table th.sortable:hover .sort-indicator {
    opacity: 0.5;
}

#emoji-table th.sort-asc .sort-indicator::after {
    content: "▲";
    opacity: 1;
}

#emoji-table th.sort-desc .sort-indicator::after {
    content: "▼";
    opacity: 1;
}

#emoji-table tbody tr {
    border-bottom: 1px solid #ecf0f1;
    transition: background-color 0.2s;
}

#emoji-table tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

#emoji-table tbody tr:hover {
    background-color: #e8f4f8;
}

#emoji-table td {
    padding: 12px 15px;
}

/* Column-specific styles */
.code-point {
    font-family: 'Courier New', Courier, monospace;
    color: #8e44ad;
    font-weight: 500;
}

.count {
    font-family: 'Courier New', Courier, monospace;
    color: #2980b9;
    font-weight: 600;
    text-align: center;
    width: 60px;
}

.character {
    font-size: 24px;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.2s;
    user-select: none;
}

.character:hover {
    background-color: #d5e8f7;
}

.character:focus {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

.utf8 {
    font-family: 'Courier New', Courier, monospace;
    color: #27ae60;
    font-size: 0.9rem;
    word-break: break-all;
    max-width: 200px;
    line-height: 1.4;
}

.byte-size {
    font-family: 'Courier New', Courier, monospace;
    color: #e67e22;
    font-weight: 600;
    text-align: center;
}

.name {
    color: #555;
}

/* Copied Feedback */
.copied {
    background-color: #d4edda !important;
    animation: copyFeedback 1.5s ease-out;
}

@keyframes copyFeedback {
    0% {
        background-color: #28a745;
    }
    100% {
        background-color: #d4edda;
    }
}

.copy-indicator {
    position: relative;
}

.copy-indicator::after {
    content: '✓ Copied!';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #28a745;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-family: sans-serif;
    white-space: nowrap;
    pointer-events: none;
    animation: fadeOut 1.5s ease-out;
    z-index: 100;
}

@keyframes fadeOut {
    0% {
        opacity: 1;
    }
    70% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

/* Empty State */
.empty-state td {
    text-align: center;
    padding: 60px 20px;
    color: #7f8c8d;
    font-size: 1.1rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    color: #7f8c8d;
    font-size: 0.9rem;
    margin-top: 20px;
}

footer a {
    color: #3498db;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

footer p {
    margin: 5px 0;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    header {
        padding: 15px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    #search-controls {
        padding: 15px;
    }

    .pagination-controls {
        padding: 10px 15px;
        flex-direction: column;
        align-items: stretch;
    }

    .page-navigation {
        flex-wrap: wrap;
        justify-content: center;
    }

    .page-navigation button {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    #emoji-table th,
    #emoji-table td {
        padding: 10px 8px;
        font-size: 0.9rem;
    }

    .character {
        font-size: 20px;
    }

    #table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 480px) {
    #search-input {
        min-width: 100%;
    }

    .page-navigation button {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    #emoji-table th,
    #emoji-table td {
        padding: 8px 6px;
        font-size: 0.85rem;
    }

    .character {
        font-size: 18px;
    }
}

/* Search Controls with Help Trigger */
.search-input-container {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    width: 100%;
}

#help-trigger {
    background: #3498db;
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#help-trigger:hover {
    background: #2980b9;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

#help-trigger:focus {
    outline: 2px solid #2980b9;
    outline-offset: 2px;
}

#help-trigger:active {
    transform: translateY(0);
}

.help-icon {
    font-size: 18px;
    line-height: 1;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    cursor: pointer;
}

.modal-container {
    position: relative;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 800px;
    max-height: 90vh;
    width: 90%;
    margin: 20px;
    transform: scale(0.7);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.modal.show .modal-container {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-header h2 {
    margin: 0;
    color: #2c3e50;
    font-size: 1.5rem;
    font-weight: 600;
}

#modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6c757d;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#modal-close:hover {
    background: #f8f9fa;
    color: #495057;
}

#modal-close:focus {
    outline: 2px solid #3498db;
    outline-offset: 1px;
}

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

.help-section {
    margin-bottom: 28px;
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section h3 {
    color: #2c3e50;
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 12px;
    border-bottom: 2px solid #3498db;
    padding-bottom: 6px;
}

.help-section h4 {
    color: #34495e;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
    margin-top: 16px;
}

.help-section p {
    margin-bottom: 12px;
    line-height: 1.6;
    color: #555;
}

.help-section ul {
    margin: 12px 0;
    padding-left: 24px;
}

.help-section li {
    margin-bottom: 6px;
    line-height: 1.5;
    color: #555;
}

.example-box {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 16px;
    margin: 16px 0;
}

.example-box p {
    margin-bottom: 8px;
}

.example-box ul {
    margin-bottom: 8px;
}

.example-detailed {
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
    margin: 16px 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.example-breakdown {
    display: flex;
    align-items: flex-start;
    gap: 20px;
}

.emoji-large {
    font-size: 48px;
    line-height: 1;
    flex-shrink: 0;
}

.breakdown-text {
    flex: 1;
}

.breakdown-text p {
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.breakdown-text p:last-child {
    margin-bottom: 0;
}

code {
    background: #f1f3f4;
    color: #d63384;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 0.9em;
}

/* Focus trap for modal accessibility */
.modal:not(.show) * {
    pointer-events: none;
}

.modal.show * {
    pointer-events: auto;
}

/* Prevent body scroll when modal is open */
body.modal-open {
    overflow: hidden;
}

/* Modal responsive design */
@media (max-width: 768px) {
    .modal-container {
        max-width: 95%;
        margin: 10px;
        max-height: 95vh;
    }

    .modal-header {
        padding: 16px 20px 12px;
    }

    .modal-header h2 {
        font-size: 1.3rem;
    }

    .modal-body {
        padding: 20px;
    }

    .example-breakdown {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 12px;
    }

    .emoji-large {
        font-size: 40px;
    }

    .search-input-container {
        justify-content: space-between;
    }

    #help-trigger {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .modal-container {
        max-width: 100%;
        margin: 0;
        max-height: 100vh;
        border-radius: 0;
    }

    .help-section h3 {
        font-size: 1.1rem;
    }

    .breakdown-text p {
        font-size: 0.85rem;
    }

    .example-box,
    .example-detailed {
        padding: 12px;
    }
}
