/* ============== Reset & Base ============== */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
    --primary: #1976d2;
    --primary-dark: #115293;
    --secondary: #607d8b;
    --success: #2e7d32;
    --danger: #c62828;
    --warning: #f57c00;
    --info: #0288d1;
    --bg: #f5f7fa;
    --surface: #ffffff;
    --text: #212121;
    --text-muted: #6b7280;
    --border: #e0e0e0;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.15);
    --radius: 12px;
    --radius-sm: 8px;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    overscroll-behavior: contain;
    min-height: 100vh;
}

input, button, select, textarea {
    font: inherit;
    color: inherit;
}

/* ============== Header ============== */
.app-header {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; justify-content: space-between;
    height: 56px; padding: 0 12px;
    background: var(--primary); color: #fff;
    box-shadow: var(--shadow);
}
.header-left, .header-right { display: flex; align-items: center; gap: 8px; }
.app-header h1 { font-size: 18px; font-weight: 600; }

.icon-btn {
    background: transparent; border: none; color: inherit;
    width: 40px; height: 40px; border-radius: 50%;
    font-size: 22px; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: rgba(255,255,255,0.15); }

/* ============== Side menu ============== */
.side-menu {
    position: fixed; top: 0; left: -280px; width: 280px; height: 100vh;
    background: var(--surface); z-index: 200;
    transition: left 0.25s ease; box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column;
}
.side-menu.open { left: 0; }
.menu-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px; background: var(--primary); color: #fff;
}
.side-menu ul { list-style: none; flex: 1; padding: 12px 0; }
.side-menu li a {
    display: block; padding: 14px 20px; color: var(--text);
    text-decoration: none; font-size: 15px;
}
.side-menu li a:active { background: var(--bg); }
.menu-footer { padding: 12px 16px; color: var(--text-muted); font-size: 12px; border-top: 1px solid var(--border); }

.menu-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    z-index: 150; opacity: 0; pointer-events: none;
    transition: opacity 0.25s ease;
}
.menu-overlay.show { opacity: 1; pointer-events: auto; }

/* ============== Main container ============== */
.container {
    max-width: 720px; margin: 0 auto; padding: 12px;
}

/* ============== Cards / Sections ============== */
.card {
    background: var(--surface); border-radius: var(--radius);
    padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.section-title {
    font-size: 17px; font-weight: 700; color: var(--primary);
    margin-bottom: 4px;
}
.section-desc {
    font-size: 13px; color: var(--text-muted); margin-bottom: 12px;
}
.subsection-title {
    font-size: 14px; font-weight: 600; color: var(--text);
    margin: 16px 0 8px; padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

/* ============== Form ============== */
.form-row { margin-bottom: 12px; }
.form-row label {
    display: block; font-size: 13px; font-weight: 600;
    color: var(--text-muted); margin-bottom: 4px;
}
.form-row label .hint {
    font-weight: 400; color: var(--text-muted); font-size: 11px;
}
.form-row input, .form-row select, .form-row textarea {
    width: 100%; padding: 12px 14px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: #fafbfc; transition: all 0.15s;
    font-family: inherit; resize: vertical;
}
.form-row textarea { min-height: 60px; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
    outline: none; border-color: var(--primary); background: #fff;
}
.required { color: var(--danger); }

/* Side-by-side pair on wider screens */
.form-row-pair {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
@media (max-width: 480px) {
    .form-row-pair { grid-template-columns: 1fr; gap: 0; }
}

/* ============== Goods list ============== */
.goods-list { margin-bottom: 12px; }
.goods-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; background: var(--bg);
    border-radius: var(--radius-sm); margin-bottom: 6px;
    font-size: 14px;
}
.goods-row .sku { font-weight: 600; flex: 1; word-break: break-all; }
.goods-row .qty { color: var(--info); font-weight: 600; margin: 0 8px; white-space: nowrap; }
.goods-row .remove-btn {
    background: transparent; border: none; color: var(--danger);
    font-size: 18px; cursor: pointer; width: 28px; height: 28px;
}

.add-goods-row {
    display: grid; grid-template-columns: 1fr auto; gap: 6px;
    margin-bottom: 8px;
}
.add-goods-row:nth-child(3) {
    grid-template-columns: 1fr 90px auto;
}
.add-goods-row select, .add-goods-row input {
    padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: #fafbfc;
}

/* ============== Buttons ============== */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 10px 16px; border: none; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: all 0.15s; white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-large { padding: 14px 20px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--success); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }

/* ============== Photo grid ============== */
.photo-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
    margin-bottom: 8px;
}
@media (max-width: 380px) {
    .photo-grid { grid-template-columns: repeat(2, 1fr); }
}

.photo-slot {
    position: relative; aspect-ratio: 1; background: var(--bg);
    border: 2px dashed var(--border); border-radius: var(--radius-sm);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    cursor: pointer; overflow: hidden; transition: all 0.15s;
}
.photo-slot:active { transform: scale(0.97); border-color: var(--primary); }
.photo-slot.has-photo { border-style: solid; border-color: var(--success); }
.photo-slot .icon { font-size: 28px; color: var(--text-muted); margin-bottom: 4px; }
.photo-slot .label { font-size: 11px; color: var(--text-muted); text-align: center; padding: 0 4px; }
.photo-slot img { width: 100%; height: 100%; object-fit: cover; }
.photo-slot .photo-label-overlay {
    position: absolute; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.65); color: #fff;
    font-size: 11px; padding: 4px 6px; text-align: center;
    font-weight: 600;
}
.photo-slot .delete-photo-btn {
    position: absolute; top: 4px; right: 4px;
    width: 24px; height: 24px; border-radius: 50%;
    background: rgba(198,40,40,0.95); color: #fff; border: none;
    font-size: 14px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    z-index: 2;
}

.layer-actions {
    display: flex; align-items: center; gap: 12px; margin-top: 12px;
}
.layer-actions .btn { flex: 1; }
.layer-count {
    font-size: 13px; color: var(--text-muted); font-weight: 600;
    white-space: nowrap;
}

/* ============== Export actions ============== */
.export-actions { display: flex; flex-direction: column; gap: 10px; }
.export-status {
    margin-top: 12px; padding: 10px; border-radius: var(--radius-sm);
    font-size: 13px; display: none;
}
.export-status.show { display: block; }
.export-status.success { background: #e8f5e9; color: var(--success); }
.export-status.error { background: #ffebee; color: var(--danger); }
.export-status.info { background: #e3f2fd; color: var(--info); }

/* ============== Modal ============== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    z-index: 300; display: flex; align-items: center; justify-content: center;
    padding: 16px;
}
.modal {
    background: var(--surface); border-radius: var(--radius);
    width: 100%; max-width: 500px; max-height: 90vh;
    display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 16px; overflow-y: auto; flex: 1; }
.modal-footer {
    padding: 12px 16px; border-top: 1px solid var(--border);
    display: flex; gap: 8px; justify-content: flex-end;
}

/* ============== SKU Manager Modal ============== */
.sku-list { margin-bottom: 12px; max-height: 300px; overflow-y: auto; }
.sku-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px; background: var(--bg); border-radius: var(--radius-sm);
    margin-bottom: 6px; font-size: 14px;
}

/* ============== Saved reports list ============== */
.saved-report-item {
    padding: 12px; background: var(--bg); border-radius: var(--radius-sm);
    margin-bottom: 8px; cursor: pointer;
}
.saved-report-item:active { background: #e3f2fd; }
.saved-report-item .title { font-weight: 600; margin-bottom: 4px; }
.saved-report-item .meta { font-size: 12px; color: var(--text-muted); }

/* ============== Toast ============== */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.85); color: #fff;
    padding: 12px 20px; border-radius: 24px;
    font-size: 14px; z-index: 400;
    max-width: 90%; text-align: center;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.25s ease;
}
@keyframes toastIn {
    from { opacity: 0; transform: translate(-50%, 20px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* ============== Loading overlay ============== */
.loading-overlay {
    position: fixed; inset: 0; background: rgba(255,255,255,0.85);
    z-index: 500; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 16px;
}
.loader {
    width: 48px; height: 48px;
    border: 4px solid var(--border); border-top-color: var(--primary);
    border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============== Utilities ============== */
[hidden] { display: none !important; }
