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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
header {
    background-color: #2c3e50;
    color: white;
    padding: 1rem 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

header nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 1.5rem;
}

header h1 a {
    color: white;
    text-decoration: none;
}

header ul {
    list-style: none;
    display: flex;
    gap: 2rem;
}

header a {
    color: white;
    text-decoration: none;
    transition: opacity 0.2s;
}

header a:hover {
    opacity: 0.8;
}

/* Main Content */
main {
    padding: 2rem 0;
    min-height: calc(100vh - 200px);
}

/* Footer */
footer {
    background-color: #34495e;
    color: white;
    text-align: center;
    padding: 1.5rem 0;
    margin-top: 3rem;
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #2c3e50;
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-text {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: #6c757d;
}

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

/* Buttons */
button, .btn-primary, .btn-add-item, .btn-add-po {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.btn-primary {
    background-color: #3498db;
    color: white;
    font-weight: 500;
}

.btn-primary:hover {
    background-color: #2980b9;
}

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

.btn-add-item, .btn-add-po {
    background-color: #27ae60;
    color: white;
    margin-top: 1rem;
}

.btn-add-item:hover, .btn-add-po:hover {
    background-color: #229954;
}

.btn-remove-item, .btn-remove-po {
    background-color: #e74c3c;
    color: white;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
}

.btn-remove-item:hover, .btn-remove-po:hover {
    background-color: #c0392b;
}

/* Converter Page */
.converter-page {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.converter-page h2 {
    color: #2c3e50;
    margin-bottom: 1rem;
}

.converter-page > p {
    color: #6c757d;
    margin-bottom: 2rem;
}

/* Bulk Items */
.bulk-items-section {
    margin-top: 2rem;
}

.bulk-items-section h3 {
    color: #2c3e50;
    margin-bottom: 0.5rem;
}

.bulk-item {
    background-color: #f8f9fa;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    border: 1px solid #dee2e6;
}

.bulk-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #dee2e6;
}

.bulk-item-header h4 {
    color: #2c3e50;
    margin: 0;
}

/* PO References */
.po-references-section {
    margin: 1.5rem 0;
}

.po-references-section > label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #2c3e50;
}

.po-reference {
    background-color: white;
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 0.75rem;
    border: 1px solid #dee2e6;
}

.po-reference-fields {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 1rem;
    align-items: start;
}

.po-reference-fields .form-group {
    margin-bottom: 0;
}

/* PO number autocomplete dropdown */
.po-number-wrapper {
    position: relative;
}

.po-autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 100%;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    z-index: 200;
    margin-top: 2px;
    overflow: hidden;
}

.po-autocomplete-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.po-autocomplete-item:hover {
    background: #f0f4ff;
}

.po-autocomplete-item .po-item-number {
    font-weight: 600;
    color: #003d9b;
}

.po-autocomplete-item .po-item-date {
    font-size: 11px;
    color: #737685;
}

.po-autocomplete-not-found {
    padding: 8px 12px;
    font-size: 13px;
    color: #737685;
    font-style: italic;
}

/* Form Actions */
.form-actions {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid #dee2e6;
    text-align: right;
}

/* Responsive */
@media (max-width: 768px) {
    .po-reference-fields {
        grid-template-columns: 1fr;
    }
    
    .btn-remove-po {
        margin-top: 0.5rem;
    }
    
    header nav {
        flex-direction: column;
        gap: 1rem;
    }
}

/* Generic Buttons (used by admin templates) */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    font-size: 1rem;
    line-height: 1.4;
    transition: background-color 0.2s;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #545b62;
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-sm {
    padding: 0.25rem 0.6rem;
    font-size: 0.85rem;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    margin-top: 1rem;
}

.data-table th,
.data-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.data-table th {
    background: #f5f5f5;
    font-weight: 600;
    color: #2c3e50;
}

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

/* Admin layouts */
.admin-dashboard,
.admin-suppliers,
.admin-import-excel {
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.admin-menu {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.admin-card {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 1.25rem;
}

.admin-card-wide {
    grid-column: 1 / -1;
}

.admin-card form .form-group {
    margin-bottom: 0.75rem;
}

.admin-card form .form-actions {
    margin-top: 1rem;
}

.admin-card h3 {
    color: #2c3e50;
    margin-bottom: 0.5rem;
}

.admin-card p {
    color: #555;
    margin-bottom: 1rem;
}

.supplier-upload,
.supplier-list,
.import-info,
.import-form {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 1.25rem;
    margin: 1.5rem 0;
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 4px;
    margin: 1rem 0;
    border-left: 4px solid transparent;
}

.alert-success {
    background: #d1e7dd;
    color: #0f5132;
    border-left-color: #0f5132;
}

.alert-error,
.alert-danger {
    background: #f8d7da;
    color: #842029;
    border-left-color: #842029;
}

.alert-info {
    background: #cfe2ff;
    color: #084298;
    border-left-color: #084298;
}

/* Log entry styling (job status page) */
.log-entry {
    margin: 0.2rem 0;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Footer */
footer p {
    margin: 0;
}


/* ----------------------------------------------------------------
   Flash alerts (admin supplier edit page)
   ---------------------------------------------------------------- */
.alert {
    padding: 0.75rem 1rem;
    margin: 1rem 0;
    border-radius: 4px;
    font-size: 0.95rem;
}
.alert-error {
    background: #fee;
    border: 1px solid #c33;
    color: #900;
}
.alert-ok {
    background: #e6f7e6;
    border: 1px solid #2d8a2d;
    color: #1f5e1f;
}

/* ----------------------------------------------------------------
   PDF text diff (Job Result page)
   ---------------------------------------------------------------- */
.diff-pane {
    font-family: 'Menlo', 'Consolas', monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    max-height: 480px;
    overflow-y: auto;
    padding: 0.5rem;
}
.diff-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    padding: 0.05rem 0.25rem;
    border-radius: 2px;
}
.diff-row-equal {
    color: #555;
}
.diff-row-added {
    background: #fde2e1;
    color: #900;
    border: 1px solid #c33;
    font-weight: 500;
}
.diff-row-removed {
    background: #efefef;
    color: #777;
    text-decoration: line-through;
}
.diff-row-changed {
    background: #fff7d6;
    color: #6b5400;
    border-left: 3px solid #f0c674;
    padding-left: 0.4rem;
}
.diff-marker {
    width: 1ch;
    color: #999;
    text-align: center;
    flex-shrink: 0;
}
.diff-text {
    white-space: pre-wrap;
    word-break: break-word;
    flex: 1;
}

/* The inline job-result diff summary card. */
.diff-summary {
    display: flex;
    gap: 1.5rem;
    padding: 0.75rem 1rem;
    background: #fff8e1;
    border: 1px solid #f0d97b;
    border-radius: 4px;
    margin: 1rem 0;
    font-size: 0.9rem;
    color: #6b5400;
}
.diff-summary strong { color: #2c3e50; }

/* Per-file diff block on the Job Result page. */
.pdf-diff-card {
    margin: 1rem 0;
    padding: 1rem 1.25rem;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
}
.pdf-diff-card h3 { margin-top: 0; }
.diff-file-block {
    margin-top: 1rem;
    padding: 0.75rem;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}
.diff-file-block h4 {
    margin: 0 0 0.25rem 0;
    font-size: 1rem;
    color: #2c3e50;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.diff-file-meta {
    color: #6c757d;
    font-size: 0.85rem;
    margin: 0 0 0.5rem 0;
}
.diff-tag {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.diff-tag-changed {
    background: #fde2e1;
    color: #900;
    border: 1px solid #c33;
}
.diff-tag-same {
    background: #e6f7e6;
    color: #1f5e1f;
    border: 1px solid #2d8a2d;
}
.diff-tag-multi {
    background: #e7f1ff;
    color: #084298;
    border: 1px solid #b6d4fe;
}
.diff-reference-block {
    margin-top: 0.75rem;
    padding: 0.75rem;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: #fafbfc;
}
.diff-reference-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid #e9ecef;
}
.diff-reference-label {
    font-size: 0.9rem;
    color: #495057;
}

/* The dynamic file input group on the converter page. */
.template-file-row {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: #f8f9fa;
    border: 1px dashed #c0c4c8;
    border-radius: 4px;
}
.template-file-row label {
    font-size: 0.9rem;
    color: #495057;
}

/* Tabular comparison layout (reference vs user). */
.diff-compare {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 0.5rem;
}
.diff-compare .diff-pane {
    margin: 0;
}
.diff-compare .diff-pane-header {
    background: #2c3e50;
    color: white;
    padding: 0.4rem 0.6rem;
    border-radius: 4px 4px 0 0;
    font-weight: 600;
    font-size: 0.85rem;
    margin: 0;
}


/* Transient badge shown next to the "PO References *" heading
   after the server has scanned the uploaded PDFs for PO numbers.
   Matches the colour palette used by the existing alerts. */
.po-status-badge {
    display: inline-block;
    margin-left: 0.6rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78em;
    font-weight: 600;
    vertical-align: middle;
}
.po-status-info {
    background: #e9ecef;
    color: #495057;
    font-style: italic;
}
.po-status-ok {
    background: #d4edda;
    color: #155724;
}
.po-status-warn {
    background: #fff3cd;
    color: #856404;
}
.po-status-error {
    background: #f8d7da;
    color: #721c24;
}

/* Raw AI JSON debug card (Job Result page) */
.debug-card {
    background: #fffbe6;
    border: 1px solid #f0c674;
    border-radius: 6px;
    padding: 1rem 1.25rem;
    margin: 1.5rem 0;
}
.debug-card details > summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.debug-card details > summary::-webkit-details-marker {
    display: none;
}
.debug-card details > summary::before {
    content: "▶ ";
    font-size: 0.8em;
    color: #777;
}
.debug-card details[open] > summary::before {
    content: "▼ ";
}
.debug-card-intro {
    color: #555;
    margin: 0.75rem 0 1rem;
}
.debug-raw-block {
    margin: 1rem 0;
    padding: 0.75rem;
    background: #fff;
    border: 1px solid #e8d27a;
    border-radius: 4px;
}
.debug-raw-block h4 {
    margin: 0 0 0.5rem 0;
    color: #6a4f00;
}
.debug-raw-pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 0.75rem;
    border-radius: 4px;
    overflow: auto;
    max-height: 480px;
    font-family: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
    font-size: 0.8rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0.5rem 0 0;
}
.debug-copy-btn,
.debug-pretty-btn {
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
}
.btn-small {
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
}
.debug-empty {
    color: #777;
    font-style: italic;
}
