/* ============================================================================
   taiwanbeetles - Custom CSS Styles
   Taiwanese Leaf Litter Beetles Project
   Color palette: #5d3535 | #996633 | #ba5b06 | white
   ============================================================================ */

/* ============================================================================
   CSS Reset & Normalize
   ============================================================================ */

*, *::before, *::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

body {
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
}

/* Leaflet map tiles must NOT be display:block or max-width:100% */
.leaflet-container img {
    display: inline !important;
    max-width: none !important;
    max-height: none !important;
}

/* Reset our button styles for Leaflet zoom controls */
.leaflet-control-zoom a,
.leaflet-control a {
    background: white !important;
    color: #333 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    font-size: 18px !important;
    font-weight: bold !important;
    width: 26px !important;
    height: 26px !important;
    line-height: 26px !important;
    display: block !important;
    text-align: center !important;
    text-decoration: none !important;
}

.leaflet-control-zoom a:hover,
.leaflet-control a:hover {
    background: #f4f4f4 !important;
    color: var(--primary-color) !important;
}

.leaflet-control-zoom-in {
    border-bottom: 1px solid #ccc !important;
}

/* Custom beetle marker - CSS circle pin */


/* ============================================================================
   DNA Barcode / sequence display
   ============================================================================ */

.barcode-expand {
    cursor: pointer;
}

.barcode-expand summary {
    list-style: none;
    cursor: pointer;
    color: var(--accent-color);
    font-size: 0.85rem;
}

.barcode-expand summary::-webkit-details-marker {
    display: none;
}

.barcode-expand summary::before {
    content: '▶ ';
    font-size: 0.7rem;
}

.barcode-expand[open] summary::before {
    content: '▼ ';
}

.barcode-full {
    display: block;
    margin-top: 0.4rem;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.78rem;
    word-break: break-all;
    overflow-wrap: break-word;
    white-space: normal;
    background: var(--light-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.5rem;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.5;
    color: var(--text-dark);
    user-select: all;
}

td code {
    word-break: break-all;
    white-space: normal;
    font-size: 0.82rem;
}

.text-no {
    color: var(--text-muted);
    font-style: italic;
}

input, button, textarea, select {
    font: inherit;
}

p, h1, h2, h3, h4, h5, h6 {
    overflow-wrap: break-word;
}

ul, ol {
    list-style: none;
    padding: 0;
    margin: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

table {
    border-collapse: collapse;
}

:root {
    --primary-color: #5d3535;
    --primary-dark: #3d2020;
    --primary-light: #7a4848;
    --accent-color: #996633;
    --accent-alt: #ba5b06;
    --accent-hover: #7a4f20;
    --light-bg: #fdf7f4;
    --warm-white: #fff9f6;
    --text-dark: #2c1c1c;
    --text-muted: #7a6060;
    --border-color: #e8d5cc;
    --success-color: #3a8a3a;
    --warning-color: #ba5b06;
    --error-color: #c0392b;
}

/* ============================================================================
   Global Styles
   ============================================================================ */

body {
    background-color: var(--warm-white);
    color: var(--text-dark);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ============================================================================
   Header & Navigation
   ============================================================================ */

header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 0.8rem 1.5rem;
    box-shadow: 0 2px 10px rgba(61, 32, 32, 0.25);
}

header nav {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

body > header > nav {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

body > header > nav > ul {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 1.5rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

body > header > nav > ul > li {
    list-style: none;
    display: block;
}

.nav-brand {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    color: white;
}

.nav-brand img {
    height: 52px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.3));
}

.nav-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.nav-brand-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.01em;
}

.nav-brand-subtitle {
    font-size: 0.68rem;
    color: var(--accent-color);
    font-weight: 400;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

body > header > nav a {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.95rem;
    transition: color 0.2s ease;
}

body > header > nav a:hover {
    color: var(--accent-color);
}

@media (max-width: 768px) {
    body > header > nav {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    body > header > nav > ul {
        flex-wrap: wrap;
        gap: 1rem;
    }
}

/* ============================================================================
   Main Content
   ============================================================================ */

main {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
    min-height: calc(100vh - 300px);
}

/* ============================================================================
   Cards Grid
   ============================================================================ */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin: 2rem 0;
}

.card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
}

.card:hover {
    box-shadow: 0 6px 12px rgba(93, 53, 53, 0.15);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.card h3 {
    color: var(--primary-color);
    margin: 0 0 1rem 0;
    font-size: 1.3rem;
    word-break: break-word;
}

.card p {
    margin: 0.5rem 0;
    color: #666;
    font-size: 0.95rem;
}

.card strong {
    color: var(--primary-color);
    font-weight: 600;
}

.card em {
    color: #999;
    font-style: italic;
}

.card [role="button"] {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.6rem 1.2rem;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 4px;
    transition: background 0.3s ease;
    font-size: 0.95rem;
}

.card [role="button"]:hover {
    background: var(--primary-dark);
}

article header {
    background: none;
    color: var(--text-dark);
    padding: 2rem 0;
    border-bottom: 3px solid var(--accent-color);
    margin-bottom: 2rem;
    box-shadow: none;
}

.header-title-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.otu-badge {
    font-size: 0.75rem;
    color: #999;
    font-weight: 400;
    white-space: nowrap;
    flex-shrink: 0;
    display: block;
    margin-top: 0.15rem;
}

article header h1 {
    margin: 0 0 0.5rem 0;
    color: var(--primary-color);
    font-size: 2.5rem;
}

article header p {
    margin: 0;
    color: #666;
    font-size: 1.1rem;
}

/* ============================================================================
   Breadcrumb
   ============================================================================ */

.breadcrumb {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 0.75rem;
    font-size: 0.88rem;
    width: auto;
    justify-content: flex-start;
}

.breadcrumb a {
    color: var(--accent-color);
    font-weight: 500;
    transition: color 0.2s ease;
}

.breadcrumb a:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

.breadcrumb .sep {
    color: var(--text-muted);
    font-size: 0.85rem;
    user-select: none;
}

.breadcrumb span:not(.sep) {
    color: var(--text-dark);
    font-weight: 600;
}

/* ============================================================================
   Section Styling
   ============================================================================ */

section {
    margin: 2rem 0;
}

section h2 {
    color: var(--primary-color);
    font-size: 1.8rem;
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 0.5rem;
    margin: 2rem 0 1rem 0;
}

/* ============================================================================
   Footer
   ============================================================================ */

footer {
    background: var(--primary-color);
    color: white;
    padding: 2rem 0;
    margin-top: 3rem;
    text-align: center;
    border-top: 3px solid var(--accent-color);
}

footer small {
    font-size: 0.85rem;
    opacity: 0.9;
}

/* ============================================================================
   Tables
   ============================================================================ */

table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    background: white;
}

thead {
    background: var(--primary-color);
    color: white;
}

th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
}

td {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

tbody tr:hover {
    background: var(--light-bg);
}

/* ============================================================================
   Forms
   ============================================================================ */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="file"],
textarea,
select {
    display: block;
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.65rem 0.9rem;
    font-size: 1rem;
    font-family: inherit;
    background: white;
    color: var(--text-dark);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
textarea:focus,
select:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(93, 53, 53, 0.1);
}

label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text-dark);
}

.form-field {
    margin-bottom: 1.25rem;
}

.form-field label {
    display: block;
    margin-bottom: 0.3rem;
}

.form-field label input,
.form-field label select,
.form-field label textarea {
    margin-top: 0.3rem;
}

.form-field small {
    display: block;
    margin-top: 0.3rem;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.form-note {
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.6;
}

fieldset {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1.25rem 1.5rem;
    margin: 0;
}

legend {
    font-weight: 600;
    color: var(--primary-color);
    padding: 0 0.5rem;
    font-size: 1rem;
}

hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1.5rem 0;
}

.form-inline {
    display: inline;
    margin: 0;
    padding: 0;
}

/* ============================================================================
   Buttons
   ============================================================================ */

button, [role="button"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.65rem 1.4rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s ease;
    font-weight: 500;
    font-size: 0.95rem;
    text-decoration: none;
    line-height: 1.4;
}

button:hover, [role="button"]:hover {
    background: var(--primary-dark);
    color: white;
}

.btn-danger,
button.btn-danger,
a.btn-danger[role="button"] {
    background: var(--error-color);
}

.btn-danger:hover,
button.btn-danger:hover,
a.btn-danger[role="button"]:hover {
    background: #a93226;
}

.btn-neutral,
a.btn-neutral[role="button"] {
    background: var(--text-muted);
}

.btn-neutral:hover,
a.btn-neutral[role="button"]:hover {
    background: #5a4545;
}

.btn-disabled,
a.btn-disabled[role="button"] {
    background: var(--border-color);
    color: var(--text-muted);
    cursor: not-allowed;
    pointer-events: none;
}

.btn-warning-action {
    background: var(--accent-alt);
    color: white;
}

.btn-warning-action:hover {
    background: #8f3f00;
}

.btn-full {
    width: 100%;
    display: flex;
}

button.danger {
    background: var(--error-color);
}

button.danger:hover {
    background: #a93226;
}

/* ============================================================================
   Page Actions (Back / Logout bar)
   ============================================================================ */

.page-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.page-actions-right {
    margin-left: auto;
}

/* ============================================================================
   Login Card
   ============================================================================ */

.login-card {
    max-width: 420px;
    margin: 3rem auto;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 2rem 2.5rem;
    box-shadow: 0 4px 20px rgba(61, 32, 32, 0.1);
}

.login-card header {
    background: none;
    color: var(--text-dark);
    padding: 0 0 1.25rem 0;
    margin-bottom: 1.25rem;
    border-bottom: 2px solid var(--accent-color);
    box-shadow: none;
    text-align: center;
}

.login-card header h1 {
    font-size: 1.6rem;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.login-card header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0;
}

.login-card form div {
    margin-bottom: 1rem;
}

.login-card form button {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.75rem;
    font-size: 1rem;
}

.error-notice {
    background: rgba(192, 57, 43, 0.1);
    border-left: 4px solid var(--error-color);
    border-radius: 4px;
    padding: 0.85rem 1rem;
    margin-bottom: 1.25rem;
    color: #7b1a1a;
    font-size: 0.95rem;
}

/* ============================================================================
   Flash Messages
   ============================================================================ */

.flash-success {
    background: rgba(39, 174, 96, 0.12);
    border-left: 4px solid var(--success-color);
    border-radius: 4px;
    padding: 0.85rem 1rem;
    margin-bottom: 1.25rem;
    color: #1e5631;
}

.flash-error {
    background: rgba(192, 57, 43, 0.1);
    border-left: 4px solid var(--error-color);
    border-radius: 4px;
    padding: 0.85rem 1rem;
    margin-bottom: 1.25rem;
    color: #7b1a1a;
}

/* ============================================================================
   Maps (Leaflet)
   ============================================================================ */

.map-container {
    height: 400px;
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin: 1rem 0;
    background: var(--light-bg);
    z-index: 0;
}

/* ============================================================================
   Homepage - stats + map side-by-side layout
   ============================================================================ */

.homepage-stats-map {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.homepage-stats-col {
    flex: 1 1 0;
    min-width: 0;
}

.homepage-map-col {
    flex: 0 0 33%;
    min-width: 280px;
    position: sticky;
    top: 1rem;
}

.homepage-map {
    height: 480px !important;
}

/* Stats chips row */
.stats-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 1rem 0 2rem 0;
}

.stat-chip {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 0.3rem 0.8rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}

.stat-num {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.8rem;
    color: #666;
}

@media (max-width: 768px) {
    .homepage-stats-map {
        flex-direction: column;
    }

    .homepage-map-col {
        flex: none;
        width: 100%;
        position: static;
    }

    .homepage-map {
        height: 300px !important;
    }
}

.map-container-lg {
    height: 520px;
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin: 1rem 0;
    background: var(--light-bg);
    z-index: 0;
}

/* ============================================================================
   Content Lists (article/section - bullets back for readable content)
   ============================================================================ */

article ul:not(.plain-list),
section ul:not(.plain-list) {
    list-style: disc;
    padding-left: 1.5rem;
    margin: 0.75rem 0;
}

article ol,
section ol {
    list-style: decimal;
    padding-left: 1.5rem;
    margin: 0.75rem 0;
}

article ul:not(.plain-list) li,
section ul:not(.plain-list) li,
article ol li,
section ol li {
    padding: 0.2rem 0;
    color: var(--text-dark);
    font-size: 0.95rem;
}

.section-mt {
    margin-top: 2rem;
}

/* ============================================================================
   Alerts & Status Messages
   ============================================================================ */

.alert {
    padding: 1rem;
    border-radius: 4px;
    margin: 1rem 0;
    border-left: 4px solid;
}

.alert-success {
    background: rgba(39, 174, 96, 0.1);
    border-color: var(--success-color);
    color: #1e5631;
}

.alert-warning {
    background: rgba(243, 156, 18, 0.1);
    border-color: var(--warning-color);
    color: #7d4d00;
}

.alert-error {
    background: rgba(231, 76, 60, 0.1);
    border-color: var(--error-color);
    color: #7b1a1a;
}

/* ============================================================================
   Utility Classes
   ============================================================================ */

.text-center {
    text-align: center;
}

.text-muted {
    color: #999;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mt-2 {
    margin-top: 1rem;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* ============================================================================
   Responsive Design
   ============================================================================ */

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

    article header h1 {
        font-size: 1.8rem;
    }


    main {
        margin: 1rem auto;
    }

    section {
        margin: 1.5rem 0;
    }
}

/* ============================================================================
   Search Page
   ============================================================================ */

.search-form {
    margin: 1.5rem 0;
}

.search-input-group {
    display: flex;
    align-items: stretch;
    max-width: 700px;
    gap: 0;
}

.search-input-group input[type="search"] {
    flex: 1 1 auto;
    font-size: 1rem;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-right: none;
    border-radius: 4px 0 0 4px;
    margin: 0;
    background: white;
    color: var(--text-dark);
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

.search-input-group input[type="search"]:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(93, 53, 53, 0.1);
}

.search-input-group button[type="submit"] {
    flex: 0 0 auto;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    border-radius: 0 4px 4px 0;
    background: var(--primary-color);
    color: white;
    border: 2px solid var(--primary-color);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s ease, border-color 0.2s ease;
    font-weight: 500;
    margin: 0;
    display: inline-flex;
    align-items: center;
}

.search-input-group button[type="submit"]:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.search-hint {
    margin-top: 0.5rem;
    color: var(--text-muted);
}

.search-hint small {
    font-size: 0.85rem;
}

/* No results */

.no-results {
    padding: 2rem;
    text-align: center;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-muted);
}

.no-results p {
    margin: 0.5rem 0;
    color: var(--text-muted);
}

.no-results p:last-child {
    margin-top: 1rem;
}

/* Search intro */

.search-intro {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem 2rem;
    color: var(--text-dark);
}

.search-intro p {
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
}

/* Plain list */

.plain-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.plain-list li {
    padding: 0.3rem 0 0.3rem 1.4rem;
    position: relative;
    color: var(--text-dark);
    font-size: 0.95rem;
}

.plain-list li::before {
    content: '–';
    position: absolute;
    left: 0;
    color: var(--accent-color);
    font-weight: 600;
}


/* Card h4 */

.card h4 {
    color: var(--primary-color);
    margin: 0 0 0.75rem 0;
    font-size: 1.1rem;
    font-weight: 600;
    word-break: break-word;
}

/* ============================================================================
   Dark Mode Support (optional)
   ============================================================================ */

/*
@media (prefers-color-scheme: dark) {
    body {
        background-color: #1a1a1a;
        color: #e0e0e0;
    }

    .card {
        background: #2a2a2a;
        border-color: #444;
    }

    .card p {
        color: #bbb;
    }

    table {
        background: #2a2a2a;
    }

    tbody tr:hover {
        background: #333;
    }
}
 */

.dna-sequence {
    overflow-wrap: break-word;
}
