:root {
    --color-primary: #1a73e8;
    --color-primary-dark: #1557b0;
    --color-primary-light: #e8f0fe;
    --color-accent: #00bcd4;
    --color-accent-dark: #008c9e;
    --color-success: #34a853;
    --color-warning: #fbbc04;
    --color-danger: #ea4335;
    --color-bg: #f5f7fa;
    --color-surface: #ffffff;
    --color-text: #1f2937;
    --color-text-secondary: #6b7280;
    --color-border: #e5e7eb;
    --color-cyan: #00bcd4;
    --color-magenta: #e91e63;
    --color-yellow: #ffc107;
    --color-black-ink: #37474f;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --transition: 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 2rem;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-left .logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-left .logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
}

.header-center nav {
    display: flex;
    gap: 0.25rem;
}

.nav-link {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--color-text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    transition: var(--transition);
}

.nav-link:hover {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.nav-link.active {
    background: var(--color-primary);
    color: white;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

/* Spectro status */
.spectro-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

#btnSpectroReconnect {
    padding: 0.15rem 0.45rem;
    font-size: 0.75rem;
    line-height: 1;
    min-width: auto;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.connected {
    background: var(--color-success);
    box-shadow: 0 0 6px var(--color-success);
}

.status-dot.disconnected {
    background: var(--color-danger);
}

.status-dot.reading {
    background: var(--color-warning);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Language switcher */
.lang-switcher {
    display: flex;
    gap: 0.25rem;
}

.lang-btn {
    background: none;
    border: 2px solid transparent;
    border-radius: 6px;
    padding: 0.25rem 0.4rem;
    cursor: pointer;
    font-size: 1.3rem;
    transition: var(--transition);
    line-height: 1;
}

.lang-btn:hover {
    background: var(--color-primary-light);
}

.lang-btn.active {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

/* Main content */
.app-main {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem;
}

/* Pages */
.page {
    display: none;
}

.page.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.page-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Cards */
.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.card h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--color-text);
}

/* Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
}

.stat-card.clickable {
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
}

.stat-card.clickable:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-icon {
    font-size: 2rem;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
}

.printer-icon { background: var(--color-primary-light); }
.profile-icon { background: #fce4ec; }
.workflow-icon { background: #e0f7fa; }

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    display: block;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.82rem;
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    border-radius: var(--radius);
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}
.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-dark);
}

.btn-secondary {
    background: var(--color-border);
    color: var(--color-text);
}
.btn-secondary:hover:not(:disabled) {
    background: #d1d5db;
}

.btn-accent {
    background: var(--color-accent);
    color: white;
}
.btn-accent:hover:not(:disabled) {
    background: var(--color-accent-dark);
}

.btn-success {
    background: var(--color-success);
    color: white;
}
.btn-success:hover:not(:disabled) {
    background: #2d9249;
}

.btn-danger {
    background: var(--color-danger);
    color: white;
}
.btn-danger:hover:not(:disabled) {
    background: #c62828;
}

.btn-icon {
    font-size: 1.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
    color: var(--color-text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    transition: var(--transition);
    background: var(--color-surface);
    color: var(--color-text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-select-large {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 2rem;
    width: 90%;
    max-width: 520px;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.modal-header h3 {
    margin-bottom: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-text-secondary);
    padding: 0.25rem;
}

/* Printers grid */
.printers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.printer-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--color-primary);
    transition: var(--transition);
}

.printer-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.printer-card h4 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.printer-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    margin-bottom: 0.75rem;
}

.printer-meta .tag {
    background: var(--color-primary-light);
    color: var(--color-primary);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.8rem;
}

.printer-profile {
    font-size: 0.85rem;
    padding: 0.5rem;
    background: #e8f5e9;
    border-radius: var(--radius-sm);
    color: var(--color-success);
    margin-bottom: 0.75rem;
}

.printer-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* Workflow steps indicator */
.workflow-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.wf-step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    transition: var(--transition);
    opacity: 0.5;
}

.wf-step.active {
    opacity: 1;
    background: var(--color-primary-light);
}

.wf-step.completed {
    opacity: 1;
}

.wf-step-num {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.wf-step.active .wf-step-num {
    background: var(--color-primary);
    color: white;
}

.wf-step.completed .wf-step-num {
    background: var(--color-success);
    color: white;
}

.wf-step-label {
    font-weight: 600;
    font-size: 0.85rem;
}

.wf-step-line {
    width: 40px;
    height: 2px;
    background: var(--color-border);
    flex-shrink: 0;
}

/* Workflow panels */
.workflow-panel {
    display: none;
}

.workflow-panel.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

.choice-buttons {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    margin: 2rem 0;
}

.workflow-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 1rem 0;
}

.wf-action-step {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--color-bg);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--color-primary);
    transition: var(--transition);
}

.wf-action-step.disabled {
    opacity: 0.5;
    border-left-color: var(--color-border);
}

.wf-action-step.done {
    border-left-color: var(--color-success);
    background: #e8f5e9;
}

.wf-action-num {
    font-weight: 700;
    color: var(--color-primary);
    min-width: 2rem;
}

.wf-action-step .btn {
    margin-left: auto;
}

/* Results */
.result-row {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--color-border);
}

.result-row:last-child {
    border-bottom: none;
}

.profile-result {
    margin: 1rem 0;
}

/* Profiles grid */
.profiles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.profile-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--color-accent);
}

.profile-card.active-profile {
    border-left-color: var(--color-success);
}

.profile-card h4 {
    margin-bottom: 0.5rem;
}

.profile-delta {
    display: flex;
    gap: 2rem;
    font-size: 0.85rem;
    margin: 0.75rem 0;
}

.delta-value {
    text-align: center;
}

.delta-value strong {
    display: block;
    font-size: 1.3rem;
}

.delta-good { color: var(--color-success); }
.delta-ok { color: var(--color-warning); }
.delta-bad { color: var(--color-danger); }

/* Jobs list */
.jobs-list {
    max-height: 400px;
    overflow-y: auto;
}

.job-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}

.job-item:last-child {
    border-bottom: none;
}

.job-type-badge {
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.job-type-badge.linearization { background: #e3f2fd; color: #1565c0; }
.job-type-badge.ink_limit { background: #fce4ec; color: #c62828; }
.job-type-badge.profiling { background: #e8f5e9; color: #2e7d32; }

.job-status {
    margin-left: auto;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.job-status.completed { background: #e8f5e9; color: var(--color-success); }
.job-status.failed { background: #ffebee; color: var(--color-danger); }
.job-status.pending,
.job-status.processing { background: #fff8e1; color: #f57f17; }

/* Toast */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--color-surface);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--color-primary);
    font-size: 0.9rem;
    animation: slideInRight 0.3s ease;
    max-width: 360px;
}

.toast.success { border-left-color: var(--color-success); }
.toast.error { border-left-color: var(--color-danger); }
.toast.warning { border-left-color: var(--color-warning); }

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Bridge download card */
.bridge-download-card {
    margin-bottom: 1.5rem;
    border-left: 4px solid var(--color-primary, #00bcd4);
}

.bridge-download-desc {
    margin: 0.5rem 0 1rem;
    color: var(--color-text-secondary);
    font-size: 0.9rem;
}

.bridge-steps {
    margin: 0.75rem 0 1rem 1.25rem;
    font-size: 0.9rem;
    line-height: 1.7;
}

.bridge-steps code {
    background: #e2e8f0;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

.bridge-download-warning {
    margin: 0.75rem 0 0;
    padding: 0.6rem 0.75rem;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 6px;
    font-size: 0.85rem;
    color: #92400e;
}

.bridge-url-hint {
    margin: 0.75rem 0 0;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    word-break: break-all;
}

.bridge-url-hint code {
    font-size: 0.72rem;
}

.bridge-download-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

/* Target download panel */
.target-download-panel {
    margin-top: 1rem;
    padding: 1rem;
    background: #ecfdf5;
    border: 1px solid #6ee7b7;
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.target-download-panel p {
    width: 100%;
    margin: 0 0 0.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #065f46;
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* Empty state */
.empty-state {
    text-align: center;
    color: var(--color-text-secondary);
    padding: 2rem;
    font-size: 0.95rem;
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 1rem;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    border-top: 1px solid var(--color-border);
}

/* Chart canvas */
canvas {
    width: 100% !important;
    max-height: 300px;
}

/* Ink limits table */
.ink-limits-table {
    width: 100%;
    border-collapse: collapse;
}

.ink-limits-table th,
.ink-limits-table td {
    padding: 0.6rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.ink-limits-table th {
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: 0.85rem;
}

.ink-bar {
    height: 20px;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.ink-bar-c { background: var(--color-cyan); }
.ink-bar-m { background: var(--color-magenta); }
.ink-bar-y { background: var(--color-yellow); }
.ink-bar-k { background: var(--color-black-ink); }

/* Responsive */
@media (max-width: 768px) {
    .app-header {
        padding: 0 1rem;
        flex-wrap: wrap;
        height: auto;
        padding: 0.75rem 1rem;
    }

    .header-center nav {
        order: 3;
        width: 100%;
        overflow-x: auto;
        padding: 0.5rem 0;
    }

    .workflow-steps {
        overflow-x: auto;
        justify-content: flex-start;
        padding: 1rem;
    }

    .wf-step-label {
        display: none;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .choice-buttons {
        flex-direction: column;
        align-items: center;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}
