/* =====================================================
   Materials Registry (Реестр материалов)
   LeanSpace — mat- prefix namespace
   ===================================================== */

/* ---- Wrapper ---- */

.mat-wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 16px 48px;
    box-sizing: border-box;
}

/* ---- Header ---- */

.mat-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.mat-title {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 700;
    color: #111827;
    line-height: 1.3;
}

.mat-subtitle {
    margin: 0;
    font-size: 14px;
    color: #6b7280;
    line-height: 1.5;
}

/* ---- Filter tabs ---- */

.mat-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.mat-filter-btn {
    padding: 6px 16px;
    border-radius: 20px;
    border: 1.5px solid #e5e7eb;
    background: #fff;
    color: #374151;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
    white-space: nowrap;
}

.mat-filter-btn:hover {
    border-color: #3b82f6;
    color: #3b82f6;
    background: #eff6ff;
}

.mat-filter-btn.active {
    background: #3b82f6;
    border-color: #3b82f6;
    color: #fff;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.30);
}

/* ---- Grid ---- */

.mat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    align-items: start;
}

/* ---- Card ---- */

.mat-card {
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08), 0 2px 10px rgba(0, 0, 0, 0.05);
    border: 1.5px solid #f1f5f9;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.mat-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.10);
    border-color: #e2e8f0;
}

.mat-card-warn {
    border-left: 3px solid #ef4444;
    border-left-width: 3px;
}

.mat-card-warn:hover {
    border-color: #ef4444;
    border-left-color: #ef4444;
}

/* ---- Card header ---- */

.mat-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.mat-card-title-block {
    flex: 1;
    min-width: 0;
}

.mat-card-name {
    font-size: 15px;
    font-weight: 600;
    color: #111827;
    line-height: 1.35;
    word-break: break-word;
    margin-bottom: 3px;
}

.mat-card-code {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    background: #f3f4f6;
    border-radius: 4px;
    padding: 1px 7px;
    font-family: 'Courier New', monospace;
    letter-spacing: 0.03em;
}

.mat-card-badges {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

/* ---- Badges ---- */

.mat-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    border-radius: 10px;
    padding: 2px 9px;
    white-space: nowrap;
    line-height: 1.6;
}

.mat-badge-warn {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.mat-badge-ok {
    background: #f0fdf4;
    color: #16a34a;
    border: 1px solid #bbf7d0;
}

.mat-badge-type {
    background: #f8fafc;
    color: #475569;
    border: 1px solid #e2e8f0;
}

/* ---- Stock row ---- */

.mat-stock-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mat-stock-info {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.mat-stock-value {
    font-size: 28px;
    font-weight: 700;
    color: #111827;
    line-height: 1;
    letter-spacing: -0.5px;
}

.mat-stock-unit {
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
}

.mat-stock-bar-wrap {
    height: 6px;
    background: #f1f5f9;
    border-radius: 3px;
    overflow: hidden;
}

.mat-stock-bar {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease;
    min-width: 2px;
}

.mat-stock-limits {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #9ca3af;
    line-height: 1.4;
}

/* ---- Card meta section ---- */

.mat-card-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mat-meta-row {
    font-size: 12px;
    color: #6b7280;
    line-height: 1.5;
    word-break: break-word;
}

.mat-location  { color: #6366f1; }
.mat-storage   { color: #0891b2; }
.mat-lead      { color: #d97706; }
.mat-reorder-qty { color: #7c3aed; }

/* ---- Card actions ---- */

.mat-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 4px;
    border-top: 1px solid #f1f5f9;
    margin-top: auto;
}

/* ---- Buttons ---- */

.mat-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 18px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s, box-shadow 0.15s, transform 0.1s;
    line-height: 1;
    white-space: nowrap;
}

.mat-btn:active {
    transform: scale(0.97);
}

.mat-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.mat-btn-primary {
    background: #3b82f6;
    color: #fff;
    box-shadow: 0 1px 4px rgba(59, 130, 246, 0.25);
}

.mat-btn-primary:hover:not(:disabled) {
    background: #2563eb;
    box-shadow: 0 3px 10px rgba(59, 130, 246, 0.35);
}

.mat-btn-secondary {
    background: #fff;
    color: #374151;
    border: 1.5px solid #d1d5db;
}

.mat-btn-secondary:hover:not(:disabled) {
    background: #f9fafb;
    border-color: #9ca3af;
}

.mat-btn-danger {
    background: #fef2f2;
    color: #dc2626;
    border: 1.5px solid #fecaca;
}

.mat-btn-danger:hover:not(:disabled) {
    background: #dc2626;
    color: #fff;
    border-color: #dc2626;
}

.mat-btn-ai {
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
    color: #fff;
    box-shadow: 0 1px 4px rgba(124, 58, 237, 0.25);
}

.mat-btn-ai:hover:not(:disabled) {
    background: linear-gradient(135deg, #6d28d9 0%, #5b21b6 100%);
    box-shadow: 0 3px 10px rgba(124, 58, 237, 0.35);
}

.mat-btn-stock {
    background: #ecfdf5;
    color: #059669;
    border: 1.5px solid #a7f3d0;
    font-weight: 600;
}

.mat-btn-stock:hover:not(:disabled) {
    background: #059669;
    color: #fff;
    border-color: #059669;
}

.mat-btn-sm {
    padding: 5px 12px;
    font-size: 12px;
    border-radius: 6px;
}

.mat-btn-sq {
    padding: 8px 14px;
    font-size: 18px;
    line-height: 1;
    border-radius: 6px;
    flex-shrink: 0;
}

/* ---- Empty / loading states ---- */

.mat-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 56px 24px;
    color: #374151;
}

.mat-empty p {
    margin: 0 0 6px;
}

.mat-empty-hint {
    color: #9ca3af;
    font-size: 14px;
}

.mat-empty-error {
    color: #dc2626;
}

.mat-loading {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 24px;
    color: #9ca3af;
    font-size: 15px;
}

/* ---- Modal overlay ---- */

.mat-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
    backdrop-filter: blur(2px);
}

/* ---- Modal ---- */

.mat-modal {
    background: #fff;
    border-radius: 14px;
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.20);
    animation: matModalIn 0.18s ease;
    overflow: hidden;
}

.mat-modal-sm {
    max-width: 400px;
}

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

.mat-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px 14px;
    border-bottom: 1px solid #f1f5f9;
    flex-shrink: 0;
}

.mat-modal-header h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: #111827;
}

.mat-modal-close {
    background: none;
    border: none;
    font-size: 18px;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}

.mat-modal-close:hover {
    background: #f3f4f6;
    color: #374151;
}

.mat-modal-body {
    padding: 18px 22px;
    overflow-y: auto;
    flex: 1;
}

.mat-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 22px;
    border-top: 1px solid #f1f5f9;
    flex-shrink: 0;
    flex-wrap: wrap;
}

/* ---- Form ---- */

.mat-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 4px;
}

.mat-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.mat-field-wide {
    grid-column: 1 / -1;
}

.mat-field label {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.mat-field input,
.mat-field select,
.mat-field textarea {
    padding: 8px 11px;
    border: 1.5px solid #e5e7eb;
    border-radius: 7px;
    font-size: 14px;
    color: #111827;
    background: #fafafa;
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
    box-sizing: border-box;
    width: 100%;
}

.mat-field input:focus,
.mat-field select:focus,
.mat-field textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
    background: #fff;
}

.mat-field textarea {
    resize: vertical;
    min-height: 64px;
}

.mat-field select {
    cursor: pointer;
    appearance: auto;
}

/* ---- Section title ---- */

.mat-section-title {
    font-size: 13px;
    font-weight: 700;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 20px 0 12px;
    padding-bottom: 7px;
    border-bottom: 1.5px solid #f1f5f9;
}

/* ---- Field hint ---- */

.mat-field-hint {
    font-size: 11px;
    color: #9ca3af;
    margin: 4px 0 0;
    line-height: 1.5;
}

/* ---- Stock adjust modal controls ---- */

.mat-stock-adjust-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

.mat-stock-delta-input {
    flex: 1;
    text-align: center;
    font-size: 20px;
    font-weight: 700;
    padding: 8px 12px !important;
    border: 1.5px solid #e5e7eb;
    border-radius: 7px;
    color: #111827;
    background: #fafafa;
    min-width: 0;
}

.mat-stock-delta-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
    background: #fff;
}

/* =====================================================
   Responsive
   ===================================================== */

@media (max-width: 1024px) {
    .mat-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .mat-wrap {
        padding: 16px 12px 40px;
    }

    .mat-title {
        font-size: 18px;
    }

    .mat-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .mat-header {
        flex-direction: column;
        align-items: stretch;
    }

    .mat-header .mat-btn-primary {
        width: 100%;
    }

    .mat-form-grid {
        grid-template-columns: 1fr;
    }

    .mat-field-wide {
        grid-column: auto;
    }

    .mat-modal {
        max-width: 100%;
        max-height: 95vh;
        border-radius: 14px 14px 0 0;
        margin-top: auto;
    }

    .mat-modal-overlay {
        align-items: flex-end;
        padding: 0;
    }
}

@media (max-width: 480px) {
    .mat-stock-value {
        font-size: 22px;
    }

    .mat-card {
        padding: 13px 12px;
    }

    .mat-card-actions {
        gap: 5px;
    }

    .mat-btn-sm {
        padding: 5px 9px;
        font-size: 11px;
    }

    .mat-filters {
        gap: 6px;
    }

    .mat-filter-btn {
        padding: 5px 12px;
        font-size: 12px;
    }

    .mat-modal-header,
    .mat-modal-body,
    .mat-modal-footer {
        padding-left: 16px;
        padding-right: 16px;
    }
}
