/* CNC Simulator Styles */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-panel: #0f3460;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --accent-green: #4ade80;
    --accent-red: #f87171;
    --accent-yellow: #fbbf24;
    --accent-blue: #60a5fa;
    --border-color: #334155;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

#app {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 100vh;
}

/* Верхняя панель */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.top-bar h1 {
    font-size: 1.5rem;
    color: var(--accent-blue);
}

.status-indicators {
    display: flex;
    gap: 15px;
}

.status-indicator {
    padding: 5px 12px;
    border-radius: 4px;
    background: var(--bg-panel);
    font-size: 0.9rem;
}

.status-indicator.emergency {
    background: var(--accent-red);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.progress-display {
    display: flex;
    align-items: center;
    gap: 10px;
}

.progress-bar {
    width: 150px;
    height: 20px;
    background: var(--bg-panel);
    border-radius: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-green));
    transition: width 0.3s ease;
}

/* Основная область */
.main-content {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 10px;
    padding: 10px;
    overflow: hidden;
}

/* Панель визуализации */
.visualization-panel {
    position: relative;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
}

#cnc-3d-view {
    width: 100%;
    height: 100%;
}

.view-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.view-controls button {
    padding: 8px 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.view-controls button:hover {
    background: var(--accent-blue);
}

.coordinate-display {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px;
    border-radius: 4px;
    font-family: 'Consolas', monospace;
}

.coord-row {
    display: flex;
    gap: 10px;
}

.coord-row span:first-child {
    color: var(--accent-blue);
    font-weight: bold;
}

/* Панель управления */
.control-panel {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 15px;
    overflow-y: auto;
}

.mode-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
}

.mode-tab {
    flex: 1;
    padding: 10px;
    background: var(--bg-panel);
    border: none;
    color: var(--text-primary);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.mode-tab.active {
    background: var(--accent-blue);
}

.mode-tab:hover:not(.active) {
    background: var(--border-color);
}

.control-section {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.control-section:last-child {
    border-bottom: none;
}

.control-section h3 {
    margin-bottom: 10px;
    color: var(--accent-blue);
    font-size: 1rem;
}

.button-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

/* Кнопки */
button {
    cursor: pointer;
    font-family: inherit;
}

.btn-power {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    font-size: 1rem;
    transition: transform 0.1s, opacity 0.2s;
}

.btn-power:active {
    transform: scale(0.98);
}

.btn-green {
    background: var(--accent-green);
    color: #000;
}

.btn-red {
    background: var(--accent-red);
    color: #000;
}

.btn-blue {
    background: var(--accent-blue);
    color: #000;
}

.btn-yellow {
    background: var(--accent-yellow);
    color: #000;
}

.btn-gray {
    background: var(--border-color);
    color: var(--text-primary);
}

.btn-emergency {
    width: 100%;
    max-width: 120px;
    padding: 6px;
    background: #dc2626;
    border: 2px solid #991b1b;
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
    border-radius: 50%;
    aspect-ratio: 1;
    margin: 10px auto;
    display: block;
    cursor: pointer;
    transition: transform 0.1s;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.4);
}

.btn-emergency:active {
    transform: scale(0.95);
}

.btn-emergency.active {
    background: #991b1b;
    animation: none;
}

.btn-emergency-reset {
    width: 100%;
    padding: 10px;
    background: var(--border-color);
    border: 1px solid var(--accent-red);
    color: var(--accent-red);
    border-radius: 4px;
}

/* Ручное управление */
.jog-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.axis-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.axis-label {
    font-weight: bold;
    color: var(--accent-blue);
}

.btn-jog {
    width: 50px;
    height: 50px;
    background: var(--bg-panel);
    border: 2px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    font-size: 1.2rem;
    transition: background 0.2s;
}

.btn-jog:hover {
    background: var(--accent-blue);
}

.btn-jog:active {
    background: var(--accent-green);
}

.feed-control, .spindle-control {
    margin-bottom: 15px;
}

.feed-control label, .spindle-control label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-secondary);
}

input[type="range"] {
    width: 100%;
    margin-bottom: 10px;
}

.btn-small {
    padding: 5px 10px;
    margin-right: 5px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 4px;
}

/* Редактор кода */
#gcode-editor {
    width: 100%;
    height: 200px;
    background: #0d1117;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: 'Consolas', monospace;
    font-size: 0.9rem;
    padding: 10px;
    resize: vertical;
    border-radius: 4px;
}

.editor-buttons {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.editor-buttons button {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 4px;
}

.code-status {
    margin-top: 10px;
    padding: 10px;
    border-radius: 4px;
    font-family: 'Consolas', monospace;
    font-size: 0.85rem;
}

.code-status.success {
    background: rgba(74, 222, 128, 0.2);
    color: var(--accent-green);
}

.code-status.error {
    background: rgba(248, 113, 113, 0.2);
    color: var(--accent-red);
}

/* Автоматический режим */
.auto-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.btn-large {
    padding: 15px;
    font-weight: bold;
    border: none;
    border-radius: 6px;
}

.single-block-control {
    margin-bottom: 15px;
}

.single-block-control label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.override-controls {
    margin-bottom: 15px;
}

.override-controls label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-secondary);
}

.program-progress {
    margin-top: 10px;
}

.program-progress label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-secondary);
}

#program-line {
    display: block;
    margin-top: 5px;
    font-family: 'Consolas', monospace;
    color: var(--accent-blue);
}

/* Инструмент и заготовка */
.tool-workpiece-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
}

.tool-workpiece-controls button {
    padding: 10px;
    border: none;
    border-radius: 4px;
}

.info-display {
    background: var(--bg-panel);
    padding: 10px;
    border-radius: 4px;
    font-family: 'Consolas', monospace;
    font-size: 0.85rem;
}

.info-display div {
    margin-bottom: 5px;
}

/* Обучающая панель */
.training-panel {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 10px 20px;
    overflow-y: auto;
    position: relative;
}

.resize-handle {
    position: absolute;
    left: 0;
    right: 0;
    height: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: ns-resize;
    z-index: 10;
}

.resize-handle-top {
    top: -6px;
}

.resize-handle-bottom {
    bottom: -6px;
}

.resize-handle span {
    display: flex;
    gap: 3px;
    color: var(--text-secondary);
    font-size: 12px;
    opacity: 0.5;
    transition: opacity 0.2s, color 0.2s;
}

.resize-handle:hover span {
    opacity: 1;
    color: var(--accent-blue);
}

.resize-handle:hover {
    background: rgba(96, 165, 250, 0.1);
}

.resize-handle.active span {
    color: var(--accent-green);
    opacity: 1;
}

.training-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 10px;
}

.training-header h2 {
    color: var(--accent-blue);
    font-size: 1.1rem;
}

.module-selector {
    display: flex;
    gap: 5px;
}

.module-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background: var(--bg-panel);
    color: var(--text-primary);
    font-weight: bold;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.module-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}

.module-btn.completed {
    background: var(--accent-green);
    border-color: var(--accent-green);
}

.training-content {
    background: var(--bg-panel);
    padding: 12px 15px;
    border-radius: 6px;
    margin-bottom: 10px;
    min-height: 60px;
    max-height: 120px;
    overflow-y: auto;
    font-size: 0.9rem;
}

.training-content h3 {
    color: var(--accent-blue);
    margin-bottom: 8px;
    font-size: 1rem;
}

.training-content p {
    margin-bottom: 8px;
    line-height: 1.4;
}

.training-content ol, .training-content ul {
    margin-left: 15px;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.training-content li {
    margin-bottom: 3px;
}

.task-list {
    background: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-radius: 4px;
    margin-top: 8px;
}

.task-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
    padding: 6px 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    font-size: 0.85rem;
}

.task-item.completed {
    opacity: 0.6;
    text-decoration: line-through;
}

.task-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.hint-box {
    background: rgba(96, 165, 250, 0.2);
    border-left: 3px solid var(--accent-blue);
    padding: 8px 12px;
    margin-top: 10px;
    border-radius: 0 4px 4px 0;
    font-size: 0.85rem;
}

.warning-box {
    background: rgba(251, 191, 36, 0.2);
    border-left: 3px solid var(--accent-yellow);
    padding: 8px 12px;
    margin-top: 10px;
    border-radius: 0 4px 4px 0;
    font-size: 0.85rem;
}

.training-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-nav {
    padding: 8px 16px;
    background: var(--accent-blue);
    border: none;
    border-radius: 4px;
    color: #000;
    font-weight: bold;
    font-size: 0.85rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn-nav:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#step-indicator {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Модальные окна */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.hidden {
    display: none;
}

.modal-dialog {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-dialog h3 {
    color: var(--accent-blue);
    margin-bottom: 15px;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.modal-buttons button {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
}

/* Уведомления */
.notifications {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.notification {
    padding: 15px 20px;
    border-radius: 6px;
    background: var(--bg-panel);
    border-left: 4px solid var(--accent-blue);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
    max-width: 350px;
}

.notification.success {
    border-left-color: var(--accent-green);
}

.notification.error {
    border-left-color: var(--accent-red);
}

.notification.warning {
    border-left-color: var(--accent-yellow);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Отображение ошибок */
.error-display {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent-red);
    color: #000;
    padding: 15px 25px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 4px 20px rgba(248, 113, 113, 0.4);
    z-index: 1001;
}

.error-display.hidden {
    display: none;
}

#error-dismiss {
    background: none;
    border: none;
    color: #000;
    font-size: 1.2rem;
    cursor: pointer;
}

/* Скрытые элементы */
.hidden {
    display: none !important;
}

/* Адаптивность */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .control-panel {
        max-height: 500px;
    }
}

/* Скроллбар */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-blue);
}
