/* FinKote Portal Styles */

:root {
    --primary: #1e40af;
    --primary-dark: #1e3a8a;
    --primary-light: #3b82f6;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --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;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.5;
    min-height: 100vh;
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: var(--primary);
    color: white;
    padding: 1rem 0;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    text-decoration: none;
}

.logo span {
    color: var(--gray-300);
    font-weight: 400;
}

.nav {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.nav a {
    color: var(--gray-200);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    transition: background 0.2s;
}

.nav a:hover,
.nav a.active {
    background: var(--primary-dark);
    color: white;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--gray-200);
    font-size: 0.875rem;
}

.customer-switcher {
    appearance: none;
    -webkit-appearance: none;
    background: var(--primary-dark);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius);
    padding: 0.25rem 1.75rem 0.25rem 0.5rem;
    font-size: 0.8rem;
    cursor: pointer;
    max-width: 220px;
    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='white' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
}

.customer-switcher:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.4);
}

.customer-switcher option {
    background: var(--primary);
    color: white;
}

/* Main Content */
.main {
    flex: 1;
    padding: 2rem 0;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--gray-900);
}

/* Cards */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-800);
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: var(--gray-700);
    font-size: 0.875rem;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

.form-input::placeholder {
    color: var(--gray-400);
}

.form-input-sm {
    padding: 0.375rem 0.5rem;
    font-size: 0.875rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #047857;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

.btn-lg {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-card {
    background: white;
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo h1 {
    font-size: 1.75rem;
    color: var(--primary);
}

.login-logo p {
    color: var(--gray-500);
    margin-top: 0.25rem;
}

.login-error {
    background: #fef2f2;
    color: var(--danger);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
    display: none;
}

.login-error.show {
    display: block;
}

/* Quote Builder */
.quote-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.line-items-container {
    margin-bottom: 1.5rem;
}

.line-item {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    position: relative;
}

.line-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.line-item-number {
    font-weight: 600;
    color: var(--gray-600);
}

.line-item-remove {
    color: var(--danger);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    transition: background 0.2s;
}

.line-item-remove:hover {
    background: #fef2f2;
}

.line-item-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
}

.line-item-calc {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-200);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
    font-size: 0.875rem;
}

.calc-label {
    color: var(--gray-500);
}

.calc-value {
    font-weight: 600;
    color: var(--gray-800);
}

.calc-value.total {
    color: var(--success);
    font-size: 1.125rem;
}

/* Dimension Fields */
.dimension-fields {
    display: none;
}

.dimension-fields.active {
    display: grid;
}

/* Quote Summary */
.quote-summary {
    background: var(--gray-800);
    color: white;
    padding: 1.5rem;
    border-radius: var(--radius);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.quote-total-label {
    font-size: 1rem;
    color: var(--gray-300);
}

.quote-total-value {
    font-size: 2rem;
    font-weight: 700;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

th {
    background: var(--gray-50);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-600);
}

tr:hover {
    background: var(--gray-50);
}

.table-actions {
    display: flex;
    gap: 0.5rem;
}

/* Status Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

/* Sidebar */
.layout-with-sidebar {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1.5rem;
}

.sidebar {
    position: sticky;
    top: 1rem;
    align-self: start;
}

.recent-quotes {
    list-style: none;
}

.recent-quote-item {
    padding: 0.75rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.recent-quote-item:hover {
    background-color: var(--gray-100);
}

.recent-quote-item:last-child {
    border-bottom: none;
}

.recent-quote-number {
    font-weight: 600;
    color: var(--primary);
}

.recent-quote-date {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.recent-quote-total {
    font-weight: 600;
}

/* Alerts & Messages */
.alert {
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

/* Loading State */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--gray-500);
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 0.75rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-400);
    line-height: 1;
}

.modal-close:hover {
    color: var(--gray-600);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Responsive */
@media (max-width: 768px) {
    .layout-with-sidebar {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
    }

    .quote-header {
        grid-template-columns: 1fr;
    }

    .header-content {
        flex-direction: column;
        gap: 1rem;
    }

    .nav {
        flex-wrap: wrap;
        justify-content: center;
    }

    .quote-summary {
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
    }

    .line-item-fields {
        grid-template-columns: 1fr 1fr;
    }
}

/* Facility Size Warning Styles */
.facility-warning {
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-left: 4px solid #f59e0b;
    border-radius: var(--radius);
    font-size: 0.875rem;
}

.facility-warning.hard-block {
    background: #fee2e2;
    border-color: #dc2626;
    border-left-color: #dc2626;
}

.facility-warning-content {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.facility-warning-icon {
    flex-shrink: 0;
    font-size: 1rem;
}

.facility-warning-message {
    color: #92400e;
    line-height: 1.4;
}

.facility-warning.hard-block .facility-warning-message {
    color: #991b1b;
}

.facility-warning-action {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(245, 158, 11, 0.3);
}

.facility-warning-action label {
    display: block;
    font-weight: 500;
    color: #92400e;
    margin-bottom: 0.5rem;
}

.facility-alternative-select {
    width: 100%;
    max-width: 300px;
}

/* Help Tooltips */
.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--gray-300);
    color: var(--gray-600);
    font-size: 0.625rem;
    font-weight: 700;
    cursor: help;
    margin-left: 0.375rem;
    position: relative;
    vertical-align: middle;
    line-height: 1;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}

.help-icon:hover {
    background: var(--primary);
    color: white;
}

.help-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--gray-800);
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.4;
    max-width: 260px;
    width: max-content;
    white-space: normal;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.help-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--gray-800);
}

.help-icon:hover .help-tooltip {
    opacity: 1;
    visibility: visible;
}

/* Floating Help Button */
.help-fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
}

.help-fab:hover {
    background: var(--primary-dark);
    transform: scale(1.1);
}

/* Large Modal Variant */
.modal.modal-lg {
    max-width: 640px;
}

/* Guide Page Styles */
.guide-toc {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.5rem;
}

.guide-toc a {
    color: var(--primary);
    text-decoration: none;
    padding: 0.375rem 0;
    display: block;
    font-size: 0.875rem;
}

.guide-toc a:hover {
    text-decoration: underline;
}

.guide-section {
    scroll-margin-top: 1rem;
}

.guide-section h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary);
}

.guide-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
    margin: 1rem 0 0.5rem;
}

.guide-section p,
.guide-section li {
    font-size: 0.875rem;
    color: var(--gray-700);
    line-height: 1.6;
}

.guide-section ul,
.guide-section ol {
    margin-left: 1.25rem;
    margin-bottom: 0.75rem;
}

.guide-section li {
    margin-bottom: 0.25rem;
}

.guide-section code {
    background: var(--gray-100);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-size: 0.8125rem;
}

.tip {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
    border-left: 4px solid var(--primary);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    margin: 0.75rem 0;
}

.tip strong {
    display: block;
    margin-bottom: 0.25rem;
}

/* ========================================
   Production Lot Tracking
   ======================================== */

/* Progress bar - 6 stage pipeline */
.stage-progress {
    display: flex;
    align-items: center;
    gap: 0;
    min-width: 180px;
}

.stage-step {
    display: flex;
    align-items: center;
}

.stage-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--gray-300);
    flex-shrink: 0;
    transition: background 0.2s;
}

.stage-dot.completed {
    background: var(--success);
}

.stage-dot.current {
    background: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.2);
    animation: stage-pulse 2s ease-in-out infinite;
}

.stage-dot.shipped {
    background: var(--gray-500);
}

.stage-line {
    width: 16px;
    height: 2px;
    background: var(--gray-300);
    flex-shrink: 0;
}

.stage-line.completed {
    background: var(--success);
}

@keyframes stage-pulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.2); }
    50% { box-shadow: 0 0 0 5px rgba(30, 64, 175, 0.1); }
}

/* Stage label badge */
.stage-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}

.stage-badge.stage-1 { background: #dbeafe; color: #1e40af; }
.stage-badge.stage-2 { background: #fef3c7; color: #92400e; }
.stage-badge.stage-3 { background: #fce7f3; color: #9d174d; }
.stage-badge.stage-4 { background: #ede9fe; color: #5b21b6; }
.stage-badge.stage-5 { background: #d1fae5; color: #065f46; }
.stage-badge.stage-6 { background: var(--gray-200); color: var(--gray-600); }

/* Tracking filter bar */
.tracking-filters {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.tracking-filters .form-group {
    margin-bottom: 0;
}

.tracking-status-toggle {
    display: inline-flex;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    overflow: hidden;
}

.tracking-status-toggle button {
    padding: 0.375rem 0.75rem;
    border: none;
    background: white;
    color: var(--gray-600);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.tracking-status-toggle button.active {
    background: var(--primary);
    color: white;
}

.tracking-status-toggle button:hover:not(.active) {
    background: var(--gray-100);
}

/* Tracking table tweaks */
.tracking-table td {
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
    vertical-align: middle;
}

.tracking-table th {
    font-size: 0.7rem;
    padding: 0.5rem 0.75rem;
}

.tracking-table .lot-number {
    font-weight: 600;
    color: var(--gray-800);
}

.tracking-table .facility-badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    background: var(--gray-100);
    color: var(--gray-700);
}

/* Tracking empty / disabled state */
.tracking-disabled {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--gray-500);
}

.tracking-disabled h3 {
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

/* Lot count summary */
.tracking-summary {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.tracking-stat {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.tracking-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-800);
}

.tracking-stat-label {
    font-size: 0.8rem;
    color: var(--gray-500);
}

/* Auto-refresh indicator */
.auto-refresh-indicator {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: var(--gray-400);
}

.refresh-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
}

/* Mobile: collapse progress bar to text */
@media (max-width: 768px) {
    .stage-progress {
        display: none;
    }
    .tracking-table .mobile-stage {
        display: block;
    }
    .tracking-table td, .tracking-table th {
        padding: 0.4rem 0.5rem;
        font-size: 0.78rem;
    }
}

@media (min-width: 769px) {
    .tracking-table .mobile-stage {
        display: none;
    }
}

/* Print Styles */
@media print {
    .header, .sidebar, .btn, .nav, .help-fab {
        display: none !important;
    }

    .main {
        padding: 0;
    }

    .card {
        box-shadow: none;
        border: 1px solid var(--gray-300);
    }

    .facility-warning {
        break-inside: avoid;
    }
}
