:root {
    --color-primary: #6ea68f;
    --color-primary-dark: #5a9276;
    --color-background: #ffffff;
    --color-background-light: #fafafa;
    --color-border: #e8e8e8;
    --color-text: #222222;
    --color-text-light: #666666;
    --color-text-lighter: #999999;
    --color-error: #e74c3c;
    --color-success: #27ae60;
    --color-warning: #f39c12;
    --spacing-unit: 8px;
    --border-radius: 6px;
    --shadow-small: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-medium: 0 2px 8px rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--color-background-light);
    color: var(--color-text);
    display: flex;
    overflow: visible;
    overscroll-behavior-y: auto;
}

.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* Sidebar Navigation
   Visible by default; responsive rules handle when to hide it.
*/

/* Main Content */
.app-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
}

.app-content__header {
    padding: calc(var(--spacing-unit) * 2) calc(var(--spacing-unit) * 3);
    background: var(--color-background);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    overscroll-behavior: auto;
}

.app-content__title {
    display: inline-flex;
    align-items: center;
    gap: calc(var(--spacing-unit) * 1);
    font-size: 24px;
    font-weight: 600;
    color: var(--color-text);
}

.app-content__logo {
    width: 36px;
    height: 36px;
    display: inline-block;
    object-fit: contain;
    object-position: center;
    border-radius: var(--border-radius);
    background: transparent;
    border: 1px solid var(--color-border);
    flex-shrink: 0;
    padding: 0;
}

.app-content__actions {
    display: flex;
    gap: calc(var(--spacing-unit) * 1.5);
}

.app-content__body {
    flex: 1;
    overflow-y: auto;
    padding: calc(var(--spacing-unit) * 2) calc(var(--spacing-unit) * 3);
    overscroll-behavior: contain;
}

/* Item Editor */
.item-editor {
    background: var(--color-background);
    padding: calc(var(--spacing-unit) * 2);
    border-radius: var(--border-radius);
    margin-bottom: calc(var(--spacing-unit) * 2);
    box-shadow: var(--shadow-small);
    display: flex;
    gap: calc(var(--spacing-unit) * 1.5);
    align-items: center;
}

.hidden {
    display: none !important;
}

.item-editor.hidden {
    display: none;
}

.header-add-item-btn {
    width: 36px;
    height: 36px;
    font-size: 18px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    cursor: pointer;
}

.header-add-item-btn:hover {
    background: var(--color-primary-dark);
}

.item-editor__plus {
    font-size: 24px;
    color: var(--color-primary);
    font-weight: 700;
    line-height: 1;
}

.item-editor__input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 16px;
    color: var(--color-text);
    padding: calc(var(--spacing-unit) * 0.5) 0;
    outline: none;
}

.item-editor__input::placeholder {
    color: var(--color-text-lighter);
}

.item-editor__quantity-unit {
    display: flex;
    gap: calc(var(--spacing-unit) * 1);
    align-items: center;
}

.item-editor__field {
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) * 0.75) calc(var(--spacing-unit) * 1);
    font-size: 14px;
    font-family: inherit;
    min-width: 80px;
}

.item-editor__field--short {
    max-width: 60px;
}

.item-editor__field--medium {
    max-width: 80px;
}

.item-editor__field:focus {
    outline: none;
    border-color: var(--color-primary);
}

.category-picker-wrapper {
    position: relative;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.category-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: auto;
    min-width: 100%;
    max-width: min(420px, calc(100vw - 2rem));
    background: white;
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.category-dropdown.active {
    display: block;
}

.category-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: calc(var(--spacing-unit) * 0.75) calc(var(--spacing-unit) * 1);
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
    box-sizing: border-box;
    white-space: nowrap;
}

.category-picker-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    gap: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: #f3f3f3;
    color: var(--color-text);
    font-size: 14px;
    cursor: pointer;
}

/* Make the hidden edit-category-id take minimal layout space so the
   picker button can align to the right edge of its row. */
.edit-category-id {
    width: 1px;
    min-width: 1px;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    font-size: 0;
    line-height: 0;
    display: inline-block;
    vertical-align: middle;
}

.category-picker-button:hover {
    border-color: var(--color-primary);
    background: #e8ece8;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: none;
    align-items: center;
    justify-content: center;
    padding: calc(var(--spacing-unit) * 2);
    z-index: 2000;
}

.modal-overlay.active {
    display: flex;
}

.category-modal {
    width: min(94vw, 420px);
    max-height: 90vh;
    background: white;
    border-radius: 18px;
    box-shadow: var(--shadow-medium);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.category-modal__header {
    padding: calc(var(--spacing-unit) * 1.25) calc(var(--spacing-unit) * 1.5);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    gap: calc(var(--spacing-unit) * 1);
    align-items: center;
}

.category-modal__input {
    flex: 1;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) * 0.75) calc(var(--spacing-unit) * 1);
    font-size: 14px;
    background: white;
    outline: none;
}

.category-modal__add {
    border: none;
    background: var(--color-primary);
    color: white;
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) * 0.75) calc(var(--spacing-unit) * 1);
    cursor: pointer;
    font-weight: 600;
}

.category-modal__body {
    overflow-y: auto;
    max-height: calc(90vh - 88px);
    background: var(--color-background-light);
}

.category-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: calc(var(--spacing-unit) * 1);
    padding: calc(var(--spacing-unit) * 1) calc(var(--spacing-unit) * 1.25);
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
    background: white;
    transition: background 0.2s, border-color 0.2s;
}

.category-list-item:hover,
.category-list-item.active {
    background: rgba(110, 166, 143, 0.12);
}

.category-list-item.active {
    border-color: transparent;
}

.category-list-item__meta {
    display: inline-flex;
    align-items: center;
    gap: calc(var(--spacing-unit) * 1);
    min-width: 0;
    flex: 1;
}

.category-list-item__color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid var(--color-border);
    background: var(--color-text-lighter);
}

.category-list-item__label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.category-list-item__delete {
    background: none;
    border: none;
    color: var(--color-text-lighter);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 0;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.category-list-item__delete:hover {
    color: var(--color-error);
    opacity: 0.9;
}

.category-picker-button__meta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: calc(var(--spacing-unit) * 1);
    width: 100%;
    height: 100%;
    min-width: 0;
}

.category-picker-button__color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--color-text-lighter);
    border: 1px solid var(--color-border);
}

.category-picker-button__label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    line-height: 1;
}

.category-modal__close {
    background: none;
    border: none;
    color: var(--color-text-light);
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.category-modal__close:hover {
    color: var(--color-text);
}

.category-option:last-child {
    border-bottom: none;
}

.category-option:hover {
    background: var(--color-background-light);
}

.category-option-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.category-option-delete {
    background: none;
    border: none;
    color: var(--color-error);
    cursor: pointer;
    font-size: 18px;
    padding: 0 calc(var(--spacing-unit) * 0.5);
    line-height: 1;
}

.category-option-delete:hover {
    color: var(--color-error);
    opacity: 0.8;
}

.item-editor__submit {
    background: var(--color-primary);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.item-editor__submit:hover {
    background: var(--color-primary-dark);
}

/* Bereichsgruppen */
.area-group {
    margin-bottom: calc(var(--spacing-unit) * 3);
}

.area-header {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing-unit) * 1.5);
    margin-bottom: calc(var(--spacing-unit) * 1.5);
    padding-left: 0;
    cursor: grab;
    user-select: none;
    -webkit-user-drag: element;
}

.area-header__color {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: var(--border-radius);
    background: #f3f3f3;
    border: 1px solid var(--color-border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.area-header__color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.55);
}

.area-header.dragging {
    opacity: 0.6;
    transform: scale(0.98);
    cursor: grabbing;
}

.area-header.drag-over-category {
    outline: 2px dashed rgba(0,0,0,0.12);
    background: rgba(0,0,0,0.03);
}

.area-header__name {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
    flex: 1;
}

.area-header__count {
    background: var(--color-background-light);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-light);
}

.area-header__toggle {
    background: none;
    border: none;
    color: var(--color-text-light);
    cursor: pointer;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    transition: background 0.2s, color 0.2s;
    margin-left: 8px;
    flex-shrink: 0;
    font-size: 16px;
}

.area-header__toggle:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--color-primary);
}

.area-header__icon {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: calc(var(--spacing-unit) * 0.75);
    margin-left: 0;
    color: white;
    background: var(--color-primary);
    border-radius: var(--border-radius);
    flex-shrink: 0;
}

.area-header__icon svg {
    width: 20px;
    height: 20px;
}

/* Items List */
.items-container {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-unit) * 0.5);
}

.item-row {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing-unit) * 1);
    padding: calc(var(--spacing-unit) * 1.25) calc(var(--spacing-unit) * 1.5);
    background: var(--color-background);
    border-radius: var(--border-radius);
    transition: all 0.2s;
    cursor: move;
    border: 1px solid transparent;
}

.item-row--editing {
    background: #e3f2fd;
}

.item-row.dragging {
    opacity: 0.5;
    background: var(--color-background-light);
}

.item-row.drag-over {
    background: #e3f2fd;
    border: 1px solid var(--color-primary);
}

.item-row:hover {
    background: var(--color-background-light);
    box-shadow: var(--shadow-small);
}

.item-row.dragging:hover {
    box-shadow: none;
}

.item-row.checked {
    opacity: 0.6;
}

.item-row.checked .item-row__name {
    text-decoration: line-through;
    color: var(--color-text-light);
}

.item-row__check {
    display: flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.item-row__check input {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--color-primary);
}

.item-row__quantity {
    font-size: 13px;
    color: var(--color-text-light);
    font-weight: 600;
    min-width: 50px;
    flex-shrink: 0;
}

.item-row__name {
    flex: 1;
    font-size: 15px;
    color: var(--color-text);
    word-break: break-word;
}

.item-row__area {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing-unit) * 0.5);
    font-size: 12px;
    color: var(--color-text-light);
    flex-shrink: 0;
}

.item-row__area-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.item-row__delete,
.item-row__edit {
    background: none;
    border: none;
    color: var(--color-text-lighter);
    cursor: pointer;
    padding: calc(var(--spacing-unit) * 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    flex-shrink: 0;
}

.item-row__delete:hover {
    color: var(--color-error);
}

.item-row__edit:hover {
    color: var(--color-primary);
}

.edit-name,
.edit-quantity,
.edit-unit,
.edit-category {
    padding: calc(var(--spacing-unit) * 0.75) calc(var(--spacing-unit) * 1);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    font-size: 14px;
    font-family: inherit;
    background: white;
}

.edit-name {
    flex: 1;
    min-width: 150px;
}

.edit-quantity {
    width: 60px;
}

.edit-unit {
    width: 70px;
}

.edit-category {
    width: 120px;
}

/* Top drop area for uncategorized items - hidden until drag over */
.top-drop-area {
    display: block;
    height: 20px;
    padding: 0;
    margin-bottom: calc(var(--spacing-unit) * 1);
    border: none;
    background: transparent;
    color: transparent;
    font-size: 0;
    line-height: 0;
    cursor: default;
    overflow: hidden;
}

.top-drop-area.drag-over {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(var(--spacing-unit) * 2) calc(var(--spacing-unit) * 2);
    min-height: 108px;
    border-radius: var(--border-radius);
    background: rgba(110, 166, 143, 0.14);
    border: 1px dashed var(--color-border);
    overflow: hidden;
}

.top-drop-area.drag-over::before {
    content: '+';
    position: absolute;
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius);
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(110, 166, 143, 0.9);
    font-size: 18px;
    font-weight: 700;
    box-shadow: 0 0 0 1px rgba(110, 166, 143, 0.14);
    pointer-events: none;
}

.edit-category-wrapper {
    position: relative;
}

.edit-category-wrapper .category-dropdown {
    left: 0;
    right: auto;
    min-width: 100%;
}

/* Error Messages */
.error-message {
    background: #fee;
    color: var(--color-error);
    padding: calc(var(--spacing-unit) * 1.5) calc(var(--spacing-unit) * 2);
    border-radius: var(--border-radius);
    margin-bottom: calc(var(--spacing-unit) * 2);
    display: none;
    animation: slideDown 0.3s ease;
}

.error-message.show {
    display: block;
}

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

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }


    .app-content__body {
        padding: calc(var(--spacing-unit) * 1.5) calc(var(--spacing-unit) * 1.5);
    }

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

    .item-editor__quantity-unit {
        width: 100%;
        order: 3;
    }

    .category-dropdown {
        position: absolute;
        width: 100%;
        left: 0;
        right: auto;
    }
}
