/* ========================================
   Usborne Stock Manager - Complete CSS
   Mobile-first, PWA-ready
   ======================================== */

/* --- CSS Variables --- */
:root {
    --primary: #2c3074;
    --primary-dark: #1e2153;
    --primary-light: #4052b5;
    --bg: #F1F5F9;
    --bg-dark: #1E2A38;
    --card: #FFFFFF;
    --text: #1E293B;
    --text-secondary: #64748B;
    --text-light: #94A3B8;
    --success: #4fa15e;
    --success-light: #e6f3e9;
    --warning: #c9a800;
    --warning-light: #fefce0;
    --danger: #e4032d;
    --danger-light: #fde8ec;
    --purple: #712d66;
    --purple-light: #f5e6f3;
    --yellow-bright: #f6eb45;
    --border: #E2E8F0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --tab-height: 60px;
    --header-height: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --transition: 0.2s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: clip; /* clip instead of hidden — doesn't break position:fixed in Safari */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--primary);
    text-decoration: none;
}

img {
    max-width: 100%;
    display: block;
}

/* --- App Layout --- */
#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden; /* fallback clip for older browsers */
    min-height: 100dvh;
}

/* --- Header --- */
#app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 16px;
    padding-top: var(--safe-top);
    background: linear-gradient(135deg, #2c3074 0%, #712d66 100%);
    color: #FFFFFF;
    box-shadow: var(--shadow);
}

#app-header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.header-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #FFFFFF;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--transition);
    font-size: 18px;
}

.header-btn:active {
    background: rgba(255, 255, 255, 0.25);
}

/* --- Main Content --- */
#page-content {
    flex: 1;
    padding: 16px;
    padding-bottom: calc(var(--tab-height) + var(--safe-bottom) + 16px);
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
}

/* --- Tab Bar --- */
#tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    display: flex;
    align-items: stretch;
    height: calc(var(--tab-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: #FFFFFF;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 2px;
    transition: color var(--transition);
    -webkit-tap-highlight-color: transparent;
    position: relative;
    min-width: 0;
}

.tab-item.active {
    color: var(--primary);
}

.tab-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: var(--primary);
    border-radius: 0 0 3px 3px;
}

.tab-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.tab-label {
    font-size: 10px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* --- Cards --- */
.card {
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 12px;
    transition: box-shadow var(--transition);
}

.card:active {
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.card-subtitle {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.card-value {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--cv, var(--text));
    line-height: 1.15;
}

.card-value-sm {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.card-detail {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-muted);
    margin-top: 4px;
}

.card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.card-icon.blue { background: #DBEAFE; color: var(--primary); }
.card-icon.green { background: var(--success-light); color: var(--success); }
.card-icon.yellow { background: var(--warning-light); color: var(--warning); }
.card-icon.red { background: var(--danger-light); color: var(--danger); }
.card-icon.purple { background: var(--purple-light); color: var(--purple); }

/* Stat Cards Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.stats-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 12px;
    border-top: 3px solid var(--st-top, var(--border));
}

.stat-card-hdr {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 8px;
}

.stat-card-hdr .card-icon {
    margin-bottom: 0;
    flex-shrink: 0;
}

.stat-card-hdr .card-subtitle {
    margin-bottom: 0;
}

.stat-inline-vals {
    display: flex;
    align-items: baseline;
    gap: 4px;
    flex-wrap: wrap;
}

.two-col-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

@media (min-width: 769px) {
    .two-col-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.stat-inline-vals .card-value,
.stat-inline-vals .card-detail {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--cv, var(--text));
}

.stat-sep {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-muted);
}

.stat-card .card-icon {
    margin-bottom: 8px;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    line-height: 1.4;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #FFFFFF;
}

.btn-primary:active:not(:disabled) {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: #FFFFFF;
}

.btn-success:active:not(:disabled) {
    background: #059669;
}

.btn-danger {
    background: var(--danger);
    color: #FFFFFF;
}

.btn-danger:active:not(:disabled) {
    background: #DC2626;
}

.btn-warning {
    background: var(--warning);
    color: #FFFFFF;
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}

.btn-outline:active:not(:disabled) {
    background: rgba(37, 99, 235, 0.05);
}

.btn-outline-danger {
    background: transparent;
    color: var(--danger);
    border: 1.5px solid var(--danger);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
}

.btn-ghost:active {
    background: var(--bg);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 16px;
    border-radius: var(--radius-lg);
}

.btn-block {
    display: flex;
    width: 100%;
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* --- Forms --- */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    background: #FFFFFF;
    transition: border-color var(--transition), box-shadow var(--transition);
    -webkit-appearance: none;
    appearance: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(44, 48, 116, 0.15);
}

.form-input::placeholder {
    color: var(--text-light);
}

.form-textarea {
    min-height: 80px;
    resize: vertical;
}

.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748B' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

.form-inline {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.form-inline .form-group {
    margin-bottom: 0;
}

/* --- Tables --- */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-lg);
    background: var(--card);
    box-shadow: var(--shadow);
    margin-bottom: 12px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}

.data-table thead {
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
}

.data-table th:hover {
    color: var(--text);
}

.data-table th.sorted-asc::after {
    content: ' \25B2';
    font-size: 10px;
}

.data-table th.sorted-desc::after {
    content: ' \25BC';
    font-size: 10px;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:active {
    background: var(--bg);
}

.data-table .cell-actions {
    display: flex;
    gap: 6px;
}

.data-table tfoot td {
    padding: 10px 12px;
    font-weight: 700;
    background: var(--bg);
    border-top: 2px solid var(--border);
}

/* Editable cell */
.editable-cell {
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background var(--transition);
}

.editable-cell:hover {
    background: #EEF2FF;
}

.editable-cell input {
    width: 80px;
    padding: 4px 6px;
    border: 1.5px solid var(--primary);
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
}

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-red {
    background: var(--danger-light);
    color: var(--danger);
}

.badge-yellow {
    background: #f6eb45;
    color: #5a4a00;
}

.badge-green {
    background: var(--success-light);
    color: #047857;
}

.badge-blue {
    background: #DBEAFE;
    color: var(--primary);
}

.badge-gray {
    background: var(--bg);
    color: var(--text-secondary);
}

.badge-purple {
    background: var(--purple-light);
    color: var(--purple);
}

/* --- Margin Dots --- */
.margin-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.margin-dot.red { background: var(--danger); }
.margin-dot.yellow { background: var(--warning); }
.margin-dot.green { background: var(--success); }

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
    display: none;
}

.modal-container {
    background: var(--card);
    width: 100%;
    max-height: 90vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 700;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background var(--transition);
}

.modal-close-btn:active {
    background: var(--bg);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-shrink: 0;
}

/* --- Toast Notifications --- */
#toast-container {
    position: fixed;
    top: calc(var(--safe-top) + 8px);
    left: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--text);
    color: #FFFFFF;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: slideDown 0.3s ease;
    pointer-events: auto;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

.toast.warning {
    background: var(--warning);
}

.toast.info {
    background: var(--primary);
}

.toast.removing {
    animation: slideUp 0.3s ease forwards;
    opacity: 0;
}

.toast-icon {
    font-size: 18px;
    flex-shrink: 0;
}

/* --- Loading Overlay --- */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3000;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* --- Scanner Overlay --- */
.scanner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 500;
    background: #000000;
    display: flex;
    flex-direction: column;
}

.scanner-overlay video {
    width: 100%;
    flex: 1;
    object-fit: cover;
}

.scanner-controls {
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    gap: 16px;
}

.scanner-target {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 250px;
    height: 150px;
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-radius: 12px;
}

.scanner-flash {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--success);
    opacity: 0;
    pointer-events: none;
    animation: flashGreen 0.4s ease;
}

/* --- Progress Bar --- */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg);
    border-radius: 100px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 100px;
    transition: width 0.3s ease;
}

.progress-bar-fill.green { background: var(--success); }
.progress-bar-fill.yellow { background: var(--warning); }
.progress-bar-fill.red { background: var(--danger); }

/* --- Lists --- */
.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
}

.list-item:first-child {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.list-item:last-child {
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    border-bottom: none;
}

.list-item:only-child {
    border-radius: var(--radius-lg);
}

.list-item:active {
    background: var(--bg);
}

.list-item-content {
    flex: 1;
    min-width: 0;
}

.list-item-title {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.list-item-right {
    text-align: right;
    flex-shrink: 0;
}

.list-group {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 16px;
}

/* --- Empty State --- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.empty-state-text {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

/* --- Search Bar --- */
.search-bar {
    position: relative;
    margin-bottom: 16px;
}

.search-bar input {
    width: 100%;
    padding: 10px 14px 10px 40px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 15px;
    background: var(--card);
    color: var(--text);
    font-family: inherit;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(44, 48, 116, 0.15);
}

.search-bar .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    pointer-events: none;
}

/* --- Section Headers --- */
.section-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
}

.section-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* --- Alert / Info Box --- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 12px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.alert-info {
    background: #e0e4f5;
    color: #2c3074;
}

.alert-success {
    background: var(--success-light);
    color: #065F46;
}

.alert-warning {
    background: var(--warning-light);
    color: #92400E;
}

.alert-danger {
    background: var(--danger-light);
    color: #991B1B;
}

.alert-icon {
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 1px;
}

/* --- Chip / Tag --- */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 500;
    background: var(--bg);
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.chip.active {
    background: var(--primary);
    color: #FFFFFF;
}

/* --- Tag chip (book tags — light blue bg) --- */
.tag-chip {
    display: inline-flex;
    align-items: center;
    background: #dbeafe;
    color: #1d4ed8;
    border: 1px solid #93c5fd;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    margin: 2px;
    white-space: nowrap;
    letter-spacing: 0.01em;
}
.tag-chip button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 0 0 5px;
    color: rgba(29,78,216,0.6);
    font-size: 14px;
    line-height: 1;
}
.tag-chip button:hover { color: #1d4ed8; }

/* Tag chip in vanzare/quotes table (clickable filter) */
.tag-chip-filter {
    display: inline-flex;
    align-items: center;
    background: #dbeafe;
    color: #1d4ed8;
    border-radius: 5px;
    padding: 3px 9px;
    font-size: 11px;
    font-weight: 600;
    margin: 2px;
    cursor: pointer;
    white-space: nowrap;
    border: 1px solid #93c5fd;
    transition: background 0.15s, color 0.15s;
}
.tag-chip-filter:hover { background: #bfdbfe; }
.tag-chip-filter.active {
    background: #712d66;
    color: #ffffff;
    border-color: #5a2253;
}

/* Selected table row — used on sale/offers pages */
tr.row-selected {
    background: var(--primary) !important;
}
tr.row-selected td,
tr.row-selected td span:not(.tag-chip-filter),
tr.row-selected td div:not(.tag-chip-filter) {
    color: #ffffff !important;
}
tr.row-selected .text-muted,
tr.row-selected .text-sm {
    color: rgba(255,255,255,0.75) !important;
}
tr.row-selected input {
    background: rgba(255,255,255,0.15) !important;
    color: #ffffff !important;
    border-color: rgba(255,255,255,0.35) !important;
}
tr.row-selected input::placeholder {
    color: rgba(255,255,255,0.5) !important;
}
/* Preserve tag chip colors on selected rows */
tr.row-selected .tag-chip-filter {
    background: #dbeafe !important;
    color: #1d4ed8 !important;
    border-color: #93c5fd !important;
}
tr.row-selected .tag-chip-filter.active {
    background: #712d66 !important;
    color: #fff !important;
    border-color: #5a2253 !important;
}

/* Quotes stock badge in tags column */
.quotes-stock-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    margin-bottom: 3px;
}

/* Tag filter card — used on offers/sale/stock pages */
.filter-tag-card,
.quotes-tag-card {
    background: #eff6ff;
    border: 2px solid #3b82f6;
    border-radius: var(--radius-lg);
    padding: 10px 12px 10px;
    box-shadow: 0 1px 4px rgba(59,130,246,0.15);
}

.filter-tag-label,
.quotes-tag-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #1d4ed8;
    margin-bottom: 8px;
}

/* Action chip buttons — edit/change qty in stock, etc. */
.btn-action-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    background: #dbeafe;
    color: #1d4ed8;
    border: 1px solid #93c5fd;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    line-height: 1.4;
}
.btn-action-chip:hover,
.btn-action-chip:active {
    background: #712d66;
    color: #fff;
    border-color: #5a2253;
}

/* Quotes — scrollable book list */
.quotes-scroll-wrap {
    overflow-y: auto;
    max-height: 52vh;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 2px;
}

/* --- Divider --- */
.divider {
    height: 1px;
    background: var(--border);
    margin: 16px 0;
}

/* --- Sale Cart --- */
.cart-item {
    background: var(--card);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 8px;
    border-left: 3px solid var(--primary);
}

.cart-item-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.cart-item-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
}

.cart-item-price {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
}

/* --- Receipt / Invoice Style --- */
.receipt-line {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 14px;
    border-bottom: 1px dashed var(--border);
}

.receipt-line:last-child {
    border-bottom: none;
}

.receipt-total {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    font-size: 18px;
    font-weight: 700;
    border-top: 2px solid var(--text);
    margin-top: 8px;
}

/* --- Confirm Dialog --- */
.confirm-dialog {
    text-align: center;
    padding: 8px 0;
}

.confirm-dialog p {
    font-size: 15px;
    margin-bottom: 20px;
    line-height: 1.5;
}

.confirm-dialog .btn-group {
    justify-content: center;
}

/* --- Scanner Input Area --- */
.scanner-input-area {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    align-items: center;
}

.scanner-input-area input {
    flex: 1;
    padding: 12px 14px;
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    font-size: 16px;
    font-family: monospace;
    letter-spacing: 1px;
    text-align: center;
}

.scanner-input-area input:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(44, 48, 116, 0.2);
}

/* --- Scanned List (sidebar on desktop, panel on mobile) --- */
.scanned-list {
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 12px;
    max-height: 300px;
    overflow-y: auto;
}

.scanned-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.scanned-item:last-child {
    border-bottom: none;
}

/* --- Type Selector --- */
.type-selector {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.type-option {
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    border: 1.5px solid var(--border);
    background: #FFFFFF;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.type-option.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #FFFFFF;
}

/* --- Toolbar --- */
.toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar-spacer {
    flex: 1;
}

/* --- File Upload --- */
.file-upload {
    position: relative;
    display: inline-block;
}

.file-upload input[type="file"] {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
}

.file-upload label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: var(--primary);
    color: #FFFFFF;
    transition: background var(--transition);
}

.file-upload label:active {
    background: var(--primary-dark);
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

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

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes flashGreen {
    0% { opacity: 0.4; }
    100% { opacity: 0; }
}

/* --- Utility Classes --- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-italic { font-style: italic; }
.font-bold { font-weight: 700; }
.font-mono { font-family: monospace; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.p-0 { padding: 0; }
.p-16 { padding: 16px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-row { flex-direction: row; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.w-full { width: 100%; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Line completion states */
.line-complete {
    background: var(--success-light) !important;
}

.line-partial {
    background: var(--warning-light) !important;
}

/* --- Responsive: Desktop --- */
@media (min-width: 769px) {
    #tab-bar {
        top: 0;
        bottom: auto;
        height: var(--header-height);
        border-top: none;
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow);
        padding-bottom: 0;
    }

    .tab-item {
        flex-direction: row;
        gap: 8px;
    }

    .tab-item.active::before {
        top: auto;
        bottom: 0;
        width: 100%;
        height: 3px;
        border-radius: 3px 3px 0 0;
    }

    .tab-label {
        font-size: 13px;
    }

    #app-header {
        display: none;
    }

    #page-content {
        padding-top: calc(var(--header-height) + 16px);
        padding-bottom: 16px;
        padding-left: 24px;
        padding-right: 24px;
    }

    .modal-overlay {
        align-items: center;
    }

    .modal-container {
        max-width: 560px;
        border-radius: var(--radius-xl);
        max-height: 80vh;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* --- Print --- */
@media print {
    #tab-bar,
    #app-header,
    #toast-container,
    #loading-overlay,
    .modal-overlay {
        display: none !important;
    }

    #page-content {
        padding: 0;
    }

    body {
        background: #FFFFFF;
    }
}

/* --- Login Screen --- */
#login-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: linear-gradient(135deg, #2c3074 0%, #712d66 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-container {
    width: 100%;
    max-width: 400px;
    background: var(--card);
    border-radius: var(--radius-xl);
    padding: 40px 32px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
    text-align: center;
}

.login-logo {
    margin-bottom: 16px;
}

.login-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.login-form .form-group {
    text-align: left;
    margin-bottom: 16px;
}

.login-form label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.login-form .form-input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.login-form .form-input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(44, 48, 116, 0.1);
}

.btn-block {
    display: block;
    width: 100%;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    margin-top: 24px;
}

.login-error {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 13px;
    margin-top: 12px;
    text-align: center;
}

.login-error.hidden {
    display: none;
}

/* --- User Badge in Header --- */
#user-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: rgba(255,255,255,0.9);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-logout {
    background: none;
    border: none;
    color: rgba(255,255,255,0.8);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: color 0.2s, background 0.2s;
}

.btn-logout:hover {
    color: #fff;
    background: rgba(255,255,255,0.15);
}

/* Header flex layout fix */
#app-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ---- Page tabs (Stock, etc.) ---- */
.tab-btn {
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.tab-btn:hover:not(.active) {
    color: var(--text);
}

/* ---- Stock lots hover tooltip ---- */
.stock-cost-cell {
    position: relative;
    cursor: default;
}
.lots-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    z-index: 300;
    background: #1a1a2e;
    color: #f0f0f0;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    line-height: 1.6;
    box-shadow: 0 4px 16px rgba(0,0,0,.35);
    pointer-events: none;
}
.stock-cost-cell:hover .lots-tooltip {
    display: block;
}
.lots-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 16px;
    border: 5px solid transparent;
    border-top-color: #1a1a2e;
}

/* --- Nav Drawer (More Menu) --- */
#nav-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.48);
    z-index: 250;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

#nav-drawer-overlay.hidden {
    display: none;
}

#nav-drawer {
    background: var(--card);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 8px 16px calc(var(--safe-bottom) + 20px);
    width: 100%;
    max-width: 600px;
    animation: slideUp 0.25s ease;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
}

.nav-drawer-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 6px auto 16px;
}

.nav-drawer-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 12px;
    padding-left: 4px;
}

#nav-drawer-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding-bottom: 4px;
}

/* 11 items: 4+4+3 rows — keep 4 cols on mobile */
@media (max-width: 380px) {
    #nav-drawer-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.nav-drawer-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 4px;
    border-radius: 12px;
    border: none;
    background: var(--bg);
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    color: var(--text);
    text-align: center;
    transition: background var(--transition), transform var(--transition);
    -webkit-tap-highlight-color: transparent;
    line-height: 1.3;
}

.nav-drawer-btn:active {
    background: var(--border);
    transform: scale(0.93);
}

.nav-drawer-btn.drawer-active {
    color: var(--primary);
}

.nav-drawer-btn.drawer-active .nav-drawer-icon {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.nav-drawer-icon {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

@media (min-width: 769px) {
    #nav-drawer {
        border-radius: var(--radius-xl);
        margin-bottom: calc(var(--header-height) + 12px);
        max-width: 480px;
    }
    #nav-drawer-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}
