:root {
    --primary: #232f3e;
    --primary-light: #37475a;
    --accent: #ff9900;
    --accent-hover: #e88b00;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --success: #059669;
    --error: #dc2626;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ─── Header ─── */
header {
    width: 100%;
    background: var(--primary);
    color: white;
    padding: 1.25rem 2rem;
    text-align: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    position: relative;
}

.header-user {
    position: absolute;
    top: 50%;
    right: 1.5rem;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.8125rem;
    color: rgba(255, 255, 255, 0.7);
}

.btn-logout {
    padding: 0.3rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.logo {
    text-decoration: none;
    color: white;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

header h1 span {
    color: var(--accent);
}

header p {
    margin-top: 0.25rem;
    font-size: 0.875rem;
    opacity: 0.7;
}

/* ─── Breadcrumb ─── */
.breadcrumb {
    width: 100%;
    max-width: 1100px;
    padding: 1rem 1rem 0;
    font-size: 0.8125rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
}

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

.breadcrumb a:hover {
    text-decoration: underline;
}

.bc-sep {
    margin: 0 0.375rem;
    opacity: 0.5;
}

.bc-current {
    font-weight: 600;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
}

.bc-logo {
    width: 20px;
    height: 20px;
    object-fit: contain;
    border-radius: 3px;
}

/* ─── Main ─── */
main {
    width: 100%;
    max-width: 1100px;
    padding: 1rem 1rem 2rem;
}

/* ─── Card ─── */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    font-size: 1.125rem;
    font-weight: 700;
}

.card-body {
    padding: 1.5rem;
}

/* ─── Forms ─── */
.form-group {
    margin-bottom: 1rem;
}

label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.3rem;
}

select,
input[type="text"] {
    width: 100%;
    padding: 0.6rem 0.75rem;
    font-size: 0.875rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: white;
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

input[type="file"] {
    width: 100%;
    padding: 0.4rem 0;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

select:focus,
input[type="text"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(255, 153, 0, 0.15);
}

select {
    cursor: pointer;
    appearance: none;
    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='%236b7280' d='M6 8.825a.5.5 0 0 1-.354-.146l-4-4a.5.5 0 1 1 .708-.708L6 7.617l3.646-3.646a.5.5 0 1 1 .708.708l-4 4A.5.5 0 0 1 6 8.825z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.25rem;
}

input[type="text"]::placeholder {
    color: #9ca3af;
}

/* Inline form (add keyword) */
.inline-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.inline-form input[type="text"] {
    flex: 1;
}

.inline-form .btn {
    margin-top: 0;
    white-space: nowrap;
}

/* Client add form */
.add-client-form {
    margin-bottom: 1.25rem;
}

/* Product add form */
.add-product-form {
    margin-bottom: 1.25rem;
}

.form-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 140px;
    margin-bottom: 0;
}

.form-group-btn {
    flex: 0 0 auto !important;
    min-width: auto !important;
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--accent);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none;
}

.btn:hover {
    background: var(--accent-hover);
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
}

.btn-secondary {
    background: var(--primary-light);
    color: white;
}

.btn-secondary:hover {
    background: var(--primary);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-muted);
    transition: background 0.15s, color 0.15s;
}

.btn-danger-icon:hover {
    background: #fef2f2;
    color: var(--error);
}

/* ─── Client Grid ─── */
.client-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.client-card {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 1rem 1.25rem;
    background: var(--bg);
    border-radius: 10px;
    text-decoration: none;
    color: var(--text);
    transition: box-shadow 0.2s, transform 0.15s;
    position: relative;
}

.client-card:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.client-logo {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    overflow: hidden;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1px solid var(--border);
}

.client-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.client-initials {
    font-size: 1rem;
    font-weight: 800;
    color: var(--primary-light);
}

.client-info {
    flex: 1;
    min-width: 0;
}

.client-info h3 {
    font-size: 0.9375rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.client-info p {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

.client-delete {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    opacity: 0;
    transition: opacity 0.15s;
}

.client-card:hover .client-delete {
    opacity: 1;
}

/* ─── Product Thumbnails ─── */
.col-img {
    width: 50px;
    padding: 0.375rem 0.5rem !important;
}

.product-thumb {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: white;
}

.product-thumb-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background: var(--bg);
    border: 1px solid var(--border);
}

/* ─── Product Header (keyword page) ─── */
.product-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 1rem 1.25rem;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.product-header-img {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: white;
    flex-shrink: 0;
}

.product-header-info h2 {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 0.375rem;
}

/* ─── Data Tables ─── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table thead th {
    text-align: left;
    padding: 0.625rem 0.75rem;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
}

.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.sortable:hover {
    color: var(--text);
}

.sort-icon::after {
    content: '⇅';
    margin-left: 0.25rem;
    opacity: 0.3;
    font-size: 0.625rem;
}

.sort-asc .sort-icon::after {
    content: '▲';
    opacity: 0.8;
}

.sort-desc .sort-icon::after {
    content: '▼';
    opacity: 0.8;
}

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

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

.data-table tbody tr:hover {
    background: #f9fafb;
}

.table-link {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
}

.table-link:hover {
    color: var(--accent-hover);
}

.actions {
    width: 40px;
    text-align: center;
}

.col-check {
    width: 36px;
    text-align: center;
}

.col-pos {
    width: 90px;
    text-align: center;
}

.col-vol {
    width: 90px;
    text-align: right;
}

.volume-editable {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8125rem;
    font-weight: 600;
    background: #eff6ff;
    color: #2563eb;
    cursor: pointer;
    min-width: 40px;
    text-align: right;
    transition: background 0.15s;
}

.volume-editable:hover {
    background: #dbeafe;
}

.volume-input {
    width: 70px;
    padding: 0.15rem 0.375rem;
    font-size: 0.8125rem;
    font-weight: 600;
    border: 2px solid #2563eb;
    border-radius: 4px;
    background: white;
    color: #2563eb;
    text-align: right;
    outline: none;
    -moz-appearance: textfield;
}

.volume-input::-webkit-outer-spin-button,
.volume-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.mono {
    font-family: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.8125rem;
}

.text-muted {
    color: var(--text-muted);
}

/* Group rows in product table */
.group-row td {
    background: var(--bg);
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--primary-light);
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

/* ─── Product Info Bar ─── */
.product-info {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-wrap: wrap;
}

.pill {
    display: inline-block;
    padding: 0.2rem 0.625rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--accent);
    color: var(--primary);
}

.pill-muted {
    background: var(--border);
    color: var(--text-muted);
}

/* ─── Rank Badges ─── */
.rank-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8125rem;
    font-weight: 700;
}

.rank-found {
    background: #ecfdf5;
    color: var(--success);
}

.rank-notfound {
    background: var(--bg);
    color: var(--text-muted);
}

/* ─── Amazon Badges ─── */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.6875rem;
    font-weight: 700;
    white-space: nowrap;
    margin: 0.1rem 0.125rem;
}

.badge-amazons-choice {
    background: #1a3a4a;
    color: #ff9900;
}

.badge-best-seller {
    background: #ff9900;
    color: var(--primary);
}

.badge-prime {
    background: #00a8e1;
    color: white;
}

.badge-climate-pledge-friendly {
    background: #267346;
    color: white;
}

.badge-default {
    background: var(--bg);
    color: var(--text-muted);
}

/* ─── Flash Messages ─── */
.flash-messages {
    margin-bottom: 1rem;
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    animation: slideUp 0.3s ease;
}

.flash-success {
    background: #ecfdf5;
    color: var(--success);
    border: 1px solid #a7f3d0;
}

.flash-error {
    background: #fef2f2;
    color: var(--error);
    border: 1px solid #fecaca;
}

/* ─── Empty State ─── */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 0;
    font-size: 0.9375rem;
}

/* ─── Spinner ─── */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2.5px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 0.375rem;
}

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

@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Checkbox ─── */
input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* ─── Tabs ─── */
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}

.tab {
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ─── Chart ─── */
.chart-container {
    position: relative;
    height: 400px;
}

.chart-toggle {
    display: flex;
    gap: 0.375rem;
}

.chart-type-btn {
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
    background: var(--bg);
    color: var(--text-muted);
}

.chart-type-btn.active {
    background: var(--accent);
    color: var(--primary);
}

/* ─── Login Page ─── */
.login-body {
    background: var(--primary);
    justify-content: center;
    min-height: 100vh;
}

.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem 1rem;
}

.login-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
    animation: fadeIn 0.4s ease;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.02em;
}

.login-header h1 span {
    color: var(--accent);
}

.login-header p {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.login-messages {
    margin-bottom: 1.25rem;
}

.login-form .form-group {
    margin-bottom: 1.25rem;
}

.login-form input[type="email"],
.login-form input[type="password"] {
    width: 100%;
    padding: 0.7rem 0.875rem;
    font-size: 0.9375rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: white;
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.login-form input[type="email"]:focus,
.login-form input[type="password"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(255, 153, 0, 0.15);
}

.login-form input::placeholder {
    color: #9ca3af;
}

.login-btn {
    width: 100%;
    padding: 0.75rem;
    font-size: 0.9375rem;
    margin-top: 0.5rem;
}

.login-locked {
    text-align: center;
    padding: 1.5rem 0;
}

.locked-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
}

.login-locked p {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.locked-detail {
    font-size: 0.875rem !important;
    font-weight: 400 !important;
    color: var(--text-muted) !important;
}

.login-footer {
    margin-top: 2rem;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.4);
}

/* ─── Footer ─── */
footer {
    margin-top: auto;
    padding: 1.5rem;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ─── Responsive ─── */
@media (max-width: 640px) {
    main {
        padding: 0.75rem;
    }

    .card-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }

    .form-row {
        flex-direction: column;
    }

    .form-row .form-group {
        min-width: 100%;
    }

    .inline-form {
        flex-direction: column;
    }

    .data-table {
        font-size: 0.8125rem;
    }

    .col-pos {
        width: 70px;
    }

    .keyword-table .actions,
    .keyword-table .col-check {
        width: 30px;
    }

    .client-grid {
        grid-template-columns: 1fr;
    }

    .product-header {
        flex-direction: column;
        text-align: center;
    }
}
