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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    background: #f4f5f7;
    color: #333;
}

.app {
    margin: 24px 16px;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.app-header h1 {
    font-size: 22px;
    font-weight: 600;
}

.badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-ok  { background: #d4edda; color: #155724; }
.badge-off { background: #f8d7da; color: #721c24; }

.flash-ok  { color: #155724; font-size: 13px; }
.flash-err { color: #721c24; font-size: 13px; }

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid #ddd;
    margin-bottom: 20px;
}
.tab-btn {
    background: none;
    border: none;
    padding: 8px 18px;
    cursor: pointer;
    font-size: 14px;
    color: #555;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color .15s, border-color .15s;
}
.tab-btn:hover  { color: #111; }
.tab-btn.active { color: #2563eb; border-bottom-color: #2563eb; font-weight: 600; }

/* Panels */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.tab-panel h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
}

/* Settings form */
.hint {
    background: #eef2ff;
    border-left: 3px solid #6366f1;
    padding: 8px 12px;
    border-radius: 4px;
    margin-bottom: 16px;
    line-height: 1.5;
}
.hint code {
    background: #e0e7ff;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
    word-break: break-all;
}

#config-form label {
    display: block;
    margin-bottom: 12px;
    font-weight: 500;
}
#config-form input {
    display: block;
    width: 100%;
    max-width: 480px;
    margin-top: 4px;
    padding: 7px 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 14px;
    font-family: monospace;
}
#config-form input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}

/* Buttons */
.btn-row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.btn {
    padding: 8px 16px;
    border: 1px solid #ccc;
    border-radius: 5px;
    background: #fff;
    cursor: pointer;
    font-size: 14px;
    transition: background .15s;
}
.btn:hover { background: #f0f0f0; }
.btn-primary {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }

#save-status { margin-top: 8px; color: #555; font-size: 13px; height: 18px; }

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
#item-search {
    padding: 7px 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 14px;
    width: 260px;
}

/* Status lines */
#items-status, #dupes-status {
    margin-bottom: 10px;
    font-size: 13px;
    color: #555;
    min-height: 18px;
}

/* Data table */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table th {
    background: #f1f3f5;
    text-align: left;
    padding: 7px 10px;
    font-weight: 600;
    border-bottom: 2px solid #ddd;
    white-space: nowrap;
}
.data-table td {
    padding: 6px 10px;
    border-bottom: 1px solid #eee;
    vertical-align: top;
}
.data-table tbody tr:hover { background: #f9f9fb; }

#items-table-wrap { overflow-x: auto; }

/* Duplicate sections */
.dupe-section { margin-bottom: 20px; border: 1px solid #ddd; border-radius: 6px; overflow: hidden; }

.suspect-divider-row td {
    background: #e0e7ff;
    color: #3730a3;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 5px 10px;
}
.suspect-row td { background: #f5f3ff; }
.suspect-row:hover td { background: #ede9fe; }
.suspect-label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; font-size: 12px; color: #4338ca; font-weight: 600; white-space: nowrap; }

.section-header {
    background: #f7f8fa;
    padding: 10px 14px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.section-header:hover { background: #eff0f3; }
.count {
    font-weight: 400;
    font-size: 12px;
    color: #777;
}

.section-body { padding: 12px; }
.section-body.hidden { display: none; }

.dupe-group {
    margin-bottom: 14px;
    border-left: 3px solid #f59e0b;
    padding-left: 10px;
    overflow-x: auto;
}
.dupe-group:last-child { margin-bottom: 0; }

.dupe-table tbody tr:nth-child(odd)  { background: #fffbeb; }
.dupe-table tbody tr:nth-child(even) { background: #fef3c7; }

.stock-zero { color: #dc2626; font-weight: 600; }
.stock-low  { color: #d97706; font-weight: 600; }

.status-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.status-active   { background: #d1fae5; color: #065f46; }
.status-inactive { background: #f3f4f6; color: #6b7280; }

.center { text-align: center; }

.dupe-title { font-weight: 500; font-size: 13px; }

.reason-row { margin-bottom: 8px; display: flex; gap: 6px; flex-wrap: wrap; }

.reason-badge {
    display: inline-block;
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
}

.btn-sm { padding: 3px 8px; font-size: 12px; }

.keep-label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; font-size: 12px; white-space: nowrap; }

.field-pick-label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.field-pick { transform: scale(0.9); accent-color: #2563eb; }
.merge-row  { padding: 10px 12px; border-top: 1px solid #eee; text-align: right; }

.btn-keep  { background: #ecfdf5; color: #065f46; border-color: #6ee7b7; }
.btn-keep:hover  { background: #d1fae5; border-color: #34d399; }

.btn-unmatch { background: #f9fafb; color: #6b7280; border-color: #d1d5db; }
.btn-unmatch:hover { background: #f3f4f6; color: #374151; }

.btn-rematch { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.btn-rematch:hover { background: #fde68a; border-color: #f59e0b; }

.row-unmatched { opacity: 0.35; }
.row-unmatched td { pointer-events: none; }
.row-unmatched .remove-row-btn { pointer-events: auto; }

/* Sales Analytics */
.analytics-section {
    margin-bottom: 28px;
}
.analytics-section h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.chart-toggle-group {
    margin-left: auto;
    display: inline-flex;
    gap: 3px;
    flex-shrink: 0;
}
.chart-toggle {
    font-size: 11px;
    padding: 2px 9px;
    border-radius: 10px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    color: #6b7280;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.chart-toggle.active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    overflow-x: auto;
    padding-bottom: 4px;
}
.bar-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 36px;
    flex: 1;
}
.bar-count {
    font-size: 10px;
    color: #555;
    min-height: 14px;
    margin-bottom: 2px;
}
.bar-wrap {
    width: 100%;
    height: 120px;
    display: flex;
    align-items: flex-end;
    background: #f1f3f5;
    border-radius: 3px;
}
.bar-fill {
    width: 100%;
    background: #2563eb;
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transition: height .3s;
}
.bar-total {
    font-size: 9px;
    color: #6b7280;
    margin-top: 2px;
    white-space: nowrap;
}
.bar-lbl {
    font-size: 10px;
    color: #777;
    margin-top: 3px;
    white-space: nowrap;
}

.name-edit-input {
    width: 100%;
    min-width: 140px;
    padding: 3px 6px;
    border: 1px solid #2563eb;
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    box-shadow: 0 0 0 2px rgba(37,99,235,.1);
}

.row-actions { white-space: nowrap; text-align: center; }

.similarity-badge {
    display: inline-block;
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 6px;
}
