@font-face {
    font-family: "Seven Segment";
    src: url("../fonts/7segment.ttf") format("truetype");
    font-display: swap;
}

:root {
    --bg: #0f1115;
    --panel: #171a21;
    --panel-2: #11151e;
    --border: #2a2f3a;
    --row-border: #202633;
    --text: #e8edf5;
    --muted: #aeb8c8;
    --accent: #4ea1ff;
    --ok: #16c784;
    --danger-bg: #6b1b24;
    --stripe-even: #222b3d;
    --input-bg: #0b0e13;
    --dot-off: #667085;
    --green: #27ae60;
    --red: #e74c3c;
}

:root[data-theme="light"] {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --panel-2: #eef2f7;
    --border: #d7dee8;
    --row-border: #e5ebf3;
    --text: #111827;
    --muted: #5f6b7a;
    --accent: #2563eb;
    --ok: #16a34a;
    --danger-bg: #f8b4bd;
    --stripe-even: #f2f6fb;
    --input-bg: #ffffff;
    --dot-off: #9aa5b5;
}

/* ============================================================================
   2. GLOBAL STYLES
   ============================================================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
}

.app {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100vh;
    overflow: hidden;
}

/* Top header */
.header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: #000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand img {
    display: block;
    height: 48px;
    width: auto;
}

.brand-title {
    color: #fff;
    font-size: clamp(1.25rem, 2.4vw, 1.85rem);
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
}

.header-contest {
    display: flex;
    align-items: center;
    gap: 20px;
    min-width: 0px;
    max-width: 900px;
}

.header-contest a {
    color: var(--green);
}

.header-contest a:hover {
    color: var(--red);
}

.header-right {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.theme-toggle {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

.theme-toggle:hover {
    border-color: var(--accent);
}

.status {
    color: var(--muted);
    font-size: 0.92rem;
}

.status .dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: var(--dot-off);
    margin-right: 6px;
    vertical-align: middle;
}

.status.connected .dot {
    background: var(--ok);
}

/* Shared controls */
.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 0.88rem;
}

.filters label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

input[type="text"],
select {
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
}

.content {
    display: grid;
    grid-template-columns: 1fr 3fr;
    grid-template-rows: 1fr 2fr;
    grid-template-areas:
        "activity"
        "active"
        "qso"
        "score";
    gap: 12px;
    padding: 12px;
    min-height: 0;
    align-items: stretch;
    overflow: auto;
    position: relative;
}

.panel-activity {
    grid-area: activity;
    grid-column: 1;
    grid-row: 2;
}

.panel-qso {
    grid-area: qso;
    grid-column: 2;
    grid-row: 2;
}

.panel-score {
    grid-area: score;
    grid-column: 1;
    grid-row: 1;
}

.panel-users {
    grid-area: users;
    grid-column: 2;
    grid-row: 1;
}

.panel {
    min-width: 0;
    min-height: 0;
    max-height: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--panel);
    display: flex;
    flex-direction: column;
}

.panel h2 {
    margin: 0;
    font-size: 1rem;
}

.panel-header {
    border-bottom: 1px solid var(--border);
    padding: 8px 10px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    align-content: flex-start;
    min-height: 74px;
    gap: 6px 10px;
}

.panel-header > * {
    min-width: 0;
}

.panel-header .filters {
    font-size: 0.84rem;
}

.center {
    text-align: center;
}

/* Tables: Shared Foundation */
.table-wrap {
    overflow-y: auto;
    overflow-x: auto;
    min-height: 0;
    flex: 1 1 auto;
}

.table-wrap.hide-x-scroll {
    overflow-x: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--panel-2);
    color: var(--muted);
}

#activeUsersHead th {
    cursor: pointer;
    user-select: none;
}

th,
td {
    border-bottom: 1px solid var(--row-border);
    text-align: left;
    vertical-align: top;
    padding: 6px 8px;
    white-space: nowrap;
}

td.summary {
    white-space: normal;
    min-width: 200px;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Panel: Activity Log */
.activity-table {
    font-size: 0.8rem;
    min-width: 0;
}

.activity-table th,
.activity-table td {
    padding: 5px 4px;
}

.activity-table td.summary {
    min-width: 120px;
}

/* Panel: QSO Log */
.qso-log-table {
    min-width: 1020px;
}

#qsoBody tr:nth-child(even) td {
    background: var(--stripe-even);
}

.qso-log-table th:last-child,
.qso-log-table td:last-child {
    width: 62px;
    padding-left: 4px;
    padding-right: 4px;
}

.qso-summary {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    color: var(--muted);
    font-size: 0.95rem;
    font-weight: 600;
}

.qso-summary .val,
.active-summary .val {
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 800;
}

/* QSO tags and tooltips */
.qso-tags {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.qso-tag-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: help;
}

.qso-tag-tooltip::after {
    content: attr(data-popup);
    position: absolute;
    right: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 0.76rem;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 10;
}

.qso-tag-tooltip:hover::after,
.qso-tag-tooltip:focus-within::after {
    opacity: 1;
    visibility: visible;
}

.qso-tag-pota {
    font-size: 1rem;
    line-height: 1;
}

.qso-tag-dupe {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 999px;
    background: #f59e0b;
    color: #111827;
    font-size: 0.74rem;
    font-weight: 700;
    line-height: 1.2;
}

.qso-actions {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
}

.qso-actions .filters {
    min-width: 0;
}

.qso-actions .filters input {
    width: 140px;
    max-width: 100%;
}

.qso-sound-toggle {
    position: relative;
    width: 34px;
    min-width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.qso-sound-toggle:hover {
    border-color: var(--accent);
}

.qso-sound-icon {
    width: 21px;
    height: 21px;
    display: block;
    margin: auto;
    color: currentColor;
}

.qso-sound-fill {
    fill: currentColor;
}

.qso-sound-wave {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}

.qso-sound-slash {
    fill: none;
    stroke: currentColor;
    stroke-width: 2.25;
    stroke-linecap: round;
    opacity: 0;
}

.qso-sound-toggle.is-muted {
    border-color: var(--border);
    background: var(--panel-2);
    color: var(--muted);
}

.qso-sound-toggle.is-muted .qso-sound-slash {
    opacity: 1;
}

/* Panel: Active Users */
.active-users-table {
    font-size: 0.8rem;
    min-width: 860px;
}

.active-users-table th,
.active-users-table td {
    padding: 5px 6px;
}

.active-users-table th:nth-child(1) {
    width: 28px;
}
.active-users-table th:nth-child(2) {
    width: 96px;
}
.active-users-table th:nth-child(3) {
    width: 72px;
}
.active-users-table th:nth-child(4) {
    width: 64px;
}
.active-users-table th:nth-child(5) {
    width: 70px;
}
.active-users-table th:nth-child(6) {
    width: 58px;
}
.active-users-table th:nth-child(7),
.active-users-table th:nth-child(8) {
    width: 86px;
}
.active-users-table th:nth-child(9),
.active-users-table th:nth-child(10) {
    width: 102px;
}
.active-users-table th:nth-child(11),
.active-users-table th:nth-child(12),
.active-users-table th:nth-child(13) {
    width: 72px;
}

#activeUsersBody tr.is-transmitting td:not(.status-cell) {
    background: var(--danger-bg);
}

#activeUsersBody tr:nth-child(even):not(.is-transmitting) td {
    background: var(--stripe-even);
}

/* Active Users status indicator */
.status-cell {
    text-align: center;
    padding: 6px 4px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 20px;
    width: 20px;
    max-width: 20px;
}

.status-ball {
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: block;
}

.status-ball.status-green {
    background-color: #22c55e;
    box-shadow: 0 0 4px rgba(34, 197, 94, 0.6);
}

.status-ball.status-yellow {
    background-color: #eab308;
    box-shadow: 0 0 4px rgba(234, 179, 8, 0.6);
}

.status-ball.status-red {
    background-color: #ef4444;
    box-shadow: 0 0 4px rgba(239, 68, 68, 0.6);
}

.status-ball.status-unknown {
    background-color: var(--dot-off);
}

/* Band badges */
.band-badge {
    display: inline-block;
    min-width: 3.2em;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 800;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
}

.band-badge[data-band="160m"] {
    background: #7f1d1d;
    color: #ffffff;
}
.band-badge[data-band="80m"] {
    background: #dc2626;
    color: #ffffff;
}
.band-badge[data-band="40m"] {
    background: #ea580c;
    color: #ffffff;
}
.band-badge[data-band="30m"] {
    background: #facc15;
    color: #111827;
}
.band-badge[data-band="20m"] {
    background: #16a34a;
    color: #ffffff;
}
.band-badge[data-band="17m"] {
    background: #86efac;
    color: #111827;
}
.band-badge[data-band="15m"] {
    background: #2563eb;
    color: #ffffff;
}
.band-badge[data-band="12m"] {
    background: #7dd3fc;
    color: #111827;
}
.band-badge[data-band="10m"] {
    background: #9333ea;
    color: #ffffff;
}
.band-badge[data-band="6m"] {
    background: #7dd3fc;
    color: #111827;
}
.band-badge[data-band="2m"] {
    background: #581c87;
    color: #ffffff;
}
.band-badge[data-band="70cm"] {
    background: #dc2626;
    color: #ffffff;
}
.band-badge[data-band="30m"],
.band-badge[data-band="17m"],
.band-badge[data-band="12m"],
.band-badge[data-band="6m"] {
    border: 1px solid rgba(17, 24, 39, 0.28);
}

.power-badge {
    display: inline-block;
    min-width: 2.8em;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 400;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    filter: brightness(1.25);
    border-color: var(--text);
}
.power-badge[data-power="0"] {
    background: #0000ff;
    color: #ffffff;
}
.power-badge[data-power="1"] {
    background: #2f00df;
    color: #ffffff;
}
.power-badge[data-power="2"] {
    background: #4f00bf;
    color: #ffffff;
}
.power-badge[data-power="3"] {
    background: #6f009f;
    color: #ffffff;
}
.power-badge[data-power="4"] {
    background: #700070;
    color: #ffffff;
}
.power-badge[data-power="5"] {
    background: #7f007f;
    color: #ffffff;
}
.power-badge[data-power="6"] {
    background: #900070;
    color: #ffffff;
}
.power-badge[data-power="7"] {
    background: #af005f;
    color: #ffffff;
}
.power-badge[data-power="8"] {
    background: #bf004f;
    color: #ffffff;
}
.power-badge[data-power="9"] {
    background: #df002f;
    color: #ffffff;
}
.power-badge[data-power="10"] {
    background: #ff0000;
    color: #ffffff;
}

/* Tag Badge */
.tag-badge {
    display: inline-block;
    min-width: 3.2em;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 800;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
}

.tag-badge[data-tag="dupe"] {
    background: #f59e0b;
    color: #111827;
}

/* Clocks */
.clock-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 2px;
    padding: 1px 8px 1px 20px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-tertiary);
    min-width: 152px;
}

.clock-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    color: var(--text-secondary);
    white-space: nowrap;
}

.clock-value {
    display: inline-block;
    width: 8ch;
    text-align: left;
    font-size: 34px;
    font-weight: 400;
    line-height: 0.95;
    letter-spacing: 0.03em;
    font-family: "Seven Segment", "Monaco", "Menlo", "Ubuntu Mono", monospace;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    margin-right: 0;
}

.clock-value[data-digit-color="red"] {
    color: var(--red);
}

.clock-value[data-digit-color="green"] {
    color: var(--green);
}

#score-summary {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    overflow-y: auto;
}

.scoreDetail {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.scoreIndent {
    width: 25px;
}

.scoreLabel {
    text-align: right;
    flex: 0 0 100px;
    font-weight: bold;
}

.scoreDetail > span {
    flex: 1 1 auto;
    min-width: 0;
}

#scoreTotalScore {
    font-weight: bold;
    font-size: 24px;
    color: var(--green);
}

#scoreExplanation > ul > li {
    line-height: 25px;
}

#scoreExplanation > ul > li > b {
    color: var(--green);
}
