/* Общие стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --text-color: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Навигация */
.navbar {
    background: var(--surface-color);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
}

.nav-brand a {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    text-decoration: none;
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    flex-direction: column;
    gap: 4px;
}

.nav-toggle span {
    width: 25px;
    height: 3px;
    background: var(--text-color);
    border-radius: 3px;
    transition: all 0.3s;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav-menu a {
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s;
}

.nav-menu a:hover {
    color: var(--primary-color);
}

/* Контейнер */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    width: 100%;
}

main.container {
    flex: 1;
    padding: 2rem 1rem;
}

/* Карточки */
.card {
    background: var(--surface-color);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.card-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
}

/* Кнопки */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.3s;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: #1d4ed8;
}

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

.btn-success:hover {
    background: #059669;
}

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

.btn-danger:hover {
    background: #dc2626;
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
}

/* Таблицы */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface-color);
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background: var(--background-color);
    font-weight: 600;
    color: var(--text-color);
}

tr:hover {
    background: var(--background-color);
}

/* Статусы */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

.badge-secondary {
    background: #f1f5f9;
    color: #475569;
}

/* Формы */
.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-color);
}

input, select, textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.3s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

/* Сетка */
.grid {
    display: grid;
    gap: 1.5rem;
}

.grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.grid-3 {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.grid-4 {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

/* Дашборд */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* Детали */
.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.detail-label {
    font-weight: 500;
    color: var(--text-secondary);
}

.detail-value {
    color: var(--text-color);
}

/* Предупреждение о низком остатке */
.alert {
    padding: 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border-left: 4px solid var(--warning-color);
}

.alert-danger {
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid var(--danger-color);
}

/* Footer */
.footer {
    background: var(--surface-color);
    padding: 2rem 0;
    margin-top: auto;
    text-align: center;
    color: var(--text-secondary);
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.1);
}

/* Мобильные карточки для таблиц */
.mobile-card {
    display: block;
}

/* Переключатель вида */
.view-toggle {
    display: inline-flex;
    gap: 0.5rem;
    background: var(--background-color);
    padding: 0.25rem;
    border-radius: 6px;
}

.view-toggle-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.view-toggle-btn:hover {
    background: var(--surface-color);
    color: var(--text-color);
}

.view-toggle-btn.active {
    background: var(--surface-color);
    color: var(--primary-color);
    font-weight: 600;
    box-shadow: var(--shadow);
}

/* Вид списком */
.list-view {
    display: none;
}

.list-view.active {
    display: block;
}

.list-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface-color);
    transition: all 0.2s;
    cursor: pointer;
    position: relative;
}

.list-item:hover {
    background: var(--background-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.list-item:active {
    background: var(--border-color);
}

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

.list-item-icon {
    font-size: 1.5rem;
    margin-right: 0.75rem;
    width: 35px;
    text-align: center;
    flex-shrink: 0;
}

.list-item-content {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.list-item-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-subtitle {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-meta {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    font-size: 0.8125rem;
}

.list-item-meta-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-secondary);
}

.list-item-actions {
    display: none;
}

.list-item-arrow {
    margin-left: 0.5rem;
    color: var(--text-secondary);
    font-size: 1.25rem;
    flex-shrink: 0;
}

/* Dropdown меню действий */
.actions-dropdown {
    position: relative;
    display: inline-block;
}

.actions-btn {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.actions-dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background: var(--surface-color);
    min-width: 160px;
    box-shadow: var(--shadow-lg);
    border-radius: 6px;
    z-index: 100;
    overflow: hidden;
}

.actions-dropdown.active .actions-dropdown-content {
    display: block;
}

.actions-dropdown-content a,
.actions-dropdown-content button {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    text-align: left;
    border: none;
    background: none;
    cursor: pointer;
    text-decoration: none;
    color: var(--text-color);
    transition: background 0.2s;
}

.actions-dropdown-content a:hover,
.actions-dropdown-content button:hover {
    background: var(--background-color);
}

/* Адаптивность для планшетов */
@media (max-width: 768px) {
    .nav-toggle {
        display: flex;
    }

    .nav-menu {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--surface-color);
        flex-direction: column;
        padding: 0;
        box-shadow: var(--shadow-lg);
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease-in-out;
        gap: 0;
    }

    .nav-menu li {
        border-bottom: 1px solid var(--border-color);
    }

    .nav-menu li:last-child {
        border-bottom: none;
    }

    .nav-menu a {
        display: block;
        padding: 1rem 1.5rem;
    }

    .nav-menu.active {
        max-height: 600px;
    }

    .nav-toggle.active span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }

    .nav-toggle.active span:nth-child(2) {
        opacity: 0;
    }

    .nav-toggle.active span:nth-child(3) {
        transform: rotate(-45deg) translate(7px, -7px);
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-value {
        font-size: 2rem;
    }

    .card {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .card-title {
        font-size: 1.25rem;
    }

    /* Модальные окна на планшетах */
    .modal-content {
        width: 95%;
    }

    /* Формы на планшетах */
    input, select, textarea {
        font-size: 16px; /* Предотвращает зум на iOS */
    }
}

/* Адаптивность для смартфонов */
@media (max-width: 640px) {
    /* Основные отступы */
    main.container {
        padding: 1rem 0.75rem;
    }

    .navbar .container {
        padding: 0.75rem;
    }

    /* Статистика в одну колонку */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem;
        text-align: left;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .stat-info {
        flex: 1;
    }

    .stat-value {
        font-size: 1.75rem;
        margin-bottom: 0.25rem;
    }

    .stat-label {
        font-size: 0.875rem;
        margin: 0;
    }

    .stat-card .btn {
        width: auto;
        margin: 0;
    }

    /* Скрываем таблицы, показываем карточки */
    .table-responsive {
        display: none;
    }

    .mobile-card {
        display: block;
    }

    .mobile-card-item {
        background: var(--surface-color);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 1rem;
        margin-bottom: 0.75rem;
    }

    .mobile-card-header {
        display: flex;
        justify-content: space-between;
        align-items: start;
        margin-bottom: 0.75rem;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid var(--border-color);
    }

    .mobile-card-title {
        font-weight: 600;
        font-size: 1.125rem;
        color: var(--text-color);
        flex: 1;
        margin-right: 0.5rem;
    }

    .mobile-card-body {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .mobile-card-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.25rem 0;
    }

    .mobile-card-label {
        font-size: 0.875rem;
        color: var(--text-secondary);
        font-weight: 500;
    }

    .mobile-card-value {
        font-size: 0.875rem;
        color: var(--text-color);
        text-align: right;
    }

    .mobile-card-actions {
        display: flex;
        gap: 0.5rem;
        margin-top: 0.75rem;
        padding-top: 0.75rem;
        border-top: 1px solid var(--border-color);
    }

    .mobile-card-actions .btn {
        flex: 1;
        padding: 0.625rem 0.75rem;
        font-size: 0.875rem;
        margin: 0;
        width: auto;
        text-align: center;
    }

    /* Кнопки на мобильных */
    .btn {
        padding: 0.625rem 1rem;
        font-size: 0.9375rem;
        touch-action: manipulation;
    }

    .btn-sm {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    /* Карточки */
    .card {
        padding: 0.875rem;
        border-radius: 8px;
    }

    .card-title {
        font-size: 1.125rem;
    }
    
    /* Форма фильтра */
    .filter-form > div {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    
    .filter-form .form-group {
        min-width: 100% !important;
        flex: none !important;
        margin-bottom: 0.75rem !important;
    }
    
    .filter-form .btn {
        width: 100%;
    }
    
    /* Переключатели графиков */
    .view-toggle {
        gap: 0.25rem;
        flex-wrap: wrap;
    }
    
    .view-toggle-btn {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }

    /* Формы */
    .form-group {
        margin-bottom: 1rem;
    }

    label {
        font-size: 0.9375rem;
        margin-bottom: 0.375rem;
    }

    input, select, textarea {
        padding: 0.625rem;
        font-size: 16px; /* Предотвращает зум на iOS */
    }

    /* Модальные окна - полноэкранные */
    .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        animation: modalSlideUp 0.3s ease-out;
    }

    @keyframes modalSlideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

    .modal-content form {
        padding: 1rem;
        max-height: calc(100vh - 140px);
        overflow-y: auto;
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-header h2 {
        font-size: 1.125rem;
    }

    .modal-footer {
        padding: 1rem;
        margin: 0;
        position: sticky;
        bottom: 0;
        background: var(--surface-color);
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .modal-footer .btn:last-child {
        margin-bottom: 0;
    }

    /* Детальные страницы */
    .detail-row {
        flex-direction: column;
        align-items: flex-start;
        padding: 0.625rem 0;
        gap: 0.25rem;
    }

    .detail-label {
        font-size: 0.875rem;
    }

    .detail-value {
        font-size: 1rem;
        font-weight: 500;
    }

    /* Вкладки */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0;
    }

    .tab-btn {
        padding: 0.75rem 1rem;
        font-size: 0.9375rem;
        white-space: nowrap;
        min-width: fit-content;
    }

    /* Badges */
    .badge {
        font-size: 0.8125rem;
        padding: 0.25rem 0.625rem;
    }

    /* Навигация - увеличенные области нажатия */
    .nav-menu a {
        font-size: 1rem;
        padding: 1.125rem 1.5rem;
    }

    /* Footer */
    .footer {
        padding: 1.5rem 0;
        font-size: 0.875rem;
    }

    /* Скрываем элементы на мобильных */
    .hide-mobile {
        display: none !important;
    }

    /* Переключатель вида на мобильных */
    .view-toggle {
        width: 100%;
        justify-content: center;
    }

    /* Список на мобильных */
    .list-item {
        padding: 0.625rem 0.75rem;
    }

    .list-item-icon {
        font-size: 1.25rem;
        width: 30px;
    }

    .list-item-meta {
        gap: 0.5rem;
    }

    .list-item-meta-item {
        font-size: 0.75rem;
    }

    .list-item-arrow {
        font-size: 1rem;
    }
}

/* Адаптивность для очень маленьких экранов */
@media (max-width: 360px) {
    .navbar .container {
        padding: 0.5rem;
    }

    .nav-brand a {
        font-size: 1.25rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .mobile-card-item {
        padding: 0.75rem;
    }

    .card {
        padding: 0.75rem;
    }

    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
}

/* Анимации HTMX */
.htmx-swapping {
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

.htmx-settling {
    opacity: 1;
}

/* Вкладки */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 0;
    background: var(--background-color);
}

.tab-btn {
    padding: 1rem 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.3s;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.tab-btn:hover {
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: var(--surface-color);
}

.tab-content {
    display: none;
}

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

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

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface-color);
    border-radius: 8px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.3s;
}

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

.modal-content form {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    margin-top: 1rem;
    flex-wrap: wrap;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    max-height: calc(90vh - 180px);
}

/* Детальная информация в модальном окне */
.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
    gap: 1rem;
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
    flex-shrink: 0;
}

.detail-value {
    color: var(--text-color);
    font-size: 0.875rem;
    text-align: right;
    word-wrap: break-word;
}

/* Утилиты */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.flex {
    display: flex;
}

.flex-wrap {
    flex-wrap: wrap;
}

.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* Графики */
canvas {
    max-width: 100%;
    height: auto !important;
}

.card canvas {
    margin: 1rem 0;
}

@media (max-width: 768px) {
    canvas {
        max-height: 250px !important;
    }
    
    .grid-2 {
        grid-template-columns: 1fr;
    }
}
