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

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #231f20;
    color: #fffeff;
}

header {
    background: #27245c;
    padding: 0.75rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #ef432b;
}

header h1 { font-size: 1.3rem; color: #efebc5; }

footer {
    background: #27245c;
    padding: 0.4rem 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.6rem;
    border-top: 1px solid #3d3a7a;
    font-size: 0.75rem;
    color: #a9c0c4;
}

.footer-brand {
    font-weight: 700;
    color: #efebc5;
}

.footer-sep {
    color: #3d3a7a;
}

.status-dot {
    width: 12px; height: 12px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.5rem;
}
.status-dot.connected { background: #a9c0c4; }
.status-dot.disconnected { background: #ef432b; }

/* Main 4-column layout */
.main-layout {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 380px;
    gap: 0.75rem;
    padding: 0.75rem;
    height: calc(100vh - 52px - 30px);
    overflow: hidden;
}

/* Each of the 3 actuator columns */
.actuator-column {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Section panel (top or bottom half of a column) */
.section-panel {
    background: #27245c;
    border: 1px solid #3d3a7a;
    border-radius: 8px;
    padding: 0.75rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.section-panel h2 {
    font-size: 0.95rem;
    color: #ef432b;
    text-align: center;
    margin-bottom: 0.6rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid #3d3a7a;
}

/* Actuator control row within a section */
.actuator-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0;
    flex: 1;
}

.actuator-row + .actuator-row {
    border-top: 1px solid #3d3a7a1a;
}

.jog-btn {
    width: 128px;
    height: 112px;
    font-size: 3rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.jog-btn.neg {
    background: #3d3a7a;
    color: #efebc5;
}
.jog-btn.neg:hover { background: #4e4b8f; }
.jog-btn.neg:active { background: #27245c; }

.jog-btn.pos {
    background: #5c7a8a;
    color: #efebc5;
}
.jog-btn.pos:hover { background: #6b8d9e; }
.jog-btn.pos:active { background: #4d6874; }

.position-group {
    flex: 1;
    text-align: center;
    min-width: 0;
}

.position-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: #efebc5;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.actuator-status {
    font-size: 0.65rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 2px;
    padding: 1px 4px;
    border-radius: 3px;
    display: inline-block;
}

.status-ok { color: #a9c0c4; }
.status-fault { color: #ef432b; background: #ef432b1a; }
.status-stall { color: #efebc5; background: #efebc51a; }
.status-limit { color: #a9c0c4; background: #a9c0c41a; }
.status-offline { color: #666; }

/* Sidebar (4th column) */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.sidebar-section {
    background: #27245c;
    border: 1px solid #3d3a7a;
    border-radius: 8px;
    padding: 0.75rem;
}

.sidebar-section h2 {
    font-size: 0.95rem;
    margin-bottom: 0.6rem;
    color: #ef432b;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.action-buttons button {
    width: 100%;
    padding: 1.2rem;
    font-size: 1.2rem;
    min-height: 96px;
    border-radius: 10px;
    touch-action: manipulation;
}

/* Jog step selector */
.jog-step-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.jog-step-group label {
    font-size: 0.8rem;
    color: #a9c0c4;
    white-space: nowrap;
}

.jog-step-group select {
    flex: 1;
    background: #231f20;
    border: 1px solid #3d3a7a;
    color: #fffeff;
    padding: 0.8rem;
    border-radius: 8px;
    font-size: 1.2rem;
    min-height: 64px;
    font-family: 'Space Grotesk', sans-serif;
}

/* Recipe section */
.recipe-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.recipe-actions {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.6rem;
    overflow: hidden;
}

.recipe-actions input[type="text"] {
    flex: 1;
    min-width: 0;
    background: #231f20;
    border: 1px solid #3d3a7a;
    color: #fffeff;
    padding: 0.8rem;
    border-radius: 8px;
    font-size: 1.1rem;
    min-height: 64px;
    font-family: 'Space Grotesk', sans-serif;
}

.recipe-actions button {
    flex-shrink: 0;
}

button {
    background: #ef432b;
    color: #fffeff;
    border: none;
    padding: 0.6rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

button:hover { background: #d63a24; }
button.secondary { background: #3d3a7a; }
button.secondary:hover { background: #4e4b8f; }
button.danger { background: #8b2020; }
button.danger:hover { background: #a72828; }

.recipe-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

.recipe-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 0.5rem;
    border-bottom: 1px solid #3d3a7a;
    transition: background 0.2s;
    min-height: 72px;
}

.recipe-item:hover { background: #231f20; }

.recipe-item .recipe-name {
    font-size: 0.9rem;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 0.5rem;
}

.recipe-item .recipe-btns {
    display: flex;
    gap: 0.3rem;
    flex-shrink: 0;
}

.recipe-item button {
    padding: 0.6rem 0.8rem;
    font-size: 0.95rem;
    min-height: 56px;
}

/* Toast notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
}

.toast {
    background: #27245c;
    border: 1px solid #3d3a7a;
    border-radius: 4px;
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.5rem;
    animation: fadeIn 0.3s;
    max-width: 280px;
    font-size: 0.85rem;
}

.toast.success { border-left: 4px solid #a9c0c4; }
.toast.error { border-left: 4px solid #ef432b; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(1rem); }
    to { opacity: 1; transform: translateX(0); }
}

/* Responsive */
@media (max-width: 1100px) {
    .main-layout {
        grid-template-columns: 1fr 1fr;
        height: auto;
    }
    .sidebar { grid-column: 1 / -1; }
}

@media (max-width: 600px) {
    .main-layout {
        grid-template-columns: 1fr;
    }
}
