/* ===== CSS Variables & Themes ===== */
:root {
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #555770;
    --text-muted: #8b8da3;
    --accent: #4361ee;
    --accent-hover: #3a56d4;
    --accent-light: rgba(67, 97, 238, 0.1);
    --danger: #e63946;
    --danger-hover: #c62828;
    --success: #2a9d8f;
    --success-hover: #238b7e;
    --warning: #f4a261;
    --warning-hover: #e08c3a;
    --border: #e0e4e8;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.3s ease;
}

[data-theme="dark"] {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-input: #1a1a2e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --text-muted: #6c6c80;
    --accent: #6c83f7;
    --accent-hover: #5a73e8;
    --accent-light: rgba(108, 131, 247, 0.15);
    --border: #2a2a40;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.4);
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
        sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition:
        background var(--transition),
        color var(--transition);
    line-height: 1.5;
}

/* ===== Header ===== */
header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.header-top h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.shift-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--accent-light);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
}

.shift-time {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* ===== Tab Navigation ===== */
.tab-nav {
    display: flex;
    gap: 4px;
    padding: 0 12px 10px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.tab-nav::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    flex-shrink: 0;
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.tab-btn:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.tab-btn.active {
    background: var(--accent);
    color: #ffffff;
}

/* ===== Tab Content ===== */
.tab-content {
    display: none;
    padding: 16px;
    max-width: 600px;
    margin: 0 auto;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Machine Panel ===== */
.machine-panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.machine-header {
    background: var(--accent);
    color: #ffffff;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.machine-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.machine-badge {
    font-size: 0.8rem;
    opacity: 0.8;
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 10px;
    border-radius: 12px;
}

.machine-body {
    padding: 20px;
}
/* ===== Forms ===== */
.form-group {
    margin-bottom: 14px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition:
        border-color var(--transition),
        box-shadow var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

/* ===== Autocomplete ===== */
.autocomplete-wrapper {
    position: relative;
}

.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    max-height: 200px;
    overflow-y: auto;
    z-index: 50;
    box-shadow: var(--shadow-lg);
    display: none;
}

.autocomplete-list.show {
    display: block;
}

.autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border);
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: var(--accent-light);
    color: var(--accent);
}

/* ===== Buttons ===== */
.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.btn {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-primary {
    background: var(--accent);
    color: #ffffff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-success {
    background: var(--success);
    color: #ffffff;
}

.btn-success:hover {
    background: var(--success-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-warning {
    background: var(--warning);
    color: #ffffff;
}

.btn-warning:hover {
    background: var(--warning-hover);
}

.btn-danger {
    background: var(--danger);
    color: #ffffff;
    flex: 0;
    padding: 6px 10px;
    font-size: 0.8rem;
}

.btn-danger:hover {
    background: var(--danger-hover);
}

/* Time Info Bars*/
.time-info {
    margin: 16px 0;
    display: flex;
    gap: 8px;
}

.available-time {
    background: rgba(42, 157, 143, 0.1);
    border: 1px solid var(--success);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 0.85rem;
    font-weight: 480;
    color: var(--success);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
}

.total-downtime-bar {
    background: var(--accent-light);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 0.85rem;
    font-weight: 480;
    color: var(--accent);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
}

.time-value {
    font-size: 1.1rem;
    font-weight: 800;
}

/* ===== Results Panel ===== */
.results-panel {
    margin-top: 20px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    animation: fadeIn 0.4s ease;
}

.result-card {
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
    border: 1px solid var(--border);
}

.result-card.highlight {
    background: var(--accent-light);
    border-color: var(--accent);
}

.result-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 4px;
    transition: color 0.3s ease;
}

.result-value:hover {
    color: var(--success);
}

.result-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== Downtime Section ===== */
.downtime-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.downtime-section h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.downtime-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.downtime-form select {
    flex: 1;
    min-width: 140px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
}

.downtime-form input {
    flex: 1;
    min-width: 100px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
}

.downtime-form input::placeholder {
    color: var(--text-muted);
}

.downtime-form .btn {
    padding: 8px 14px;
    font-size: 0.85rem;
    flex: 0;
}

.downtime-log {
    max-height: 250px;
    overflow-y: auto;
}

.downtime-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    border: 1px solid var(--border);
    font-size: 0.85rem;
    animation: fadeIn 0.3s ease;
}

.downtime-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.downtime-type {
    font-weight: 600;
    color: var(--text-primary);
}

.downtime-detail {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.downtime-duration {
    font-weight: 700;
    color: var(--warning);
    margin: 0 10px;
    white-space: nowrap;
}

.downtime-entry .btn-danger {
    flex-shrink: 0;
}

/* Прошедшие простои — приглушенные */
.downtime-entry[data-future="false"] {
    opacity: 0.5;
}

.past-badge {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ===== Tape Calculator ===== */
.tape-calculator {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.tape-calculator h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text-primary);
}

/* ===== Reference Panel ===== */
.reference-panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.reference-panel h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.reference-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.product-list {
    margin-top: 4px;
}

.product-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    border: 1px solid var(--border);
}

.product-info {
    flex: 1;
    min-width: 0;
}

.product-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.product-details {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 0.9rem;
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--danger);
}

.modal form,
.modal-body {
    padding: 24px;
}

/* ===== Section Divider ===== */
.section-divider {
    margin: 20px 0;
    border: none;
    border-top: 1px dashed var(--border);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Notification ===== */
.notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 1000;
    transition: transform 0.4s ease;
    border-left: 4px solid var(--accent);
    max-width: 90vw;
    text-align: center;
}

.notification.show {
    transform: translateX(-50%) translateY(0);
}

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

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

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .header-top h1 {
        font-size: 1.1rem;
    }

    .time-info {
        gap: 6px;
    }

    .available-time,
    .total-downtime-bar {
        padding: 8px 10px;
        font-size: 0.78rem;
    }

    .time-info .time-value {
        font-size: 0.95rem;
    }
    .tab-btn {
        padding: 7px 12px;
        font-size: 0.82rem;
    }

    .results-panel {
        gap: 8px;
        /*grid-template-columns: 1fr;*/
    }
    .result-card {
        padding: 8px 8px;
    }
    .result-value {
        font-size: 1.2rem;
    }
    .result-label {
        font-size: 0.7rem;
    }

    /*.form-row {
        grid-template-columns: 1fr;
    }*/

    .machine-body {
        padding: 16px;
        max-width: 480px;
    }

    .downtime-form {
        flex-direction: column;
    }

    .downtime-form select,
    .downtime-form input {
        min-width: 100%;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    .shift-indicator {
        font-size: 0.78rem;
        padding: 5px 10px;
    }
}
/* ===== Items Calculator Results ===== */
.items-calc-results {
    margin-top: 16px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.items-calc-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    border: 1px solid var(--border);
}

.items-calc-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.items-calc-value {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--accent);
}

.items-calc-value.highlight {
    color: var(--success);
}

/* Секция с разбивкой по паллетам/коробкам */
.items-calc-section {
    margin-top: 14px;
    padding: 12px;
    background: var(--accent-light);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
}

.items-calc-section-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    text-align: center;
}

/* Кнопка обновления */
.refresh-btn {
    background: var(--accent-light);
    border: 1px solid var(--accent);
    color: var(--accent);
    font-size: 1.3rem;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    line-height: 1;
    flex-shrink: 0;
}

.refresh-btn:hover {
    background: var(--accent);
    color: #ffffff;
    transform: scale(1.05);
}

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