/*
 * ACE (Automation Control Engineering) Suite
 * Copyright (c) 2026 ACE Systems. All rights reserved.
 * Property of ACE Systems - Whakatane, Bay of Plenty, New Zealand.
 *
 * Proprietary and confidential. Unauthorised copying, distribution or
 * modification of this file, in whole or in part, is prohibited.
 */
/* ============================================
   PCS UDT/AOI REPORT — styling
   Matches the ACE-suite palette (dark blue header, blue accent) and gives
   tables the same look-and-feel as the exported .xlsx workbooks (bold
   headers, cell borders, zebra striping, Excel status colours).
   ============================================ */
:root {
    --header-bg: linear-gradient(135deg, #2c3e50 0%, #4a6491 100%);
    --main-bg: #eaf2fa;
    --border-color: #ddd;
    --text-dark: #333;
    --text-light: #555;
    --primary-accent: #0056b3;
    --primary-btn: #3498db;
    --secondary-btn: #6c757d;
    --table-header-bg: #f0f0f0;
    --table-header-border: #b0b0b0;
    --row-alt: #f8fbff;
    /* Excel's "Good" / "Bad" / "Neutral" cell styles */
    --status-ok-bg: #c6efce;   --status-ok-text: #006100;
    --status-mis-bg: #ffc7ce;  --status-mis-text: #9c0006;
    --status-nim-bg: #ffeb9c;  --status-nim-text: #9c5700;
    --status-nis-bg: #d9d9d9;  --status-nis-text: #404040;
    --type-udt-bg: #d1e7dd; --type-udt-text: #0f5132;
    --type-aoi-bg: #cff4fc; --type-aoi-text: #055160;
}

body, html {
    height: 100%; margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--main-bg);
    color: var(--text-dark);
    display: flex; flex-direction: column;
}

.header {
    flex-shrink: 0; display: flex; justify-content: space-between; align-items: center;
    background: var(--header-bg); color: white; padding: 12px 30px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.header h1 { margin: 0; font-size: 1.5em; font-weight: 600; }
.header a {
    padding: 8px 16px; border-radius: 5px; font-weight: 500; cursor: pointer;
    color: white; text-decoration: none; display: inline-block; border: none;
    font-size: 0.9em; background-color: var(--secondary-btn);
    transition: background-color 0.2s ease;
}
.header a:hover { background-color: #5a6268; }

.main-container {
    flex-grow: 1; overflow-y: auto; padding: 30px;
    max-width: 95%; margin: 0 auto; width: 100%; box-sizing: border-box;
}
.content-section {
    background: white; border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    padding: 30px; margin-bottom: 30px;
}
h2 {
    border-bottom: 2px solid var(--primary-accent); padding-bottom: 10px;
    margin-top: 0; font-size: 1.4rem; color: var(--text-dark);
}
.page-intro { color: #666; line-height: 1.5; max-width: 1000px; }
.page-intro strong { color: var(--text-dark); }

/* ---- Processing status (matches other ACE pages) ---- */
.processing-status {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 12px 16px;
    margin: 12px 0 18px 0;
    font-size: 0.95em;
    color: #444;
}
.processing-status.busy { border-color: #007bff; color: #0056b3; }
.processing-status.error { border-color: #dc3545; color: #a71d2a; }
.processing-status.done { border-color: #198754; color: #0f5132; }

/* ---- Tabs ---- */
.tabs {
    display: flex; gap: 4px; margin: 15px 0 20px 0;
    border-bottom: 2px solid var(--primary-accent);
}
.tab {
    padding: 10px 22px; border: none; background: #f0f0f0; color: #555;
    cursor: pointer; font-size: 0.95em; font-weight: 500;
    border-radius: 6px 6px 0 0;
    border: 1px solid transparent; border-bottom: none;
    margin-bottom: -2px;
}
.tab:hover { background: #e0e0e0; }
.tab.active {
    background: white; color: var(--primary-accent);
    border-color: var(--primary-accent);
    border-bottom: 2px solid white;
    font-weight: 600;
}
.tab-panel { display: block; }
.tab-panel.hidden { display: none; }

/* ---- Controls panel ---- */
.controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 18px;
    margin-bottom: 20px;
    padding: 18px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}
.control-group { display: flex; flex-direction: column; }
.control-group label {
    font-weight: 600; margin-bottom: 6px;
    color: var(--text-light); font-size: 0.88em;
}
.control-group input[type="text"], .control-group select {
    padding: 8px 10px; font-size: 0.95em;
    border: 1px solid var(--border-color); border-radius: 5px;
    box-sizing: border-box;
}
.control-hint {
    font-size: 0.78em; color: #888; margin-top: 4px;
}
.control-hint code {
    background: #eef1f4; padding: 1px 4px; border-radius: 3px;
    font-size: 0.9em;
}
.control-actions { flex-direction: row; align-items: flex-end; gap: 8px; }

.file-picker {
    max-height: 160px; overflow-y: auto;
    background: white; border: 1px solid var(--border-color); border-radius: 5px;
    padding: 6px 8px; font-size: 0.88em;
}
.file-picker label {
    display: block; font-weight: normal; padding: 2px 0;
    cursor: pointer; margin-bottom: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-picker label:hover { background: #f0f7ff; }
.file-picker input[type="checkbox"] { margin-right: 6px; vertical-align: middle; }
.file-picker-actions { margin-top: 4px; display: flex; gap: 12px; }
.btn-link {
    background: none; border: none; color: var(--primary-accent);
    cursor: pointer; padding: 2px 0; font-size: 0.82em; text-decoration: underline;
}
.btn-link:hover { color: #003d80; }

.btn-primary {
    padding: 9px 16px; border-radius: 5px; cursor: pointer;
    font-size: 0.95em; font-weight: 500; border: 1px solid transparent;
    background: var(--primary-btn); color: white;
}
.btn-primary:hover { background: #217bbe; }
.btn-primary:disabled { background: #bdd3e3; cursor: not-allowed; }
.btn-secondary {
    padding: 9px 16px; border-radius: 5px; cursor: pointer;
    font-size: 0.95em; font-weight: 500;
    background: #6c757d; color: white; border: 1px solid transparent;
}
.btn-secondary:hover { background: #5a6268; }
.btn-secondary:disabled { background: #b0b6bb; cursor: not-allowed; }

/* ---- Section header inside report container ---- */
.report-file-block { margin-bottom: 30px; }
.report-file-header {
    background: linear-gradient(135deg, #2c3e50 0%, #4a6491 100%);
    color: white;
    padding: 8px 14px;
    border-radius: 5px 5px 0 0;
    font-size: 1em;
    font-weight: 600;
    display: flex; justify-content: space-between; align-items: center;
}
.report-file-header .row-count {
    font-size: 0.82em; font-weight: 400; opacity: 0.85;
}
.report-subhead {
    margin: 22px 0 8px 0; font-size: 1.05em; font-weight: 600;
    color: var(--primary-accent);
    padding-bottom: 4px; border-bottom: 1px solid #cfe2ff;
}

/* ---- Excel-look tables ---- */
.excel-table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--table-header-border);
    border-top: none;
    max-height: 700px;      /* keep it manageable — inner scroll for long lists */
    overflow-y: auto;
    background: white;
}
.excel-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86em;
    background: white;
}
.excel-table th, .excel-table td {
    border: 1px solid #d0d0d0;
    padding: 5px 9px;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}
.excel-table th {
    background: var(--table-header-bg);
    color: #222;
    font-weight: 700;
    border-color: var(--table-header-border);
    position: sticky; top: 0; z-index: 1;
    cursor: pointer;
    user-select: none;
}
.excel-table th.sortable::after {
    content: '\2195';    /* up-down arrow */
    margin-left: 4px; color: #888; font-weight: normal; font-size: 0.85em;
}
.excel-table th.sorted-asc::after  { content: '\25B2'; color: #333; }
.excel-table th.sorted-desc::after { content: '\25BC'; color: #333; }
.excel-table tbody tr:nth-child(even) { background: var(--row-alt); }
.excel-table tbody tr:hover { background: #e8f2fd; }
.excel-table td.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.excel-table td.pct     { text-align: right; font-variant-numeric: tabular-nums; }
.excel-table td.description {
    white-space: normal;
    max-width: 400px;
    color: #444;
}
.excel-table td.name {
    font-family: 'Consolas', 'Courier New', monospace;
    font-weight: 600;
    color: #114;
}

/* Type badge (UDT / AOI) */
.type-badge {
    display: inline-block; font-size: 0.78em; font-weight: 700;
    padding: 2px 7px; border-radius: 3px; letter-spacing: 0.02em;
}
.type-badge.UDT { background: var(--type-udt-bg); color: var(--type-udt-text); }
.type-badge.AOI { background: var(--type-aoi-bg); color: var(--type-aoi-text); }

/* Status cells (Excel style) */
.status-cell {
    font-weight: 700; text-align: center;
    font-size: 0.82em; letter-spacing: 0.02em;
}
.status-OK          { background: var(--status-ok-bg);  color: var(--status-ok-text); }
.status-MISMATCH    { background: var(--status-mis-bg); color: var(--status-mis-text); }
.status-NOT-IN-MASTER { background: var(--status-nim-bg); color: var(--status-nim-text); }
.status-NOT-IN-SITE { background: var(--status-nis-bg); color: var(--status-nis-text); }

/* Highlight cells that participate in a mismatch (revision differs) */
.excel-table td.mismatch-cell {
    background: #ffe1e4;
    color: #9c0006;
    font-weight: 600;
}
/* Cross-plant compare: group headers for each site */
.excel-table th.master-col   { background: #d6e6ff; }
.excel-table th.site-col     { background: #eef4fa; }
.excel-table th.status-col   { background: #f0e6ff; }

.no-data {
    text-align: center; font-size: 1em; color: var(--text-light);
    padding: 30px; background: #f8f9fa; border-radius: 6px; border: 1px dashed #ccc;
    margin-top: 10px;
}

/* Report summary tile row (S88 REPORT_SHEET) */
.summary-tiles {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px; margin: 4px 0 22px 0;
}
.summary-tile {
    background: linear-gradient(135deg, #f0f7ff 0%, #dfeeff 100%);
    border: 1px solid #cfe2ff; border-radius: 8px;
    padding: 12px 16px;
    display: flex; flex-direction: column; gap: 4px;
}
.summary-tile .st-label { font-size: 0.72em; text-transform: uppercase; letter-spacing: 0.04em; color: #446; }
.summary-tile .st-value { font-size: 1.4em; font-weight: 700; color: var(--primary-accent); }
.summary-tile .st-sub   { font-size: 0.78em; color: #555; }
