/* PillPaw - Main Styles */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height for iOS */
    overflow: hidden;
    color: #333;
    margin: 0;
    padding: 0;
    touch-action: manipulation;
    /* Prevent double-tap zoom */
    -webkit-user-select: none;
    /* Prevent text selection */
    user-select: none;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height for iOS */
    overflow: hidden;
}

/* Header */
.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    height: 60px;
    position: relative;
    z-index: 10;
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
    color: #2196F3;
    margin: 0;
    cursor: pointer;
    user-select: none;
}

.result-label {
    background: #4CAF50;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 15px;
    font-weight: 600;
    font-size: 1rem;
}

/* Canvas Area - 3/4 aspect ratio */
.canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    overflow: hidden;
    min-height: 0;
}

.camera-view,
.result-view {
    width: 100%;
    height: 100%;
    max-width: calc((100vh - 200px) * 0.75);
    /* Conservative for iOS */
    max-width: calc((100dvh - 160px) * 0.75);
    /* Dynamic viewport for iOS */
    max-height: 100%;
    aspect-ratio: 3/4;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    position: relative;
}

#cameraFeed {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#resultImage {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    border-radius: 20px;
    z-index: 10;
}

.loading-overlay .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

.loading-overlay p {
    font-size: 1rem;
    margin: 0;
    opacity: 0.9;
}

/* Error Overlay */
.error-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(180, 90, 0, 0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    border-radius: 20px;
    z-index: 15;
    text-align: center;
    padding: 2rem;
    box-sizing: border-box;
    -webkit-user-select: text;
    /* Allow text selection on iOS */
    user-select: text;
    /* Allow text selection */
}

.error-overlay .error-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.error-overlay h3 {
    margin-bottom: 1rem;
    font-size: 1.3rem;
    color: white;
    -webkit-user-select: text;
    /* Allow text selection on iOS */
    user-select: text;
    /* Allow text selection */
}

.error-overlay p {
    margin-bottom: 1.5rem;
    opacity: 0.9;
    color: white;
    font-size: 1rem;
    -webkit-user-select: text;
    /* Allow text selection on iOS */
    user-select: text;
    /* Allow text selection */
}

.error-overlay .btn {
    flex: none;
    align-self: center;
    min-width: 120px;
    max-width: 200px;
}

/* Camera Instructions Overlay */
.camera-instructions {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg,
        rgba(56, 239, 125, 0.92) 0%,     /* Fresh green */
        rgba(17, 153, 142, 0.94) 25%,    /* Teal */
        rgba(7, 89, 133, 0.95) 50%,      /* Deep blue */
        rgba(81, 40, 136, 0.94) 75%,     /* Purple */
        rgba(126, 58, 242, 0.92) 100%    /* Bright purple */
    );
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    color: white;
    border-radius: 12px;
    z-index: 15;
    text-align: center;
    padding: 2rem 1.5rem 1rem 1.5rem;
    box-sizing: border-box;
    animation: fadeIn 0.3s ease-out;
}

.camera-instructions .camera-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.9;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.1); opacity: 1; }
}

.camera-instructions h3 {
    margin-bottom: 0.5rem;
    font-size: 1.4rem;
    font-weight: 600;
    color: white;
}

.camera-instructions > p {
    margin-bottom: 1.5rem;
    opacity: 0.9;
    font-size: 1rem;
}

.instruction-steps {
    margin-bottom: 1.5rem;
}

.instruction-steps .step {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-bottom: 0.8rem;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    backdrop-filter: blur(5px);
}

.instruction-steps .step-icon {
    font-size: 1.2rem;
    margin-right: 0.8rem;
    min-width: 24px;
}

.instruction-steps span:last-child {
    font-size: 0.9rem;
    opacity: 0.95;
}

.instruction-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.start-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    opacity: 0.8;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.start-hint .arrow-icon {
    font-size: 1.5rem;
    animation: bounceDown 2s ease-in-out infinite;
}

@keyframes bounceDown {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(8px); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* Button Bar */
.button-bar {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 0.5rem;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom)); /* iOS safe area */
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    min-height: 70px;
    position: relative;
    z-index: 10;
}

.camera-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    width: 90%;
    max-width: 400px;
}

.result-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    width: 90%;
    max-width: 400px;
}

.pill-count-display {
    background: #4CAF50;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 15px;
    font-weight: 600;
    font-size: 1rem;
}

/* Camera Section */
.camera-section {
    width: 90%;
    max-width: 400px;
    height: 80vh;
    background: white;
    border-radius: 20px;
    padding: 1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.camera-container {
    position: relative;
    width: 100%;
    aspect-ratio: 3/4;
    background: #f0f0f0;
    border-radius: 15px;
    overflow: hidden;
    margin-bottom: 1rem;
    max-height: 60vh;
}

#cameraFeed {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.camera-controls {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
    flex-shrink: 0;
    margin-top: auto;
    padding-top: 0.5rem;
}

/* Buttons */
.btn {
    padding: 0.7rem 1rem;
    border: none;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    flex: 1;
    touch-action: manipulation;
    /* Prevent double-tap zoom on buttons */
    -webkit-tap-highlight-color: transparent;
    /* Remove tap highlight */
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn:disabled:hover {
    transform: none;
    box-shadow: none;
}

.btn-primary {
    background: #2196F3;
    color: white;
}

.btn-success {
    background: #4CAF50;
    color: white;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-outline {
    background: transparent;
    color: #2196F3;
    border: 2px solid #2196F3;
}

.btn-icon {
    padding: 0.7rem;
    border: none;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(33, 150, 243, 0.1);
    color: #2196F3;
    border: 2px solid #2196F3;
    touch-action: manipulation;
    /* Prevent double-tap zoom on buttons */
    -webkit-tap-highlight-color: transparent;
    /* Remove tap highlight */
}

/* Results Section */
.results-section {
    width: 90%;
    max-width: 400px;
    height: 80vh;
    background: white;
    border-radius: 20px;
    padding: 1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.results-header h2 {
    color: #333;
    font-size: 1.3rem;
}

.pill-count {
    text-align: center;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.count-display {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    padding: 1rem;
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.count-number {
    font-size: 2.5rem;
    font-weight: bold;
    line-height: 1;
}

.count-label {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-top: 0.3rem;
}

.result-image-container {
    margin-bottom: 0.5rem;
    border-radius: 15px;
    overflow: hidden;
    position: relative;
    aspect-ratio: 3/4;
    /* Match camera aspect ratio */
    flex: 1;
    width: 100%;
    /* Ensure it matches camera container width */
    min-height: 0;
}

#resultImage {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

#resultOverlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.processing-time {
    text-align: center;
    color: #666;
    font-size: 0.8rem;
    flex-shrink: 0;
    margin-top: auto;
}

/* Loading Section */
.loading-section {
    text-align: center;
    color: white;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading-section p {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

.loading-detail {
    opacity: 0.8;
    font-size: 1rem !important;
}

/* Error Section */
.error-section {
    text-align: center;
    color: white;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.1);
    padding: 2rem;
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

.error-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.error-section h3 {
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.error-section p {
    margin-bottom: 1.5rem;
    opacity: 0.9;
}

/* Footer */
.footer {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    text-align: center;
    padding: 1rem;
    font-size: 0.9rem;
    opacity: 0.8;
}

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

.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* Debug Panel Styles - Quake-style overlay */
.debug-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50vh;
    /* Half screen height */
    background: rgba(0, 0, 0, 0.9);
    color: white;
    z-index: 9999;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(5px);
    transform: translateY(-100%);
    transition: transform 0.3s ease-out, box-shadow 0.3s ease-out;
}

.debug-panel.visible {
    transform: translateY(0);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.debug-header {
    background: rgba(255, 255, 255, 0.1);
    padding: 12px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
    font-weight: bold;
}

.debug-buttons {
    display: flex;
    gap: 10px;
}

.debug-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    min-height: 44px;
    /* iOS touch target */
    min-width: 44px;
    transition: background 0.2s ease;
}

.debug-btn:hover,
.debug-btn:active {
    background: rgba(255, 255, 255, 0.3);
}

.debug-content {
    flex: 1;
    padding: 8px 12px;
    overflow-y: auto;
    overflow-x: hidden;
    word-break: break-word;
    -webkit-overflow-scrolling: touch;
    /* Smooth iOS scrolling */
    line-height: 1.2;
    -webkit-user-select: text;
    /* Allow text selection on iOS */
    user-select: text;
    /* Allow text selection */
}

.debug-entry {
    margin-bottom: 2px;
    padding: 2px 0;
    border-left: 3px solid transparent;
    padding-left: 6px;
    -webkit-user-select: text;
    /* Allow text selection on iOS */
    user-select: text;
    /* Allow text selection */
}

.debug-timestamp {
    color: #999;
    margin-right: 8px;
    font-size: 10px;
}

.debug-error {
    color: #ff6b6b;
    border-left-color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
}

.debug-warn {
    color: #ffd93d;
    border-left-color: #ffd93d;
    background: rgba(255, 217, 61, 0.1);
}

.debug-info {
    color: #74c0fc;
    border-left-color: #74c0fc;
}

.debug-log {
    color: #e0e0e0;
}