/* 
   Mano Pro Simulator - Premium Design System 
   Aesthetic: "Modern Engineering Layout" (Linear/Vercel inspired)
*/

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

:root {
    /* Color Palette - Slate & Indigo */
    --color-bg-app: #f8fafc;
    /* Slate 50 */
    --color-bg-surface: #ffffff;
    /* White */
    --color-bg-sidebar: #f1f5f9;
    /* Slate 100 */
    --color-bg-code: #0f172a;
    /* Slate 900 */

    --color-border: #e2e8f0;
    /* Slate 200 */
    --color-border-hover: #cbd5e1;
    /* Slate 300 */

    --color-text-main: #0f172a;
    /* Slate 900 */
    --color-text-muted: #64748b;
    /* Slate 500 */
    --color-text-inverse: #f8fafc;
    /* Slate 50 */

    --color-primary: #4f46e5;
    /* Indigo 600 */
    --color-primary-hover: #4338ca;
    /* Indigo 700 */
    --color-primary-bg: #eef2ff;
    /* Indigo 50 */

    --color-success: #10b981;
    /* Emerald 500 */
    --color-danger: #ef4444;
    /* Red 500 */
    --color-accent: #f59e0b;
    /* Amber 500 */
    --color-warning-bg: #fef3c7;

    /* Typography */
    --font-ui: 'Inter', -apple-system, sans-serif;
    --font-code: 'JetBrains Mono', monospace;

    /* Spacing & Layout */
    --header-height: 56px;
    /* Slightly compacted header */
    --radius-sm: 6px;
    --radius-md: 8px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Base Reset */
* {
    box-sizing: border-box;
    outline: none;
    -webkit-font-smoothing: antialiased;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-ui);
    background: var(--color-bg-app);
    color: var(--color-text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Header --- */
.app-header {
    height: var(--header-height);
    background: var(--color-bg-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 15px;
    color: var(--color-text-main);
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: transparent;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Blue bubble is now part of the SVG itself */
}

.controls-area {
    display: flex;
    gap: 10px;
}

/* Buttons */
.btn {
    height: 32px;
    /* Smaller/Compacted */
    padding: 0 12px;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid transparent;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
    box-shadow: 0 1px 2px rgba(79, 70, 229, 0.2);
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
    transform: translateY(-1px);
}

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

.btn-outline {
    background: white;
    border-color: var(--color-border);
    color: var(--color-text-main);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: var(--color-bg-app);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(100%);
}

/* --- Tab Navigation --- */
.tab-nav {
    display: flex;
    gap: 24px;
    padding: 0 24px;
    background: var(--color-bg-surface);
    border-bottom: 1px solid var(--color-border);
    height: 44px;
    /* Shorter tab bar */
}

.tab-btn {
    height: 44px;
    background: transparent;
    border: none;
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
    position: relative;
    border-bottom: 2px solid transparent;
    transition: color 0.2s;
}

.tab-btn:hover {
    color: var(--color-primary);
}

.tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
    font-weight: 600;
}

/* --- Workspace Layout --- */
.workspace {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--color-bg-app);
}

.tab-pane {
    position: absolute;
    inset: 0;
    padding: 16px;
    /* Reduced outer padding */
    display: none;
    overflow-y: hidden;
    /* Sim tab shouldn't scroll main body */
}

.tab-pane.active {
    display: block;
    animation: fade 0.2s;
}

@keyframes fade {
    from {
        opacity: 0
    }

    to {
        opacity: 1
    }
}

/* --- Editor Tab --- */
.editor-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 16px;
    height: 100%;
    max-width: 1600px;
    margin: 0 auto;
}

.editor-card {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-toolbar {
    height: 40px;
    background: #fafafa;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 12px;
    color: var(--color-text-muted);
    font-weight: 500;
}

.code-wrapper {
    flex: 1;
    position: relative;
    background: var(--color-bg-code);
}

textarea.code-input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    color: #e2e8f0;
    padding: 16px;
    font-family: var(--font-code);
    font-size: 14px;
    line-height: 1.6;
    resize: none;
}

.status-panel {
    padding: 16px;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.status-header {
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-main);
}

.log-box {
    flex: 1;
    background: #f8fafc;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 10px;
    font-family: var(--font-code);
    font-size: 12px;
    overflow-y: auto;
    color: var(--color-text-muted);
}

.log-message {
    margin-bottom: 4px;
    padding-bottom: 4px;
    border-bottom: 1px dashed #e2e8f0;
}

.log-success {
    color: var(--color-success);
}

.log-error {
    color: var(--color-danger);
}

/* --- Simulator Tab --- */
.sim-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    /* Narrower sidebar: 280px */
    gap: 12px;
    height: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
}

.sim-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    /* Tighter gap */
    height: 100%;
    /* Flex settings to prevent overflow */
    min-height: 0;
    overflow-y: auto;
}

/* Compact Info Cards */
.info-card {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 10px;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.card-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    font-weight: 700;
    margin: 0 0 8px 0;
}

/* Compact Registers */
.reg-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.reg-item {
    background: #f8fafc;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    display: flex;
    flex-direction: column;
}

.reg-name {
    font-size: 9px;
    color: var(--color-text-muted);
    font-weight: 600;
    margin-bottom: 1px;
}

.reg-value {
    font-family: var(--font-code);
    font-size: 13px;
    color: var(--color-text-main);
    font-weight: 600;
}

/* Compact Flags into Single Row */
.flags-grid {
    display: flex;
    gap: 6px;
    justify-content: space-between;
    /* Spread evenly */
}

.flag-item {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: white;
    border: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    color: var(--color-text-muted);
    transition: all 0.2s;
}

.flag-item.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

/* Timing Panel Compact */
.timing-grid {
    display: flex;
    justify-content: space-between;
}

.led-indicator {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #e2e8f0;
    border: 1px solid #cbd5e1;
    color: #94a3b8;
    font-size: 9px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.led-indicator.active {
    background: #4f46e5;
    border-color: #4338ca;
    color: #fff;
    box-shadow: 0 0 6px rgba(79, 70, 229, 0.4);
}

/* --- Memory Card --- */
.mem-card-container {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.mem-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.mem-toolbar {
    height: 48px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    flex-shrink: 0;
}

.mem-actions {
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: space-between;
}

.btn-group {
    background: #e2e8f0;
    padding: 2px;
    border-radius: 6px;
    display: flex;
    gap: 2px;
}

.mem-btn {
    border: none;
    background: transparent;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    border-radius: 4px;
    cursor: pointer;
}

.mem-btn.active {
    background: #fff;
    color: #0f172a;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.mem-input {
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
    font-family: 'JetBrains Mono';
    width: 180px;
    margin-right: 12px;
}

.toggle-switch {
    display: flex;
    align-items: center;
    font-size: 11px;
    color: #475569;
    cursor: pointer;
    gap: 6px;
    white-space: nowrap;
}

.mem-body-wrapper {
    flex: 1;
    overflow: auto;
    background: #fff;
    position: relative;
}

.mem-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-code);
    font-size: 13px;
    /* Slightly larger for readability */
}

.mem-table th {
    text-align: left;
    padding: 10px 14px;
    background: #f8fafc;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-weight: 600;
    position: sticky;
    top: 0;
    opacity: 1;
    z-index: 1;
}

.mem-table td {
    padding: 8px 14px;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text-main);
}

.mem-table tr:hover td {
    background: #f1f5f9;
    cursor: pointer;
}

.mem-table tr.highlight {
    background: var(--color-primary-bg);
    border-left: 3px solid var(--color-primary);
}

.match-highlight {
    background-color: var(--color-warning-bg) !important;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: white;
    width: 800px;
    /* Fixed Table Distortion by increasing width */
    max-height: 80vh;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 16px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
}

.modal-title {
    font-weight: 700;
    font-size: 16px;
}

.modal-close {
    background: none;
    border: none;
    color: #64748b;
    font-size: 20px;
    cursor: pointer;
}

.trace-table-container {
    flex: 1;
    overflow: auto;
    padding: 0;
}

.trace-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'JetBrains Mono';
    font-size: 12px;
}

.trace-table th {
    background: #f1f5f9;
    position: sticky;
    top: 0;
    padding: 10px;
    text-align: left;
    font-weight: 600;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
}

.trace-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #e2e8f0;
    color: #334155;
    white-space: nowrap;
}

.trace-table tr:hover {
    background: #f8fafc;
}

.hidden {
    display: none !important;
}

/* --- Small Button Variant --- */
.btn-sm {
    height: 26px;
    padding: 0 10px;
    font-size: 11px;
}

/* --- I/O Floating Bubble --- */
.io-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--color-primary) 0%, #6366f1 100%);
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4), 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 50;
    transition: all 0.2s ease;
    color: white;
    font-size: 13px;
    font-weight: 700;
    font-family: var(--font-ui);
    padding: 0;
}

.io-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.5), 0 4px 8px rgba(0, 0, 0, 0.15);
}

.io-bubble.has-output {
    animation: pulse-glow 1.5s infinite;
}

@keyframes pulse-glow {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4), 0 2px 4px rgba(0, 0, 0, 0.1);
    }
    50% {
        box-shadow: 0 4px 20px rgba(16, 185, 129, 0.6), 0 2px 4px rgba(0, 0, 0, 0.1);
    }
}

/* --- I/O Floating Modal --- */
.io-floating-modal {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 340px;
    background: var(--color-bg-surface);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 51;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px) scale(0.95);
    transition: all 0.2s ease;
    overflow: hidden;
}

.io-floating-modal.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.io-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--color-primary) 0%, #6366f1 100%);
    color: white;
}

.io-modal-title {
    font-size: 13px;
    font-weight: 600;
}

.io-modal-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.15s;
}

.io-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.io-modal-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.io-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.io-label {
    font-size: 11px;
    color: var(--color-text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.io-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.io-input-field {
    flex: 1;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-code);
    font-size: 14px;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.io-input-field:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.io-queue-display {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f8fafc;
    border-radius: var(--radius-sm);
    font-size: 12px;
}

.io-queue-label {
    color: var(--color-text-muted);
    font-weight: 500;
}

.io-queue-content {
    flex: 1;
    font-family: var(--font-code);
    color: var(--color-primary);
    font-weight: 600;
}

.io-clear-btn {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 11px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.15s;
}

.io-clear-btn:hover {
    background: #e2e8f0;
    color: var(--color-danger);
}

.io-output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.io-output-display {
    min-height: 80px;
    max-height: 120px;
    padding: 12px;
    background: var(--color-bg-code);
    border-radius: var(--radius-sm);
    font-family: var(--font-code);
    font-size: 13px;
    color: #10b981;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.5;
}

.io-output-display:empty::before {
    content: "(no output)";
    color: #475569;
    font-style: italic;
}

/* --- Input Required Modal --- */
.modal-sm {
    width: 400px;
}

.modal-body {
    padding: 20px;
}

.modal-body p {
    margin: 0 0 16px 0;
    color: var(--color-text-muted);
    font-size: 14px;
}

.modal-body .io-input-field {
    width: 100%;
    height: 48px;
    font-size: 20px;
    text-align: center;
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* --- Log Warning --- */
.log-warning {
    color: var(--color-accent);
}
