:root {
    --bg: #050505;
    --surface: #121212;
    --glass: rgba(20, 20, 20, 0.85);
    --primary: #8b5cf6; /* Violet */
    --accent: #06b6d4; /* Cyan */
    --text: #e2e8f0;
    --text-mute: #94a3b8;
    --border: #27272a;
    --danger: #ef4444;
    --success: #10b981;
    --font-main: 'Inter', -apple-system, sans-serif;
    --font-mono: 'Fira Code', monospace;
}

/* THEMES */
body.theme-matrix { --bg:#000; --surface:#020; --primary:#0f0; --accent:#0f0; --text:#0f0; --glass:rgba(0,20,0,0.9); }
body.theme-lab { --bg:#f8fafc; --surface:#fff; --primary:#2563eb; --accent:#0891b2; --text:#0f172a; --glass:rgba(255,255,255,0.9); --border:#e2e8f0; }

* { box-sizing: border-box; margin: 0; padding: 0; outline: none; -webkit-tap-highlight-color: transparent; }

body {
    background: var(--bg); color: var(--text);
    font-family: var(--font-main); height: 100vh;
    display: flex; flex-direction: column; overflow: hidden;
    transition: background 0.3s, color 0.3s;
}

/* STATUS BAR */
.status-bar {
    height: 30px; background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center; padding: 0 15px;
    font-size: 0.8rem; color: var(--text-mute); z-index: 200;
}

/* LAYOUT */
.app-container { display: flex; flex: 1; overflow: hidden; position: relative; }

/* SIDEBAR */
.sidebar {
    width: 70px; background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; align-items: center; padding-top: 10px;
    z-index: 100; transition: width 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    overflow-y: auto; overflow-x: hidden;
}
.sidebar:hover { width: 220px; }

.nav-item {
    width: 90%; height: 45px; display: flex; align-items: center;
    border-radius: 8px; margin-bottom: 5px; cursor: pointer;
    color: var(--text-mute); transition: 0.2s; white-space: nowrap; overflow: hidden;
}
.nav-item:hover, .nav-item.active { background: var(--primary); color: white; box-shadow: 0 0 15px rgba(139, 92, 246, 0.3); }
.nav-icon { min-width: 70px; text-align: center; font-size: 1.2rem; }
.nav-label { opacity: 0; transition: 0.2s; font-weight: 500; }
.sidebar:hover .nav-label { opacity: 1; }

@media (max-width: 768px) {
    .app-container { flex-direction: column-reverse; }
    .sidebar {
        width: 100%; height: 60px; flex-direction: row; border-right: none; border-top: 1px solid var(--border);
        justify-content: space-between; padding: 0 10px; overflow-x: auto;
    }
    .sidebar:hover { width: 100%; }
    .nav-item { flex-direction: column; justify-content: center; height: 100%; min-width: 60px; font-size: 0.7rem; gap: 2px; }
    .nav-icon { min-width: auto; font-size: 1.2rem; }
    .nav-label { opacity: 1; font-size: 0.7rem; display: block; }
}

/* MAIN CONTENT */
.main-view { flex: 1; position: relative; background: radial-gradient(circle at 10% 20%, rgba(139,92,246,0.05) 0%, transparent 40%); overflow: hidden; }

.tab-pane { display: none; width: 100%; height: 100%; padding: 20px; overflow-y: auto; animation: slideIn 0.2s ease-out; }
.tab-pane.active { display: block; }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* CALCULATOR */
.calc-grid {
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px;
    max-width: 450px; margin: 0 auto; height: 100%; grid-template-rows: 140px auto;
}
.display-area {
    grid-column: 1 / -1; background: var(--surface); border-radius: 12px;
    padding: 15px; text-align: right; display: flex; flex-direction: column;
    justify-content: flex-end; border: 1px solid var(--border);
}
.calc-input { font-size: 2.2rem; font-family: var(--font-mono); word-break: break-all; }
.calc-res { font-size: 1rem; color: var(--text-mute); }

.keypad { display: grid; grid-template-columns: subgrid; grid-column: 1 / -1; gap: 10px; }
.btn {
    border: none; border-radius: 10px; font-size: 1.1rem; cursor: pointer;
    background: #1f1f22; color: var(--text); transition: 0.1s;
    display: flex; align-items: center; justify-content: center;
}
.btn:active { transform: scale(0.95); }
.btn.op { background: var(--accent); color: #000; }
.btn.action { background: var(--primary); color: #fff; }
.btn.fn { background: #3f3f46; }
.btn.sci { background: #27272a; font-size: 0.9rem; }
.btn.wide { grid-column: span 2; }

/* TOOLS */
.tools-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 15px; margin-top: 20px; }
.tool-card {
    background: var(--glass); border: 1px solid var(--border); padding: 20px;
    border-radius: 12px; text-align: center; cursor: pointer; transition: 0.2s;
}
.tool-card:hover { border-color: var(--primary); transform: translateY(-3px); }
.tool-card i { font-size: 2rem; color: var(--primary); margin-bottom: 10px; display: block; }

/* MEASURE */
.measure-viewport { position: relative; height: 100%; background: #000; display: flex; flex-direction: column; }
.camera-feed { position: absolute; width: 100%; height: 100%; object-fit: cover; }
.hud-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
.hud-ui { position: absolute; bottom: 30px; left: 0; width: 100%; display: flex; justify-content: center; gap: 30px; z-index: 10; pointer-events: auto; }
.reticle {
    position: absolute; top: 50%; left: 50%; width: 24px; height: 24px;
    transform: translate(-50%, -50%); border: 2px solid rgba(255,255,255,0.8);
    border-radius: 50%; pointer-events: none; z-index: 5;
}
.reticle::after { content:''; position: absolute; top: 50%; left: 50%; width: 4px; height: 4px; background: #fff; border-radius: 50%; transform: translate(-50%,-50%); }
.hud-info {
    position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.6); backdrop-filter: blur(8px); padding: 10px 20px;
    border-radius: 20px; text-align: center; color: white; border: 1px solid rgba(255,255,255,0.2);
}
.action-btn { width: 50px; height: 50px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,0.3); color: white; cursor: pointer; font-size: 1.2rem; backdrop-filter: blur(4px); }
.action-btn.main { width: 70px; height: 70px; background: #fff; color: #000; }

/* UI ELEMENTS */
.glass-panel { background: var(--glass); border: 1px solid var(--border); padding: 20px; border-radius: 12px; margin-bottom: 15px; backdrop-filter: blur(10px); }
.modern-input { width: 100%; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--text); margin-bottom: 10px; font-family: var(--font-mono); }
.btn-sm { padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; background: #3f3f46; color: white; font-weight: 500; }
.btn-sm.primary { background: var(--primary); }
.btn-sm.danger { background: var(--danger); }
.btn-group { display: flex; gap: 10px; flex-wrap: wrap; }
.split-view { display: flex; gap: 20px; height: 100%; }
.split-view > * { flex: 1; display: flex; flex-direction: column; }
#note-input { background: transparent; border: none; height: 100%; color: var(--text); font-family: var(--font-mono); resize: none; }
#note-preview { overflow-y: auto; padding-left: 10px; border-left: 1px solid var(--border); }
#terminal-ui { border-radius: 8px; border: 1px solid var(--border); }
.code-output { background: #000; padding: 15px; border-radius: 8px; font-family: monospace; color: var(--accent); min-height: 50px; }

/* MODAL */
.modal-wrap { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 1000; display: none; justify-content: center; align-items: center; padding: 20px; }
.modal-box { width: 500px; max-width: 100%; max-height: 90vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 25px; box-shadow: 0 25px 50px rgba(0,0,0,0.5); }
.modal-footer { margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px; }
#tm-result { margin-top: 15px; text-align: center; font-size: 1.2rem; color: var(--accent); font-weight: bold; }