:root {
    --bg: #f5f5f5;
    --surface: #ffffff;
    --border: #e0e0e0;
    --text: #1a1a1a;
    --muted: #777777;
    --accent: #2563eb;
    --accent-dim: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --empty: #d4d4d4;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.header h1 { margin: 0; font-size: 1.25rem; }
.header-actions { display: flex; gap: 0.75rem; align-items: center; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.875rem;
    cursor: pointer;
    white-space: nowrap;
    min-height: 44px;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dim); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.25rem 0.5rem; min-height: 36px; font-size: 0.8125rem; }

/* Container */
.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }

/* Search bar */
.search-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.search-bar input {
    flex: 1;
    padding: 0.625rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 1rem;
    min-height: 44px;
}
.search-bar input:focus { outline: none; border-color: var(--accent); }

/* Toolbar */
.toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}
.toolbar select {
    padding: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.875rem;
    min-height: 44px;
}

/* Tote cards grid */
.totes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.tote-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    position: relative;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.tote-card:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.tote-card.empty { border-style: dashed; box-shadow: none; }
.tote-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37,99,235,0.2); }

.tote-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}
.tote-number {
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--accent);
}
.item-badge {
    background: var(--accent);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.125rem 0.5rem;
    border-radius: 12px;
}
.item-badge.empty-badge {
    background: var(--empty);
    color: var(--muted);
}
.tote-name { font-size: 1rem; margin-bottom: 0.25rem; }
.tote-location { font-size: 0.8125rem; color: var(--muted); }

.tote-card .select-check {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
}

/* Tote detail */
.tote-info {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.tote-info-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
}
.tote-info-left { flex: 1; min-width: 200px; }
.tote-info-right { text-align: center; }
.tote-info-right img { max-width: 150px; border-radius: 4px; }

.editable {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text);
    font-size: inherit;
    padding: 0.25rem 0.5rem;
    width: 100%;
}
.editable:hover { border-color: var(--border); }
.editable:focus { outline: none; border-color: var(--accent); background: var(--bg); }

.tote-detail-number {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

/* Items list */
.items-section h2 {
    font-size: 1.125rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.item-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 0.5rem;
}
.item-row .item-check { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; }
.item-row .item-info { flex: 1; min-width: 0; }
.item-row .item-name { font-weight: 500; }
.item-row .item-meta { font-size: 0.8125rem; color: var(--muted); }
.item-row .item-qty { font-size: 0.875rem; color: var(--muted); white-space: nowrap; }
.item-row .item-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }

/* Add item form */
.add-item-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}
.add-item-form .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}
.add-item-form input,
.add-item-form select {
    padding: 0.625rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.9375rem;
    min-height: 44px;
}
.add-item-form input:focus,
.add-item-form select:focus { outline: none; border-color: var(--accent); }

/* Bulk actions bar */
.bulk-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 2px solid var(--accent);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
}
.bulk-bar.hidden { display: none; }

/* Search results */
.search-results {
    margin-top: 1rem;
}
.search-result-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
}
.search-result-item .result-tote {
    font-size: 0.8125rem;
    color: var(--accent);
    margin-bottom: 0.25rem;
}
.search-result-item .result-name { font-weight: 500; }
.search-result-item .result-desc { font-size: 0.8125rem; color: var(--muted); }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.modal-overlay.hidden { display: none; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
}
.modal h2 { margin: 0 0 1rem; font-size: 1.25rem; }
.modal label { display: block; font-size: 0.875rem; color: var(--muted); margin-bottom: 0.25rem; }
.modal input, .modal select {
    width: 100%;
    padding: 0.625rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 1rem;
    margin-bottom: 0.75rem;
    box-sizing: border-box;
    min-height: 44px;
}
.modal input:focus, .modal select:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.5rem; }

/* Labels print page */
.label-controls {
    margin-bottom: 1rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.label-sheet {
    width: 8.5in;
    margin: 0 auto;
    background: white;
    color: #000;
    min-height: 11in;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

.label-grid {
    padding-top: 0.5in;
    padding-left: 0.1625in;
}

.label-row {
    display: flex;
    height: 2in;
}

.label-cell {
    width: 4in;
    height: 2in;
    padding: 0.125in;
    overflow: hidden;
    display: flex;
    align-items: flex-start;
    gap: 0.125in;
    box-sizing: border-box;
    border: 1px dashed #ccc;
}
.label-cell:first-child {
    margin-right: 0.1875in;
}

.label-cell.test-mode {
    border: 1px solid #666;
}

.label-qr { width: 1.5in; height: 1.5in; flex-shrink: 0; }
.label-qr img { width: 100%; height: 100%; object-fit: contain; }
.label-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-width: 0;
    position: relative;
    height: 100%;
}
.label-tote-number {
    font-size: 18pt;
    font-weight: 700;
    line-height: 1.2;
}
.label-tote-name {
    font-size: 10pt;
    color: #555;
    margin-top: 2pt;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.label-item-count {
    position: absolute;
    bottom: 0.125in;
    right: 0;
    font-size: 9pt;
    color: #888;
}

/* Print styles */
@media print {
    .no-print { display: none !important; }
    body { background: white; color: black; margin: 0; padding: 0; }
    @page { size: letter; margin: 0; }
    .label-sheet { width: 8.5in; box-shadow: none; min-height: auto; }
    .label-grid { padding-top: 0.5in; padding-left: 0.1625in; }
    .label-cell { border: none; }
    .label-cell.test-mode { border: 1px solid #666; }
    .label-tote-name { color: #555; }
    .label-item-count { color: #888; }
}

/* Label sheet responsive scaling */
@media screen and (max-width: 900px) {
    .label-sheet {
        width: 100%;
        transform-origin: top left;
        min-height: auto;
    }
}

/* Responsive */
@media (max-width: 640px) {
    .totes-grid { grid-template-columns: 1fr; }
    .tote-info-header { flex-direction: column; }
    .add-item-form .form-row { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .header h1 { font-size: 1rem; }
    .search-bar { flex-direction: column; }
}
