body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Outfit', sans-serif;
    margin: 0;
    padding: 2rem;
    box-sizing: border-box;
    min-height: 100vh;
    background-image: 
        radial-gradient(at 0% 0%, rgba(255, 0, 127, 0.04) 0px, transparent 40%),
        radial-gradient(at 100% 100%, rgba(0, 242, 254, 0.04) 0px, transparent 40%);
}

.dashboard-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: var(--bg-color);
}
.auth-overlay[hidden] { display: none; }
.auth-card {
    display: grid;
    justify-items: center;
    gap: 1rem;
    width: min(100%, 26rem);
    padding: 2rem;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: var(--panel-bg);
    box-shadow: var(--card-glow);
    text-align: center;
}
.auth-card h2,
.auth-card p { margin: 0; }
.auth-card p { color: var(--text-muted); }
.header-identity {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
}
.account-menu {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.35rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}
.account-menu #account-name::after { content: " ·"; }
.account-menu .time-btn { padding: 0; }

/* HEADER */
.header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: nowrap;
    gap: 1rem;
}

h1 {
    font-size: 2.2rem;
    font-weight: 800;
    margin: 0;
    background: linear-gradient(135deg, var(--cyan), var(--gradient-end));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

h1 span {
    font-weight: 400;
    color: var(--text-muted);
    -webkit-text-fill-color: var(--text-muted);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

/* STATS CARDS */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(140px, 1fr));
    gap: 0.75rem;
    overflow-x: auto;
}

.card {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.25rem;
    box-shadow: var(--card-glow);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.stat-card {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.8rem 1rem;
    white-space: nowrap;
}

.card-icon {
    font-size: 1em;
    line-height: 1;
    width: 1em;
    height: 1em;
    flex: 0 0 1em;
    display: inline-block;
    text-align: center;
    border-radius: 0;
}

.card-icon.pending { background: rgba(245, 158, 11, 0.1); }
.card-icon.active { background: rgba(59, 130, 246, 0.1); }
.card-icon.completed { background: rgba(16, 185, 129, 0.1); }
.card-icon.failed { background: rgba(244, 63, 94, 0.1); }
.card-icon.performance { background: rgba(139, 92, 246, 0.1); }

.stat-info {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    flex-direction: row;
    align-items: baseline;
    gap: 0.45rem;
}

.stat-info .value {
    margin-left: auto;
    text-align: right;
}

.stat-info .label {
    color: var(--text-color);
    font-size: 0.95rem;
    font-weight: 700;
}

.stat-info .value {
    font-size: 1rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}

/* SECTION */
.section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}

.section-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-color);
    border-left: 4px solid var(--magenta);
    padding-left: 10px;
    margin-bottom: 0.5rem;
}

.tag-table-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.tag-table-heading .section-title { margin-bottom: 0; }

.tag-table-controls {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.tag-table-controls label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.45rem;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
}

.tag-table-controls input { width: min(19rem, 70vw); }

.tag-pagination {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.tag-pagination .table-result-count { justify-self: start; }

.tag-pagination-pages {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.tag-pagination-pages #tag-page-status,
.tag-pagination-pages #products-page {
    min-width: 4.5rem;
    text-align: center;
    font-family: 'Outfit', sans-serif;
}

.tag-page-size-control {
    display: inline-flex;
    align-items: center;
    justify-self: end;
    gap: 0.45rem;
    font-weight: 600;
    white-space: nowrap;
}

.tag-pagination button:disabled { cursor: not-allowed; opacity: 0.65; }

/* AP GRID & CARDS */
.gateway-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

.ap-card {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    padding: 1.5rem;
}

.ap-card.online, tr.ap-row.online {
    border-left: 4px solid var(--green);
}

.ap-card.offline, tr.ap-row.offline {
    border-left: 4px solid var(--red);
}

.ap-card.unknown, tr.ap-row.unknown {
    border-left: 4px solid var(--text-muted);
}

.ap-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.8rem;
}

.ap-title-inline {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--cyan);
    word-break: break-all;
    line-height: 1.4;
}

.status-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    text-transform: uppercase;
}

.status-badge.online {
    background: var(--green-glow);
    color: var(--green);
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.status-badge.offline {
    background: rgba(244, 63, 94, 0.12);
    color: var(--red);
    border: 1px solid rgba(244, 63, 94, 0.25);
}

.status-badge.unknown {
    background: rgba(100, 116, 139, 0.12);
    color: var(--text-muted);
    border: 1px solid rgba(100, 116, 139, 0.25);
}

.ap-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 1rem;
}

.ap-col {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.col-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    padding-bottom: 0.25rem;
    margin-bottom: 0.15rem;
}

.data-row {
    font-size: 0.82rem;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.data-row .lbl {
    color: var(--text-muted);
    font-size: 0.78rem;
    flex-shrink: 0;
}

.data-row .val {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    word-break: break-all;
    text-align: right;
}

.warn-alert {
    color: var(--red);
    font-weight: 700 !important;
}

/* TABLES */
.table-container {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow-x: auto;
    box-shadow: var(--card-glow);
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th, td {
    padding: 1rem 1.25rem;
    text-align: left;
}

th {
    background: var(--layer-bg);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border-color);
}

td {
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 0.9rem;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: var(--table-row-bg);
}

.mapping-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1rem;
    box-shadow: var(--card-glow);
}

.mapping-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    align-items: end;
}

.mapping-form label { color: var(--text-muted); font-size: 0.8rem; font-weight: 600; }
.mapping-form label { display: flex; flex-direction: column; gap: 0.35rem; }

.mapping-panel input,
.mapping-panel select,
.mapping-panel button,
#mappings-table button {
    box-sizing: border-box;
    min-height: 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--control-bg);
    color: var(--text-color);
    padding: 0.55rem 0.75rem;
    font: inherit;
}

.mapping-panel button,
#mappings-table button { cursor: pointer; color: var(--cyan); font-weight: 600; }
.mapping-panel button:hover,
#mappings-table button:hover { border-color: var(--border-hover); }
.mapping-panel button.secondary { color: var(--text-muted); }
#mappings-table button { min-height: 2rem; margin-right: 0.45rem; padding: 0.3rem 0.65rem; }
#mappings-table button.danger { color: var(--red); }
.mapping-ok { color: var(--green); align-self: center; }
.mapping-error { color: var(--red); align-self: center; }

/* TABLE ROW STATUS SIDEBARS & TIMESTAMP COLORING */
tr.ap-row, tr.tag-row {
    position: relative;
    transition: background 0.2s ease;
}

/* Left Vertical Status Strip */
tr.ap-row.online td:first-child,
tr.tag-row.online td:first-child {
    box-shadow: inset 4px 0 0 0 var(--green);
}

tr.ap-row.offline td:first-child,
tr.tag-row.offline td:first-child {
    box-shadow: inset 4px 0 0 0 var(--red);
}

tr.tag-row.unresponsive td:first-child {
    box-shadow: inset 4px 0 0 0 #f59e0b;
}

tr.ap-row.unknown td:first-child,
tr.tag-row.unknown td:first-child {
    box-shadow: inset 4px 0 0 0 var(--text-muted);
}

/* Right Vertical Last Seen Status Column Color */
td.last-seen {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

td.last-seen.online {
    color: var(--green);
    font-weight: 600;
}

td.last-seen.unresponsive {
    color: #f59e0b;
    font-weight: 600;
}

td.last-seen.offline {
    color: var(--red);
    font-weight: 600;
}

td.last-seen.unknown {
    color: var(--text-muted);
}

td.last-seen.unresponsive {
    color: #f59e0b;
    font-weight: 600;
}

td.last-seen.unknown {
    color: var(--text-muted);
}

.tag-mac-code {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: var(--cyan);
}

.rssi-val.good { color: var(--green); }
.rssi-val.weak { color: var(--red); }

.tag-status-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: 5px;
    text-transform: uppercase;
    display: inline-block;
}

.tag-status-badge.ok {
    background: var(--green-glow);
    color: var(--green);
}

.tag-status-badge.error {
    background: rgba(244, 63, 94, 0.12);
    color: var(--red);
}

.tag-status-badge.pending {
    background: rgba(245, 158, 11, 0.12);
    color: #f59e0b;
}

.tag-status-badge.active {
    background: rgba(59, 130, 246, 0.12);
    color: #3b82f6;
}

.tag-status-badge.completed {
    background: var(--green-glow);
    color: var(--green);
}

.tag-status-badge.failed {
    background: rgba(244, 63, 94, 0.12);
    color: var(--red);
}

.tag-status-badge.unknown {
    background: rgba(100, 116, 139, 0.12);
    color: var(--text-muted);
}

/* API REFERENCE ACCORDION */
.api-details {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--card-glow);
}

.api-summary {
    padding: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    background: var(--layer-bg);
    user-select: none;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

.api-summary:hover {
    background: var(--layer-bg);
    color: var(--cyan);
}

.api-content {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.api-subsection-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.8rem;
    color: var(--text-muted);
}

.method {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 800;
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    border-radius: 5px;
    display: inline-block;
}

.method.get {
    background: var(--green-glow);
    color: var(--green);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.method.post {
    background: var(--cyan-glow);
    color: var(--cyan);
    border: 1px solid rgba(0, 242, 254, 0.2);
}

.method.delete {
    background: var(--magenta-glow);
    color: var(--magenta);
    border: 1px solid rgba(255, 0, 127, 0.2);
}

.endpoint-link {
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-color);
    text-decoration: none;
    transition: all 0.2s ease;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.2);
}

.endpoint-link:hover	{ color: var(--cyan);       border-bottom-color: var(--cyan);}
.subtext		 		{ color: var(--text-muted); font-size: 0.75rem;}
.desc 					{ color: var(--text-muted);}
.battery-ok 			{ color: #4caf50; }
.battery-low 			{ color: #f44336; }
.cold 					{ color: #2196f3; }
.normal 				{ color: #4caf50; }
.hot 					{ color: #f44336; }

/* TWO-LINE ENTRY STYLES FOR AP & TAGS */
.ap-entry-container, .tag-entry-container {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    width: 100%;
}

.ap-line, .tag-line {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    font-size: 0.88rem;
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    line-height: 1.4;
}

.static-line {
    background: rgba(0, 242, 254, 0.05);
    border-left: 3px solid var(--cyan);
}

.metrics-line {
    background: rgba(16, 185, 129, 0.05);
    border-left: 3px solid var(--green);
}

.mac-title, .tag-mac-code {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--cyan);
}

.badge-tag {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.static-badge {
    background: rgba(0, 242, 254, 0.15);
    color: var(--cyan);
    border: 1px solid rgba(0, 242, 254, 0.3);
}

.metrics-badge {
    background: rgba(16, 185, 129, 0.15);
    color: var(--green);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.static-details, .metrics-details {
    color: var(--text-color);
    font-size: 0.85rem;
}

.static-details strong, .metrics-details strong {
    color: var(--text-color);
    font-family: 'JetBrains Mono', monospace;
}

/* API DOCS */

.api-details {
    margin-top: 2rem;
    background: var(--surface-dim);
    border-radius: 12px;
    padding: 1rem;
}

.api-summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--cyan);
    padding: 0.5rem 0;
}

.api-content {
    margin-top: 1rem;
}

.api-search-row {
    margin-bottom: 1.5rem;
    display: flex;
    gap: 10px;
}

.api-search-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--control-bg);
    color: var(--text-color);
    font-family: inherit;
    font-size: 0.95rem;
}

.api-docs-container {
    margin-top: 1rem;
}

.api-loading {
    color: var(--text-muted);
    font-style: italic;
}

.api-segment-header {
    cursor: pointer;
    padding: 0.75rem 1rem;
    margin-top: 1rem;
    background: var(--surface-dim);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.api-segment-content {
    display: none;
    padding-top: 0.5rem;
    overflow-x: auto;
}

.api-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
}

.api-table th,
.api-table td {
    padding: 0.6rem;
    border-bottom: 1px solid var(--border-color);
}

.method.get {
    color: var(--cyan);
}

.method.post {
    color: var(--yellow);
}

.endpoint-link {
    color: var(--cyan);
    border-bottom: 1px dotted var(--cyan);
}

.endpoint-link.disabled {
    color: var(--text-muted);
    border-bottom: none;
}

/* HISTORICAL TELEMETRY GRAPH MODAL */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--modal-backdrop);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.25s ease;
}

.modal-card {
    background: var(--panel-bg);
    border: 1px solid var(--border-hover);
    border-radius: 20px;
    width: 90%;
    max-width: 760px;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    box-sizing: border-box;
    padding: 1.5rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.8rem;
}

.modal-close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close-btn:hover { color: var(--magenta); }

.history-tabs { display: flex; gap: 0.5rem; }
.history-tabs button {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--control-bg);
    color: var(--text-muted);
    font: inherit;
    cursor: pointer;
}
.history-tabs button[aria-selected="true"] { border-color: var(--border-hover); color: var(--cyan); background: var(--surface-dim); }
.history-panel { display: grid; gap: 1rem; }
.history-panel[hidden] { display: none; }
.history-note { margin: 0; color: var(--text-muted); font-size: 0.82rem; }
.graph-container {
    background: var(--control-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas#ap-signal-canvas,
canvas#battery-history-canvas {
    width: 100%;
    max-width: 700px;
    height: 240px;
}

.history-stats-row {
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: var(--surface-dim);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.8rem 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.h-stat { display: flex; flex-direction: column; align-items: center; }
.h-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; font-weight: 600; }
.h-val { font-family: 'JetBrains Mono', monospace; font-size: 1.1rem; color: var(--cyan); font-weight: 700; margin-top: 2px; }

@keyframes fadeIn { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: scale(1); } }

/* SERVER IP & PORT ROLES GRID */
.topology-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.topology-subtitle {
    margin: 0.35rem 0 0;
    color: var(--text-muted);
    font-size: 0.84rem;
}

.topology-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.45rem 0.8rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
}

.topology-legend > span {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.topology-heading-status { display: flex; flex-direction: column; align-items: flex-end; gap: 0.65rem; }

.topology-map {
    --topology-green: #10b981;
    --topology-orange: #f59e0b;
    --topology-red: #f43f5e;
    --topology-unknown: #64748b;
    display: grid;
    grid-template-columns: minmax(230px, 1fr) 86px minmax(220px, 1fr) 86px minmax(230px, 1fr);
    grid-template-rows: auto 62px auto;
    align-items: stretch;
    gap: 0;
}

.topology-node { min-width: 0; }
.topology-mqtt { grid-column: 1; grid-row: 3; }
#topology-link-mqtt-aps { grid-column: 2; grid-row: 3; }
.topology-aps { grid-column: 3; grid-row: 3; }
#topology-link-aps-tags { grid-column: 4; grid-row: 3; }
.topology-tags { grid-column: 5; grid-row: 3; }
.topology-service-hosts { grid-column: 5; grid-row: 1; }
#topology-link-script-mqtt { grid-column: 1; grid-row: 2; }
.topology-script { grid-column: 1; grid-row: 1; }
#topology-link-script-catalogue { grid-column: 2; grid-row: 1; }
.topology-catalogue { grid-column: 3; grid-row: 1; }

.topology-link {
    --link-color: var(--topology-unknown);
    position: relative;
    min-width: 0;
    color: var(--link-color);
}

.topology-link.health-green { --link-color: var(--topology-green); }
.topology-link.health-orange { --link-color: var(--topology-orange); }
.topology-link.health-red { --link-color: var(--topology-red); }
.topology-link.health-unknown { --link-color: var(--topology-unknown); }

.signal-track {
    position: absolute;
    display: block;
    overflow: hidden;
    background: color-mix(in srgb, var(--link-color) 38%, transparent);
    box-shadow: 0 0 7px color-mix(in srgb, var(--link-color) 38%, transparent);
}

.topology-horizontal .signal-track {
    left: 8px;
    right: 8px;
    height: 2px;
}

.topology-horizontal .signal-forward { top: calc(50% - 6px); }
.topology-horizontal .signal-reverse { top: calc(50% + 5px); }

.topology-vertical .signal-track {
    top: 5px;
    bottom: 5px;
    width: 2px;
}

.topology-vertical .signal-forward { left: calc(50% - 6px); }
.topology-vertical .signal-reverse { left: calc(50% + 5px); }

.signal-track::after {
    content: "";
    position: absolute;
    width: 24px;
    height: 100%;
    opacity: 0;
    background: linear-gradient(90deg, transparent, #fff, var(--link-color), transparent);
    filter: drop-shadow(0 0 5px var(--link-color));
}

.topology-vertical .signal-track::after {
    width: 100%;
    height: 24px;
    background: linear-gradient(180deg, transparent, #fff, var(--link-color), transparent);
}

.topology-link.traffic .signal-track::after { opacity: 1; }
.topology-link.traffic.topology-horizontal .signal-forward::after { animation: signal-forward-x 1.35s linear infinite; }
.topology-link.traffic.topology-horizontal .signal-reverse::after { animation: signal-reverse-x 1.35s linear infinite; }
.topology-link.traffic.topology-vertical .signal-forward::after { animation: signal-forward-y 1.35s linear infinite; }
.topology-link.traffic.topology-vertical .signal-reverse::after { animation: signal-reverse-y 1.35s linear infinite; }

.topology-link-label {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 1;
    transform: translate(-50%, -50%);
    padding: 2px 5px;
    border: 1px solid color-mix(in srgb, var(--link-color) 42%, transparent);
    border-radius: 5px;
    background: var(--control-bg);
    color: var(--link-color);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.61rem;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
}

@keyframes signal-forward-x { from { left: -26px; } to { left: 100%; } }
@keyframes signal-reverse-x { from { right: -26px; } to { right: 100%; } }
@keyframes signal-forward-y { from { top: -26px; } to { top: 100%; } }
@keyframes signal-reverse-y { from { bottom: -26px; } to { bottom: 100%; } }

.topology-device-list,
.topology-status-counts {
    display: flex;
    flex-direction: column;
    gap: 0.42rem;
    margin-top: 0.2rem;
}

.topology-status-counts {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 1rem;
}

.topology-device-list {
    max-height: 142px;
    overflow: auto;
    padding-right: 0.2rem;
}

.topology-device,
.topology-empty,
.topology-status-counts > span {
    display: grid;
    grid-template-columns: 0.6rem minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.42rem;
    min-width: 0;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
}

.topology-status-counts > span {
    display: inline-flex;
    grid-template-columns: none;
    white-space: nowrap;
}

.topology-device strong {
    overflow: hidden;
    color: var(--text-color);
    font-size: 0.72rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topology-device time { font-size: 0.65rem; white-space: nowrap; }
.topology-ap-management {
    color: inherit;
}

.topology-ap-management a {
    color: var(--cyan);
    text-decoration: none;
}

.topology-ap-management a:hover,
.topology-ap-management a:focus-visible {
    text-decoration: underline;
}

.topology-ap-identity {
    display: flex;
    min-width: 0;
    width: 100%;
    flex-direction: column;
    gap: 1px;
}

.topology-ap-headline {
    display: flex;
    min-width: 0;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
}

.topology-ap-headline strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topology-ap-identity small {
    overflow: hidden;
    color: var(--text-muted);
    font-size: 0.61rem;
    font-weight: 400;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.service-host-list {
    display: flex;
    flex-direction: column;
    gap: 0.42rem;
}

.service-host-list > div {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.65rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.68rem;
}

.service-host-list strong,
.service-host-list a {
    overflow: hidden;
    max-width: 15rem;
    color: var(--text-color);
    font-size: 0.72rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.service-host-list a {
    text-decoration: none;
}

.service-host-list a[href]:hover,
.service-host-list a[href]:focus-visible {
    color: var(--cyan);
    text-decoration: underline;
}
.topology-status-counts strong { color: var(--text-color); font-size: 0.86rem; }

.topology-badge-unknown {
    background: rgba(100, 116, 139, 0.12);
    border-color: rgba(100, 116, 139, 0.3);
    color: #94a3b8;
}

.health-badge-green {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
    color: #10b981;
}

.health-badge-orange {
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.35);
    color: #f59e0b;
}

.health-badge-red {
    background: rgba(244, 63, 94, 0.12);
    border-color: rgba(244, 63, 94, 0.35);
    color: #f43f5e;
}

.health-badge-unknown {
    background: rgba(100, 116, 139, 0.12);
    border-color: rgba(100, 116, 139, 0.3);
    color: #94a3b8;
}

.topology-node.health-green { border-color: rgba(16, 185, 129, 0.36); }
.topology-node.health-orange { border-color: rgba(245, 158, 11, 0.42); }
.topology-node.health-red { border-color: rgba(244, 63, 94, 0.42); }

.server-roles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1rem;
}

.role-card {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--card-glow);
}

.role-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.role-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding-bottom: 0.5rem;
}

.role-card-title-link {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-color);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s ease;
}

.brand-icon {
    display: block;
    height: 20px;
    width: auto;
    max-width: 40px;
    flex: 0 0 auto;
    object-fit: contain;
}

.brand-attribution {
    margin: 0.65rem 0 0;
    color: var(--text-muted);
    font-size: 0.61rem;
    line-height: 1.45;
    opacity: 0.72;
}

.brand-attribution a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

a.role-card-title-link:hover {
    color: var(--cyan);
    text-decoration: underline;
}

.role-card-details-grid {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.detail-row {
    display: flex;
    align-items: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
}

.topology-script-uptime {
    flex-basis: 100%;
    gap: 6px;
}

.topology-script-uptime .detail-label {
    color: var(--text-muted);
    font-weight: 600;
}

.detail-uptime-val {
    color: var(--cyan);
    font-weight: 600;
}

.detail-val {
    color: var(--text-color);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    background: var(--surface-dim);
    padding: 2px 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    width: fit-content;
}

.detail-val-ports {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
}

.topology-catalogue .role-card-details-grid {
    align-items: flex-start;
    flex-wrap: nowrap;
}

.topology-catalogue .detail-val-ports {
    flex-direction: column;
    flex-wrap: nowrap;
}

.port-row {
    display: grid;
    grid-template-columns: 0.5rem auto auto auto;
    align-items: center;
    column-gap: 3px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    color: var(--text-color);
    background: var(--surface-dim);
    padding: 2px 5px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    width: fit-content;
    white-space: nowrap;
}

.port-protocol,
.port-number {
    display: block;
}

.role-card-badge {
    font-size: 0.7rem;
    font-family: 'JetBrains Mono', monospace;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(0, 242, 254, 0.12);
    color: var(--cyan);
    border: 1px solid rgba(0, 242, 254, 0.25);
}

.role-ports-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-end;
}

.port-badge {
    font-size: 0.72rem;
    font-family: 'JetBrains Mono', monospace;
    padding: 2px 8px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-dim);
    border: 1px solid var(--border-color);
}

.port-badge.green {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
    border-color: rgba(16, 185, 129, 0.3);
}

.port-badge.orange {
    background: rgba(245, 158, 11, 0.12);
    color: #f59e0b;
    border-color: rgba(245, 158, 11, 0.35);
}

.port-badge.red {
    background: rgba(244, 63, 94, 0.12);
    color: #f43f5e;
    border-color: rgba(244, 63, 94, 0.35);
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.dot.green {
    background-color: #10b981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.dot.unknown {
    background-color: #64748b;
    box-shadow: none;
}

.dot.orange {
    background-color: #f59e0b;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
}

.dot.red {
    background-color: #f43f5e;
    box-shadow: 0 0 8px rgba(244, 63, 94, 0.6);
}

.latency-tag {
    font-size: 0.68rem;
    opacity: 0.85;
    margin-left: 0;
    justify-self: start;
    font-variant-numeric: tabular-nums;
}

.role-card-endpoint {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--cyan);
    word-break: break-all;
    background: var(--control-bg);
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.role-card-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* TELEMETRY CHARTS SECTION */
.telemetry-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
    flex-wrap: wrap;
    gap: 0.8rem;
}

.telemetry-controls .section-title { margin-bottom: 0; }

.time-range-group {
    display: flex;
    gap: 6px;
    background: var(--control-bg);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.time-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: 'Outfit', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.time-btn:hover { color: var(--text-color); }
.time-btn.active {
    background: var(--cyan);
    color: var(--on-accent);
    font-weight: 700;
    box-shadow: 0 0 12px rgba(0, 242, 254, 0.4);
}

/* Shared controls for data tables on Labels and Products. */
.table-control {
    box-sizing: border-box;
    height: 38px;
    min-height: 38px;
    padding: 0 0.65rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--control-bg);
    color: var(--text-color);
    font-family: 'Outfit', sans-serif;
    font-size: 0.8rem;
}
.table-control:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.table-control::placeholder { color: var(--text-muted); }
:is(button, summary, .tag-pagination span).table-control { font-weight: 600; }
.tag-pagination span.table-control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}
button.table-control:hover:not(:disabled), summary.table-control:hover { border-color: var(--border-hover); color: var(--text-color); }
select.table-control { cursor: pointer; }
select.table-control option { color: var(--text-color); background: var(--surface-input); }

.telemetry-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    gap: 1.25rem;
}

.telemetry-chart-card {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.telemetry-chart-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chart-wrapper {
    position: relative;
    width: 100%;
    height: 220px;
}

/* DASHBOARD NAVIGATION */
.primary-nav {
    position: static;
    z-index: 20;
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.4rem;
    background: var(--nav-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 14px 35px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.nav-tabs {
    display: flex;
    flex: 1 1 auto;
    gap: 0.35rem;
    overflow-x: auto;
}

.nav-description {
    min-width: 0;
    margin: 0 0.7rem 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.35;
    text-align: right;
}

.nav-tab {
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    white-space: nowrap;
    transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.nav-tab { padding: 0.75rem 1.15rem; }
.nav-tab:hover { color: var(--text-color); border-color: var(--border-color); }
.nav-tab:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.nav-tab.active {
    color: var(--on-accent);
    background: linear-gradient(135deg, var(--cyan), var(--gradient-end));
    box-shadow: 0 0 20px rgba(0, 242, 254, 0.2);
}

.dashboard-views,
.dashboard-view {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.dashboard-view[hidden] { display: none; }
.dashboard-view.active { animation: view-enter 0.2s ease-out; }


#view-api .api-details { margin-top: 0; }
#view-api .api-details + .api-details { margin-top: 1.25rem; }
.documentation-copy p,
.documentation-copy li { color: var(--text-muted); line-height: 1.6; }
.documentation-copy h3 { margin: 1.25rem 0 0.55rem; font-size: 0.95rem; color: var(--text-color); }
.documentation-copy pre {
    margin: 0;
    padding: 1rem;
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--code-bg);
    color: var(--cyan);
    font-family: 'JetBrains Mono', monospace;
    line-height: 1.55;
}
.documentation-copy code { color: var(--cyan); }
.documentation-links { display: flex; flex-wrap: wrap; gap: 0.65rem; }
.download-button {
    display: inline-block;
    margin: 0.25rem 0 0.5rem;
    padding: 0.7rem 1rem;
    border: 1px solid rgba(0, 242, 254, 0.35);
    border-radius: 9px;
    background: var(--cyan-glow);
    color: var(--cyan);
    font-weight: 700;
    text-decoration: none;
}
.download-button:hover { border-color: var(--cyan); }

@keyframes view-enter {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 720px) {
    body { padding: 1rem; }
    .dashboard-container { gap: 1rem; }
    .header { align-items: flex-start; flex-direction: column; }
    .primary-nav { align-items: stretch; width: 100%; }
    .nav-tabs { width: 100%; }
    .nav-tab { flex: 1 0 auto; padding: 0.65rem 0.85rem; }
    .nav-description { margin: 0; padding: 0.2rem 0.35rem 0.35rem; text-align: left; }
    .telemetry-grid { grid-template-columns: minmax(0, 1fr); }
    .telemetry-chart-title { align-items: flex-start; flex-direction: column; gap: 0.35rem; }
    .topology-heading { flex-direction: column; }
    .topology-heading-status { align-items: flex-start; }
    .topology-legend { justify-content: flex-start; }
    .topology-map { display: flex; flex-direction: column; gap: 0.75rem; }
    .topology-link { display: none; }
}

@media (min-width: 721px) and (max-width: 1120px) {
    .topology-map {
        grid-template-columns: minmax(190px, 1fr) 58px minmax(190px, 1fr) 58px minmax(190px, 1fr);
    }
    .topology-link-label { font-size: 0.55rem; padding-inline: 3px; }
}

@media (prefers-reduced-motion: reduce) {
    .topology-link.traffic .signal-track::after { animation: none !important; opacity: 0; }
}

#logs-status {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.2;
    text-align: left;
}

.logs-controls {
    min-width: 0;
    flex: 1;
}

#view-logs .telemetry-controls {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0;
}

#view-logs > .section {
    gap: 0.5rem;
}

#view-logs .section-title {
    line-height: 2rem;
}

.logs-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.logs-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.logs-level-filter {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
}

.logs-level-filter select,
.logs-level-filter input {
    min-height: 2rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--control-bg);
    color: var(--text-color);
    padding: 0.3rem 0.55rem;
    font: inherit;
    cursor: pointer;
}

.logs-level-filter select:focus-visible,
.logs-level-filter input:focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 2px;
}

#logs-search {
    width: 11rem;
}

@media (max-width: 720px) {
    .logs-actions { justify-content: flex-start; }
}

#logs-output {
    margin: 0;
    max-height: 65vh;
    overflow: auto;
    padding: 1rem;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-color);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.log-line {
    color: var(--text-color);
}

.log-line::before {
    content: "●";
    display: inline-block;
    width: 1.1em;
    color: #64748b;
}

.log-level-trace { color: #808080; }
.log-level-trace::before { color: #808080; }
.log-level-debug { color: #00ffff; }
.log-level-debug::before { color: #00ffff; }
.log-level-info { color: #00c000; }
.log-level-info::before { color: #00c000; }
.log-token-white { color: #ffffff; }
.log-level-warn { color: #ffff00; }
.log-level-warn::before { color: #ffff00; }
.log-level-error { color: #ff0000; }
.log-level-error::before { color: #ff0000; }
.log-level-crit {
    background: #c00000;
    color: #ffffff;
    font-weight: 700;
}
.log-level-crit::before { color: #ffffff; }
#mapping-form[hidden] { display: none; }
#view-labels > .section { margin-bottom: 0; }
#mapping-status { margin: 0; }
#mapping-status:empty { display: none; }
.settings-help { color: var(--text-muted); }
.settings-panel { display: grid; gap: 1rem; }
.settings-card {
    display: grid;
    gap: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--card-bg);
    box-shadow: var(--card-glow);
}

.settings-card-wide {
    grid-column: 1 / -1;
}

.users-table .user-open { padding: 0; border: 0; background: none; color: var(--text-color); font: inherit; font-weight: 700; cursor: pointer; }
.users-table .user-open:hover { color: var(--cyan); }
.user-status { display: inline-block; padding: .25rem .6rem; border-radius: 6px; font-size: .75rem; font-weight: 700; }
.user-status.active { color: var(--green); background: var(--green-glow); }
.user-status.disabled { color: var(--red); background: rgba(244, 63, 94, .12); }
.user-dialog { width: min(760px, calc(100vw - 2rem)); padding: 1.25rem; border: 1px solid var(--border-color); border-radius: 14px; background: var(--surface-input); color: var(--text-color); box-shadow: var(--card-glow); }
.user-dialog::backdrop { background: var(--modal-backdrop); }
.user-dialog form { display: grid; gap: 1rem; }
.user-dialog-header, .user-dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.user-dialog-header h2 { margin: 0; font-size: 1.2rem; }
.user-editor-grid { display: grid; grid-template-columns: min-content minmax(8rem, 1fr) min-content minmax(8rem, 1fr) auto auto; align-items: center; gap: .6rem .75rem; }
.user-editor-grid label { color: var(--text-muted); font-size: .8rem; font-weight: 600; white-space: nowrap; }
.user-editor-grid input:not([type="checkbox"]), .user-editor-grid select { box-sizing: border-box; width: 100%; min-width: 0; padding: .55rem; border: 1px solid var(--border-color); border-radius: 7px; background: var(--bg-color); color: var(--text-color); font: inherit; }
.user-editor-grid input[type="checkbox"] { justify-self: center; accent-color: var(--cyan); }
.user-editor-grid :disabled { opacity: .6; }
.user-dialog-actions { justify-content: flex-end; }
.user-dialog-actions #user-delete { margin-right: auto; }
.user-dialog-actions button { padding: .55rem 1rem; border: 1px solid var(--border-color); border-radius: 7px; background: var(--cyan-glow); color: var(--cyan); font: inherit; cursor: pointer; }
.user-dialog-actions button.secondary { background: rgba(244, 63, 94, .12); color: var(--red); }
.user-dialog-actions [hidden] { display: none; }
#user-dialog-status { margin: 0; }
#user-dialog-status:empty { display: none; }
@media (max-width: 900px) { .user-editor-grid { grid-template-columns: minmax(5rem, auto) minmax(0, 1fr); } }
.settings-card[hidden] { display: none; }
.settings-card h3 { margin: 0; color: var(--text-color); font-size: 1rem; }
.catalogue-settings-heading { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.75rem; }
.settings-subsection {
    display: grid;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}
.settings-subsection[hidden] { display: none; }
.settings-subsection h3 { margin: 0; color: var(--text-color); font-size: 1rem; }
.settings-form label.settings-checkbox { flex-direction: row; align-items: center; align-self: end; min-height: 2.5rem; }
.settings-form label.settings-checkbox input { width: 1rem; min-height: 1rem; }
.settings-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    align-items: end;
}
.settings-form[hidden] { display: none; }
.catalogue-settings-form { grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(180px, 1fr) max-content; }
.catalogue-settings-form label[hidden], .catalogue-settings-actions button[hidden] { display: none; }
.catalogue-settings-form > label:first-child { grid-column: 1; grid-row: 1; }
.catalogue-settings-form > #catalogue-endpoint-field { grid-column: 2; grid-row: 1; }
.catalogue-settings-form > #catalogue-key-field { grid-column: 3; grid-row: 1; }
.catalogue-settings-actions { grid-column: 4; grid-row: 1; display: flex; align-items: end; gap: 0.75rem; }
.catalogue-settings-actions button { flex: 0 0 auto; }
.settings-form label { display: flex; flex-direction: column; gap: 0.35rem; color: var(--text-muted); font-size: 0.8rem; font-weight: 600; }
.settings-form input,
.settings-form select,
.settings-form button {
    box-sizing: border-box;
    min-height: 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--layer-bg);
    color: var(--text-color);
    padding: 0.55rem 0.7rem;
    font: inherit;
}
.settings-form button { cursor: pointer; color: var(--cyan); font-weight: 600; }
.settings-form button.secondary { color: var(--text-muted); }
.night-schedule {
    grid-column: 1 / -1;
    min-width: 0;
    margin: 0;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}
.night-schedule legend { padding: 0 0.35rem; color: var(--text-color); font-weight: 600; }
.night-schedule legend span { color: var(--text-muted); font-size: 0.75rem; font-weight: 400; }
.night-schedule-head,
.night-schedule-row {
    display: grid;
    grid-template-columns: repeat(7, minmax(34px, 1fr)) minmax(100px, 1.6fr) minmax(100px, 1.6fr) minmax(52px, 0.9fr);
    gap: 0.5rem;
    align-items: center;
    text-align: center;
}
.night-schedule-head { padding: 0 0.35rem 0.4rem; color: var(--text-muted); font-size: 0.75rem; }
.night-schedule-row { padding: 0.35rem; border-top: 1px solid var(--border-color); }
.night-schedule-row input[type="checkbox"] { justify-self: center; width: 1rem; min-height: 1rem; }
.night-schedule-row input[type="time"] { width: 100%; }
@media (max-width: 560px) {
    .night-schedule { overflow-x: auto; }
    .night-schedule-head,
    .night-schedule-row { min-width: 680px; }
}
.settings-state {
    align-self: end;
    display: flex;
    align-items: center;
    min-height: 2.5rem;
    color: var(--text-muted);
}
.settings-state.configured { color: var(--green); }
.settings-state.missing { color: var(--orange); }
#catalogue-status,
#sleep-mode-status { margin: 0; }
#catalogue-status:empty,
#sleep-mode-status:empty { display: none; }
.settings-readonly {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.65rem;
}
.settings-readonly[hidden] { display: none; }
.settings-readonly > div {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 0;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--layer-bg);
}
.settings-readonly span { color: var(--text-muted); font-size: 0.8rem; font-weight: 600; }
.settings-readonly code,
.settings-readonly strong { color: var(--text-color); overflow-wrap: anywhere; }
.modal-history-content {
    box-sizing: border-box;
    max-height: min(550px, calc(95vh - 180px));
    min-height: 280px;
    overflow-y: auto;
    padding: 18px;
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}
.history-status { margin: 0; color: var(--text-subtle); font-size: .78rem; }
.history-status:empty { display: none; }
.audit-timeline { display: flex; flex-direction: column; gap: 16px; margin: 0; padding: 0; list-style: none; }
.audit-item { display: flex; gap: 16px; position: relative; }
.audit-item:not(:last-child)::after { content: ""; position: absolute; left: 8px; top: 20px; bottom: -18px; width: 2px; background: var(--border-color); }
.audit-icon { position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; flex: 0 0 18px; width: 18px; height: 18px; border-radius: 50%; border: 1px solid #3164a1; background: #17345c; color: #80b6ff; font-size: .7rem; font-weight: 700; }
.audit-icon::before { content: "i"; }
.audit-icon[data-kind="edit"]::before { content: "✎"; }
.audit-icon[data-kind="error"] { border-color: #a34555; background: #45212e; color: #ffa6b4; }
.audit-content { flex: 1; min-width: 0; }
.audit-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; margin-bottom: 8px; }
.audit-event { color: var(--text-color); font-size: .84rem; font-weight: 700; }
.audit-user-inline { color: var(--text-subtle); font-size: .76rem; }
.audit-time { color: var(--text-subtle); font-family: "JetBrains Mono", monospace; font-size: .72rem; white-space: nowrap; }
.audit-message { margin: 0 0 7px; color: var(--text-soft); font-size: .73rem; }
.audit-meta-grid { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: center; gap: 4px 12px; margin: 0; }
.audit-meta-grid .pill-label { width: fit-content; padding: 2px 6px; border-radius: 4px; background: var(--surface-hover); color: var(--text-soft); font-size: .65rem; font-weight: 700; white-space: nowrap; }
.audit-meta-grid .pill-value { margin: 0; color: var(--text-color); font-size: .7rem; overflow-wrap: anywhere; }

.tag-modal-metrics {
    display: grid;
    grid-template-columns: repeat(5, max-content);
    justify-content: space-between;
    row-gap: 4px;
    margin-top: 9px;
    color: var(--text-subtle);
    font-size: .67rem;
}
.tag-modal-metrics-head, .tag-modal-metrics-row { display: contents; }
.tag-modal-metrics-head > span { color: var(--text-subtle); font-size: .58rem; font-weight: 700; text-align: center; }
.tag-modal-metrics-row > :nth-child(2),
.tag-modal-metrics-row > :nth-child(3),
.tag-modal-metrics-row > :nth-child(5) { text-align: right; font-variant-numeric: tabular-nums; }
.tag-modal-metrics-row > :nth-child(4) { white-space: nowrap; font-size: .57rem; }
.tag-modal-metrics-row code { color: var(--cyan); font-size: .58rem; }
.tag-modal-metrics-rule { grid-column: 1 / -1; border-top: 1px solid var(--border-color); margin-top: 2px; }

.mapping-previews { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 1rem; margin: 1rem 0; }
.mapping-previews[hidden], .mapping-previews [hidden] { display: none; }
.mapping-previews figure { margin: 0; padding: 1rem; border: 1px solid var(--border-color); border-radius: 12px; }
.mapping-previews figcaption { font-weight: 600; }
.mapping-previews p { color: var(--text-muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.mapping-previews img { display: block; max-width: 100%; height: auto; margin: 1rem 0; border: 1px solid var(--border-color); image-rendering: pixelated; }
.mapping-previews a { color: var(--cyan); }

.products-database-dialog {
    box-sizing: border-box;
    width: min(620px, calc(100vw - 2rem));
    max-height: min(90vh, 760px);
    padding: 0;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--surface-dialog);
    color: var(--text-color);
    box-shadow: var(--dialog-shadow);
}
.products-database-dialog::backdrop { background: var(--modal-backdrop); }
.product-database-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 18px;
    border-bottom: 1px solid var(--border-color);
}
.product-database-header h2 { margin: 0; font-size: 1.2rem; }
.product-database-body { display: grid; gap: 1rem; padding: 18px; }
.product-database-count { margin: 0; color: var(--text-muted); font-size: 0.85rem; }
.product-database-section {
    display: grid;
    justify-items: start;
    gap: 0.65rem;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--surface-control);
}
.product-database-section h3 { margin: 0; font-size: 0.95rem; }
.product-database-section select { box-sizing: border-box; width: 100%; padding: 0.5rem; border: 1px solid var(--border-color); border-radius: 7px; background: var(--surface-hover); color: var(--text-color); font: inherit; }
.product-database-actions { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.65rem 1rem; width: 100%; margin-top: -0.4rem; }
.product-database-export-row { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 0.65rem 1rem; width: 100%; }
.product-database-export-details { display: grid; gap: 0.2rem; flex: 1 1 250px; }
.product-database-export-row .product-action { margin-left: auto; flex: 0 0 auto; }
.product-database-section .product-database-checkbox { display: flex; align-items: center; gap: 0.55rem; min-width: 0; font-weight: 400; }
.product-database-actions .product-action { margin-left: auto; flex: 0 0 auto; }
.product-database-checkbox input { margin: 0; }
.product-database-section [hidden] { display: none; }
.product-database-section p { margin: 0; color: var(--text-muted); font-size: 0.8rem; }
.product-database-section label { color: var(--text-muted); font-size: 0.8rem; font-weight: 600; }
.product-database-section input[type="file"] {
    box-sizing: border-box;
    width: 100%;
    color: var(--text-color);
    font: inherit;
    font-size: 0.8rem;
}
.product-database-section input[type="file"]::file-selector-button {
    margin-right: 0.75rem;
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--border-color);
    border-radius: 7px;
    background: var(--surface-hover);
    color: var(--text-color);
    font: inherit;
    cursor: pointer;
}
.product-database-section .product-action { justify-self: end; }
.product-action:disabled { opacity: 0.5; cursor: not-allowed; }
#products-database-status { margin: 0; color: var(--text-muted); font-size: 0.8rem; }
#products-database-status:empty { display: none; }
.product-dialog {
    width: min(800px, calc(100vw - 2rem));
    max-height: min(95vh, 980px);
    padding: 0;
    overflow: hidden;
    color: var(--text-color);
    background: var(--surface-dialog);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--dialog-shadow);
}
.product-dialog::backdrop { background: var(--modal-backdrop); }
.product-dialog [hidden] { display: none !important; }
#product-form { display: flex; flex-direction: column; max-height: min(95vh, 980px); }
.product-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 18px 18px 9px;
}
.product-form-tabs, .product-modal-header-actions, .product-modal-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.product-form-tabs button {
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border-color);
    border-radius: 7px;
    color: var(--text-muted);
    background: var(--surface-control);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}
.product-form-tabs button:hover { color: var(--cyan); }
.product-form-tabs button.active {
    color: #fff;
    background: #64748b;
    border-color: #64748b;
}
.product-regulatory-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    color: var(--orange);
    background: rgba(245, 158, 11, 0.12);
    font-size: 0.73rem;
}
.product-close {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: 7px;
    background: var(--surface-control);
    color: var(--text-color);
    font-size: 1.3rem;
    cursor: pointer;
}
.product-modal-body {
    overflow-y: auto;
    overflow-x: hidden;
    padding: 9px 18px;
}
.product-modal-split {
    display: grid;
    grid-template-columns: minmax(0, 285px) minmax(0, 1fr);
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
}
.product-modal-sidebar, .product-modal-main {
    display: grid;
    align-content: start;
    align-items: center;
    gap: 9px 10px;
    padding: 18px 12px;
}
.product-modal-sidebar {
    grid-template-columns: max-content minmax(0, 1fr);
    border-right: 1px solid var(--border-color);
    background: var(--surface-muted);
}
.product-modal-main {
    grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr);
    background: var(--surface-content);
}
.product-modal-main .product-main-wide { grid-column: span 3; }
.product-dialog label {
    color: var(--text-subtle);
    font-size: 0.73rem;
    font-weight: 700;
}
.product-dialog input, .product-dialog select, .product-dialog textarea {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    min-height: 36px;
    padding: 7px 10px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 7px;
    outline: none;
    color: var(--text-color);
    background: var(--surface-input);
    font: inherit;
    font-size: 0.82rem;
}
.product-dialog input:focus, .product-dialog select:focus, .product-dialog textarea:focus {
    border-color: var(--cyan);
}
.product-dialog input:read-only, .product-dialog select:disabled, .product-dialog textarea:read-only {
    color: var(--text-soft);
    background: var(--field-readonly);
}
.product-input-unit { position: relative; }
.product-input-unit input { padding-right: 28px; text-align: right; }
.product-input-unit span { position: absolute; right: 11px; top: 8px; color: var(--text-muted); }
.product-modal-sidebar input[type="number"] { text-align: right; }
.product-regulatory-section {
    margin-top: 18px;
    padding: 18px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--surface-alt);
}
.product-regulatory-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.product-regulatory-field { display: grid; gap: 5px; }
.product-proof { display: grid; grid-template-columns: 120px 1fr; align-items: center; gap: 12px; margin-top: 14px; }
.product-bovin-sections { display: grid; gap: 18px; }
.product-bovin-card {
    padding: 18px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--surface-content);
}
.product-bovin-card h3 { margin: 0 0 12px; font-size: 0.78rem; color: var(--text-soft); }
.product-bovin-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.product-race-previews { margin-top: 12px; }
#product-race-details { margin: 10px 0 0; color: var(--text-muted); font-size: 0.75rem; }
.product-specs-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    padding: 18px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--surface-alt);
}
.product-specs-grid label { display: grid; align-content: start; gap: 5px; }
.product-specs-grid select { height: auto; min-height: 330px; }
.product-modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 18px 18px;
    gap: 12px;
}
.product-action {
    min-width: 105px;
    min-height: 36px;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 7px;
    color: var(--text-color);
    background: var(--surface-hover);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}
.product-action.primary { color: var(--on-accent); background: var(--cyan); border-color: var(--cyan); }
.product-action.danger { color: #fff; background: #9f3147; border-color: #9f3147; }
.product-action:hover:not(:disabled) { filter: brightness(1.13); }
#product-form-status { min-height: 0; margin: 0 18px 8px; color: var(--orange); font-size: 0.8rem; }
#product-form-status:empty { display: none; }
@media (max-width: 840px) {
    .product-modal-split { grid-template-columns: 1fr; }
    .product-modal-sidebar { border-right: 0; border-bottom: 1px solid var(--border-color); }
    .product-modal-main { grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr); }
}
@media (max-width: 620px) {
    .product-dialog { width: min(95vw, 800px); }
    .product-modal-header { flex-wrap: wrap; padding: 12px; }
    .product-form-tabs { order: 2; width: 100%; overflow-x: auto; }
    .product-form-tabs button { white-space: nowrap; }
    .product-modal-header-actions { margin-left: auto; }
    .product-modal-body { padding: 9px 12px; }
    .product-modal-sidebar, .product-modal-main { grid-template-columns: 1fr; padding: 12px; gap: 8px; }
    .product-modal-main .product-main-wide { grid-column: auto; }
    .product-regulatory-grid, .product-bovin-grid, .product-specs-grid { grid-template-columns: 1fr; }
    .product-specs-grid select { min-height: 180px; }
    .product-proof { grid-template-columns: 1fr; }
    .product-modal-footer { flex-wrap: wrap; padding: 9px 12px 12px; }
    .product-modal-actions { width: 100%; flex-wrap: wrap; }
}


.product-heading { align-items: flex-start; }
.product-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.75rem;
}
.product-actions .table-control { white-space: nowrap; }
.product-browser-controls,
.product-range-controls,
.tag-browser-controls,
.tag-range-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.product-range-controls, .tag-range-controls { justify-content: flex-end; }
.product-range-controls[hidden], .tag-range-controls[hidden] { display: none; }
.product-search-control { flex: 1 1 19rem; min-width: 0; }
#products-status-filter { width: 11.5rem; }
#tag-status-filter { width: 11.5rem; }
#products-range-field { width: 10.5rem; }
#tag-range-field { width: 10.5rem; }
.product-range-controls input, .tag-range-controls input { width: 7rem; }
.product-filter-button { white-space: nowrap; cursor: pointer; }
.product-filter-button:hover { border-color: var(--border-hover); }
.product-browser-controls { position: relative; z-index: 2; }
.tag-browser-controls { position: relative; z-index: 2; }
.product-fields-control { position: relative; flex: 0 0 auto; z-index: 3; }
.product-fields-control > summary {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    list-style: none;
    user-select: none;
}
.product-fields-control > summary::-webkit-details-marker { display: none; }
.product-fields-control > summary::after { content: "▾"; color: var(--text-muted); }
.product-fields-control[open] > summary::after { transform: rotate(180deg); }
.product-fields-control:not([open]) .product-fields-menu { display: none; }
.product-fields-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    display: grid;
    gap: 0.25rem;
    min-width: 11rem;
    max-height: min(65vh, 420px);
    overflow-y: auto;
    padding: 0.55rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface-dialog);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.45);
}
.product-fields-menu label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 1.8rem;
    padding: 0.2rem 0.35rem;
    color: var(--text-color);
    font-size: 0.8rem;
    white-space: nowrap;
    cursor: pointer;
}
.product-fields-menu label:hover { background: rgba(0, 242, 254, 0.08); }
.product-fields-menu input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    margin: 0;
    flex: none;
    accent-color: var(--cyan);
    cursor: pointer;
}

.products-pagination #products-page { min-width: 7rem; }
.products-pagination #products-page-size { width: 5rem; }
.products-table { min-width: 1320px; }
.products-table.columns-customized { min-width: 100%; }
.products-table [hidden] { display: none !important; }
#tags-table [hidden] { display: none !important; }
.products-table th { white-space: nowrap; }
.products-table tbody tr { cursor: pointer; }
.products-table th button {
    border: 0;
    padding: 0;
    background: none;
    color: inherit;
    font: inherit;
    font-weight: inherit;
    text-transform: inherit;
    cursor: pointer;
}
.products-table th button:hover,
.products-table th button:focus-visible { color: var(--cyan); }
.products-table th button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.product-sort-arrow { color: var(--cyan); }
.product-alert {
    display: inline-block;
    margin: 0 0.2rem 0.2rem 0;
    padding: 0.2rem 0.45rem;
    border-radius: 5px;
    background: rgba(100, 116, 139, 0.18);
    white-space: nowrap;
    font-size: 0.75rem;
}
.product-alert.red { color: var(--red); background: rgba(244, 63, 94, 0.13); }
.product-alert.orange { color: var(--orange); background: rgba(245, 158, 11, 0.13); }
@media (max-width: 720px) {
    .product-actions { flex: 1 1 100%; justify-content: flex-start; }
    .product-search-control { flex-basis: 100%; }
    .products-pagination { grid-template-columns: 1fr; justify-items: center; }
    .products-pagination .tag-page-size-control { justify-self: center; }
}

@media (max-width: 1080px) {
    .catalogue-settings-form { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
    .catalogue-settings-form > label:first-child,
    .catalogue-settings-form > #catalogue-endpoint-field,
    .catalogue-settings-form > #catalogue-key-field { grid-column: auto; grid-row: auto; }
    .catalogue-settings-actions { grid-column: 1 / -1; grid-row: auto; justify-content: flex-end; flex-wrap: wrap; }
}

/* Queue selection controls */
#view-jobs .section-title { margin-bottom: 0; }
.queue-controls, .queue-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 0.75rem; margin: 0; }
.queue-actions { justify-content: flex-end; }
.queue-actions #jobs-selection-count { margin-right: auto; color: var(--text-muted); }
.queue-select-cell { width: 3rem; text-align: center; padding-left: 0.75rem; padding-right: 0.75rem; }
.queue-select-cell input { width: 1rem; height: 1rem; cursor: pointer; accent-color: var(--cyan); }
.queue-empty { text-align: center; color: var(--text-muted); }
.queue-action-status { min-height: 1.25rem; color: var(--text-muted); }
.queue-actions button:disabled { opacity: 0.5; cursor: not-allowed; }


/* Labels detail modal: dimensions and icons follow Smart Label Pro's tags-details modal. */
.tag-assignment-dialog, .tag-nfc-dialog { color-scheme: inherit; }
.tag-assignment-dialog {
    box-sizing: border-box;
    width: min(800px, calc(100vw - 2rem));
    max-width: 95vw;
    max-height: 95vh;
    padding: 0;
    overflow: hidden;
    color: var(--text-color);
    background: var(--surface-dialog);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--dialog-shadow);
    font-size: 1rem;
}
.tag-assignment-dialog::backdrop {
    background: var(--modal-backdrop);
    backdrop-filter: blur(4px);
}
.tag-modal-shell { display: flex; flex-direction: column; max-height: 95vh; }
.tag-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 18px 9px;
}
.tag-modal-tabs, .tag-modal-header-actions, .tag-modal-chips, .tag-modal-footer {
    display: flex;
    align-items: center;
}
.tag-modal-tabs { gap: 18px; }
.tag-modal-header-actions { gap: 12px; }
.tag-modal-chips { gap: 8px; }
.tag-modal-tabs button, .tag-modal-header-actions button, .tag-modal-chips button,
.tag-modal-chips > span, .tag-modal-footer button {
    box-sizing: border-box;
    height: 28px;
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 12px;
    color: var(--text-soft);
    background: var(--surface-control);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font: inherit;
    font-size: .7rem;
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
    box-shadow: 0 1px 2px rgb(0 0 0 / .05);
}
.tag-modal-tabs button { gap: 8px; font-size: .8rem; }
.tag-modal-tabs button, .tag-modal-header-actions button, .tag-modal-chips button,
.tag-modal-footer button { cursor: pointer; }
.tag-modal-tabs button.active { color: #fff; background: #64748b; border-color: #64748b; }
.tag-modal-footer #mapping-transfer { color: var(--on-accent); background: var(--cyan); border-color: var(--cyan); }
.tag-assignment-dialog button:hover:not(:disabled), .tag-nfc-dialog button:hover:not(:disabled) { border-color: var(--border-hover); }
.tag-assignment-dialog button:focus-visible, .tag-assignment-dialog input:focus-visible,
.tag-assignment-dialog select:focus-visible, .tag-nfc-dialog button:focus-visible,
.tag-nfc-dialog input:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.tag-modal-quiet-action { min-width: 150px; }
.tag-modal-close { width: 28px; min-width: 28px; padding: 0 !important; }
.tag-modal-header-actions button:disabled, .tag-modal-footer button:disabled { opacity: .48; cursor: not-allowed; }
#mapping-dialog-status { margin: 0 18px; font-size: .75rem; }
#mapping-dialog-status:empty { display: none; }
.tag-modal-panel { min-height: 0; overflow-y: auto; padding: 9px 18px; }
.tag-modal-panel[hidden], .tag-assignment-dialog [hidden] { display: none !important; }
.tag-modal-summary {
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}
.tag-modal-summary-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 9px 14px;
}
.tag-modal-summary-top strong {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-soft);
    font-size: .75rem;
    font-weight: 800;
    letter-spacing: .05em;
    white-space: nowrap;
}
.tag-modal-summary-top strong .tag-ref-icon { width: 14px; height: 14px; }
.tag-modal-chips > button, .tag-modal-chips > span { width: 80px; min-width: 80px; padding: 0; gap: 4px; }
.tag-modal-chips .tag-ref-icon, .tag-modal-footer .tag-ref-icon, .tag-modal-quiet-action .tag-ref-icon { width: 14px; height: 14px; }
.tag-modal-summary .mapping-form {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 0 18px;
}
.tag-modal-summary .mapping-form label {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    color: var(--text-subtle);
    font-size: .7rem;
    font-weight: 700;
    white-space: nowrap;
}
.tag-modal-summary .mapping-form input, .tag-modal-summary .mapping-form select {
    box-sizing: border-box;
    width: 150px;
    min-width: 150px;
    height: 28px;
    min-height: 28px;
    color: var(--text-color);
    background: var(--surface-input);
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 10px;
    padding: 0 12px;
    font: inherit;
    font-size: .7rem;
}
.tag-modal-summary .mapping-form select { padding-right: 26px; }
.tag-modal-summary .mapping-form #mapping-template { width: 320px; }
.tag-modal-model-info {
    margin: 0;
    padding: 9px 18px;
    color: var(--text-subtle);
    font-family: "JetBrains Mono", monospace;
    font-size: .7rem;
    line-height: 1.4;
}
.tag-assignment-dialog .mapping-previews { display: block; margin: 0; }
.tag-modal-preview-stage { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 18px 0 0; }
.tag-modal-preview-row { display: flex; align-items: flex-start; justify-content: center; gap: 24px; width: 100%; }
.tag-modal-source-card { display: grid; gap: 3px; width: 350px; flex: 0 0 350px; padding: 12px; background: var(--surface-alt); border: 1px solid var(--border-color); border-radius: 12px; }
.tag-modal-source-row { display: grid; grid-template-columns: 9px minmax(0, 1fr) auto; column-gap: 9px; align-items: center; color: var(--text-soft); font-size: .72rem; font-weight: 700; }
.tag-modal-source-row > :last-child { grid-column: 3; justify-self: end; color: var(--text-subtle); font-size: .68rem; font-weight: 500; text-align: right; }
.tag-modal-source-led { width: 9px; height: 9px; border-radius: 50%; background: #64748b; box-shadow: 0 0 0 3px rgba(148, 163, 184, .12); }
.tag-modal-source-row[data-state="found"] .tag-modal-source-led { background: var(--green); box-shadow: 0 0 0 3px var(--green-glow); }
.tag-modal-source-row[data-state="missing"] .tag-modal-source-led,
.tag-modal-source-row[data-state="error"] .tag-modal-source-led { background: var(--red); box-shadow: 0 0 0 3px rgba(244, 63, 94, .12); }
.tag-modal-device {
    box-sizing: border-box;
    position: relative;
    width: min(358px, 100%);
    padding: 12px 34px 12px 28px;
    background-color: #e2e8f0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.12'/%3E%3C/svg%3E");
    border-radius: 16px;
    box-shadow: inset 0 3px 4px rgba(255,255,255,.7), inset 0 -3px 4px rgba(15,23,42,.15), inset 0 0 0 1px rgba(15,23,42,.1), 0 8px 24px -4px rgba(15,23,42,.15), 0 0 0 1px rgba(15,23,42,.3);
}
.tag-modal-screen {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
    padding: 0;
    color: #64748b;
    font: inherit;
    cursor: pointer;
    background: #fff;
    border: 1.5px solid #64748b;
    border-radius: 2px;
    overflow: hidden;
}
.tag-modal-screen:disabled { cursor: default; }
.tag-modal-screen:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.tag-modal-screen img { display: block; width: 100%; height: auto; margin: 0; border: 0; image-rendering: pixelated; }
.tag-modal-screen img.tag-preview-superseded { display: none; }
#mapping-preview-placeholder { color: #64748b; text-align: center; padding: 2rem; }
.tag-modal-device-led { position: absolute; top: 10px; right: 6px; width: 16px; height: 8px; border-radius: 2px; background: #28544d; }
.tag-modal-preview-stage > p { margin: 0; color: var(--text-subtle); font-size: .7rem; text-align: center; overflow-wrap: anywhere; }
.tag-modal-preview-stage > p:empty { display: none; }
.tag-modal-footer { justify-content: flex-end; flex-wrap: wrap; gap: 18px; padding: 9px 18px 18px; }
.tag-modal-footer button { width: 130px; min-width: 130px; }

.tag-modal-chips #mapping-nfc-open:disabled { opacity: .48; cursor: not-allowed; }
.tag-nfc-dialog {
    box-sizing: border-box;
    width: min(450px, calc(100vw - 2rem));
    max-width: 95vw;
    padding: 0;
    color: var(--text-color);
    background: var(--surface-dialog);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--dialog-shadow);
}
.tag-nfc-dialog::backdrop { background: var(--modal-backdrop); backdrop-filter: blur(4px); }
.tag-nfc-dialog form { margin: 0; }
.tag-nfc-header, .tag-nfc-footer { display: flex; align-items: center; padding: 18px; }
.tag-nfc-header { justify-content: space-between; padding-bottom: 9px; }
.tag-nfc-header h2 { display: inline-flex; align-items: center; gap: 8px; margin: 0; color: var(--text-color); font-size: .8rem; font-weight: 700; }
.tag-nfc-close, .tag-nfc-footer button {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 28px;
    min-height: 28px;
    padding: 0 12px;
    color: var(--text-soft);
    background: var(--surface-control);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font: inherit;
    font-size: .7rem;
    font-weight: 600;
    cursor: pointer;
}
.tag-nfc-close { width: 28px; padding: 0; }
.tag-nfc-body { display: flex; flex-direction: column; gap: 8px; padding: 9px 18px; }
.tag-nfc-body label { font-size: .7rem; font-weight: 700; }
.tag-nfc-body input {
    box-sizing: border-box;
    width: 100%;
    height: 28px;
    min-height: 28px;
    padding: 0 12px;
    color: var(--text-color);
    background: var(--surface-input);
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 10px;
    font: inherit;
    font-size: .7rem;
}
#tag-nfc-status { min-height: 1rem; margin: 0; font-size: .7rem; }
.tag-nfc-footer { justify-content: flex-end; gap: 18px; padding-top: 9px; }
.tag-nfc-footer button { width: 130px; }
.tag-nfc-footer #mapping-nfc-update { color: var(--on-accent); background: var(--cyan); border-color: var(--cyan); }
.tag-nfc-footer button:disabled { opacity: .48; cursor: not-allowed; }
.tag-nfc-dialog .tag-ref-icon { width: 14px; height: 14px; }
@media (max-width: 760px) {
    .tag-modal-header { align-items: flex-start; flex-wrap: wrap; padding: 16px; }
    .tag-modal-header-actions { width: 100%; justify-content: flex-end; }
    .tag-modal-panel { padding: 9px 16px; }
    .tag-modal-summary .mapping-form { padding: 0 14px; }
    .tag-modal-summary .mapping-form label { width: 100%; justify-content: space-between; }
    .tag-modal-summary .mapping-form input, .tag-modal-summary .mapping-form select { flex: 1; }
    .tag-modal-summary .mapping-form #mapping-template { width: auto; min-width: 0; }
    #mapping-dialog-status { margin: 0 16px; }
    .tag-modal-footer { padding: 9px 16px 16px; }
    .tag-modal-footer button { flex: 1; min-width: 0; }
    .tag-modal-preview-row { flex-wrap: wrap; gap: 16px; }
    .tag-modal-source-card { width: min(358px, 100%); flex-basis: min(358px, 100%); box-sizing: border-box; }
}
tr.tag-row { cursor: pointer; }
tr.tag-row:focus-visible,
#tags-table .tag-history-cell:focus-visible,
#tags-table .tag-battery-history-cell:focus-visible { outline: 2px solid var(--cyan); outline-offset: -2px; }
#tags-table .tag-history-cell,
#tags-table .tag-battery-history-cell { cursor: pointer; }

.appearance-card { grid-template-columns: 1fr; }
.appearance-card label { display: grid; grid-template-columns: 6rem minmax(0, 14rem); align-items: center; gap: .75rem; color: var(--text-muted); font-size: .85rem; font-weight: 600; }
.appearance-card select { min-width: 0; padding: .55rem; border: 1px solid var(--border-color); border-radius: 8px; background: var(--surface-input); color: var(--text-color); font: inherit; }
