@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400;700&display=swap');

/* --- 1. VARIABLES & BASE --- */
:root {
    --font-primary: 'Roboto', 'Segoe UI', system-ui, sans-serif;
    --bg: #050505;
    --card: rgba(20,20,20,0.85);
    --text: #fff;
    --text-muted: #aaa;
    --accent: #4ade80; /* Tailwind Green 500 */
    --danger: #ef4444; /* Tailwind Red 500 */
    --info: #3b82f6; /* Tailwind Blue 500 */
    --warning: #f59e0b; /* Tailwind Amber 500 */
}
* { margin:0; padding:0; box-sizing:border-box; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}
canvas { position:fixed; top:0; left:0; z-index:0; opacity:0.3; pointer-events:none; }
.hidden { display:none !important; }

/* --- 2. AUTH VIEW --- */
.auth-body { display:flex; align-items:center; justify-content:center; }
#auth-view { width:100vw; height:100vh; display:flex; align-items:center; justify-content:center; z-index:10; }
.auth-box {
    background: var(--card); backdrop-filter: blur(15px); border:1px solid rgba(255,255,255,0.1);
    padding:40px; border-radius:20px; width:90%; max-width:400px; text-align:center; box-shadow:0 10px 40px rgba(0,0,0,0.8);
}
.auth-title { font-size:2.5rem; font-weight:100; margin-bottom:15px; letter-spacing: 2px; }
.input-group { margin:20px 0; text-align:left; }
.input-group input {
    width:100%; padding:14px; background:rgba(0,0,0,0.5); border:1px solid #333; border-radius:8px;
    color:white; font-size:1rem; outline:none; transition:border-color 0.2s;
}
.input-group input:focus { border-color:var(--accent); }
.auth-btn {
    width:100%; padding:14px; background:var(--accent); color:var(--bg); border:none; border-radius:8px;
    font-weight:700; cursor:pointer; font-size:1.1rem; margin-top:10px; transition:background 0.2s;
}
.auth-btn:hover:not(:disabled) { background: #34d399; }
.auth-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.switch-auth { margin-top:20px; color:var(--text-muted); font-size: 0.9rem; }
.switch-auth a { color:var(--text); font-weight:bold; cursor:pointer; text-decoration:none; transition:color 0.2s; }
.switch-auth a:hover { color:var(--accent); }

/* --- 3. HEADER & LAYOUT --- */
#app-view, #admin-view {
    max-width:1000px; margin:0 auto; padding:20px; position:relative; z-index:10;
}
header {
    text-align:center; margin:40px 0 30px; position:relative; width:100%;
}
.logout-btn {
    position:absolute; top:0; right:0; background:rgba(255,255,255,0.1); color:var(--text-muted);
    border:none; padding:8px 16px; border-radius:6px; cursor:pointer; font-size: 0.9rem;
    transition:background 0.2s;
}
.logout-btn:hover { background:rgba(255,255,255,0.2); color:var(--text); }
h1 {
    font-size:3rem; font-weight:100; letter-spacing:4px;
    background: linear-gradient(90deg, #fff, #aaa);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.header-subtitle { color: var(--text-muted); font-weight: 300; margin-top: 5px; }

/* --- 4. INPUT & STATUS --- */
.input-area {
    background: var(--card); backdrop-filter: blur(10px);
    padding:30px; border-radius:20px; border:1px solid rgba(255,255,255,0.1);
    max-width:700px; margin:0 auto 40px; box-shadow:0 5px 20px rgba(0,0,0,0.4);
}
/* ─────── ULTRA PREMIUM 3D MIC BUTTON ─────── */
.mic-container {
    position: relative;
    width: 160px;
    height: 160px;
    margin: 0 auto 30px;
    perspective: 1000px;
    cursor: pointer;
}

#micBtn {
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 30% 30%, #6ee2a0, #1a1a2e);
    border: none;
    border-radius: 50%;
    position: relative;
    transform-style: preserve-3d;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 
        0 20px 40px rgba(0, 0, 0, 0.6),
        0 0 60px rgba(74, 222, 128, 0.4),
        inset 0 -8px 20px rgba(0, 0, 0, 0.4),
        inset 0 8px 20px rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

/* 3D Inner glow ring */
#micBtn::before {
    content: '';
    position: absolute;
    top: 10px; left: 10px; right: 10px; bottom: 10px;
    border: 4px solid rgba(74, 222, 128, 0.6);
    border-radius: 50%;
    box-shadow: 
        0 0 40px rgba(74, 222, 128, 0.8),
        inset 0 0 30px rgba(74, 222, 128, 0.3);
    animation: breathe 4s infinite ease-in-out;
}

/* Floating particles inside */
#micBtn::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 30%, rgba(74, 222, 128, 0.4) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(100, 200, 255, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.1) 0%, transparent 60%);
    animation: float 12s infinite linear;
}

/* Pressed / Recording State */
#micBtn.recording {
    background: radial-gradient(circle at 30% 30%, #ff3b5c, #8b001a);
    animation: recordingPulse 1.5s infinite;
    transform: scale(1.08) rotateX(5deg);
    box-shadow: 
        0 30px 60px rgba(255, 59, 92, 0.6),
        0 0 100px rgba(255, 59, 92, 0.8),
        inset 0 -10px 30px rgba(0, 0, 0, 0.6);
}

#micBtn.recording::before {
    border-color: rgba(255, 59, 92, 0.9);
    box-shadow: 0 0 60px rgba(255, 59, 92, 1), inset 0 0 40px rgba(255, 59, 92, 0.4);
    animation: none;
}

/* Hover lift + tilt */
#micBtn:hover:not(.recording) {
    transform: translateY(-12px) rotateX(10deg) rotateY(5deg);
    box-shadow: 
        0 40px 80px rgba(0, 0, 0, 0.7),
        0 0 80px rgba(74, 222, 128, 0.6);
}

/* SVG Icon (larger, centered, premium) */
#micBtn svg {
    width: 64px;
    height: 64px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.5));
    z-index: 2;
}

/* Stop square when recording */
#micBtn.recording svg {
    width: 48px;
    height: 48px;
}

/* Animations */
@keyframes recordingPulse {
    0%, 100% { transform: scale(1.08) rotateX(5deg); }
    50% { transform: scale(1.15) rotateX(0deg); }
}

@keyframes breathe {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.05); }
}

@keyframes float {
    0% { transform: rotate(0deg) translateX(10px) rotate(0deg); }
    100% { transform: rotate(360deg) translateX(10px) rotate(-360deg); }
}

@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(239,68,68,0.7)} 70%{box-shadow:0 0 0 20px rgba(239,68,68,0)} 100%{box-shadow:0 0 0 0 rgba(239,68,68,0)} }

.text-input-group { display:flex; gap:10px; margin-top:15px; }
.text-input-group input { 
    flex:1; padding:14px; background:rgba(0,0,0,0.4); border:1px solid #333; border-radius:8px; 
    color:white; font-size:1rem; outline:none; 
}
#sendBtn { 
    background:var(--info); color:white; border:none; padding:0 24px; border-radius:8px; 
    cursor:pointer; font-weight:700; transition:background 0.2s; 
}
#sendBtn:hover:not(:disabled) { background: #2563eb; }
#sendBtn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Status Messages */
.message-box {
    margin-top:15px; padding:10px; border-radius:8px; font-size:0.9rem; text-align:center;
    font-weight: 600; min-height: 1.2em;
    /* FIX: Base state is invisible, but keeps height */
    border: 1px solid transparent; 
    background: none; 
}
.error-msg { 
    color:var(--danger); 
}
/* FIX 2: Only apply error background/border when the element is NOT empty */
.error-msg:not(:empty) { 
    background:rgba(239,68,68,0.2); 
    border:1px solid var(--danger); 
}
.success-msg { background:rgba(74,222,128,0.2); color:var(--accent); border:1px solid var(--accent); }
.loading-msg { background:rgba(59,130,246,0.2); color:var(--info); border:1px solid var(--info); }
.info-msg { color:var(--text-muted); background: none; border: none; }


/* --- 5. RESULTS --- */
#results-area {
    opacity:0; transform:translateY(20px); transition:all 0.6s ease;
}
#results-area.visible { opacity:1; transform:none; }
.search-term { font-size: 1rem; margin-bottom: 20px; text-align: center; color: var(--text-muted); }
.badges { display:flex; gap:15px; justify-content:center; margin-bottom:30px; }
.badge { 
    background:rgba(255,255,255,0.1); padding:6px 14px; border-radius:20px; font-size:0.9rem; 
    font-weight: 700; color: var(--accent);
}
.results-main-header { text-align:center; margin:20px 0 40px; font-weight:300; font-size: 2rem; }

/* ─────── NEW STUNNING NEWS GRID ─────── */
.news-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: 120px;
    gap: 20px;
    padding: 20px 0;
    max-width: 1400px;
    margin: 0 auto;
}

.news-card {
    background: rgba(30, 30, 40, 0.7);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(100, 100, 120, 0.2);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.4),
        0 0 20px rgba(74, 222, 128, 0.1);
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
}

.news-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, 
        rgba(74, 222, 128, 0.15) 0%, 
        rgba(100, 100, 255, 0.05) 100%);
    opacity: 0;
    transition: opacity 0.4s;
    pointer-events: none;
}

.news-card:hover {
    transform: translateY(-12px) scale(1.02);
    box-shadow: 
        0 20px 40px rgba(0, 0, 0, 0.6),
        0 0 40px rgba(74, 222, 128, 0.3);
    z-index: 10;
}

.news-card:hover::before {
    opacity: 1;
}

.news-card:hover .read-more-btn {
    background: var(--accent);
    color: #000;
    transform: translateY(0);
}

/* Card Content */
.news-meta {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.8rem;
    font-weight: 400;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 16px 20px 0;
}

.news-title {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.3;
    margin: 12px 20px;
    background: linear-gradient(90deg, #fff, #aaa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.news-summary {
    color: rgba(255, 255, 255, 0.85);
    font-size: 1rem;
    line-height: 1.6;
    flex-grow: 1;
    padding: 0 20px;
    font-family: 'Georgia', serif;
    font-style: italic;
}

/* Read More Button */
.read-more-btn {
    margin: 16px 20px;
    padding: 12px 24px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(74, 222, 128, 0.5);
    border-radius: 50px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 0.85rem;
    align-self: flex-start;
    transition: all 0.3s ease;
    transform: translateY(20px);
    backdrop-filter: blur(10px);
}

.read-more-btn:hover {
    background: var(--accent);
    color: #000;
    border-color: transparent;
}

/* ─────── CARD SIZE VARIANTS (Masonry Magic) ─────── */
.card-small   { grid-column: span 4; grid-row: span 3; }
.card-medium  { grid-column: span 6; grid-row: span 4; }
.card-large   { grid-column: span 8; grid-row: span 5; }
.card-wide    { grid-column: span 12; grid-row: span 3; }
.card-tall    { grid-column: span 4; grid-row: span 6; }

/* Optional: Featured first card */
.news-card:first-child {
    grid-column: span 8;
    grid-row: span 5;
    background: rgba(40, 40, 60, 0.8);
    border: 1px solid rgba(74, 222, 128, 0.4);
}

.news-card:first-child .news-title {
    font-size: 2rem;
    margin: 20px;
}

.news-card:first-child .news-summary {
    font-size: 1.2rem;
    padding: 0 20px 20px;
}

/* --- 6. ADMIN DASHBOARD --- */
.stats-grid {
    display:grid; grid-template-columns:repeat(auto-fit, minmax(200px,1fr)); gap:20px; margin:30px 0;
}
.stat-card {
    background:var(--card); padding:25px; border-radius:12px; text-align:center;
    border:1px solid rgba(255,255,255,0.1); box-shadow:0 3px 10px rgba(0,0,0,0.5);
}
.stat-label { font-size: 0.9rem; color: var(--text-muted); font-weight: 300; margin-bottom: 5px; }
.stat-value { font-size:2.5rem; font-weight:700; color:var(--accent); }

.admin-table-container h2 {
    font-weight: 300; font-size: 1.8rem; margin-bottom: 20px;
    display: flex; align-items: center; gap: 10px;
}
.section-icon { font-size: 1.5rem; }

table {
    width:100%; border-collapse:collapse; background:rgba(255,255,255,0.05); border-radius:12px; overflow:hidden;
    margin-top:20px; font-size: 0.9rem;
}
th, td { padding:14px; text-align:left; border-bottom:1px solid rgba(255,255,255,0.1); }
th { background:rgba(0,0,0,0.5); font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.08); }
.user-role-admin { color: var(--accent); font-weight: 700; }
.log-type-voice { color: var(--info); }
.log-type-text { color: var(--warning); }

/* ─────── PROCESSING OVERLAY (INSANE) ─────── */
.processing-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle, rgba(74,222,128,0.3) 0%, transparent 70%);
}

.processing-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Voice Wave Bars */
.voice-wave {
    display: flex;
    gap: 6px;
    height: 60px;
    align-items: center;
}

.voice-wave span {
    width: 6px;
    height: 10px;
    background: #4ade80;
    border-radius: 3px;
    animation: wave 1.4s ease-in-out infinite;
    box-shadow: 0 0 20px #4ade80;
}

.voice-wave span:nth-child(1) { animation-delay: 0s; height: 20px; }
.voice-wave span:nth-child(2) { animation-delay: 0.1s; height: 40px; }
.voice-wave span:nth-child(3) { animation-delay: 0.2s; height: 60px; }
.voice-wave span:nth-child(4) { animation-delay: 0.3s; height: 40px; }
.voice-wave span:nth-child(5) { animation-delay: 0.4s; height: 20px; }

@keyframes wave {
    0%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(2.5); }
}

/* Orbiting Particles */
.orbit-particles {
    position: absolute;
    width: 140px;
    height: 140px;
}

.particle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    box-shadow: 0 0 20px #4ade80;
}

.particle:nth-child(1) { animation: orbit 3s linear infinite; }
.particle:nth-child(2) { animation: orbit 3s linear infinite 0.75s; }
.particle:nth-child(3) { animation: orbit 3s linear infinite 1.5s; }
.particle:nth-child(4) { animation: orbit 3s linear infinite 2.25s; }

@keyframes orbit {
    0% { transform: translate(-50%, -50%) rotate(0deg) translateX(70px) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg) translateX(70px) rotate(-360deg); }
}

/* Processing Text */
.processing-text {
    margin-top: 20px;
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 2px;
    color: #4ade80;
    text-shadow: 0 0 20px #4ade80;
    animation: pulseText 2s infinite;
}

@keyframes pulseText {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* Lock button during processing */
#micBtn.processing {
    pointer-events: none;
    cursor: not-allowed;
    opacity: 0.8;
}