/* ERP AI Invoice Engine - AdminLTE White Theme
   Matches erp_base_html AdminLTE skin-blue styling */

@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700&display=swap');

:root {
    --primary: #3c8dbc;
    --primary-dark: #367fa9;
    --primary-light: #d4eaf7;
    --success: #00a65a;
    --success-light: #e6f7ee;
    --warning: #f39c12;
    --warning-light: #fef5e5;
    --danger: #dd4b39;
    --danger-light: #fbe9e7;
    --info: #00c0ef;
    --info-light: #e0f7fa;

    /* Aliases for JS inline styles */
    --accent: #3c8dbc;
    --accent-hover: #367fa9;
    --bg-secondary: #f9fafb;
    --bg-card: #ffffff;
    --bg-hover: #f5f8fc;

    --bg-body: #ecf0f5;
    --bg-white: #ffffff;
    --bg-header: #3c8dbc;
    --bg-header-dark: #367fa9;
    --bg-table-head: #f9fafb;
    --bg-table-hover: #f5f8fc;
    --bg-sidebar: #222d32;

    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    --text-white: #ffffff;
    --text-link: #3c8dbc;

    --border: #d2d6de;
    --border-light: #f4f4f4;
    --radius: 3px;
    --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 2px 8px rgba(0,0,0,0.15);
}

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

body {
    font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--text-link); text-decoration: none; }
a:hover { color: var(--primary-dark); text-decoration: underline; }
code { background: #f4f4f4; padding: 1px 5px; border-radius: 3px; font-size: 12px; color: #c7254e; border: 1px solid #e1e1e1; }

/* ================= HEADER ================= */
.app-header {
    background: var(--bg-header);
    border-bottom: none;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    height: 50px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.app-header h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-white);
    letter-spacing: 0.3px;
}

.app-header .version {
    font-size: 11px;
    color: rgba(255,255,255,0.65);
    margin-left: 8px;
    background: rgba(0,0,0,0.15);
    padding: 1px 6px;
    border-radius: 3px;
}

.health-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: rgba(255,255,255,0.8);
}

.health-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: rgba(255,255,255,0.3);
    border: 1px solid rgba(255,255,255,0.4);
}
.health-dot.healthy { background: #00e676; border-color: #00c853; box-shadow: 0 0 6px rgba(0,230,118,0.5); }
.health-dot.degraded { background: var(--warning); border-color: #e8960b; }
.health-dot.unhealthy { background: var(--danger); border-color: #c62828; }

/* ================= TAB NAV ================= */
.tab-nav {
    display: flex;
    background: var(--bg-white);
    border-bottom: 2px solid var(--border);
    padding: 0 20px;
    overflow-x: auto;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.tab-btn {
    padding: 12px 22px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    margin-bottom: -2px;
    font-family: inherit;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: var(--bg-table-hover);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: transparent;
}

/* ================= TAB CONTENT ================= */
.tab-content {
    display: none;
    padding: 20px;
    max-width: 100%;
    margin: 0;
}
.tab-content.active { display: block; }

/* ================= CARDS (AdminLTE .box) ================= */
.card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-top: 3px solid var(--primary);
    border-radius: var(--radius);
    padding: 15px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    margin: -15px -15px 15px;
    color: var(--text-primary);
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-white);
    border-radius: var(--radius) var(--radius) 0 0;
}

/* Tables inside cards extend to edges */
.card > .table-wrapper {
    margin: 0 -15px -15px;
    border: none;
    border-top: 1px solid var(--border-light);
    border-radius: 0 0 var(--radius) var(--radius);
}

/* Upload zone */
.card > .upload-zone { margin: 0; }

/* ================= STAT CARDS (AdminLTE small-box) ================= */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px 20px;
    text-align: center;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary);
}

.stat-card:nth-child(2)::before { background: var(--success); }
.stat-card:nth-child(3)::before { background: var(--warning); }
.stat-card:nth-child(4)::before { background: var(--danger); }
.stat-card:nth-child(5)::before { background: var(--info); }
.stat-card:nth-child(6)::before { background: #605ca8; }

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.stat-card:nth-child(2) .stat-value { color: var(--success); }
.stat-card:nth-child(3) .stat-value { color: var(--warning); }
.stat-card:nth-child(4) .stat-value { color: var(--danger); }
.stat-card:nth-child(5) .stat-value { color: var(--info); }
.stat-card:nth-child(6) .stat-value { color: #605ca8; }

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* ================= UPLOAD AREA ================= */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 50px 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s;
    background: #fafcfe;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-zone .icon {
    font-size: 52px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.upload-zone p {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 4px 0;
}

.upload-zone .browse-link {
    color: var(--primary);
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
}

/* Progress Bar */
.progress-bar {
    height: 6px;
    background: #e9ecef;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 16px;
}

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

.upload-status {
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-secondary);
}

.upload-queue { margin-top: 12px; }

.queue-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #f9fafb;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    margin-bottom: 6px;
    font-size: 13px;
}

.queue-item .name { flex: 1; font-weight: 500; color: var(--text-primary); }
.queue-item .status { margin-left: 12px; font-size: 16px; }

/* ================= TABLES ================= */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    background: var(--bg-table-head);
    padding: 10px 12px;
    text-align: left;
    color: var(--text-secondary);
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    white-space: nowrap;
}

.data-table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
    color: var(--text-primary);
}

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

.data-table tfoot tr td {
    background: #f9fafb;
}

.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* ================= BADGES ================= */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-success { background: var(--success); color: var(--text-white); }
.badge-warning { background: var(--warning); color: var(--text-white); }
.badge-danger { background: var(--danger); color: var(--text-white); }
.badge-info { background: var(--info); color: var(--text-white); }
.badge-default { background: #d2d6de; color: #444; }

/* Confidence bar */
.confidence-bar {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
}

.confidence-fill {
    width: 55px;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
}

.confidence-fill .bar {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}

.confidence-fill .bar.high { background: var(--success); }
.confidence-fill .bar.medium { background: var(--warning); }
.confidence-fill .bar.low { background: var(--danger); }

/* ================= BUTTONS ================= */
.btn {
    padding: 6px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: #f4f4f4;
    color: #444;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: inherit;
    line-height: 1.5;
}

.btn:hover { background: #e7e7e7; border-color: #aaa; }

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--text-white);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-success {
    background: var(--success);
    border-color: var(--success);
    color: var(--text-white);
}
.btn-success:hover { background: #008d4c; border-color: #008d4c; }

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: var(--text-white);
}
.btn-danger:hover { background: #d73925; border-color: #d73925; }

.btn-warning {
    background: var(--warning);
    border-color: var(--warning);
    color: var(--text-white);
}

.btn-info {
    background: var(--info);
    border-color: var(--info);
    color: var(--text-white);
}

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

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

/* ================= FORMS ================= */
.form-group { margin-bottom: 12px; }

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

.form-input, .form-select {
    width: 100%;
    padding: 6px 12px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 6px rgba(60, 141, 188, 0.35);
}

/* ================= SEARCH DROPDOWN ================= */
.search-dropdown { position: relative; }

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    max-height: 220px;
    overflow-y: auto;
    z-index: 50;
    display: none;
    box-shadow: var(--shadow-lg);
}

.search-results.show { display: block; }

.search-result-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid var(--border-light);
    transition: background 0.1s;
}

.search-result-item:hover {
    background: var(--primary-light);
}

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

.search-result-item .sku {
    font-weight: 700;
    color: var(--primary);
}

.search-result-item .name {
    color: var(--text-muted);
    font-size: 12px;
}

/* ================= REVIEW PANEL ================= */
.review-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 12px;
    background: var(--bg-white);
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.review-info {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.review-info span {
    font-size: 13px;
    color: var(--text-secondary);
}

.review-info strong {
    color: var(--text-primary);
}

.review-actions {
    display: flex;
    gap: 8px;
}

/* ================= PO SUMMARY ================= */
.po-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 0;
    padding: 0;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.po-summary-item {
    padding: 12px 16px;
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
}

.po-summary-item .label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.po-summary-item .value {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ================= FILTERS ================= */
.filters-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    align-items: center;
}

.filters-bar .form-input,
.filters-bar .form-select {
    width: auto;
    min-width: 150px;
}

/* ================= TOAST NOTIFICATIONS ================= */
.toast-container {
    position: fixed;
    top: 60px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    max-width: 420px;
    border-left: 4px solid transparent;
}

.toast-success { background: var(--success-light); color: #1b5e20; border-left-color: var(--success); }
.toast-error { background: var(--danger-light); color: #b71c1c; border-left-color: var(--danger); }
.toast-warning { background: var(--warning-light); color: #7f6003; border-left-color: var(--warning); }
.toast-info { background: var(--info-light); color: #01579b; border-left-color: var(--info); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ================= SPINNER ================= */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
}

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

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: var(--text-muted);
    gap: 10px;
    font-size: 14px;
}

/* ================= EMPTY STATE ================= */
.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--text-muted);
}

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

/* ================= INLINE EDIT ================= */
.editable {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius);
    border: 1px solid transparent;
}

.editable:hover {
    border-color: var(--border);
    background: var(--bg-table-hover);
}

/* ================= RESPONSIVE ================= */
@media (max-width: 768px) {
    .tab-content { padding: 12px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .upload-zone { padding: 24px; }
    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 6px 8px; }
    .po-summary { grid-template-columns: repeat(2, 1fr); }
    .review-header { flex-direction: column; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .tab-btn { padding: 10px 14px; font-size: 13px; }
}

/* ================= MODAL ================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: var(--bg-white);
    border-radius: var(--radius);
    width: 100%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    animation: modalFadeIn 0.2s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-table-head);
    position: sticky;
    top: 0;
    z-index: 1;
}

.modal-header span {
    font-weight: 700;
    font-size: 14px;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}

.modal-close:hover {
    color: var(--danger);
}

#po-modal-body {
    padding: 16px;
}

/* ================= GRN INLINE ISSUES ================= */
.grn-issue {
    font-size: 11px;
    line-height: 1.4;
    padding: 3px 6px;
    border-radius: 3px;
    margin-bottom: 3px;
}

.grn-issue:last-child {
    margin-bottom: 0;
}

.grn-issue-warn {
    color: #856404;
    background: #fff8e1;
    border-left: 3px solid var(--warning);
}

.grn-issue-error {
    color: #922820;
    background: #ffeaea;
    border-left: 3px solid var(--danger);
}

.grn-issue .fa {
    margin-right: 3px;
}

.grn-issue-action {
    font-size: 10px;
    color: #555;
    margin-top: 1px;
    font-style: italic;
}

.grn-issue-action .fa {
    color: var(--primary);
}

.grn-issue-ok {
    font-size: 12px;
    color: var(--success);
    font-weight: 600;
}
