@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --bg-base: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --border: #334155;
    --primary: #6366f1;
    --primary-light: rgba(99, 102, 241, 0.15);
    --primary-hover: #4f46e5;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 12px;
    --font: 'Inter', system-ui, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font);
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
    background-color: var(--bg-base);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1100px;
    height: 100dvh;
    background: var(--bg-base);
}

@media (min-width: 768px) {
    .app-container {
        height: 96dvh;
        border-radius: 20px;
        border: 1px solid var(--border);
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
        overflow: hidden;
    }
}

/* --- Header & Tabs --- */
header {
    background: var(--surface);
    padding: 1rem 1.5rem 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-title {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.main-tabs {
    display: flex;
    gap: 1.5rem;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.75rem 0;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:hover { color: var(--text-main); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* --- View Area --- */
.view-content {
    display: none;
    flex: 1;
    padding: 1.25rem;
    gap: 1.25rem;
    min-height: 0;
    overflow-y: auto;
}
.view-content.active { display: flex; }

/* --- Layout Grids --- */
.grid-2col {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    gap: 1.25rem;
    width: 100%;
    height: 100%;
}

@media (min-width: 768px) {
    .grid-2col {
        grid-template-columns: 320px 1fr;
        grid-template-rows: 1fr;
    }
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0; 
}

/* --- Form Controls --- */
.control-group { display: flex; flex-direction: column; gap: 6px; }
.control-header { display: flex; justify-content: space-between; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); }
.control-val { color: var(--primary); font-family: ui-monospace, monospace; }

input[type="range"] { width: 100%; height: 6px; background: var(--border); border-radius: 3px; outline: none; -webkit-appearance: none; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--primary); cursor: pointer; }

textarea {
    width: 100%; background: var(--bg-base); border: 1px solid var(--border);
    color: var(--text-main); padding: 0.75rem; border-radius: 8px; font-family: ui-monospace, monospace;
    font-size: 0.85rem; resize: none; outline: none;
}
textarea:focus { border-color: var(--primary); }

.btn {
    background: var(--primary); color: white; border: none; border-radius: 8px;
    padding: 0.6rem 1rem; font-weight: 600; font-size: 0.85rem; cursor: pointer; transition: 0.2s;
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.btn:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-hover); color: var(--text-main); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); }

/* --- Metric Bento Grid --- */
.bento-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric-card {
    background: var(--bg-base); border: 1px solid var(--border); border-radius: 8px;
    padding: 0.75rem; display: flex; flex-direction: column; justify-content: center;
}
.metric-label { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; font-weight: 700; }
.metric-val { font-size: 1.1rem; font-weight: 800; font-family: ui-monospace, monospace; margin-top: 2px;}

/* --- Auto-Simetria Grid --- */
.keypad-grid { display: grid; grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(4, 1fr); gap: 8px; flex: 1; }
.btn-keypad {
    position: relative; background: var(--bg-base); border: 1px solid var(--border); border-radius: 8px;
    font-size: 1.1rem; font-weight: 700; color: var(--text-main); cursor: pointer; transition: all 0.1s;
}
.btn-keypad:active { transform: scale(0.95); background: var(--primary); border-color: var(--primary); }
.btn-keypad.mode-delete:active { background: var(--danger); border-color: var(--danger); }
.badge {
    position: absolute; top: -6px; right: -6px; background: var(--primary); color: white;
    font-size: 0.65rem; font-weight: 800; padding: 2px 6px; border-radius: 10px; display: none;
}
.badge.active { display: block; }

/* --- Visualizations (FIXED HISTOGRAM) --- */
.chart-box {
    background: var(--bg-base); border: 1px solid var(--border); border-radius: 8px; padding: 1rem;
    flex: 1; min-height: 180px; display: flex; flex-direction: column; justify-content: center;
}

.chart-wrapper {
    position: relative;
    flex: 1;
    width: 100%;
    min-height: 0; 
}

.sim-bar-wrapper {
    display: flex; align-items: stretch; justify-content: space-between; height: 140px; gap: 4px;
    padding: 10px 10px 4px 10px; background: var(--bg-base); border: 1px solid var(--border); border-radius: 8px;
}
.sim-col { flex: 1; display: flex; flex-direction: column; }
.sim-bar-auto { background: var(--primary-light); border: 1px dashed var(--primary); border-bottom: none; width: 100%; transition: flex-grow 0.3s; }
.sim-bar-user { background: var(--primary); width: 100%; transition: flex-grow 0.3s; }
.sim-label { font-size: 0.6rem; text-align: center; margin-top: 4px; color: var(--text-muted); flex-shrink: 0; }

/* --- Utilities --- */
.toast {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(100px);
    background: var(--success); color: white; padding: 10px 20px; border-radius: 30px;
    font-size: 0.85rem; font-weight: 600; opacity: 0; transition: 0.3s cubic-bezier(0.16, 1, 0.3, 1); z-index: 50;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.scrollable { overflow-y: auto; flex: 1; min-height: 0; }
.hidden { display: none !important; }