/* ==========================================================================
   Rubik Bendera AI - Master Stylesheet
   Theme: Warm Natural & Elegant Modern Card UI (Warm Earth, Amber, Sand & Forest)
   ========================================================================== */

:root {
    /* Color Palette: Warm Earth, Amber, Clay, Cream & Forest */
    --bg-primary: #12100e;
    --bg-secondary: #1a1614;
    --bg-surface: #241e1b;
    --bg-surface-elevated: #2f2723;
    --bg-card: rgba(36, 30, 27, 0.75);
    --bg-glass: rgba(47, 39, 35, 0.65);
    
    --border-subtle: rgba(230, 210, 190, 0.08);
    --border-strong: rgba(230, 210, 190, 0.16);
    --border-accent: rgba(224, 138, 78, 0.35);

    --text-primary: #fdfaf6;
    --text-secondary: #d6cbbe;
    --text-muted: #9c8e82;
    --text-inverse: #161311;

    --accent-amber: #e08a4e;
    --accent-amber-glow: rgba(224, 138, 78, 0.25);
    --accent-gold: #e9c46a;
    --accent-terracotta: #c85a32;
    --accent-forest: #2a9d8f;
    --accent-emerald: #38b000;
    --accent-danger: #e63946;

    /* Typography */
    --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px rgba(224, 138, 78, 0.2);

    /* Transitions */
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;
}

/* Base Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
}

/* Background Ambient Lighting */
.background-decorations {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.blur-circle {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.28;
}

.circle-1 {
    width: 450px;
    height: 450px;
    background: radial-gradient(circle, var(--accent-amber), transparent);
    top: -100px;
    left: -100px;
}

.circle-2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, var(--accent-forest), transparent);
    bottom: -100px;
    right: -100px;
    opacity: 0.2;
}

.circle-3 {
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, var(--accent-terracotta), transparent);
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.15;
}

/* Layout Utilities */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    position: relative;
    z-index: 1;
}

/* Header */
.app-header {
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(18, 16, 14, 0.85);
    backdrop-filter: blur(16px);
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.logo-wrapper {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--accent-amber), var(--accent-terracotta));
    color: var(--text-primary);
    border-radius: var(--radius-md);
    display: grid;
    place-items: center;
    font-size: 1.5rem;
    box-shadow: var(--shadow-sm), var(--shadow-glow);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.app-title {
    font-family: var(--font-heading);
    font-size: 1.65rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.15;
}

.app-title span {
    color: var(--accent-amber);
    background: linear-gradient(120deg, var(--accent-amber), var(--accent-gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.app-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.model-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-full);
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--text-secondary);
}

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

.status-dot.ready {
    background-color: var(--accent-gold);
    box-shadow: 0 0 8px var(--accent-gold);
}

.status-dot.active {
    background-color: var(--accent-emerald);
    box-shadow: 0 0 10px var(--accent-emerald);
    animation: pulse-dot 1.5s infinite;
}

.status-dot.error {
    background-color: var(--accent-danger);
    box-shadow: 0 0 8px var(--accent-danger);
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.3); }
}

/* Alert Box */
.alert-box {
    margin: 1.5rem 0 0;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    background: rgba(230, 57, 70, 0.12);
    border: 1px solid rgba(230, 57, 70, 0.35);
    color: #ffb3b8;
    display: flex;
    align-items: flex-start;
    gap: 0.9rem;
    animation: slideDown 0.3s ease;
}

.alert-icon {
    font-size: 1.3rem;
    color: var(--accent-danger);
    margin-top: 2px;
}

.alert-content {
    flex: 1;
}

.alert-content strong {
    display: block;
    font-size: 0.95rem;
    margin-bottom: 0.2rem;
    color: #fff;
}

.alert-content p {
    font-size: 0.875rem;
    line-height: 1.4;
}

.btn-close-alert {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition-fast);
}

.btn-close-alert:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* Main Dashboard Grid */
.main-content {
    flex: 1;
    padding-top: 2rem;
    padding-bottom: 3rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.75rem;
    align-items: start;
    margin-bottom: 2rem;
}

/* Cards */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: var(--transition-normal);
}

.card:hover {
    border-color: var(--border-strong);
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.02);
}

.card-title-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.card-icon {
    color: var(--accent-amber);
    font-size: 1.15rem;
}

.card-header h2 {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
}

.card-body {
    padding: 1.5rem;
}

/* Pills & Badges */
.pill {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pill-idle {
    background: rgba(156, 142, 130, 0.15);
    color: var(--text-muted);
    border: 1px solid rgba(156, 142, 130, 0.25);
}

.pill-active {
    background: rgba(56, 176, 0, 0.15);
    color: #55f011;
    border: 1px solid rgba(56, 176, 0, 0.3);
}

.pill-info {
    background: rgba(224, 138, 78, 0.15);
    color: var(--accent-amber);
    border: 1px solid var(--border-accent);
}

/* Webcam Container & Video Frame */
.webcam-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    max-width: 440px;
    margin: 0 auto 1.5rem;
    background: #090807;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1.5px solid var(--border-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.7);
}

/* Placeholder Display */
.camera-placeholder {
    padding: 2rem 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    height: 100%;
}

.placeholder-icon-wrap {
    width: 76px;
    height: 76px;
    border-radius: var(--radius-lg);
    background: linear-gradient(145deg, var(--bg-surface-elevated), var(--bg-surface));
    border: 1px solid var(--border-strong);
    display: grid;
    place-items: center;
    font-size: 2.25rem;
    color: var(--accent-amber);
    margin-bottom: 0.5rem;
}

.camera-placeholder h3 {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    color: var(--text-primary);
    font-weight: 700;
}

.camera-placeholder p {
    font-size: 0.85rem;
    color: var(--text-muted);
    max-width: 280px;
}

.flag-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: center;
    margin-top: 0.5rem;
}

.tag {
    font-size: 0.75rem;
    background: var(--bg-surface-elevated);
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

/* Loading Overlay */
.camera-loading {
    position: absolute;
    inset: 0;
    background: rgba(18, 16, 14, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 10;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(224, 138, 78, 0.2);
    border-top: 4px solid var(--accent-amber);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

#loading-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Video / Canvas Element Inside Container */
.webcam-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.webcam-container canvas {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
    display: block;
}

/* Target Focus Frame & Laser Scan Animation */
.target-frame {
    position: absolute;
    width: 75%;
    height: 75%;
    pointer-events: none;
    z-index: 5;
    transition: var(--transition-normal);
}

.target-frame .corner {
    position: absolute;
    width: 24px;
    height: 24px;
    border-color: var(--accent-amber);
    border-style: solid;
}

.target-frame .top-left {
    top: 0; left: 0;
    border-width: 3px 0 0 3px;
    border-top-left-radius: 6px;
}
.target-frame .top-right {
    top: 0; right: 0;
    border-width: 3px 3px 0 0;
    border-top-right-radius: 6px;
}
.target-frame .bottom-left {
    bottom: 0; left: 0;
    border-width: 0 0 3px 3px;
    border-bottom-left-radius: 6px;
}
.target-frame .bottom-right {
    bottom: 0; right: 0;
    border-width: 0 3px 3px 0;
    border-bottom-right-radius: 6px;
}

.scan-line {
    position: absolute;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-amber), var(--accent-gold), transparent);
    box-shadow: 0 0 10px var(--accent-amber);
    top: 0;
    animation: scanAnim 2.2s ease-in-out infinite alternate;
}

@keyframes scanAnim {
    0% { top: 4%; opacity: 0.3; }
    50% { opacity: 1; }
    100% { top: 94%; opacity: 0.3; }
}

.frame-label {
    position: absolute;
    bottom: -28px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.725rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    background: rgba(18, 16, 14, 0.8);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    letter-spacing: 0.3px;
}

/* Control Buttons */
.controls-toolbar {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.btn {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 700;
    padding: 0.85rem 1.6rem;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    transition: all var(--transition-fast);
    text-decoration: none;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--accent-amber), var(--accent-terracotta));
    color: #ffffff;
    box-shadow: 0 4px 16px rgba(224, 138, 78, 0.35);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #e7955c, #d3653d);
    box-shadow: 0 6px 22px rgba(224, 138, 78, 0.5);
    transform: translateY(-2px);
}

.btn-secondary {
    background: rgba(230, 57, 70, 0.15);
    color: #ff7582;
    border: 1px solid rgba(230, 57, 70, 0.3);
}

.btn-secondary:hover {
    background: rgba(230, 57, 70, 0.25);
    color: #ffffff;
}

.btn-outline {
    background: var(--bg-surface-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-strong);
    padding: 0.85rem 1rem;
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* Results Card Styles */
.top-match-card {
    background: linear-gradient(145deg, rgba(47, 39, 35, 0.9), rgba(36, 30, 27, 0.95));
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-md);
    padding: 1.25rem 1.4rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.top-match-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, var(--accent-amber), var(--accent-gold));
}

.top-match-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.top-label {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-gold);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.confidence-badge {
    font-size: 1.15rem;
    font-weight: 800;
    font-family: var(--font-heading);
    color: #fff;
    background: rgba(224, 138, 78, 0.25);
    border: 1px solid var(--border-accent);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
}

.top-match-body {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.top-flag-visual {
    width: 54px;
    height: 54px;
    border-radius: var(--radius-md);
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-strong);
    display: grid;
    place-items: center;
    font-size: 1.75rem;
    color: var(--accent-amber);
    flex-shrink: 0;
}

.top-match-info h3 {
    font-family: var(--font-heading);
    font-size: 1.45rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.2;
    margin-bottom: 0.2rem;
}

.top-match-info p {
    font-size: 0.825rem;
    color: var(--text-muted);
}

/* Predictions List Breakdown */
.predictions-section {
    margin-top: 1rem;
}

.section-subtitle {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 0.9rem;
}

.label-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Single Prediction Item */
.prediction-row {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.85rem 1rem;
    transition: all var(--transition-fast);
}

.prediction-row.top-rank {
    border-color: rgba(224, 138, 78, 0.4);
    background: rgba(224, 138, 78, 0.08);
}

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

.class-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.class-percent {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.925rem;
    color: var(--accent-amber);
}

.progress-track {
    width: 100%;
    height: 9px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: var(--radius-full);
    overflow: hidden;
    border: 1px solid var(--border-subtle);
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-forest), var(--accent-amber));
    border-radius: var(--radius-full);
    transition: width 0.25s ease-out;
}

.prediction-row.top-rank .progress-fill {
    background: linear-gradient(90deg, var(--accent-amber), var(--accent-gold));
    box-shadow: 0 0 8px rgba(224, 138, 78, 0.5);
}

.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
    border: 1.5px dashed var(--border-subtle);
    border-radius: var(--radius-md);
}

.empty-state i {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

.empty-state p {
    font-size: 0.875rem;
}

/* Guide Card */
.guide-card {
    margin-top: 1rem;
}

.guide-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.25rem;
    padding: 1.5rem;
}

.guide-item {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    background: var(--bg-surface);
    padding: 1.15rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.guide-step {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-amber), var(--accent-terracotta));
    color: #fff;
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 0.95rem;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.guide-text h4 {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.3rem;
}

.guide-text p {
    font-size: 0.825rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Footer */
.app-footer {
    border-top: 1px solid var(--border-subtle);
    padding: 1.75rem 0;
    background: var(--bg-secondary);
    margin-top: auto;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.footer-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.footer-content strong {
    color: var(--text-secondary);
}

.model-url-note a {
    color: var(--accent-amber);
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px dashed var(--accent-amber);
    transition: var(--transition-fast);
}

.model-url-note a:hover {
    color: var(--accent-gold);
    border-bottom-style: solid;
}

/* Helper Utilities */
.hidden {
    display: none !important;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive Breakpoints */
@media (max-width: 900px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .webcam-wrapper {
        max-width: 380px;
    }
}

@media (max-width: 600px) {
    .container {
        padding: 0 1rem;
    }

    .app-title {
        font-size: 1.35rem;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .controls-toolbar {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
    }
}
