* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #f5f7fb;
    color: #222;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
    line-height: 1.5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

.container.narrow {
    max-width: 800px;
}

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

h1 {
    margin: 0 0 6px;
    font-size: 28px;
}

h2 {
    margin: 0;
    font-size: 20px;
}

.subtitle {
    margin: 0;
    color: #666;
    font-size: 14px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.section-subtitle {
    color: #666;
    font-size: 13px;
}

.card,
.item-card {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    margin-bottom: 20px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.summary-card {
    display: block;
    text-decoration: none;
    border-radius: 12px;
    padding: 18px;
    color: #222;
    background: #fff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.summary-label {
    font-size: 13px;
    color: #666;
    margin-bottom: 10px;
}

.summary-value {
    font-size: 30px;
    font-weight: 700;
    line-height: 1;
}

.summary-danger {
    border-left: 5px solid #dc2626;
}

.summary-warning {
    border-left: 5px solid #f59e0b;
}

.summary-low {
    border-left: 5px solid #2563eb;
}

.summary-ok {
    border-left: 5px solid #16a34a;
}

.category-summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.category-summary-card {
    display: block;
    text-decoration: none;
    color: #222;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
}

.category-summary-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.category-summary-title {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.3;
}

.category-summary-total {
    font-size: 13px;
    color: #666;
    white-space: nowrap;
}

.category-summary-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.category-summary-stat {
    background: #fff;
    border-radius: 10px;
    padding: 12px;
    border: 1px solid #eef2f7;
}

.category-summary-stat-label {
    display: block;
    color: #666;
    font-size: 12px;
    margin-bottom: 6px;
}

.category-summary-stat-value {
    display: block;
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
}

.danger-text {
    color: #b91c1c;
}

.low-text {
    color: #1d4ed8;
}

.priority-list {
    display: grid;
    gap: 12px;
}

.priority-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fafcff;
}

.priority-main {
    min-width: 0;
}

.priority-title {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.3;
}

.priority-sub {
    margin-top: 4px;
    color: #666;
    font-size: 13px;
}

.priority-meta {
    text-align: right;
    flex-shrink: 0;
}

.priority-expiry {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
}

.priority-days {
    display: inline-block;
    margin-left: 8px;
    color: #666;
    font-size: 12px;
    font-weight: 400;
}

.shopping-group-card {
    margin-bottom: 20px;
}

.shopping-group-details {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

.shopping-group-summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    cursor: pointer;
    background: #fff;
    border-bottom: 1px solid #eef2f7;
}

.shopping-group-summary::-webkit-details-marker {
    display: none;
}

.shopping-group-summary-main {
    min-width: 0;
}

.shopping-group-title {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 8px;
}

.shopping-group-counts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.shopping-group-toggle {
    color: #666;
    font-size: 13px;
    flex-shrink: 0;
}

.shopping-group-body {
    padding: 20px;
}

.shopping-group-table-card {
    box-shadow: none;
    padding: 0;
    margin-bottom: 0;
}

.shopping-group-mobile {
    margin-bottom: 0;
}

.filter-form .form-row,
.edit-form .form-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

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

label {
    font-size: 14px;
    font-weight: 600;
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cfd6e4;
    border-radius: 8px;
    background: #fff;
    font-size: 14px;
}

textarea {
    resize: vertical;
}

.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.button {
    display: inline-block;
    border: 0;
    border-radius: 8px;
    padding: 10px 14px;
    background: #e6eaf2;
    color: #222;
    text-decoration: none;
    cursor: pointer;
    font-size: 14px;
    text-align: center;
}

.button.primary {
    background: #2563eb;
    color: #fff;
}

.button.secondary {
    background: #eef2f7;
    color: #222;
}

.button.danger {
    background: #dc2626;
    color: #fff;
}

.button.small {
    padding: 7px 10px;
    font-size: 13px;
}

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert.success {
    background: #ecfdf3;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert.error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1100px;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
    vertical-align: top;
    font-size: 14px;
}

th {
    background: #f8fafc;
    font-weight: 700;
}

.badge {
    display: inline-block;
    margin: 2px 6px 2px 0;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.badge.ok {
    background: #ecfdf3;
    color: #166534;
}

.badge.warning {
    background: #fff7ed;
    color: #c2410c;
}

.badge.danger {
    background: #fef2f2;
    color: #b91c1c;
}

.badge.low {
    background: #eff6ff;
    color: #1d4ed8;
}

.inline-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.small-text {
    color: #666;
    font-size: 12px;
    margin-top: 4px;
}

.empty {
    text-align: center;
    color: #777;
    padding: 24px 12px;
}

.mobile-cards {
    display: none;
}

.item-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.item-name {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
}

.item-location {
    color: #666;
    font-size: 13px;
    margin-top: 4px;
}

.item-stock {
    text-align: right;
    flex-shrink: 0;
}

.item-stock-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
}

.item-stock-unit {
    display: block;
    color: #666;
    font-size: 12px;
    margin-top: 4px;
}

.item-status {
    margin-bottom: 14px;
}

.item-meta {
    margin: 0 0 16px;
}

.item-meta-row {
    display: grid;
    grid-template-columns: 90px 1fr;
    gap: 10px;
    padding: 8px 0;
    border-top: 1px solid #eef2f7;
}

.item-meta-row:first-child {
    border-top: 0;
    padding-top: 0;
}

.item-meta dt {
    margin: 0;
    color: #666;
    font-size: 13px;
    font-weight: 600;
}

.item-meta dd {
    margin: 0;
    font-size: 14px;
    word-break: break-word;
}

.mobile-action-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.mobile-action-grid form,
.mobile-action-grid a {
    margin: 0;
}

.mobile-action-button {
    width: 100%;
}

@media (max-width: 900px) {
    .dashboard-grid,
    .category-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {
    .page-header,
    .section-header,
    .shopping-group-summary {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-form .form-row,
    .edit-form .form-row,
    .dashboard-grid,
    .category-summary-grid,
    .category-summary-stats {
        grid-template-columns: 1fr;
    }

    .container {
        padding: 16px;
    }

    .desktop-table {
        display: none;
    }

    .mobile-cards {
        display: block;
    }

    .card,
    .item-card,
    .summary-card,
    .shopping-group-body,
    .category-summary-card {
        padding: 16px;
        border-radius: 10px;
    }

    .shopping-group-summary {
        padding: 16px;
    }

    .item-card-header,
    .priority-item,
    .category-summary-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .item-stock,
    .priority-meta,
    .shopping-group-toggle {
        text-align: left;
    }

    .item-stock-value {
        font-size: 22px;
    }
}