/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f6fa;
    color: #2c3e50;
    min-height: 100vh;
}

/* ========== Login ========== */
.login-box {
    max-width: 360px;
    margin: 15vh auto;
    padding: 40px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,.08);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.login-box h1 { font-size: 1.5rem; color: #2c3e50; }
.login-box p { font-size: .85rem; color: #7f8c8d; }
.login-box input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: .95rem;
}
.login-box button {
    width: 100%;
    padding: 12px;
    background: #2980b9;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
}
.login-box button:hover { background: #2471a3; }
.error-msg { color: #e74c3c; font-size: .85rem; min-height: 20px; }

/* ========== Header ========== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: #fff;
    border-bottom: 1px solid #eee;
    position: sticky;
    top: 0;
    z-index: 50;
}
.app-header h1 { font-size: 1.15rem; font-weight: 700; }
.header-right { display: flex; gap: 8px; }

/* ========== Buttons ========== */
.btn-sm {
    padding: 6px 14px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
    font-size: .82rem;
    cursor: pointer;
}
.btn-sm:hover { background: #f0f0f0; }
.btn-primary {
    padding: 8px 20px;
    background: #2980b9;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: .9rem;
    cursor: pointer;
}
.btn-primary:hover { background: #2471a3; }
.btn-primary:disabled { background: #bdc3c7; cursor: not-allowed; }
.btn-cancel {
    padding: 8px 20px;
    background: #ecf0f1;
    border: none;
    border-radius: 8px;
    font-size: .9rem;
    cursor: pointer;
}
.btn-cancel:hover { background: #ddd; }
.btn-danger {
    padding: 6px 12px;
    background: #e74c3c;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: .8rem;
    cursor: pointer;
}
.btn-danger:hover { background: #c0392b; }
.btn-warn {
    padding: 6px 12px;
    background: #f39c12;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: .8rem;
    cursor: pointer;
}
.btn-warn:hover { background: #e67e22; }
.btn-logout { color: #e74c3c; border-color: #e74c3c; }

/* ========== Sections ========== */
.section { padding: 20px 24px; }
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.section-header h2 { font-size: 1.2rem; font-weight: 700; }

/* ========== Tabs ========== */
.tab-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    border-bottom: 2px solid #eee;
    padding-bottom: 0;
}
.tab {
    padding: 8px 20px;
    border: none;
    background: none;
    font-size: .9rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    color: #7f8c8d;
}
.tab.active { color: #2980b9; border-bottom-color: #2980b9; font-weight: 600; }
.tab:hover { color: #2c3e50; }

/* ========== Filter Bar ========== */
.filter-bar {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.filter-bar select, .filter-bar input[type="text"] {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: .85rem;
}
.filter-bar select { min-width: 160px; }
.filter-bar input[type="text"] { min-width: 200px; }
.filter-bar label { font-size: .85rem; display: flex; align-items: center; gap: 4px; }

/* ========== Stats ========== */
.stats-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.stat-chip {
    padding: 4px 12px;
    background: #eef2f7;
    border-radius: 16px;
    font-size: .8rem;
    color: #555;
}

/* ========== Card Grid (Catalog Items) ========== */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.item-card {
    background: #fff;
    border-radius: 10px;
    border: 1px solid #eee;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: box-shadow .2s;
}
.item-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,.06); }
.item-card-image {
    width: 100%;
    height: 140px;
    border-radius: 6px;
    overflow: hidden;
    background: #f5f5f5;
}
.item-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.id-copy {
    font-family: monospace;
    font-size: .7rem !important;
    cursor: pointer;
    color: #999 !important;
    word-break: break-all;
}
.id-copy:hover { color: #2980b9 !important; }
.item-card.discontinued { opacity: .6; border-color: #e74c3c; }
.item-card-header { display: flex; justify-content: space-between; align-items: flex-start; }
.item-card-header h4 { font-size: .95rem; font-weight: 600; }
.item-card-meta { font-size: .78rem; color: #7f8c8d; }
.item-card-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: .72rem;
    background: #eef2f7;
    color: #555;
}
.tag.season-spring { background: #fff8e1; color: #f39c12; }
.tag.season-summer { background: #e3f2fd; color: #2980b9; }
.tag.season-autumn { background: #fbe9e7; color: #c08040; }
.tag.season-winter { background: #ede7f6; color: #6c5ce7; }
.tag.discontinued { background: #fde; color: #e74c3c; }
.item-card-actions { display: flex; gap: 6px; margin-top: auto; }

/* ========== Card List (Packages) ========== */
.card-list { display: flex; flex-direction: column; gap: 12px; }
.pkg-card {
    background: #fff;
    border-radius: 10px;
    border: 1px solid #eee;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.pkg-card-header { display: flex; justify-content: space-between; align-items: center; }
.pkg-card-header h4 { font-size: 1rem; font-weight: 600; }
.pkg-card-type {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: .75rem;
    font-weight: 500;
    background: #eef2f7;
}
.pkg-card-info { font-size: .85rem; color: #555; }
.pkg-card-items { font-size: .82rem; color: #7f8c8d; }
.pkg-card-footer { display: flex; justify-content: space-between; align-items: center; }

/* ========== Image Upload ========== */
.image-upload-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.image-preview {
    width: 120px;
    height: 120px;
    border: 2px dashed #ddd;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #fafafa;
}
.image-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
}
.image-preview:empty::after {
    content: 'No image';
    color: #bbb;
    font-size: .8rem;
}
.upload-status { font-size: .8rem; color: #7f8c8d; }
.upload-status.uploading { color: #f39c12; }
.upload-status.done { color: #27ae60; }
.upload-status.error { color: #e74c3c; }

/* ========== Apply Layout ========== */
.apply-layout { display: flex; gap: 24px; flex-wrap: wrap; }
.apply-panel {
    flex: 1;
    min-width: 300px;
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #eee;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.apply-panel h3 { font-size: 1rem; font-weight: 600; }
.apply-panel select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: .9rem;
}
.info-box {
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    font-size: .85rem;
    min-height: 60px;
}
.customer-list {
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.cust-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: .85rem;
    cursor: pointer;
}
.cust-row:hover { background: #f0f4f8; }
.cust-row input { margin: 0; }
.result-box {
    margin-top: 20px;
    padding: 16px;
    background: #fff;
    border-radius: 10px;
    border: 1px solid #eee;
    font-size: .9rem;
}

/* ========== Modal ========== */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: #fff;
    border-radius: 12px;
    max-height: 90vh;
    overflow-y: auto;
    width: 480px;
}
.modal-lg { width: 640px; }
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }
.modal-close {
    background: none; border: none;
    font-size: 1.5rem; cursor: pointer; color: #999;
}
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid #eee;
}

/* ========== Form ========== */
.form-row { display: flex; gap: 12px; }
.form-row > .form-group { flex: 1; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: .82rem; font-weight: 500; color: #555; }
.form-group input, .form-group select, .form-group textarea {
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: .88rem;
}
.form-group textarea { resize: vertical; }

/* ========== Chip Groups ========== */
.chip-group { display: flex; flex-wrap: wrap; gap: 4px; }
.chip-toggle {
    padding: 4px 10px;
    border-radius: 14px;
    font-size: .78rem;
    cursor: pointer;
    background: #eef2f7;
    display: flex;
    align-items: center;
    gap: 4px;
}
.chip-toggle input { display: none; }
.chip-toggle.selected { background: #2980b9; color: #fff; }

/* ========== Package Items List ========== */
.pkg-items-list { display: flex; flex-direction: column; gap: 8px; }
.pkg-item-row {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 6px;
}
.pkg-item-row select, .pkg-item-row input {
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: .82rem;
}
.pkg-item-row .item-id-input { flex: 1; }
.pkg-item-remove {
    background: none; border: none;
    color: #e74c3c; cursor: pointer; font-size: 1.2rem;
}

/* ========== Pagination ========== */
.pagination {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-top: 20px;
}
.pagination button {
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: .82rem;
}
.pagination button.active { background: #2980b9; color: #fff; border-color: #2980b9; }
.pagination button:disabled { opacity: .5; cursor: not-allowed; }

/* ========== Empty State ========== */
.empty-state {
    text-align: center;
    padding: 40px;
    color: #999;
    font-size: .9rem;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .app-header { flex-direction: column; gap: 8px; }
    .header-right { flex-wrap: wrap; }
    .form-row { flex-direction: column; }
    .apply-layout { flex-direction: column; }
    .card-grid { grid-template-columns: 1fr; }
    .modal-content, .modal-lg { width: 95%; }
}
