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

:root {
    --primary-color: #2c3e50;
    --primary-dark: #1a252f;
    --secondary-color: #3498db;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --light-bg: #ecf0f1;
    --white: #ffffff;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --border-color: #bdc3c7;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--light-bg);
    min-height: 100vh;
}

/* Accessibility - Skip Navigation Link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* Header Styles */
header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--white);
    padding: 1.5rem 0;
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

header h1 a {
    color: var(--white);
    text-decoration: none;
}

header h1 a:hover {
    opacity: 0.9;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

nav a {
    color: var(--white);
    text-decoration: none;
    transition: opacity 0.2s ease;
}

nav a:hover {
    opacity: 0.8;
    text-decoration: none;
}

nav a:visited {
    color: var(--white);
}

.user-info {
    color: var(--white);
    margin-right: 1rem;
    font-size: 0.875rem;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Content Area */
.content {
    background-color: var(--white);
    border-radius: 8px;
    padding: 2rem;
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
}

/* Typography */
h2 {
    color: var(--primary-color);
    font-size: 1.75rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

h3 {
    color: var(--primary-color);
    font-size: 1.25rem;
    margin: 1.5rem 0 1rem;
    font-weight: 600;
}

p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* Table Styles */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

thead {
    background-color: var(--light-bg);
}

thead th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background-color: #f8f9fa;
}

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

tbody td {
    padding: 14px 16px;
    color: var(--text-primary);
}

/* Empty State */
.empty-state {
    color: var(--text-secondary);
    text-align: center;
    padding: 3rem 2rem;
    font-style: italic;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px; /* WCAG AAA minimum touch target */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn:focus-visible {
    outline: 2px solid var(--primary-dark);
    outline-offset: 2px;
}

.btn-primary {
    background-color: var(--secondary-color);
    color: var(--white);
}

.btn-primary:hover {
    background-color: #2980b9;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-primary:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

.btn-success {
    background-color: var(--success-color);
    color: var(--white);
}

.btn-success:hover {
    background-color: #229954;
}

.btn-success:focus-visible {
    outline: 2px solid var(--success-color);
    outline-offset: 2px;
}

.btn-danger {
    background-color: var(--danger-color);
    color: var(--white);
}

.btn-danger:hover {
    background-color: #c0392b;
}

.btn-danger:focus-visible {
    outline: 2px solid var(--danger-color);
    outline-offset: 2px;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

input[type="text"],
input[type="email"],
input[type="date"],
input[type="url"],
textarea,
select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.25);
    border-width: 2px;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
    border-color: var(--secondary-color);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

/* Cards */
.card {
    background-color: var(--white);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.card-text {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    border-radius: 12px;
}

.badge-primary {
    background-color: var(--secondary-color);
    color: var(--white);
}

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

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

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

/* Loading States */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.loading::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% {
        content: '.';
    }
    40% {
        content: '..';
    }
    60%, 100% {
        content: '...';
    }
}

/* Spinner for loading indicators */
.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--secondary-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Button spinners */
.btn-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid white;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 0.5rem;
    vertical-align: middle;
}

.btn-spinner-dark {
    border: 2px solid var(--text-secondary);
    border-top-color: transparent;
}

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

.htmx-indicator {
    display: none;
    margin-left: 0.5rem;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-request.htmx-indicator {
    display: inline-block;
}

/* Utility Classes */
.text-center {
    text-align: center;
}

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

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }
.p-4 { padding: 2rem; }

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }

    .content {
        padding: 1.5rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    table {
        font-size: 0.875rem;
    }

    thead th,
    tbody td {
        padding: 10px 12px;
    }
}

@media (max-width: 768px) {
    /* Ensure sort buttons meet minimum touch target size on mobile */
    .sort-button {
        min-height: 44px; /* WCAG AAA minimum touch target */
        padding: 12px;
        margin: -12px; /* Expand to full cell */
    }
}

@media (max-width: 480px) {
    .content {
        padding: 1rem;
    }

    table {
        font-size: 0.75rem;
    }

    thead th,
    tbody td {
        padding: 8px;
    }

    .header-content {
        flex-direction: column;
        gap: 1rem;
    }

    nav {
        width: 100%;
        justify-content: center;
    }

    /* Maintain adequate touch targets on small screens */
    .sort-button {
        min-height: 44px;
        font-size: 0.75rem;
    }
}

/* Auth Container */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}

.auth-container .card {
    max-width: 400px;
    width: 100%;
}

/* Ensure auth buttons have comfortable touch targets */
.auth-container .btn {
    width: 100%;
    min-height: 48px; /* Extra comfortable on mobile */
}

/* Password Toggle Button */
.toggle-password-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: color 0.2s ease;
    border-radius: 4px;
}

.toggle-password-btn:hover {
    color: var(--secondary-color);
    background-color: rgba(52, 152, 219, 0.1);
}

.toggle-password-btn:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

/* Form Styles */
input[type="password"] {
    width: 100%;
    padding: 0.625rem 2.75rem 0.625rem 0.875rem; /* Extra padding on right for toggle button */
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="password"]:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.25);
    border-width: 2px;
}

input[type="password"]:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
    border-color: var(--secondary-color);
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.error-message {
    color: var(--danger-color);
    margin-bottom: 1rem;
    font-size: 0.875rem;
    min-height: 0;
}

.error-message:empty {
    display: none;
    margin-bottom: 0;
}

.success-message {
    color: var(--success-color);
    background-color: rgba(39, 174, 96, 0.1);
    border: 1px solid var(--success-color);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    line-height: 1.5;
}

.auth-links {
    text-align: center;
    margin-top: 1rem;
}

.auth-links a {
    color: var(--secondary-color);
    text-decoration: none;
}

.auth-links a:hover {
    text-decoration: underline;
}

.auth-links a:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
    border-radius: 2px;
}

.security-note {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 1rem 0;
    padding: 0.75rem;
    background-color: rgba(39, 174, 96, 0.05);
    border-radius: 4px;
    line-height: 1.4;
}

.divider {
    text-align: center;
    margin: 1.5rem 0;
    color: var(--text-secondary);
    position: relative;
}

.divider::before,
.divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background-color: var(--border-color);
}

.divider::before {
    left: 0;
}

.divider::after {
    right: 0;
}

.btn-google {
    background-color: #fff;
    color: #3c4043;
    border: 1px solid #dadce0;
    width: 100%;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
}

.btn-google:hover {
    background-color: #f8f9fa;
    box-shadow: 0 1px 2px 0 rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15);
}

.btn-google:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

/* Email Display */
.email-display {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1rem 0;
}

.email-display code {
    background-color: var(--light-bg);
    padding: 0.75rem 1rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    flex: 1;
}

.email-list {
    list-style: none;
    padding: 0;
}

.email-list li {
    padding: 0.5rem 0;
}

.email-list code {
    background-color: var(--light-bg);
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
}

/* Profile Styles */
.profile-info {
    margin: 1rem 0;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.info-row:last-child {
    border-bottom: none;
}

.info-row strong {
    color: var(--text-primary);
    font-weight: 600;
}

.info-row span {
    color: var(--text-secondary);
}

/* Statistics Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.stat-card {
    background-color: var(--light-bg);
    border-radius: 8px;
    padding: 1.5rem;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Sortable Table Headers */
.sort-button {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;
    width: 100%;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: color 0.2s ease;
    padding: 12px 16px;
    margin: -12px -16px; /* Negative margin to expand clickable area to full cell */
}

.sort-button:hover {
    color: var(--secondary-color);
}

.sort-button:focus {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
    border-radius: 4px;
}

.sort-button:focus:not(:focus-visible) {
    outline: none;
}

.sort-button:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Visual affordance for sortable columns on hover */
.sort-button:hover::after {
    content: '⇅';
    color: var(--text-secondary);
    opacity: 0.6;
    margin-left: auto;
    font-size: 0.875rem;
}

/* Hide hover indicator when column is actively sorted */
.sort-button[aria-sort="ascending"]:hover::after,
.sort-button[aria-sort="descending"]:hover::after {
    content: none;
}

/* Active sort indicator styling */
.sort-button[aria-sort="ascending"],
.sort-button[aria-sort="descending"] {
    color: var(--secondary-color);
}

.sort-indicator {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--secondary-color);
    display: inline-flex;
    align-items: center;
}

.sort-indicator svg {
    vertical-align: middle;
}

/* Ensure th cells don't add extra padding around buttons */
th.sortable {
    padding: 0;
}

/* Checkbox styles for application selection */
input[type="checkbox"].app-checkbox,
input[type="checkbox"]#select-all {
    width: auto;
    cursor: pointer;
    margin: 0;
}

#merge-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#merge-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Landing Page Styles */
.landing-page {
    max-width: 900px;
    margin: 0 auto;
}

.hero-section {
    text-align: center;
    padding: 3rem 1rem;
    background: linear-gradient(135deg, var(--white) 0%, var(--light-bg) 100%);
    border-radius: 12px;
    margin-bottom: 3rem;
    box-shadow: var(--shadow-md);
}

.hero-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 1rem;
    line-height: 1.2;
}

.hero-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.btn-large {
    padding: 1rem 2.5rem;
    font-size: 1.125rem;
    font-weight: 600;
    border-radius: 8px;
}

.features-section {
    margin-bottom: 3rem;
}

.features-section h3 {
    text-align: center;
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 2rem;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.feature-card {
    background: var(--white);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    text-align: center;
}

.feature-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-md);
}

.feature-number {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--primary-color) 100%);
    color: var(--white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 auto 1.5rem;
}

.feature-card h4 {
    font-size: 1.25rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.feature-card p {
    color: var(--text-secondary);
    line-height: 1.6;
}

.feature-card code {
    background: var(--light-bg);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
    color: var(--secondary-color);
}

.benefits-section {
    background: var(--white);
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 3rem;
}

.benefits-section h3 {
    font-size: 1.75rem;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    text-align: center;
}

.benefits-list {
    list-style: none;
    max-width: 600px;
    margin: 0 auto;
}

.benefits-list li {
    padding: 1rem;
    margin-bottom: 0.75rem;
    border-left: 4px solid var(--success-color);
    background: var(--light-bg);
    border-radius: 4px;
    color: var(--text-primary);
    line-height: 1.6;
}

.benefits-list li strong {
    color: var(--primary-color);
}

.cta-section {
    text-align: center;
    padding: 3rem 1rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--white);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
}

.cta-section h3 {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: var(--white);
}

.cta-section p {
    font-size: 1.125rem;
    margin-bottom: 2rem;
    opacity: 0.9;
}

/* Responsive adjustments for landing page */
@media (max-width: 768px) {
    .hero-title {
        font-size: 2rem;
    }

    .hero-subtitle {
        font-size: 1.125rem;
    }

    .features-grid {
        grid-template-columns: 1fr;
    }

    .btn-large {
        padding: 0.875rem 2rem;
        font-size: 1rem;
    }
}
