*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
    --bg: #f8f7f4;
    --surface: #fff;
    --border: #ddd;
    --text: #1a1a1a;
    --text-muted: #666;
    --accent: #8b0000;
    --accent-light: #a52a2a;
    --tab-bg: #eee;
    --tab-active: #8b0000;
    --tab-text: #fff;
    --row-hover: #faf5f0;
    --radius: 6px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* Password Gate */
#password-gate {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

.gate-box {
    background: var(--surface);
    padding: 3rem 2.5rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 400px;
    width: 90%;
}

.gate-box h1 {
    font-size: 1.6rem;
    color: var(--accent);
    margin-bottom: 0.25rem;
}

.gate-box p { color: var(--text-muted); margin-bottom: 1.5rem; }

#password-form {
    display: flex;
    gap: 0.5rem;
}

#password-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

#password-input:focus { border-color: var(--accent); }

#password-form button {
    padding: 0.75rem 1.5rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

#password-form button:hover { background: var(--accent-light); }

.error { color: #c00; font-size: 0.9rem; margin-top: 0.75rem; }

/* Header */
header {
    background: var(--accent);
    color: #fff;
    padding: 1.25rem 1.5rem;
    text-align: center;
}

header h1 { font-size: 1.4rem; }
.subtitle { font-size: 0.85rem; opacity: 0.85; margin-top: 0.25rem; }

/* Controls */
.controls {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.search-wrap {
    position: relative;
    margin-bottom: 0.75rem;
}

#search {
    width: 100%;
    padding: 0.6rem 1rem;
    padding-right: 5rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

#search:focus { border-color: var(--accent); }

.search-count {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Tabs */
nav[role="tablist"] {
    display: flex;
    gap: 0.25rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
}

nav[role="tablist"]::-webkit-scrollbar { display: none; }

.tab {
    flex-shrink: 0;
    padding: 0.45rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--tab-bg);
    color: var(--text);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.tab:hover { background: #ddd; }
.tab.active {
    background: var(--tab-active);
    color: var(--tab-text);
    border-color: var(--tab-active);
}

/* Loading */
#loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Content area */
#content { padding: 0.75rem; }

/* Table styling */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.data-table th {
    background: #f0eeeb;
    padding: 0.6rem 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.data-table th:hover { background: #e8e6e2; }

.data-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #eee;
    vertical-align: top;
}

.data-table tr:hover td { background: var(--row-hover); }

.data-table .highlight {
    background: #fff3cd;
    border-radius: 2px;
    padding: 0 1px;
}

/* Card layout for mobile */
.card-grid {
    display: grid;
    gap: 0.75rem;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border-left: 3px solid var(--accent);
}

.card-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.4rem;
}

.card-detail {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.card-detail strong { color: var(--text); }

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
    background: #e8e0d8;
    color: #5a4a3a;
}

.badge-rite { background: #dbeafe; color: #1e40af; }
.badge-continent { background: #d1fae5; color: #065f46; }
.badge-type { background: #fce7f3; color: #9d174d; }
.badge-order { background: #fef3c7; color: #92400e; }

/* Pagination */
#pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    border-top: 1px solid var(--border);
}

#pagination button {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

#pagination button:hover:not(:disabled) { background: var(--tab-bg); }
#pagination button:disabled { opacity: 0.4; cursor: default; }

#page-info { font-size: 0.85rem; color: var(--text-muted); }

/* Empty state */
.empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }

/* Footer */
footer {
    text-align: center;
    padding: 1.5rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

/* Responsive: table view on wider screens */
@media (max-width: 768px) {
    .data-table-wrap { display: none; }
    .card-grid-wrap { display: block; }
    header h1 { font-size: 1.2rem; }
    .controls { padding: 0.5rem; }
    #content { padding: 0.5rem; }
    .tab { padding: 0.4rem 0.65rem; font-size: 0.78rem; }
}

@media (min-width: 769px) {
    .data-table-wrap { display: block; }
    .card-grid-wrap { display: none; }
    #content { padding: 1rem 1.5rem; max-width: 1400px; margin: 0 auto; }
    .controls { padding: 0.75rem 1.5rem; }
    header { padding: 1.5rem; }
}

/* Sortable column indicator */
.data-table th .sort-arrow { margin-left: 0.25rem; font-size: 0.7rem; }
