/*
 * 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 I/O CARD UTILIZATION — styling
   Matches the existing PCS-page palette (dark blue header, blue accent).
   ============================================ */
: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: #f8f9fa;
    --used-color: #28a745;
    --unused-color: #dbdbdb;
    --unknown-color: #cccccc;
    --spare-color: #ffc107;
}

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.6rem; color: var(--text-dark);
}
.page-intro { color: #666; line-height: 1.5; max-width: 1000px; }
.page-intro em { font-style: italic; }

/* ---- Status ---- */
.index-status {
    display: none;
    background: #f0f7ff; border: 1px solid #cfe2ff;
    padding: 10px 14px; border-radius: 6px; margin: 15px 0;
    font-size: 0.95em; color: #084298;
}
.index-status.busy { border-color: #0d6efd; color: #052c65; }
.index-status.error { background: #f8d7da; border-color: #f5c2c7; color: #58151c; }
.index-status .progress-bar-track {
    width: 100%; height: 6px; background: #d7e6f5; border-radius: 3px; margin-top: 6px; overflow: hidden;
}
.index-status .progress-bar-fill { height: 100%; background: #0d6efd; width: 0%; transition: width 0.2s ease; }

/* ---- Filter panel ---- */
.filter-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
    padding: 18px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}
.filter-group { display: flex; flex-direction: column; }
.filter-group label { font-weight: 600; margin-bottom: 6px; color: var(--text-light); font-size: 0.88em; }
.filter-group input[type="text"], .filter-group input[type="number"], .filter-group select {
    padding: 8px 10px; font-size: 0.95em; border: 1px solid var(--border-color); border-radius: 5px; box-sizing: border-box;
}
.filter-checkboxes { display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.filter-checkboxes label { font-weight: normal; font-size: 0.9em; display: flex; gap: 6px; align-items: center; margin-bottom: 0; color: var(--text-dark); }
.filter-actions { flex-direction: row; align-items: flex-end; gap: 8px; }
.btn-primary, .btn-secondary {
    padding: 8px 14px; border-radius: 5px; cursor: pointer;
    font-size: 0.9em; font-weight: 500; border: 1px solid transparent;
}
.btn-primary { background: var(--primary-btn); color: white; }
.btn-primary:hover { background: #217bbe; }
.btn-secondary { background: #eee; color: #333; border-color: #ccc; }
.btn-secondary:hover { background: #ddd; }

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

#status-bar { color: #666; font-size: 0.9em; margin: 4px 2px 12px 2px; }

/* ---- Card list ---- */
#cards-container { display: flex; flex-direction: column; gap: 10px; }

.card-row {
    background: white;
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary-accent);
    border-radius: 6px;
    padding: 12px 16px;
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) minmax(240px, 2.5fr);
    gap: 12px;
    align-items: center;
}
.card-row.io-in  { border-left-color: #198754; }
.card-row.io-out { border-left-color: #dc3545; }
.card-row.io-unknown { border-left-color: #6c757d; }
.card-row .card-cell { font-size: 0.92em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-row .card-cell.controller { font-weight: 600; color: #2c3e50; }
.card-row .card-cell.module-name { color: #333; font-family: 'Consolas', 'Courier New', monospace; font-size: 0.88em; }
.card-row .card-cell .subtle { color: #888; font-size: 0.85em; }

.card-cell.util-badge {
    display: flex; align-items: center; gap: 8px;
}
.util-pct {
    font-weight: 700; font-size: 1em; min-width: 46px;
    padding: 2px 8px; border-radius: 4px; text-align: center;
}
/* Colour intent: RED means the card has no spare channels (bad — no room
   for I/O expansion), GREEN means plenty of spare (good). This is opposite
   to a "test coverage %" scale on purpose — utilisation isn't a score to
   maximise, it's a capacity-remaining indicator. */
.util-pct.hi  { background: #f8d7da; color: #842029; } /* >= 80% — full, no room */
.util-pct.mid { background: #fff3cd; color: #664d03; } /* 40–79% — getting tight */
.util-pct.lo  { background: #d1e7dd; color: #0f5132; } /* <  40% — plenty of spare */
.util-pct.unk { background: #e9ecef; color: #555; font-weight: 500; }

.util-count { font-size: 0.85em; color: #555; }

/* ---- Channel map ---- */
.channel-map {
    display: flex; flex-wrap: wrap; gap: 3px;
    padding: 4px 2px; align-items: center;
}
.chan-cell {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px;
    font-size: 0.65em; font-weight: 600;
    background: var(--unused-color); color: #666;
    border-radius: 3px; cursor: default;
    border: 1px solid transparent;
}
.chan-cell.used { background: var(--used-color); color: white; cursor: help; }
.chan-cell.unused { background: var(--unused-color); color: #888; }
.chan-cell.unknown { background: var(--unknown-color); }
.chan-cell:hover { border-color: #333; }

.card-tags {
    grid-column: 1 / -1;
    margin-top: 8px;
    padding: 10px 12px;
    background: #f8fafd;
    border: 1px solid #e5eef7;
    border-radius: 5px;
    font-size: 0.85em;
    display: none;
}
.card-row.expanded .card-tags { display: block; }
.card-tags table { width: 100%; border-collapse: collapse; }
.card-tags th, .card-tags td { padding: 4px 8px; text-align: left; border-bottom: 1px solid #eef; font-size: 0.9em; }
.card-tags th { color: #666; font-weight: 600; }
.card-tags td.ch { font-family: 'Consolas','Courier New',monospace; font-weight: 700; color: #0056b3; width: 60px; }

.card-expand-btn {
    background: none; border: none; color: #0056b3;
    font-size: 0.85em; cursor: pointer; padding: 0;
    text-decoration: none;
}
.card-expand-btn:hover { text-decoration: underline; }

/* ---- Direction chips ---- */
.dir-chip {
    display: inline-block; font-size: 0.75em; font-weight: 700;
    padding: 2px 8px; border-radius: 10px; text-transform: uppercase; letter-spacing: 0.02em;
}
.dir-chip.I { background: #d1e7dd; color: #0f5132; }
.dir-chip.O { background: #f8d7da; color: #842029; }
.dir-chip.C { background: #fff3cd; color: #664d03; }

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

/* Small screens */
@media (max-width: 900px) {
    .card-row { grid-template-columns: 1fr 1fr; }
    .card-row .card-cell.channel-map-cell { grid-column: 1 / -1; }
}
