/* ===== CSS RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.7);
    --bg-card-hover: rgba(30, 41, 59, 0.8);
    --glass: rgba(255, 255, 255, 0.04);
    --glass-border: rgba(255, 255, 255, 0.08);
    --accent-primary: #6366f1;
    --accent-secondary: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --accent-warm: #f59e0b;
    --accent-warm-glow: rgba(245, 158, 11, 0.3);
    --accent-success: #10b981;
    --accent-success-glow: rgba(16, 185, 129, 0.3);
    --accent-danger: #ef4444;
    --accent-danger-glow: rgba(239, 68, 68, 0.3);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.4);
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* ===== BACKGROUND AMBIENT ===== */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
                radial-gradient(ellipse at 80% 20%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
                radial-gradient(ellipse at 50% 80%, rgba(16, 185, 129, 0.04) 0%, transparent 50%);
    z-index: 0;
    pointer-events: none;
    animation: ambientShift 20s ease-in-out infinite alternate;
}

@keyframes ambientShift {
    0% { transform: translate(0, 0) rotate(0deg); }
    100% { transform: translate(-3%, -3%) rotate(3deg); }
}

/* ===== LAYOUT ===== */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 520px;
    margin: 0 auto;
    padding: 24px 16px 80px;
}

/* ===== HEADER ===== */
.header {
    text-align: center;
    padding: 32px 0 24px;
}

.header-icon {
    font-size: 48px;
    margin-bottom: 8px;
    display: inline-block;
    animation: bellSwing 3s ease-in-out infinite;
}

@keyframes bellSwing {
    0%, 100% { transform: rotate(0deg); }
    10% { transform: rotate(12deg); }
    20% { transform: rotate(-10deg); }
    30% { transform: rotate(6deg); }
    40% { transform: rotate(0deg); }
}

.header h1 {
    font-size: 28px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-secondary), var(--accent-primary), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.header p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 400;
}

/* ===== CLOCK DISPLAY ===== */
.clock-display {
    text-align: center;
    padding: 20px 0;
}

.clock-time {
    font-size: 64px;
    font-weight: 300;
    letter-spacing: 2px;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.clock-date {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ===== GLASS CARD ===== */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 16px;
    transition: var(--transition-smooth);
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.12);
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-title .icon {
    font-size: 16px;
}

/* ===== FORM ELEMENTS ===== */
.form-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.form-group {
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 12px 14px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    transition: var(--transition-fast);
    appearance: none;
    -webkit-appearance: none;
    outline: none;
}

.form-control:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

select.form-control {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

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

input[type="time"].form-control {
    cursor: text;
}

/* Increase time input size on tap targets */
input[type="time"].form-control::-webkit-calendar-picker-indicator {
    filter: invert(0.7);
    cursor: pointer;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
    outline: none;
    white-space: nowrap;
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--accent-primary), #7c3aed);
    color: white;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 30px var(--accent-glow);
}

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

.btn-danger-sm {
    padding: 6px 12px;
    font-size: 12px;
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-danger);
    border-radius: var(--radius-sm);
}

.btn-danger-sm:hover {
    background: rgba(239, 68, 68, 0.25);
}

/* ===== ALARM LIST ===== */
.alarm-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.alarm-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    transition: var(--transition-fast);
    animation: slideIn 0.3s ease-out;
}

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

.alarm-item:hover {
    background: var(--bg-card-hover);
}

.alarm-item-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.alarm-item-time {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 1px;
    font-variant-numeric: tabular-nums;
}

.alarm-item-object {
    font-size: 13px;
    color: var(--text-secondary);
}

.alarm-item-object .badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-secondary);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 14px;
}

.empty-state .empty-icon {
    font-size: 40px;
    margin-bottom: 8px;
    opacity: 0.5;
}

/* ===== ALARM ACTIVE OVERLAY ===== */
.alarm-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--bg-primary);
    overflow-y: auto;
    animation: fadeIn 0.4s ease;
}

.alarm-overlay.active {
    display: flex;
    flex-direction: column;
    align-items: center;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.alarm-overlay-inner {
    width: 100%;
    max-width: 520px;
    padding: 24px 16px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Pulsing alarm header */
.alarm-active-header {
    text-align: center;
    padding: 24px 0 16px;
    width: 100%;
}

.alarm-active-header .alarm-ring-icon {
    font-size: 56px;
    display: inline-block;
    animation: alarmRing 0.5s ease-in-out infinite alternate;
}

@keyframes alarmRing {
    0% { transform: rotate(-15deg) scale(1); }
    100% { transform: rotate(15deg) scale(1.1); }
}

.alarm-active-header h2 {
    font-size: 48px;
    font-weight: 800;
    letter-spacing: 2px;
    margin: 8px 0 4px;
    animation: textPulse 1.5s ease-in-out infinite alternate;
}

@keyframes textPulse {
    0% { color: var(--text-primary); }
    100% { color: var(--accent-warm); }
}

.alarm-instruction {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-secondary);
    margin: 8px 0 4px;
}

.alarm-instruction .highlight {
    color: var(--accent-warm);
    font-weight: 700;
    text-transform: uppercase;
}

/* Camera container */
.camera-container {
    width: 100%;
    margin: 16px 0;
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 2px solid var(--glass-border);
    aspect-ratio: 4 / 3;
    background: #000;
}

.camera-container.detecting {
    border-color: var(--accent-warm);
    box-shadow: 0 0 30px var(--accent-warm-glow);
}

.camera-container.success {
    border-color: var(--accent-success);
    box-shadow: 0 0 30px var(--accent-success-glow);
}

.camera-container canvas,
.camera-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.camera-error {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.85);
    color: var(--accent-danger);
    font-size: 14px;
    text-align: center;
    padding: 24px;
    gap: 8px;
}

.camera-error .icon {
    font-size: 40px;
}

/* Detection status bar */
.detection-status {
    width: 100%;
    margin-top: 12px;
}

.prediction-bars {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.prediction-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.prediction-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 90px;
    text-transform: capitalize;
}

.prediction-bar-track {
    flex: 1;
    height: 8px;
    background: var(--glass);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.prediction-bar-fill {
    height: 100%;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    transition: width 0.15s ease;
    width: 0%;
}

.prediction-bar-fill.target {
    background: linear-gradient(90deg, var(--accent-warm), #fbbf24);
}

.prediction-bar-fill.matched {
    background: linear-gradient(90deg, var(--accent-success), #34d399);
}

.prediction-value {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 42px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Hold progress ring */
.hold-progress-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.hold-progress-section.visible {
    opacity: 1;
}

.hold-ring-container {
    position: relative;
    width: 80px;
    height: 80px;
}

.hold-ring-container svg {
    transform: rotate(-90deg);
}

.hold-ring-bg {
    fill: none;
    stroke: var(--glass-border);
    stroke-width: 5;
}

.hold-ring-fill {
    fill: none;
    stroke: var(--accent-success);
    stroke-width: 5;
    stroke-linecap: round;
    stroke-dasharray: 226;
    stroke-dashoffset: 226;
    transition: stroke-dashoffset 0.1s linear;
    filter: drop-shadow(0 0 4px var(--accent-success-glow));
}

.hold-ring-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: var(--accent-success);
}

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

/* Success screen */
.success-screen {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: var(--bg-primary);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    animation: fadeIn 0.5s ease;
}

.success-screen.active {
    display: flex;
}

.success-icon {
    font-size: 80px;
    margin-bottom: 16px;
    animation: bounceIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes bounceIn {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.success-screen h2 {
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--accent-success), #34d399);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.success-screen p {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.btn-success-close {
    padding: 14px 40px;
    background: linear-gradient(135deg, var(--accent-success), #059669);
    color: white;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition-fast);
    box-shadow: 0 4px 20px var(--accent-success-glow);
}

.btn-success-close:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--accent-success-glow);
}

/* Alarm flash effect on overlay */
.alarm-overlay::before {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at center, var(--accent-danger-glow), transparent 70%);
    animation: alarmFlash 1s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: -1;
}

@keyframes alarmFlash {
    0% { opacity: 0.2; }
    100% { opacity: 0.6; }
}

/* ===== TOAST NOTIFICATION ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    z-index: 2000;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
}

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

.toast-success {
    background: var(--accent-success);
    color: white;
}

.toast-error {
    background: var(--accent-danger);
    color: white;
}

.toast-info {
    background: var(--accent-primary);
    color: white;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
    .clock-time {
        font-size: 48px;
    }
    .alarm-active-header h2 {
        font-size: 36px;
    }
    .card {
        padding: 18px;
    }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 3px;
}

/* ===== OBJECT ICON MAP ===== */
.object-icon {
    display: inline-block;
    margin-right: 4px;
}
