/* Dark theme (default) */
:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-hover: #222632;
    --border: #2a2e3a;
    --text: #e4e6eb;
    --text-muted: #8b8fa3;
    --accent: #6c8cff;
    --accent-hover: #5a7aee;
    --success: #4ade80;
    --error: #f87171;
    --radius: 8px;
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --mono: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
    color-scheme: dark;
}

/* Light theme */
[data-theme="light"] {
    --bg: #f8f9fb;
    --surface: #ffffff;
    --surface-hover: #f0f1f4;
    --border: #d8dbe3;
    --text: #1a1d27;
    --text-muted: #6b7084;
    --accent: #4a6cf7;
    --accent-hover: #3a5ce6;
    --success: #16a34a;
    --error: #dc2626;
    color-scheme: light;
}

/* Auto-detect system preference */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg: #f8f9fb;
        --surface: #ffffff;
        --surface-hover: #f0f1f4;
        --border: #d8dbe3;
        --text: #1a1d27;
        --text-muted: #6b7084;
        --accent: #4a6cf7;
        --accent-hover: #3a5ce6;
        --success: #16a34a;
        --error: #dc2626;
        color-scheme: light;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    transition: background 0.2s, color 0.2s;
}

.app {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

header {
    text-align: center;
    margin-bottom: 2rem;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.header-main {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.25rem;
}

.logo {
    width: 48px;
    height: 48px;
    border-radius: 12px;
}

.header-badges {
    display: flex;
    gap: 0.5rem;
}

.badge {
    padding: 0.2rem 0.6rem;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    border-radius: 4px;
    letter-spacing: 0.05em;
}

.badge-offline {
    background: var(--error);
    color: white;
}

.btn-install {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.2rem 0.6rem;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 4px;
    cursor: pointer;
    text-transform: uppercase;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Theme toggle */
.theme-toggle {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: background 0.15s, border-color 0.15s;
    padding: 0;
    z-index: 10;
}

.theme-toggle:hover {
    border-color: var(--accent);
}

/* Tabs */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
}

.tab {
    padding: 0.6rem 1.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* Controls */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: end;
    margin-bottom: 1.5rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.field label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

select, input[type="number"], input[type="text"] {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s, background 0.2s;
}

select:focus, input:focus {
    border-color: var(--accent);
}

select {
    cursor: pointer;
    min-width: 180px;
}

input[type="number"] {
    width: 80px;
}

input[type="text"] {
    width: 80px;
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-bottom: 0.5rem;
}

.checkbox-field input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.checkbox-field label {
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
}

/* Buttons */
.btn {
    padding: 0.5rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface-hover);
}

.btn-copy {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-copy:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-copy.copied {
    border-color: var(--success);
    color: var(--success);
}

/* Results table */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.results-header span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    font-family: var(--mono);
    font-size: 0.82rem;
}

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

tbody tr:last-child td {
    border-bottom: none;
}

td.valid-yes {
    color: var(--success);
}

td.valid-no {
    color: var(--error);
}

td.gender {
    font-family: var(--font);
}

td.dob {
    font-family: var(--font);
    font-size: 0.82rem;
}

/* Action column */
td:last-child, th:last-child {
    text-align: right;
    width: 80px;
}

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

/* Footer */
footer {
    margin-top: 3rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
}

footer a {
    color: var(--accent);
    text-decoration: none;
}

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

.share-links {
    margin-top: 0.75rem;
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    align-items: center;
}

.share-links span {
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.share-links a {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    transition: all 0.15s;
}

.share-links a:hover {
    border-color: var(--accent);
    background: var(--surface-hover);
    text-decoration: none !important;
}

/* Validator Styles */
.validator-result {
    margin-top: 2rem;
    display: flex;
    justify-content: center;
}

.result-box {
    padding: 1.5rem;
    border-radius: 8px;
    text-align: center;
    max-width: 400px;
    width: 100%;
    border: 2px solid transparent;
}

.result-valid {
    background-color: rgba(34, 197, 94, 0.1);
    border-color: #22c55e;
    color: #16a34a;
}

.result-invalid {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
    color: #dc2626;
}

.result-box strong {
    font-size: 1.25rem;
    display: block;
    margin-bottom: 0.5rem;
}

.result-box p {
    margin: 0;
    font-size: 1rem;
    opacity: 0.9;
}

[data-theme="dark"] .result-valid {
    background-color: rgba(34, 197, 94, 0.2);
}

[data-theme="dark"] .result-invalid {
    background-color: rgba(239, 68, 68, 0.2);
}

/* Searchable Dropdown */
.searchable-select {
    position: relative;
    min-width: 220px;
}

.search-input {
    width: 100% !important;
}

.dropdown-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 4px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.dropdown-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

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

.dropdown-item:hover {
    background: var(--surface-hover);
}

.dropdown-item.selected {
    background: var(--accent);
    color: white;
}

/* Responsive */
@media (max-width: 640px) {
    .app {
        padding: 1rem 0.75rem;
    }

    header {
        padding-top: 2.5rem;
        margin-bottom: 1.5rem;
    }

    .theme-toggle {
        top: -0.5rem;
        right: 0;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .header-main {
        gap: 0.75rem;
    }

    .logo {
        width: 40px;
        height: 40px;
    }

    /* Stack controls on mobile */
    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .field {
        width: 100%;
    }

    .searchable-select {
        min-width: 100%;
    }

    select, input[type="number"], input[type="text"], .search-input {
        width: 100% !important;
        min-width: 100%;
    }

    .checkbox-field {
        padding-bottom: 0;
    }

    .btn {
        width: 100%;
        padding: 0.75rem;
    }

    /* Scrollable tabs */
    .tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -0.75rem 1.5rem -0.75rem;
        padding: 0 0.75rem;
        scrollbar-width: none; /* Hide scrollbar Firefox */
    }

    .tabs::-webkit-scrollbar {
        display: none; /* Hide scrollbar Chrome/Safari */
    }

    .tab {
        flex: 0 0 auto;
        padding: 0.75rem 1rem;
    }

    /* Table responsiveness */
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }

    thead, tbody, tr {
        display: table;
        width: 100%;
        min-width: 600px; /* Ensure table doesn't squash too much */
    }

    /* Result box on mobile */
    .result-box {
        max-width: 100%;
    }

    .results-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* Tooltip Styles */
.tooltip-container {
    display: inline-flex;
    position: relative;
    margin-left: 4px;
    vertical-align: middle;
}

.tooltip-icon {
    width: 14px;
    height: 14px;
    background: var(--border);
    color: var(--text-muted);
    border-radius: 50%;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: help;
    font-weight: bold;
}

.tooltip-content {
    visibility: hidden;
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    color: var(--text);
    text-transform: none;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    width: 200px;
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.4;
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 1000;
}

.tooltip-container:hover .tooltip-content {
    visibility: visible;
}

@media (max-width: 640px) {
    .tooltip-content {
        width: 160px;
        left: auto;
        right: -20px;
        transform: none;
    }
}

/* History Styles */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.history-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
}

.history-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.75rem;
}

.history-category {
    font-weight: 700;
    color: var(--accent);
}

.history-country {
    background: var(--border);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

.history-date {
    color: var(--text-muted);
    margin-left: auto;
}

.history-results {
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
