/**
 * i-Polls - Modern Design System & Subsystem Stylesheet
 * Laboratory of Robotics, Embedded & Integrated Systems (ROBIS Lab)
 * Self-contained Dark Theme, UI Components, Grid, Tables & Tooltips.
 */

:root {
    --ip-bg: #0d1117;
    --ip-card: #161b22;
    --ip-surface: #21262d;
    --ip-surface-hover: #30363d;
    --ip-border: #30363d;
    --ip-border-light: #484f58;
    
    --ip-cyan: #00d2d3;
    --ip-cyan-dark: #00adb5;
    --ip-cyan-subtle: rgba(0, 210, 211, 0.12);
    
    --ip-blue: #38bdf8;
    --ip-blue-subtle: rgba(56, 189, 248, 0.12);
    
    --ip-green: #2ea043;
    --ip-green-subtle: rgba(46, 160, 67, 0.15);
    
    --ip-amber: #f59e0b;
    --ip-amber-subtle: rgba(245, 158, 11, 0.15);
    
    --ip-red: #f85149;
    --ip-red-subtle: rgba(248, 81, 73, 0.15);
    
    --ip-text: #f0f6fc;
    --ip-text-muted: #8b949e;
    --ip-text-dim: #6e7681;
    --ip-white: #ffffff;
}

/* Base resets & typography */
body {
    background-color: var(--ip-bg) !important;
    color: var(--ip-text) !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--ip-cyan);
    text-decoration: none;
    transition: color 0.2s ease;
}
a:hover {
    color: #48e5e6;
}

/* Standalone Grid & Container System (Works with or without Bootstrap) */
.container, .container-fluid {
    width: 100%;
    margin-right: auto;
    margin-left: auto;
    box-sizing: border-box;
}
.container {
    max-width: 1240px;
    padding-left: 1.25rem;
    padding-right: 1.25rem;
}
.container-fluid {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
}

.row {
    display: flex;
    flex-wrap: wrap;
    margin-left: -0.75rem;
    margin-right: -0.75rem;
    box-sizing: border-box;
}
.row > [class*="col"] {
    box-sizing: border-box;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}
.col-12 { flex: 0 0 100%; max-width: 100%; }
.col-md-3 { flex: 0 0 100%; max-width: 100%; }
.col-md-4 { flex: 0 0 100%; max-width: 100%; }
.col-md-5 { flex: 0 0 100%; max-width: 100%; }
.col-md-6 { flex: 0 0 100%; max-width: 100%; }
.col-md-7 { flex: 0 0 100%; max-width: 100%; }
.col-md-8 { flex: 0 0 100%; max-width: 100%; }

@media (min-width: 768px) {
    .col-md-3 { flex: 0 0 25%; max-width: 25%; }
    .col-md-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
    .col-md-5 { flex: 0 0 41.666667%; max-width: 41.666667%; }
    .col-md-6 { flex: 0 0 50%; max-width: 50%; }
    .col-md-7 { flex: 0 0 58.333333%; max-width: 58.333333%; }
    .col-md-8 { flex: 0 0 66.666667%; max-width: 66.666667%; }
}

/* Standalone Navbar: Pure CSS resilience against CDN outages */
.navbar-robis {
    background-color: var(--ip-card) !important;
    border-bottom: 1px solid var(--ip-border) !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    padding: 0.75rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}
.navbar-robis .navbar-brand {
    font-weight: 800;
    font-size: 1.25rem;
    color: #ffffff !important;
    letter-spacing: 0.5px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}
.navbar-robis .navbar-nav {
    list-style: none !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 0.4rem !important;
    margin: 0 !important;
    padding: 0 !important;
}
.navbar-robis .nav-item {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}
.navbar-robis .nav-link {
    color: rgba(240, 246, 252, 0.8) !important;
    padding: 0.5rem 0.85rem !important;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    transition: all 0.2s ease;
}
.navbar-robis .nav-link:hover, .navbar-robis .nav-link.active {
    color: #ffffff !important;
    background-color: var(--ip-surface) !important;
    border: 1px solid var(--ip-border);
}

/* Cards & Surfaces */
.card, .card-custom {
    background-color: var(--ip-card) !important;
    border: 1px solid var(--ip-border) !important;
    border-radius: 12px;
    color: var(--ip-text) !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    overflow: hidden;
}
.card-header {
    background-color: var(--ip-card) !important;
    border-bottom: 1px solid var(--ip-border) !important;
    color: var(--ip-text) !important;
    padding: 1rem 1.25rem;
}
.card-body {
    padding: 1.25rem;
}

/* KPI Summary Metric Cards */
.ip-metric-card {
    background: var(--ip-card);
    border: 1px solid var(--ip-border);
    border-radius: 12px;
    padding: 1.2rem 1.4rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}
.ip-metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}
.ip-metric-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 5px;
}
.ip-metric-card.border-cyan::before { background: var(--ip-cyan); }
.ip-metric-card.border-green::before { background: var(--ip-green); }
.ip-metric-card.border-amber::before { background: var(--ip-amber); }
.ip-metric-card.border-blue::before { background: var(--ip-blue); }

.ip-metric-label {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--ip-text-muted);
    margin-bottom: 0.35rem;
}
.ip-metric-val {
    font-size: 1.9rem;
    font-weight: 800;
    color: #ffffff;
    line-height: 1;
}
.ip-metric-icon {
    font-size: 2.2rem;
    opacity: 0.45;
    line-height: 1;
}

/* High-Contrast Tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table, table.ip-table {
    width: 100%;
    margin-bottom: 0;
    color: var(--ip-text) !important;
    border-collapse: collapse;
}
.table th, table.ip-table th {
    background-color: var(--ip-surface) !important;
    color: var(--ip-text-muted) !important;
    font-weight: 700;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--ip-border) !important;
    border-top: none;
    white-space: nowrap;
}
.table td, table.ip-table td {
    background-color: var(--ip-card) !important;
    color: var(--ip-text) !important;
    padding: 1rem 1rem;
    border-bottom: 1px solid var(--ip-border) !important;
    border-top: none;
    vertical-align: middle;
}
.table tbody tr:hover td, table.ip-table tbody tr:hover td {
    background-color: var(--ip-surface) !important;
}

/* Badges & Pills */
.badge, .ip-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.3rem 0.65rem;
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1;
    border-radius: 20px;
    white-space: nowrap;
}
.badge-cyan {
    background: var(--ip-cyan-subtle);
    color: var(--ip-cyan);
    border: 1px solid rgba(0, 210, 211, 0.35);
}
.badge-green {
    background: var(--ip-green-subtle);
    color: #4ade80;
    border: 1px solid rgba(46, 160, 67, 0.4);
}
.badge-amber {
    background: var(--ip-amber-subtle);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.4);
}
.badge-red {
    background: var(--ip-red-subtle);
    color: #f87171;
    border: 1px solid rgba(248, 81, 73, 0.4);
}
.badge-gray {
    background: var(--ip-surface);
    color: var(--ip-text-muted);
    border: 1px solid var(--ip-border);
}

/* Interactive Buttons */
.btn, .ip-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 600;
    font-size: 0.92rem;
    padding: 0.55rem 1.1rem;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    line-height: 1.4;
    user-select: none;
}
.btn-primary, .ip-btn-primary {
    background: linear-gradient(135deg, var(--ip-cyan-dark), var(--ip-cyan)) !important;
    color: #0b132b !important;
    border: none !important;
    font-weight: 700;
    box-shadow: 0 2px 10px rgba(0, 210, 211, 0.3);
}
.btn-primary:hover, .ip-btn-primary:hover {
    background: linear-gradient(135deg, var(--ip-cyan), #48e5e6) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0, 210, 211, 0.45);
    color: #0b132b !important;
}

.btn-outline-ctrl {
    background: var(--ip-surface);
    border: 1px solid var(--ip-border);
    color: var(--ip-text) !important;
    padding: 0.35rem 0.65rem;
    border-radius: 6px;
    font-size: 0.85rem;
}
.btn-outline-ctrl:hover {
    background: var(--ip-border);
    border-color: var(--ip-border-light);
    color: #ffffff !important;
    transform: translateY(-1px);
}

.btn-group {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

/* Tooltip System: Pure CSS Instant Floating Tooltips */
[data-tooltip] {
    position: relative;
    cursor: pointer;
}
[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) scale(0.95);
    background: #0b132b;
    color: #f0f6fc;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid var(--ip-border-light);
    box-shadow: 0 4px 14px rgba(0,0,0,0.5);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: all 0.15s ease;
    z-index: 9999;
}
[data-tooltip]::after {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px 6px 0 6px;
    border-style: solid;
    border-color: #0b132b transparent transparent transparent;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: all 0.15s ease;
    z-index: 9999;
}
[data-tooltip]:hover::before,
[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) scale(1);
}

/* Pulsing badge for live states */
.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ea043;
    display: inline-block;
    box-shadow: 0 0 0 0 rgba(46, 160, 67, 0.7);
    animation: pulseGlow 1.8s infinite;
}
@keyframes pulseGlow {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(46, 160, 67, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(46, 160, 67, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(46, 160, 67, 0); }
}

/* SVG Icon Helper */
.ip-icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    stroke-width: 0;
    stroke: currentColor;
    fill: currentColor;
    vertical-align: -0.15em;
}

/* Multi-column aligned form row (keeps inputs aligned regardless of label line wraps) */
.ipolls-aligned-row {
    align-items: flex-start;
}
.ipolls-aligned-row > [class*="col-"] {
    display: flex;
    flex-direction: column;
}
.ipolls-aligned-row label.form-label {
    min-height: 2.85rem;
    display: flex;
    align-items: flex-end;
    margin-bottom: 0.5rem;
}
.ipolls-aligned-row .form-text {
    min-height: 2.5rem;
    display: flex;
    align-items: flex-start;
}

