/* Mobile Stores Provision Calculator - Styles */

:root {
    /* Color Palette */
    --primary-color: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #6366f1;
    --secondary-color: #06b6d4;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;

    /* Neutral Colors */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 0.75rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;

    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
        sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: linear-gradient(135deg, var(--gray-50) 0%, var(--gray-100) 100%);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
    padding: var(--spacing-lg);
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Header */
header {
    text-align: center;
    margin-bottom: var(--spacing-2xl);
    padding: var(--spacing-xl) 0;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: var(--spacing-sm);
}

.subtitle {
    font-size: 1.125rem;
    color: var(--gray-600);
    font-weight: 400;
}

/* Sections */
section {
    background: white;
    border-radius: var(--radius-xl);
    padding: var(--spacing-xl);
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--shadow-md);
}

/* Input Section */
.input-section {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid var(--gray-200);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-700);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group input,
.form-group select {
    padding: 0.75rem 1rem;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: all 0.2s ease;
    background: white;
    width: 100%;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group .autocomplete-wrapper {
    width: 100%;
}

.form-group .autocomplete-wrapper input {
    width: 100%;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1rem;
    font-weight: 500;
    text-transform: none;
    letter-spacing: normal;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.checkbox-group small {
    color: var(--gray-500);
    font-size: 0.75rem;
    margin-top: 0.25rem;
    font-weight: 400;
}

/* Buttons */
button {
    cursor: pointer;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.2s ease;
    padding: 0.875rem 1.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    color: white;
    width: 100%;
    font-size: 1.125rem;
    padding: 1rem 2rem;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 100%);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: white;
    color: var(--gray-700);
    border: 2px solid var(--gray-300);
}

.btn-secondary:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
}

/* Controls Section */
.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-lg);
    flex-wrap: wrap;
}

.search-box {
    flex: 1;
    min-width: 250px;
}

.autocomplete-wrapper {
    position: relative;
    width: 100%;
}

.search-box input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 1rem;
    background: white url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%236b7280" stroke-width="2"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/></svg>') no-repeat 0.75rem center;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.autocomplete-items {
    position: absolute;
    border: 2px solid var(--gray-300);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    z-index: 99;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 300px;
    overflow-y: auto;
    background-color: white;
    box-shadow: var(--shadow-lg);
    display: none;
}

.autocomplete-items.active {
    display: block;
}

.autocomplete-item {
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    cursor: pointer;
    border-bottom: 1px solid var(--gray-200);
    transition: background-color 0.15s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.autocomplete-item:hover,
.autocomplete-item.active {
    background-color: var(--gray-50);
}

.autocomplete-item strong {
    color: var(--primary-color);
}

.autocomplete-item .country-name {
    font-weight: 500;
    color: var(--gray-900);
}

.autocomplete-item .country-currency {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin-left: var(--spacing-sm);
}

.button-group {
    display: flex;
    gap: var(--spacing-sm);
}

/* Results Table */
.results-section {
    padding: 0;
    overflow: hidden;
}

.table-wrapper {
    overflow-x: auto;
    max-height: 70vh;
    overflow-y: auto;
    /* Force scrollbar gutter to always be present to prevent layout shift */
    scrollbar-gutter: stable;
}

/* Fallback for browsers that don't support scrollbar-gutter */
@supports not (scrollbar-gutter: stable) {
    .table-wrapper {
        /* Reserve space for scrollbar on webkit browsers */
        padding-right: 15px;
        margin-right: -15px;
    }
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: linear-gradient(135deg, var(--gray-800) 0%, var(--gray-700) 100%);
    color: white;
}

thead th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

thead th.pin-column {
    width: 50px;
    padding: 1rem 0.5rem;
    text-align: center;
}

thead th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease;
}

thead th.sortable:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.sort-icon {
    display: inline-block;
    margin-left: var(--spacing-xs);
    font-size: 0.75rem;
}

tbody tr {
    border-bottom: 1px solid var(--gray-200);
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background-color: var(--gray-50);
}

tbody tr:last-child {
    border-bottom: none;
}

tbody td {
    padding: 1rem;
    font-size: 0.9375rem;
}

/* Pin Button */
.pin-cell {
    text-align: center;
    padding: 0.5rem;
}

.pin-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.25rem 0.5rem;
    transition: transform 0.2s ease;
    opacity: 0.5;
}

.pin-btn:hover {
    transform: scale(1.2);
    opacity: 1;
}

.pin-btn.pinned {
    opacity: 1;
}

/* Pinned Rows */
tbody tr.pinned-row {
    background: linear-gradient(90deg, rgba(79, 70, 229, 0.05) 0%, rgba(255, 255, 255, 1) 100%);
    border-left: 4px solid var(--primary-color);
    transition: all 0.4s ease;
}

tbody tr.pinned-row:hover {
    background: linear-gradient(90deg, rgba(79, 70, 229, 0.08) 0%, var(--gray-50) 100%);
}

.country-cell {
    font-weight: 600;
    color: var(--gray-900);
}

.currency-badge {
    display: inline-block;
    background: var(--gray-200);
    color: var(--gray-700);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: var(--spacing-xs);
}

.price-selector {
    padding: 0.5rem 0.75rem;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background: white;
    cursor: pointer;
    min-width: 120px;
    transition: all 0.2s ease;
}

.price-selector:hover {
    border-color: var(--primary-color);
}

.price-selector:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Price Input in Table */
.price-cell {
    position: relative;
}

.price-input-wrapper {
    position: relative;
    display: inline-block;
    min-width: 140px;
}

.price-input {
    padding: 0.5rem 0.75rem;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background: white;
    min-width: 120px;
    transition: all 0.2s ease;
    width: 100%;
}

.price-input:hover {
    border-color: var(--primary-color);
}

.price-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.price-input:disabled {
    background: var(--gray-100);
    color: var(--gray-500);
    cursor: not-allowed;
}

.price-input::placeholder {
    color: var(--gray-400);
    font-style: italic;
}

.price-input.manually-changed {
    background: linear-gradient(135deg, rgba(251, 146, 60, 0.05) 0%, white 100%);
    border-color: var(--warning-color);
    animation: inputHighlight 0.5s ease;
}

@keyframes inputHighlight {
    0% {
        background: rgba(251, 146, 60, 0.2);
        box-shadow: 0 0 0 3px rgba(251, 146, 60, 0.2);
    }
    100% {
        background: linear-gradient(135deg, rgba(251, 146, 60, 0.05) 0%, white 100%);
        box-shadow: none;
    }
}

.price-input-wrapper .autocomplete-items {
    min-width: 140px;
}

.tax-cell,
.proceeds-cell {
    color: var(--gray-700);
}

.tax-rate,
.commission-rate {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

.proceeds-cell strong {
    color: var(--success-color);
    font-size: 1rem;
}

.no-data td {
    text-align: center;
    padding: 3rem;
    color: var(--gray-500);
    font-style: italic;
}

/* Footer */
footer {
    text-align: center;
    padding: var(--spacing-xl) 0;
    color: var(--gray-600);
    font-size: 0.875rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: var(--spacing-sm);
    }

    header h1 {
        font-size: 1.875rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    section {
        padding: var(--spacing-md);
        border-radius: var(--radius-lg);
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box {
        min-width: 100%;
    }

    .button-group {
        width: 100%;
    }

    .button-group button {
        flex: 1;
    }

    table {
        font-size: 0.875rem;
    }

    thead th,
    tbody td {
        padding: 0.75rem 0.5rem;
    }
}

/* Loading State */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

.loading {
    background: linear-gradient(
        90deg,
        var(--gray-200) 0%,
        var(--gray-300) 50%,
        var(--gray-200) 100%
    );
    background-size: 1000px 100%;
    animation: shimmer 2s infinite;
}

/* Animations */
@keyframes pinHighlight {
    0% {
        background: rgba(79, 70, 229, 0.2);
    }
    100% {
        background: linear-gradient(90deg, rgba(79, 70, 229, 0.05) 0%, rgba(255, 255, 255, 1) 100%);
    }
}

@keyframes unpinHighlight {
    0% {
        background: rgba(79, 70, 229, 0.15);
        border-left: 4px solid var(--primary-color);
    }
    100% {
        background: transparent;
        border-left: none;
    }
}

tbody tr {
    transition: background-color 0.3s ease, border-left 0.3s ease;
}

tbody tr.just-pinned {
    animation: pinHighlight 0.5s ease;
}

tbody tr.just-unpinned {
    animation: unpinHighlight 0.5s ease;
}

/* Custom Price Input Styling */
.price-input.custom-price {
    border-color: var(--warning-color);
    border-width: 2px;
}

.price-input.custom-price:focus {
    border-color: var(--warning-color);
    box-shadow: 0 0 0 3px rgba(251, 146, 60, 0.2);
}

/* Advanced Mode Styles */
.advanced-fields {
    margin-top: var(--spacing-xl);
    padding-top: var(--spacing-xl);
    border-top: 2px solid var(--gray-200);
    animation: slideDown 0.3s ease-out;
}

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

.advanced-fields h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: var(--spacing-lg);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.advanced-fields h3::before {
    content: "⚙️";
    font-size: 1.5rem;
}

.advanced-fields .form-group small {
    color: var(--gray-600);
    font-size: 0.8125rem;
    font-weight: 400;
    line-height: 1.4;
}

.advanced-fields input[type="number"] {
    font-family: 'Courier New', monospace;
    font-weight: 500;
}

.advanced-column {
    background: rgba(79, 70, 229, 0.02);
    border-left: 2px solid rgba(79, 70, 229, 0.1);
}

thead .advanced-column {
    background: rgba(0, 0, 0, 0.2);
    border-left: 2px solid rgba(255, 255, 255, 0.1);
}

tbody tr:hover .advanced-column {
    background: rgba(79, 70, 229, 0.05);
}

/* Highlight advanced mode indicator in proceeds cell */
.proceeds-cell {
    position: relative;
}

tbody tr.pinned-row .advanced-column {
    background: rgba(79, 70, 229, 0.08);
}

/* Input validation and feedback */
.form-group input[type="number"]:invalid {
    border-color: var(--danger-color);
}

.form-group input[type="number"]:valid {
    border-color: var(--success-color);
}

/* Advanced mode responsive adjustments */
@media (max-width: 768px) {
    .advanced-fields h3 {
        font-size: 1.125rem;
    }

    .advanced-column {
        font-size: 0.8125rem;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
        padding: 0;
    }

    .controls,
    .input-section,
    button {
        display: none;
    }

    section {
        box-shadow: none;
        page-break-inside: avoid;
    }

    .advanced-fields {
        display: none;
    }
}
