* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, sans-serif;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: #0f0f1a;
    color: #fff;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* HEADER */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    height: 56px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo { font-size: 1.5em; }

.header h1 {
    font-size: 1.1em;
    background: linear-gradient(90deg, #4facfe, #00f2fe);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 700;
}

.header-right {
    display: flex;
    gap: 6px;
    align-items: center;
}

.api-input {
    padding: 7px 12px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    font-size: 0.85em;
    width: 200px;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: rgba(79, 172, 254, 0.2);
}

/* MAIN */
.main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 12px;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    overflow: hidden;
}

/* ============================================
   CAMERA
   ============================================ */
.camera-wrapper {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    flex: 1;
    min-height: 0;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

#video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.guide-frame {
    position: absolute;
    top: 8%;
    left: 6%;
    right: 6%;
    bottom: 8%;
    border: 2px dashed rgba(79, 172, 254, 0.5);
    border-radius: 8px;
    pointer-events: none;
    box-shadow: 0 0 0 3000px rgba(0, 0, 0, 0.2);
    transition: border-color 0.3s;
}

.guide-frame.locked {
    border-color: #43e97b;
    border-style: solid;
    box-shadow: 0 0 0 3000px rgba(0, 0, 0, 0.2), 0 0 30px rgba(67, 233, 123, 0.4);
}

.guide-frame::before {
    content: '📄 Posisikan dokumen di sini';
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    color: #4facfe;
    font-size: 0.75em;
    background: rgba(0, 0, 0, 0.75);
    padding: 4px 12px;
    border-radius: 20px;
    white-space: nowrap;
}

.guide-frame.locked::before {
    content: '🔒 Dokumen Stabil - Siap Analisis';
    color: #43e97b;
}

/* Status badge */
.status-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.78em;
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 5;
}

.status-badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #f5576c;
    box-shadow: 0 0 8px #f5576c;
    animation: pulse 1.5s infinite;
}

.status-badge.active .dot {
    background: #43e97b;
    box-shadow: 0 0 8px #43e97b;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Lock badge */
.lock-badge {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(67, 233, 123, 0.15);
    border: 2px solid #43e97b;
    backdrop-filter: blur(12px);
    padding: 14px 24px;
    border-radius: 14px;
    font-size: 1em;
    font-weight: 700;
    color: #43e97b;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 8;
    animation: lockPop 0.4s ease-out;
    box-shadow: 0 0 40px rgba(67, 233, 123, 0.5);
}

.lock-badge span:first-child { font-size: 1.6em; }

@keyframes lockPop {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    50% { transform: translate(-50%, -50%) scale(1.1); }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Countdown */
.countdown {
    position: absolute;
    bottom: 15px;
    right: 15px;
    width: 60px;
    height: 60px;
    z-index: 6;
    display: flex;
    align-items: center;
    justify-content: center;
}

.countdown-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    position: absolute;
}

.countdown-track {
    fill: none;
    stroke: rgba(255, 255, 255, 0.15);
    stroke-width: 3;
}

.countdown-progress {
    fill: none;
    stroke: #4facfe;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 94.2;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.3s linear;
}

.countdown span {
    font-weight: 700;
    font-size: 1.1em;
    color: #4facfe;
    z-index: 1;
}

/* Frame counter */
.frame-counter {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.78em;
    color: #4facfe;
    z-index: 5;
}

/* Overlay loading */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    backdrop-filter: blur(4px);
    z-index: 10;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 4px solid rgba(79, 172, 254, 0.2);
    border-top-color: #4facfe;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Controls */
.controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    flex-shrink: 0;
}

.btn {
    padding: 11px 8px;
    border: none;
    border-radius: 8px;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

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

.btn.primary { background: linear-gradient(135deg, #4facfe, #00f2fe); color: #fff; }
.btn.success { background: linear-gradient(135deg, #43e97b, #38f9d7); color: #fff; }
.btn.danger  { background: linear-gradient(135deg, #f5576c, #f093fb); color: #fff; }
.btn.warning { background: linear-gradient(135deg, #fa709a, #fee140); color: #333; }

.btn:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

/* Auto settings */
.auto-settings {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    font-size: 0.78em;
    color: #a0a0b0;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    flex-shrink: 0;
}

.auto-settings select {
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 5px;
    padding: 3px 8px;
    font-size: 1em;
}

.lock-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

/* ============================================
   RESULT PANEL
   ============================================ */
.panel-result {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    overflow: hidden;
}

.tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.tab {
    flex: 1;
    padding: 11px 8px;
    background: transparent;
    border: none;
    color: #a0a0b0;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.tab:hover { color: #fff; background: rgba(255, 255, 255, 0.03); }

.tab.active {
    color: #4facfe;
    border-bottom-color: #4facfe;
    background: rgba(79, 172, 254, 0.05);
}

.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    min-height: 0;
}

.tab-content.active { display: block; }

.tab-content::-webkit-scrollbar,
.history-box::-webkit-scrollbar {
    width: 6px;
}

.tab-content::-webkit-scrollbar-thumb,
.history-box::-webkit-scrollbar-thumb {
    background: rgba(79, 172, 254, 0.3);
    border-radius: 3px;
}

/* ============================================
   RESULT CARDS (multi text box)
   ============================================ */
.result-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.result-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    overflow: hidden;
    animation: slideIn 0.3s ease-out;
}

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

.result-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.25);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.result-card-title {
    font-size: 0.82em;
    font-weight: 700;
    color: #4facfe;
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.copy-btn {
    background: rgba(79, 172, 254, 0.15);
    border: 1px solid rgba(79, 172, 254, 0.3);
    color: #4facfe;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75em;
    font-weight: 600;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.copy-btn:hover {
    background: rgba(79, 172, 254, 0.3);
    transform: translateY(-1px);
}

.copy-btn.copied {
    background: rgba(67, 233, 123, 0.2);
    border-color: #43e97b;
    color: #43e97b;
}

.result-card-body {
    padding: 12px;
    font-size: 0.88em;
    line-height: 1.6;
    color: #e0e0f0;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
}

.result-card-body::-webkit-scrollbar {
    width: 5px;
}

.result-card-body::-webkit-scrollbar-thumb {
    background: rgba(79, 172, 254, 0.3);
    border-radius: 3px;
}

/* Kode arsip card (special) */
.result-card.kode-card {
    border-color: rgba(255, 224, 64, 0.3);
}

.result-card.kode-card .result-card-header {
    background: linear-gradient(90deg, rgba(255, 224, 64, 0.1), rgba(250, 112, 154, 0.1));
}

.result-card.kode-card .result-card-title {
    color: #fee140;
}

.result-card.kode-card .copy-btn {
    background: rgba(255, 224, 64, 0.15);
    border-color: rgba(255, 224, 64, 0.3);
    color: #fee140;
}

.kode-display {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
}

.kode-big {
    font-size: 2.2em;
    font-weight: 900;
    background: linear-gradient(135deg, #fee140, #fa709a);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 2px;
    font-family: 'Courier New', monospace;
}

.kode-detail {
    flex: 1;
    font-size: 0.9em;
    color: #e0e0f0;
}

.kode-detail .jenis {
    font-weight: 700;
    color: #fee140;
    font-size: 1.05em;
}

.kode-detail .sub {
    font-size: 0.85em;
    color: #a0a0b0;
    margin-top: 3px;
}

/* Status card */
.result-card.status-card.simpan { border-left: 4px solid #43e97b; }
.result-card.status-card.sementara { border-left: 4px solid #fee140; }
.result-card.status-card.tidak { border-left: 4px solid #f5576c; }

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    color: #606070;
    gap: 8px;
    height: 100%;
}

.empty-state.small { padding: 20px; }

.empty-icon { font-size: 3em; opacity: 0.4; }

.empty-state p { font-size: 0.95em; }
.empty-state small { font-size: 0.8em; color: #505060; }

/* History */
.history-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    background: rgba(255, 255, 255, 0.04);
    border-left: 3px solid #4facfe;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.82em;
    cursor: pointer;
    transition: all 0.15s;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(3px);
}

.history-item .time {
    color: #4facfe;
    font-size: 0.85em;
    margin-bottom: 5px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
}

.history-item .kode-mini {
    background: rgba(255, 224, 64, 0.15);
    color: #fee140;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 0.9em;
    font-weight: 700;
}

.history-item .preview {
    color: #b0b0c0;
    line-height: 1.4;
}

/* Badge */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.82em;
    font-weight: 600;
    margin: 4px 0;
}

.badge.simpan { background: #43e97b; color: #003; }
.badge.sementara { background: #fee140; color: #333; }
.badge.tidak { background: #f5576c; color: #fff; }

/* Info tab */
.info-content {
    font-size: 0.85em;
    line-height: 1.6;
    color: #c0c0d0;
}

.info-content h3 {
    color: #4facfe;
    font-size: 1.1em;
    margin-bottom: 10px;
}

.info-content h4 {
    color: #fff;
    font-size: 0.95em;
    margin: 15px 0 8px;
}

.info-content p { margin-bottom: 10px; }
.info-content strong { color: #4facfe; }

/* Kode Grid */
.kode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.kode-item {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    transition: all 0.15s;
    cursor: default;
}

.kode-item:hover {
    background: rgba(255, 224, 64, 0.08);
    border-color: rgba(255, 224, 64, 0.3);
    transform: translateY(-2px);
}

.kode-item .kode {
    font-size: 1.4em;
    font-weight: 900;
    background: linear-gradient(135deg, #fee140, #fa709a);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-family: 'Courier New', monospace;
    letter-spacing: 1px;
}

.kode-item .label {
    font-size: 0.72em;
    color: #a0a0b0;
    margin-top: 4px;
    line-height: 1.3;
}

.prompt-input {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    font-family: 'Courier New', monospace;
    font-size: 0.78em;
    resize: vertical;
    line-height: 1.5;
    min-height: 160px;
}

.btn-outline {
    margin-top: 8px;
    padding: 8px 14px;
    border-radius: 6px;
    background: transparent;
    border: 1px solid rgba(79, 172, 254, 0.4);
    color: #4facfe;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    transition: all 0.15s;
}

.btn-outline:hover {
    background: rgba(79, 172, 254, 0.1);
}

.legend {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.legend-item { margin: 6px 0; }

/* Toast notif */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #43e97b;
    color: #003;
    padding: 10px 20px;
    border-radius: 30px;
    font-weight: 700;
    font-size: 0.9em;
    opacity: 0;
    transition: all 0.3s;
    z-index: 9999;
    pointer-events: none;
    box-shadow: 0 8px 30px rgba(67, 233, 123, 0.4);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .header {
        padding: 6px 10px;
        height: 50px;
    }

    .header h1 { font-size: 0.95em; }
    .api-input { width: 130px; font-size: 0.78em; }

    .main {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
        gap: 8px;
        padding: 8px;
    }

    .controls { gap: 6px; }
    .btn { padding: 10px 4px; font-size: 0.75em; }

    .auto-settings {
        font-size: 0.72em;
        gap: 8px;
    }

    .guide-frame::before { font-size: 0.7em; }

    .countdown { width: 48px; height: 48px; bottom: 10px; right: 10px; }
}

@media (max-width: 480px) {
    .header h1 { display: none; }
    .api-input { width: 110px; }
    .kode-grid { grid-template-columns: repeat(3, 1fr); }
}