/* Hand Analyzer - Clean Minimal Design */

/* CSS Variables for consistent theming */
:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-elevated: #222222;
    --text-primary: #ffffff;
    --text-secondary: #a1a1a1;
    --text-muted: #666666;
    --border-color: #2a2a2a;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --warning: #eab308;
    --error: #ef4444;
    --controls-height: 72px;
    --header-height: 48px;
    --tabs-height: 44px;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

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

/* Main Layout */
.container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 1600px;
    margin: 0 auto;
}

/* Header */
header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

header h1 {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

/* Main Content Area */
.main-content {
    display: flex;
    flex: 1;
    min-height: 0;
    padding: 12px;
    gap: 12px;
    padding-bottom: calc(var(--controls-height) + 12px);
}

/* Panel Base Styles */
.panel {
    background-color: var(--bg-secondary);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    padding: 12px 16px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* Live & Analyzed Panels */
.live-panel {
    flex: 1;
    min-width: 0;
}

.analyzed-panel {
    flex: 0.8;
    min-width: 0;
}

.results-panel {
    width: 320px;
    flex-shrink: 0;
}

/* Video Container */
.video-container {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-primary);
    overflow: hidden;
}

video {
    display: none;
}

canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Zone Message Overlay */
.zone-message {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.85);
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    backdrop-filter: blur(8px);
    white-space: nowrap;
}

/* Placeholder */
.placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* Fixed Bottom Controls Bar */
.controls-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--controls-height);
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 0 16px;
    z-index: 100;
}

/* Buttons */
.control-btn {
    height: 44px;
    padding: 0 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.control-btn:active {
    transform: scale(0.98);
}

/* Keyboard hints */
.key-hint {
    font-size: 11px;
    font-weight: 600;
    opacity: 0.6;
    font-family: monospace;
}

/* Capture/Analyze Button - Primary */
.capture-btn {
    background-color: var(--primary);
    color: white;
    min-width: 140px;
}

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

.capture-btn:disabled,
.capture-btn.disabled {
    background-color: var(--bg-elevated);
    color: var(--text-muted);
    cursor: not-allowed;
}

.capture-btn.loading {
    pointer-events: none;
}

.capture-btn.loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
}

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

/* Flip Button - Secondary */
.flip-btn {
    background-color: var(--bg-elevated);
    color: var(--text-primary);
}

.flip-btn:hover {
    background-color: #2d2d2d;
}

/* Reset Button - Tertiary */
.reset-btn {
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.reset-btn:hover {
    background-color: var(--bg-elevated);
    color: var(--text-primary);
}

/* Orientation Button */
.orientation-btn {
    background-color: var(--bg-elevated);
    color: var(--text-secondary);
    min-width: 80px;
}

.orientation-btn:hover {
    background-color: #2d2d2d;
    color: var(--text-primary);
}

.orientation-btn.orientation-locked {
    background-color: rgba(59, 130, 246, 0.2);
    color: var(--primary);
    border: 1px solid var(--primary);
}

/* Connection Status */
.status {
    position: absolute;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-muted);
}

.status[style*="color: rgb(0, 255, 0)"]::before,
.status[style*="color: #00ff00"]::before,
.status[style*="#22c55e"]::before {
    background-color: var(--success);
}

.status[style*="color: rgb(255, 68, 68)"]::before,
.status[style*="color: #ff4444"]::before {
    background-color: var(--error);
}

/* Results Panel */
.results-content {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
    font-size: 14px;
}

.results-content .waiting {
    color: var(--text-muted);
    text-align: center;
    padding-top: 40px;
}

/* Result Summary - Main User-Facing Results */
.result-summary {
    margin-bottom: 20px;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

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

.result-label {
    color: var(--text-secondary);
    font-size: 13px;
}

.result-value-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.result-value {
    color: var(--text-primary);
    font-weight: 500;
    font-size: 14px;
}

.result-value.finger-type.diamond {
    color: var(--warning);
}

.result-value.finger-type.a-type {
    color: #a855f7;
}

.skin-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
}

/* Recommendations Section */
.recommendations {
    background-color: var(--bg-primary);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.rec-header {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.rec-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 8px 0;
}

.rec-label {
    color: var(--text-muted);
    font-size: 12px;
    min-width: 60px;
}

.rec-value {
    color: var(--text-primary);
    font-size: 13px;
    text-align: right;
    flex: 1;
    padding-left: 12px;
}

/* Details Toggle Button */
.details-toggle {
    width: 100%;
    padding: 10px 16px;
    background-color: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-bottom: 12px;
}

.details-toggle:hover {
    background-color: var(--bg-elevated);
    color: var(--text-primary);
}

/* Technical Details - Hidden by Default */
.technical-details {
    background-color: var(--bg-primary);
    border-radius: 6px;
    padding: 12px;
    border-left: 2px solid var(--text-muted);
}

.tech-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 12px;
}

.tech-label {
    color: var(--text-muted);
}

.tech-value {
    color: var(--text-secondary);
    font-family: monospace;
}

/* Finger Breakdown Table */
.finger-breakdown-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.breakdown-header {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 10px;
}

.finger-table-full {
    background-color: var(--bg-secondary);
    border-radius: 6px;
    padding: 8px;
    font-family: monospace;
    font-size: 11px;
}

.table-header-row,
.table-data-row {
    display: grid;
    grid-template-columns: 55px repeat(4, 1fr) 55px;
    gap: 4px;
    padding: 6px 4px;
    align-items: center;
}

.table-header-row {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
    margin-bottom: 4px;
}

.table-data-row {
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

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

.col-finger {
    color: var(--text-secondary);
    font-weight: 500;
}

.col-width {
    text-align: center;
    color: var(--text-secondary);
}

.col-width.tip { color: #a855f7; }
.col-width.pip { color: #06b6d4; }
.col-width.dip { color: var(--warning); }
.col-width.mcp { color: var(--success); }

.col-type {
    text-align: right;
    font-weight: 600;
}

.col-type.diamond { color: var(--warning); }
.col-type.a-type { color: #a855f7; }

/* ==================== */
/* RESPONSIVE - DESKTOP */
/* ==================== */
@media (min-width: 1025px) {
    .main-content {
        padding: 16px;
        gap: 16px;
    }

    .controls-bar {
        padding: 0 24px;
    }

    .control-btn {
        height: 48px;
        padding: 0 24px;
    }
}

/* Mobile Tabs - Hidden by default */
.mobile-tabs {
    display: none;
}

/* ==================== */
/* RESPONSIVE - TABLET (iPad) */
/* ==================== */
@media (min-width: 768px) and (max-width: 1024px) {
    /* Hide header on iPad for full screen camera */
    header {
        display: none;
    }

    .main-content {
        flex-direction: column;
        padding: 0;
        gap: 0;
        padding-bottom: var(--controls-height);
    }

    /* iPad: True full screen live camera */
    .live-panel {
        flex: 1;
        min-height: 0;
        border-radius: 0;
        background-color: #000;
    }

    .live-panel .panel-header {
        display: none;
    }

    .live-panel .video-container {
        border-radius: 0;
    }

    .analyzed-panel {
        display: none;
    }

    .results-panel {
        display: none;
    }

    /* Show tabs when analysis is done */
    .mobile-tabs.visible {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 48px;
        background-color: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color);
        z-index: 60;
        padding: 0;
    }

    .mobile-tabs .tab-btn {
        flex: 1;
        height: 100%;
        background: none;
        border: none;
        color: var(--text-muted);
        font-size: 14px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.15s ease;
        border-bottom: 2px solid transparent;
    }

    .mobile-tabs .tab-btn.active {
        color: var(--text-primary);
        border-bottom-color: var(--primary);
    }

    /* Show analyzed/results as overlays when analysis is done */
    .analyzed-panel.has-analysis {
        display: flex;
        position: fixed;
        top: 48px;
        left: 0;
        right: 0;
        bottom: var(--controls-height);
        margin: 0;
        border-radius: 0;
        z-index: 50;
    }

    .analyzed-panel.has-analysis .panel-header {
        display: none;
    }

    .results-panel.has-analysis {
        display: none;
        position: fixed;
        top: 48px;
        left: 0;
        right: 0;
        bottom: var(--controls-height);
        margin: 0;
        border-radius: 0;
        z-index: 50;
        width: 100%;
    }

    .results-panel.has-analysis .panel-header {
        display: none;
    }

    /* Tab switching */
    .results-panel.has-analysis.active-tab {
        display: flex;
    }

    .analyzed-panel.has-analysis.active-tab {
        display: flex;
    }

    .analyzed-panel.has-analysis:not(.active-tab) {
        display: none;
    }

    .controls-bar {
        gap: 16px;
    }

    .control-btn {
        height: 48px;
        padding: 0 24px;
        font-size: 15px;
    }
}

/* iPad Landscape */
@media (min-width: 1024px) and (max-width: 1366px) and (orientation: landscape) {
    .main-content {
        flex-direction: row;
    }

    .live-panel {
        flex: 1.2;
    }

    .analyzed-panel {
        flex: 1;
    }

    .results-panel {
        width: 300px;
    }
}

/* ==================== */
/* RESPONSIVE - MOBILE */
/* ==================== */
@media (max-width: 767px) {
    :root {
        --controls-height: 80px;
        --header-height: 44px;
        --tabs-height: 44px;
    }

    header {
        display: none;
    }

    .main-content {
        flex-direction: column;
        padding: 0;
        gap: 0;
        padding-bottom: var(--controls-height);
    }

    .panel-header {
        display: none;
    }

    /* Mobile: Full screen live panel */
    .live-panel {
        flex: 1;
        min-height: 0;
        border-radius: 0;
        background-color: #000;
    }

    .analyzed-panel,
    .results-panel {
        display: none;
    }

    /* Show tabs when analysis is done */
    .mobile-tabs.visible {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: var(--tabs-height);
        background-color: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color);
        z-index: 60;
        padding: 0;
    }

    .mobile-tabs .tab-btn {
        flex: 1;
        height: 100%;
        background: none;
        border: none;
        color: var(--text-muted);
        font-size: 13px;
        font-weight: 500;
        cursor: pointer;
        border-bottom: 2px solid transparent;
    }

    .mobile-tabs .tab-btn.active {
        color: var(--text-primary);
        border-bottom-color: var(--primary);
    }

    .analyzed-panel.has-analysis {
        display: flex;
        position: fixed;
        top: var(--tabs-height);
        left: 0;
        right: 0;
        bottom: var(--controls-height);
        margin: 0;
        border-radius: 0;
        z-index: 50;
    }

    .results-panel.has-analysis {
        display: none;
        position: fixed;
        top: var(--tabs-height);
        left: 0;
        right: 0;
        bottom: var(--controls-height);
        margin: 0;
        border-radius: 0;
        z-index: 50;
        width: 100%;
    }

    /* Tab switching */
    .results-panel.has-analysis.active-tab {
        display: flex;
    }

    .analyzed-panel.has-analysis.active-tab {
        display: flex;
    }

    .analyzed-panel.has-analysis:not(.active-tab) {
        display: none;
    }

    .zone-message {
        font-size: 12px;
        padding: 8px 16px;
        bottom: 12px;
    }

    /* Mobile Controls */
    .controls-bar {
        padding: 0 12px;
        gap: 8px;
        justify-content: space-between;
    }

    .control-btn {
        height: 48px;
        padding: 0 16px;
        font-size: 13px;
        flex: 1;
        max-width: 120px;
    }

    .capture-btn {
        flex: 1.5;
        max-width: 160px;
    }

    .key-hint {
        display: none;
    }

    .status {
        position: static;
        flex: none;
        font-size: 11px;
    }

    .status::before {
        width: 6px;
        height: 6px;
    }
}

/* Small phones */
@media (max-width: 375px) {
    .control-btn {
        padding: 0 12px;
        font-size: 12px;
    }

    .capture-btn {
        max-width: 140px;
    }
}

/* Landscape Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --controls-height: 60px;
        --header-height: 36px;
    }

    header h1 {
        font-size: 13px;
    }

    .main-content {
        flex-direction: row;
        padding: 8px;
    }

    .live-panel {
        flex: 1;
    }

    .results-panel {
        width: 280px;
    }

    .results-panel:not(.has-analysis) {
        display: none;
    }

    .control-btn {
        height: 40px;
        font-size: 12px;
    }
}

/* Safe area for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .controls-bar {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(var(--controls-height) + env(safe-area-inset-bottom));
    }

    .main-content {
        padding-bottom: calc(var(--controls-height) + env(safe-area-inset-bottom) + 12px);
    }
}

/* Focus states for accessibility */
.control-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
