/* Xabi - Language Detector Styles */

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-active: #4338ca;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --success: #22c55e;
    --error: #ef4444;
    --border-radius: 16px;
    --transition: 0.2s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 32px;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Main content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    min-height: 0;
}

/* Detection area - centered vertically in available space. */
.detect-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    width: 100%;
    min-height: 0;
}

/* Detect button */
.detect-button {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 8px 32px rgba(99, 102, 241, 0.3);
}

.detect-button:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 40px rgba(99, 102, 241, 0.4);
}

.detect-button:active {
    transform: scale(0.95);
}

.detect-button.recording {
    animation: pulse 1.5s ease-in-out infinite;
    background: linear-gradient(135deg, var(--error), #f97316);
}

.detect-button.recording .mic-icon {
    display: none;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }
    50% {
        box-shadow: 0 0 0 20px rgba(239, 68, 68, 0);
    }
}

.mic-icon {
    width: 72px;
    height: 72px;
    transition: visibility 0s;
}

.mic-icon svg {
    width: 100%;
    height: 100%;
}

.status-text {
    font-size: 1.125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

.status-text:empty {
    display: none;
}

/* Result display */
.result {
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: 24px;
    width: 100%;
    text-align: center;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.language-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
}

.confidence-bar {
    height: 8px;
    background: var(--surface-hover);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.confidence-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.confidence-fill.confidence-low {
    background: linear-gradient(90deg, var(--error), #f97316);
}

.confidence-fill.confidence-medium {
    background: linear-gradient(90deg, #eab308, #facc15);
}

.confidence-fill.confidence-high {
    background: linear-gradient(90deg, var(--success), #a3e635);
}

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

.flag {
    font-size: 2.5rem;
}

.language-name {
    font-size: 1.5rem;
    font-weight: 600;
}

.language-name a,
.history-item .name a {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

/* Error display */
.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    border-radius: var(--border-radius);
    padding: 16px;
    width: 100%;
    text-align: center;
    color: var(--error);
}

/* History section */
.history {
    width: 100%;
    margin-top: auto;
}

.history h2 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

#history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    background: var(--surface);
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.history-item .flag {
    font-size: 1.5rem;
}

.history-item .name {
    flex: 1;
    min-width: 0;
    font-weight: 500;
    overflow: hidden;
}

.history-item .name-long {
    font-size: 0.75rem;
}

.history-confidence-bar {
    width: 60px;
    height: 6px;
    background: var(--surface-hover);
    border-radius: 3px;
    overflow: hidden;
    flex-shrink: 0;
}

.history-confidence-fill {
    height: 100%;
    border-radius: 3px;
}

.history-confidence-fill.confidence-low {
    background: linear-gradient(90deg, var(--error), #f97316);
}

.history-confidence-fill.confidence-medium {
    background: linear-gradient(90deg, #eab308, #facc15);
}

.history-confidence-fill.confidence-high {
    background: linear-gradient(90deg, var(--success), #a3e635);
}

.history-item .time {
    font-size: 0.75rem;
    white-space: nowrap;
    color: var(--text-secondary);
    min-width: 115px;
    text-align: right;
}

/* Footer */
footer {
    text-align: center;
    padding-top: 24px;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

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

/* Result header with report button */
.result-header {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 16px;
}

.result-header .language-info {
    margin-bottom: 0;
}

.report-btn {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--error);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background var(--transition);
    line-height: 1;
}

.report-btn:hover {
    background: rgba(239, 68, 68, 0.15);
}

/* Report modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 24px;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: 24px;
    width: 100%;
    max-width: 360px;
    animation: fadeIn 0.2s ease;
}

.modal-content h2 {
    font-size: 1.125rem;
    margin-bottom: 16px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--surface-hover);
    background: var(--background);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.form-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.form-group select option {
    background: var(--background);
    color: var(--text-primary);
}

.disclaimer {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.disclaimer a {
    color: var(--primary-color);
}

.consent-group {
    margin-bottom: 8px;
}

.consent-group .consent-label {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 8px;
    align-items: start;
    width: 100%;
    margin-bottom: 0;
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--text-secondary);
    cursor: pointer;
}

.consent-label input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
    width: 18px;
    height: 18px;
    padding: 0;
    margin: 2px 0 0 0;
    border: 2px solid var(--text-secondary);
    border-radius: 3px;
    background: transparent;
    cursor: pointer;
    flex-shrink: 0;
    display: inline-block;
    position: relative;
}

.consent-label input[type="checkbox"]:checked {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.consent-label input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    left: 4px;
    top: 0;
    width: 4px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.consent-label a {
    color: var(--primary-color);
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn {
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}

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

.btn-secondary:hover:not(:disabled) {
    background: #475569;
}

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

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.report-progress {
    margin-bottom: 12px;
}

.progress-bar {
    height: 6px;
    background: var(--surface-hover);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 4px;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    border-radius: 3px;
    transition: width 0.2s ease;
    width: 0%;
}

.progress-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.report-warning {
    margin: 0 0 12px;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--error);
    font-size: 0.85rem;
    line-height: 1.4;
}

.report-status {
    margin-top: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    text-align: center;
}

.report-status.success {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.report-status.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

/* Audio preview player */
.audio-preview {
    margin-bottom: 12px;
}

.audio-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.audio-preview-header label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.audio-player {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--background);
    border-radius: 8px;
    padding: 8px 12px;
}

.audio-play-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition);
    line-height: 1;
    padding-left: 2px;
}

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

.audio-seek {
    flex: 1;
    height: 6px;
    background: var(--surface-hover);
    border-radius: 3px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
}

.audio-seek-fill {
    height: 100%;
    width: 0%;
    background: var(--primary-color);
    border-radius: 3px;
    transition: width 0.1s linear;
}

.audio-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    min-width: 28px;
    text-align: right;
}

/* Loading state — the button surface fades out and a rotating ring takes over. */
.detect-button.loading {
    pointer-events: none;
    position: relative;
    background: transparent;
    box-shadow: none;
}

.detect-button.loading .mic-icon {
    display: none;
}

.detect-button.loading::before {
    content: "";
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    padding: 10px;
    background: conic-gradient(
        from 0deg,
        transparent 0deg,
        var(--primary-color) 120deg,
        #8b5cf6 240deg,
        transparent 360deg
    );
    -webkit-mask:
        linear-gradient(#000 0 0) content-box,
        linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    animation: spinner-ring-rotate 1.2s linear infinite;
    pointer-events: none;
}

@keyframes spinner-ring-rotate {
    to {
        transform: rotate(360deg);
    }
}

/* Footer links shown alongside the powered-by text. */
.footer-links {
    margin-top: 4px;
}
.footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
}
.footer-links a:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

/* My Reports page */
.report-status-inline {
    margin-top: 6px;
    font-size: 0.875rem;
    color: var(--error);
    min-height: 0;
}
.report-status-inline:empty {
    display: none;
}
