/* ===================================================
   ATHENA REUSABLE COMPONENTS
   Unified design system based on SavedPlans pattern
   =================================================== */

/* --- Panel --- */
.ath-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.75rem;
    overflow: hidden;
}

.ath-panel-header {
    padding: 0.5rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-surface);
    cursor: pointer;
    transition: background 0.15s;
}
.ath-panel-header:hover {
    background: var(--overlay-hover);
}

/* --- Table --- */
.ath-table {
    width: 100%;
    table-layout: auto;
    font-size: 0.7rem;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--text-primary);
}

.ath-table-head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-surface);
    isolation: isolate;
}

.ath-table-head tr {
    font-size: 0.62rem;
    color: var(--text-muted);
    background: var(--bg-surface);
}

.ath-table-head th {
    background: var(--bg-surface);
    background-clip: padding-box;
    padding: 5px 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
    color: var(--text-muted);
    border-bottom: 0 !important;
    box-shadow: inset 0 -1px 0 var(--border-highlight);
}

.ath-table-head .ath-dashboard-total-row {
    background: color-mix(in srgb, var(--accent) 9%, var(--bg-surface));
}

.ath-table-head .ath-dashboard-total-row th {
    background: color-mix(in srgb, var(--accent) 9%, var(--bg-surface));
    background-clip: padding-box;
    padding-top: 6px;
    padding-bottom: 6px;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-secondary);
    border-bottom: 0 !important;
    box-shadow:
        inset 0 -1px 0 color-mix(in srgb, var(--accent) 28%, var(--border)),
        0 1px 0 color-mix(in srgb, var(--accent) 9%, var(--bg-surface));
}

.ath-dashboard-total-title {
    color: var(--text-primary) !important;
    font-size: 0.68rem;
    font-weight: 700 !important;
}

.ath-dashboard-total-title i {
    color: var(--accent);
    font-size: 0.65rem;
    margin-right: 5px;
}

.ath-dashboard-total-title + .ath-dashboard-total-scope {
    margin-left: 7px;
}

.ath-dashboard-total-scope {
    color: var(--text-muted);
    font-size: 0.58rem;
    font-weight: 500;
}

.ath-table tbody td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--overlay-subtle);
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ath-virtual-table {
    table-layout: fixed;
    min-width: 1180px;
}

.ath-virtual-table .ath-name-col,
.ath-virtual-table .ath-name-cell {
    width: 220px;
    min-width: 220px;
    max-width: 220px;
}

.ath-virtual-table .ath-name-cell {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ath-virtual-table .ath-name-cell .hab-name-editable {
    display: inline-block;
    max-width: calc(100% - 16px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}

/* --- Rows --- */
.ath-row {
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--overlay-border);
}
.ath-row:hover > td {
    background: var(--overlay-subtle);
}
.ath-row-expanded > td {
    background: rgba(52,152,219,0.04);
}

/* Detail sub-row (expanded content) */
.ath-detail-row > td {
    padding: 0 !important;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-highlight) !important;
}

/* Sub-table row inside expanded detail */
.ath-sub-row {
    font-size: 0.68rem;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--overlay-subtle);
}
.ath-sub-row:hover > td {
    background: var(--overlay-subtle);
}

.ath-virtual-row {
    height: 34px;
    min-height: 34px;
    max-height: 34px;
}

.ath-virtual-row > td,
.ath-virtual-row > th {
    height: 34px;
    min-height: 34px;
    max-height: 34px;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

/* Inline-editable habitat name */
.hab-name-editable {
    cursor: pointer;
    border-bottom: 1px dashed transparent;
    transition: border-color 0.15s, color 0.15s;
    padding-bottom: 1px;
    margin-left: 4px;
}
.hab-name-editable:hover {
    border-bottom-color: var(--primary, #3498db);
    color: var(--text-primary, #e2e8f0);
}

/* --- Chevron --- */
.ath-chevron {
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    color: var(--text-muted);
    display: inline-flex;
    width: 14px;
    height: 14px;
    text-align: center;
    line-height: 1;
}

/* --- Stat Card (refined) --- */
.ath-stat-card {
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-surface) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    text-align: center;
    transition: border-color 0.15s;
}
.ath-stat-card:hover {
    border-color: var(--border-highlight);
}
.ath-stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}
.ath-stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* --- Hover + touch tooltip --- */
.ath-tooltip-host,
.ath-tooltip-trigger {
    position: relative;
    outline: none;
}

.ath-tooltip-trigger {
    display: inline-flex;
    cursor: help;
    touch-action: manipulation;
}

.ath-tooltip-bubble {
    position: absolute;
    z-index: 1200;
    right: 0;
    bottom: calc(100% + 7px);
    width: max-content;
    max-width: min(240px, 80vw);
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--border-highlight);
    border-radius: 5px;
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    font-size: 0.7rem;
    font-weight: 500;
    line-height: 1.45;
    text-align: left;
    white-space: pre-line;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(3px);
    transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
}

.ath-tooltip-host:hover > .ath-tooltip-bubble,
.ath-tooltip-host:focus > .ath-tooltip-bubble,
.ath-tooltip-trigger:hover > .ath-tooltip-bubble,
.ath-tooltip-trigger:focus > .ath-tooltip-bubble {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.ath-tooltip-host:focus-visible,
.ath-tooltip-trigger:focus-visible {
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 45%, transparent);
}

@media (hover: none) {
    .ath-tooltip-host,
    .ath-tooltip-trigger {
        cursor: pointer;
    }
}

/* --- Inline stat pill (used in headers) --- */
.ath-stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--overlay-hover);
}
.ath-stat-pill-val {
    font-weight: 700;
}

/* --- Badge (small) --- */
.ath-badge {
    font-size: 0.55rem;
    vertical-align: middle;
    padding: 1px 5px;
    border-radius: 3px;
}

/* --- Progress --- */
.ath-progress {
    height: 3px;
    border-radius: 2px;
    background: var(--overlay-bg);
    overflow: hidden;
}
.ath-progress-bar {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s;
}

/* --- Scrollable table container --- */
.ath-table-scroll {
    max-height: 70vh;
    overflow-y: auto;
    overflow-x: auto;
    border-top: 1px solid var(--border);
}

/* --- Resource bar (inline resource display) --- */
.ath-resource-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.78rem;
}
.ath-resource-bar .ath-res-item {
    display: flex;
    align-items: center;
    gap: 4px;
}
.ath-resource-bar .ath-res-sep {
    color: var(--border);
    margin: 0 0.25rem;
}
.components-reconnect-first-attempt-visible,
.components-reconnect-repeated-attempt-visible,
.components-reconnect-failed-visible,
.components-pause-visible,
.components-resume-failed-visible,
.components-rejoining-animation {
    display: none;
}

#components-reconnect-modal.components-reconnect-show .components-reconnect-first-attempt-visible,
#components-reconnect-modal.components-reconnect-show .components-rejoining-animation,
#components-reconnect-modal.components-reconnect-paused .components-pause-visible,
#components-reconnect-modal.components-reconnect-resume-failed .components-resume-failed-visible,
#components-reconnect-modal.components-reconnect-retrying,
#components-reconnect-modal.components-reconnect-retrying .components-reconnect-repeated-attempt-visible,
#components-reconnect-modal.components-reconnect-retrying .components-rejoining-animation,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-failed .components-reconnect-failed-visible {
    display: block;
}

#components-reconnect-modal {
    background-color: var(--bg-card, #1c1d21);
    color: var(--text-primary, #e2e8f0);
    width: 22rem;
    margin: 20vh auto;
    padding: 2.5rem 2rem;
    border: 1px solid var(--border, #2d3748);
    border-radius: 12px;
    box-shadow: 0 10px 40px var(--shadow-color);
    opacity: 0;
    transition: display 0.5s allow-discrete, overlay 0.5s allow-discrete;
    animation: components-reconnect-modal-fadeOutOpacity 0.4s both;
}

#components-reconnect-modal[open] {
    animation: components-reconnect-modal-slideUp 0.6s cubic-bezier(.05, .89, .25, 1.02) 0.1s, 
               components-reconnect-modal-fadeInOpacity 0.4s ease-in-out 0.1s;
    animation-fill-mode: both;
}

#components-reconnect-modal::backdrop {
    background-color: rgba(0, 0, 0, 0.85); /* Much darker overlay */
    backdrop-filter: blur(4px); /* Glassmorphism background blur */
    animation: components-reconnect-modal-fadeInOpacity 0.4s ease-in-out;
    opacity: 1;
}

@keyframes components-reconnect-modal-slideUp {
    0% { transform: translateY(40px) scale(0.95); }
    100% { transform: translateY(0) scale(1); }
}

@keyframes components-reconnect-modal-fadeInOpacity {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

@keyframes components-reconnect-modal-fadeOutOpacity {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

.components-reconnect-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
}

#components-reconnect-modal p {
    margin: 0;
    text-align: center;
    font-size: 0.95rem;
    line-height: 1.4;
}

.text-danger {
    color: var(--danger, #ff4c4c) !important;
    font-weight: 500;
}

/* ================== LOGO & ANIMATION ================== */
.components-reconnect-logo-wrapper {
    position: relative;
    width: 120px;
    height: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 0.5rem;
}

.components-reconnect-logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
    z-index: 2;
    filter: drop-shadow(0 0 12px rgba(52, 152, 219, 0.5));
    animation: components-reconnect-logo-pulse 2s ease-in-out infinite;
}

@keyframes components-reconnect-logo-pulse {
    0% { transform: scale(1); filter: drop-shadow(0 0 10px rgba(52, 152, 219, 0.4)); }
    50% { transform: scale(1.08); filter: drop-shadow(0 0 18px rgba(52, 152, 219, 0.8)); }
    100% { transform: scale(1); filter: drop-shadow(0 0 10px rgba(52, 152, 219, 0.4)); }
}

.components-rejoining-animation {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 120px;
    height: 120px;
    z-index: 1;
}

.components-rejoining-animation div {
    position: absolute;
    border: 2px solid rgba(52, 152, 219, 0.4);
    opacity: 1;
    border-radius: 50%;
    animation: components-rejoining-anim 1.5s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}

.components-rejoining-animation div:nth-child(2) {
    animation-delay: -0.5s;
}

@keyframes components-rejoining-anim {
    0% { top: 60px; left: 60px; width: 0; height: 0; opacity: 0; }
    5% { top: 60px; left: 60px; width: 0; height: 0; opacity: 1; }
    100% { top: 0px; left: 0px; width: 120px; height: 120px; opacity: 0; }
}

/* ================== BUTTON ================== */
.athena-btn {
    border: 0;
    background-color: var(--primary, #3498db);
    color: white;
    padding: 8px 32px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s, box-shadow 0.2s;
    box-shadow: 0 4px 10px rgba(52, 152, 219, 0.3);
}

.athena-btn:hover {
    background-color: #2980b9;
    transform: translateY(-1px);
    box-shadow: 0 6px 15px rgba(52, 152, 219, 0.4);
}

.athena-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 5px rgba(52, 152, 219, 0.3);
}

/* --- Chart --- */
.ath-chart-container {
    position: relative;
    width: 100%;
}
.ath-chart-tooltip {
    position: absolute;
    top: 8px;
    right: 12px;
    background: var(--chart-tooltip-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--chart-tooltip-border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.7rem;
    pointer-events: none;
    z-index: 10;
}
.ath-chart-tooltip-time {
    font-size: 0.62rem;
    color: var(--text-muted);
    margin-bottom: 2px;
}
.ath-chart-tooltip-rows {
    max-height: 220px;
    overflow-y: auto;
}
.ath-chart-tooltip-row {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
}
.ath-chart-tooltip-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.ath-chart-hint {
    font-size: 0.62rem;
    color: var(--text-muted);
    text-align: center;
    padding-top: 4px;
}
.ath-chart-legend {
    display: flex;
    gap: 12px;
    justify-content: center;
    padding: 4px 0 0;
    font-size: 0.65rem;
    color: var(--text-muted);
}
.ath-chart-legend--dense {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 4px 10px;
    max-height: 72px;
    overflow-y: auto;
    padding: 6px 2px 0;
}
.ath-chart-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.ath-chart-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

/* --- Stat Card Delta --- */
.ath-stat-delta {
    font-size: 0.6rem;
    font-weight: 600;
    margin-top: 1px;
}
.ath-stat-delta.positive { color: #2ecc71; }
.ath-stat-delta.negative { color: #e74c3c; }
.ath-stat-delta.neutral { color: var(--text-muted); }

/* --- Period Selector --- */
.ath-period-selector {
    display: flex;
    gap: 4px;
    background: var(--overlay-subtle);
    border-radius: 6px;
    padding: 2px;
}
.ath-period-btn {
    padding: 3px 10px;
    font-size: 0.7rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}
.ath-period-btn:hover {
    color: var(--text-primary);
    background: var(--overlay-hover);
}
.ath-period-btn.active {
    color: var(--text-primary);
    background: var(--primary, #3498db);
}

[data-theme="light"] .ath-chart-tooltip {
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

/* Keep battle times and bridge controls visible even for long habitat names. */
.ath-defense-name-row { display: flex; align-items: center; gap: 3px; min-width: 0; }
.ath-defense-name-row > .badge { flex-shrink: 0; }
.ath-defense-habitat-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ath-defense-round-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; margin-top: 2px; }
@media (pointer: coarse) {
    .ath-bridge-view-trigger { min-height:44px; min-width:44px; font-size:.75rem !important; padding:4px 8px !important; }
}

/* Admin: open metric bands, contextual navigation and readable tables. */
.admin-workspace { max-width:1600px; margin:0 auto; font-size:1.0714rem; }
.admin-workspace h1 { font-size:2rem; font-weight:600; white-space:normal !important; }
.admin-workspace h2 { font-size:1.5rem; font-weight:600; margin:0 0 1rem; }
.admin-context-nav,.admin-tabs { display:flex; gap:1.5rem; flex-wrap:wrap; border-bottom:1px solid var(--border); margin-bottom:1.5rem; }
.admin-context-nav a,.admin-tabs a,.admin-tabs button { padding:.75rem 0; color:var(--text-muted); text-decoration:none; background:none; border:0; border-bottom:2px solid transparent; font-size:1rem; }
.admin-context-nav a.active,.admin-tabs .active { color:var(--accent); border-bottom-color:var(--accent); font-weight:600; }
.admin-data-age { color:var(--text-muted); font-size:.8125rem; align-self:center; }
.admin-metric-band { display:grid; grid-template-columns:repeat(auto-fit,minmax(140px,1fr)); border:1px solid var(--border); border-radius:6px; background:var(--bg-card); margin:1.5rem 0 .75rem; }
.admin-metric-band > * { padding:1rem; min-width:0; color:var(--text-primary); text-decoration:none; border-right:1px solid var(--border); }
.admin-metric-band > :last-child { border-right:0; }
.admin-metric-band small { display:block; min-height:2.75em; color:var(--text-muted); font-size:1rem; line-height:1.4; }
.admin-metric-band strong { display:block; font-size:1.85rem; font-weight:600; line-height:1.3; margin-top:.5rem; overflow-wrap:anywhere; }
.admin-metric-band a:hover { background:var(--overlay-hover); }
.admin-caption { color:var(--text-muted); font-size:.8125rem; line-height:1.5; }
.admin-section { margin-top:2rem; }
.admin-issue-list,.admin-area-list { border:1px solid var(--border); border-radius:6px; overflow:hidden; background:var(--bg-card); }
.admin-issue { display:grid; grid-template-columns:120px 1fr auto; gap:1rem; align-items:center; padding:1rem; border-bottom:1px solid var(--border); border-left:3px solid var(--accent); }
.admin-issue:last-child { border-bottom:0; }
.admin-issue.warning { border-left-color:var(--warning); }
.admin-area-list > a { display:grid; grid-template-columns:24px 190px 1fr 16px; align-items:center; gap:1rem; padding:1.25rem; border-bottom:1px solid var(--border); color:var(--text-primary); text-decoration:none; }
.admin-area-list > a:last-child { border-bottom:0; }
.admin-area-list a:hover { background:var(--overlay-hover); }
.admin-area-list span { color:var(--text-muted); font-size:1rem; }
.admin-toolbar { display:flex; flex-wrap:wrap; align-items:center; gap:.75rem; margin:1rem 0; }
.admin-toolbar input { max-width:26rem; }
.admin-toolbar select { width:auto; max-width:100%; }
.admin-workspace .table { font-size:1rem; }
.admin-workspace .table th { font-size:.875rem; white-space:nowrap; }
.admin-workspace .table td { padding:.75rem; }
.admin-workspace .card { border-radius:6px; }
.admin-pagination { display:flex; align-items:center; justify-content:flex-end; gap:1rem; margin:1rem 0; font-size:.875rem; }
.admin-chart-grid { display:grid; grid-template-columns:1fr 1fr; gap:1.5rem; }
.admin-workspace .business-metrics { border-bottom:1px solid var(--border); padding-bottom:1rem; }
.admin-workspace .alert { font-size:.875rem; }
.admin-diagnostic-links { display:flex; gap:1rem; flex-wrap:wrap; padding:1rem 0; border-top:1px solid var(--border); margin-top:1.5rem; }
@media (max-width:767px) {
 .admin-workspace h1 { font-size:1.75rem; }
 .admin-context-nav,.admin-tabs { gap:1rem; margin-bottom:1rem; }
 .admin-context-nav a,.admin-tabs a,.admin-tabs button { font-size:1rem; min-height:44px; }
 .admin-workspace .btn { min-height:44px; display:inline-flex; align-items:center; justify-content:center; }
 .admin-metric-band { grid-template-columns:repeat(2,minmax(0,1fr)); }
 .admin-metric-band > * { border-bottom:1px solid var(--border); padding:.875rem; }
 .admin-metric-band strong { font-size:1.5rem; }
 .admin-issue { grid-template-columns:1fr; gap:.5rem; }
 .admin-issue .btn { justify-self:start; }
 .admin-area-list > a { grid-template-columns:24px 1fr 16px; gap:.75rem; }
 .admin-area-list span { grid-column:2; grid-row:2; }
 .admin-area-list > a > i:last-child { grid-column:3; grid-row:1 / 3; }
 .admin-chart-grid { grid-template-columns:1fr; }
 .admin-toolbar input,.admin-toolbar select { max-width:100%; width:100%; }
 .admin-pagination { flex-wrap:wrap; gap:.5rem; }
}

/* Advanced user/manager controls are available explicitly, not competing with the customer summary. */
.admin-customer-basic th:nth-child(2),.admin-customer-basic td:nth-child(2),
.admin-customer-basic th:nth-child(3),.admin-customer-basic td:nth-child(3),
.admin-customer-basic th:nth-child(4),.admin-customer-basic td:nth-child(4),
.admin-customer-basic th:nth-child(8),.admin-customer-basic td:nth-child(8),
.admin-customer-basic th:nth-child(9),.admin-customer-basic td:nth-child(9),
.admin-customer-basic th:nth-child(12),.admin-customer-basic td:nth-child(12),
.admin-customer-basic th:nth-child(13),.admin-customer-basic td:nth-child(13),
.admin-customer-basic th:nth-child(14),.admin-customer-basic td:nth-child(14),
.admin-customer-basic th:nth-child(15),.admin-customer-basic td:nth-child(15) { display:none; }
