* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--page-bg);
    color: var(--text);
    font-family: var(--font-ui);
}

button,
input {
    font: inherit;
}

.watcher-page {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: var(--space-md);
    padding: var(--space-lg);
}

.presence-section {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    max-width: min(100%, 420px);
}

.presence-title {
    font-weight: 700;
    color: var(--text);
    margin-right: auto;
}

.presence-cards {
    display: flex;
    gap: 8px;
    align-items: center;
}

.presence-card {
    position: relative;
    min-width: 60px;
    width: 60px;
    height: 60px;
    padding: 10px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: width 200ms ease, box-shadow 200ms ease, transform 200ms ease;
    overflow: hidden;
}

.presence-card:hover,
.presence-card:focus-visible,
.presence-card.expanded {
    width: 210px;
    box-shadow: var(--shadow-strong);
    transform: translateY(-2px);
}

.presence-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 6px;
}

.presence-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--line-strong);
}

.presence-name {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.presence-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid var(--line-strong);
}

.presence-dot.online {
    background: #4caf50;
}

.presence-dot.offline {
    background: #f44336;
}

.presence-details {
    display: grid;
    gap: 4px;
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0;
    transform: translateX(-10px);
    transition: opacity 200ms ease, transform 200ms ease;
}

.presence-card:hover .presence-details,
.presence-card.expanded .presence-details,
.presence-card:focus-visible .presence-details {
    opacity: 1;
    transform: none;
}

/* Constrain width so view fits on smaller devices and centers content */
.watcher-page {
    max-width: 1200px;
    margin: 0 auto;
}

.watcher-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-md);
    border-bottom: 1px solid var(--line);
    padding-bottom: var(--space-md);
}

.watcher-title {
    display: grid;
    gap: var(--space-xs);
    min-width: 0;
}

.watcher-title h1 {
    margin: 0;
    font-size: 28px;
    font-weight: 650;
}

.watcher-title p {
    margin: 0;
    color: var(--text-muted);
    font-family: var(--font-log);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.watcher-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
    justify-content: flex-end;
}

.search-input {
    width: min(42vw, 360px);
    min-width: 220px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
    color: var(--text);
    padding: 0 12px;
    outline: none;
}

.search-input:focus {
    border-color: var(--accent);
}

.refresh-button {
    height: 38px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-raised);
    color: var(--text);
    padding: 0 14px;
    cursor: pointer;
}

.refresh-button:hover {
    border-color: var(--accent);
}

.watcher-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    gap: var(--space-sm);
}

.metric {
    min-height: 72px;
    display: grid;
    align-content: center;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
    padding: var(--space-md);
}

.metric span {
    color: var(--text-soft);
    font-size: 12px;
}

.metric strong {
    color: var(--text);
    font-size: 18px;
    font-weight: 650;
    overflow-wrap: anywhere;
}

.metric[data-tone="ok"] strong {
    color: var(--ok);
}

.metric[data-tone="warn"] strong {
    color: var(--warning);
}

.log-panel {
    min-height: 0;
    display: grid;
    grid-template-rows: auto 1fr auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface-soft);
    box-shadow: var(--shadow);
    overflow: hidden;
    max-height: calc(100vh - 220px);
}

.log-output {
    min-height: 220px;
    max-height: 100%;
    margin: 0;
    padding: var(--space-md);
    overflow: auto;
    color: var(--text);
    font-family: var(--font-log);
    font-size: 13px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.log-controls {
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--line);
    background: var(--surface-soft);
}

.log-tabs {
    /* ensure the tablist aligns with page theme */
}

.log-controls [role="tablist"] {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap; /* allow tabs to wrap to next line on narrow screens */
}

.log-controls [role="tab"] {
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
}

.log-controls [role="tab"][aria-selected="true"] {
    background: linear-gradient(180deg, rgba(0,0,0,0.02), transparent);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 700;
}

.log-entries {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.log-entry {
    padding: 10px 14px;
    border-bottom: 1px solid var(--line-weak);
    background: transparent;
    font-family: var(--font-log);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.log-empty {
    padding: var(--space-md);
    color: var(--text-soft);
}

.dev-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid var(--line);
    background: var(--surface-soft);
}

.dev-input {
    flex: 1 1 auto;
    height: 36px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text-muted);
}

.dev-tooltip {
    display: inline-block;
    color: #fff;
    background: #c22;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 12px;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 120ms ease, transform 120ms ease;
}

.dev-input-wrap:hover .dev-tooltip {
    opacity: 1;
    transform: none;
}

.dev-send {
    height: 36px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: var(--surface-raised);
    color: var(--text);
    cursor: not-allowed;
}

.dev-send:not([disabled]) {
    cursor: pointer;
}

/* Responsive adjustments */
@media (max-width: 840px) {
    .log-output {
        min-height: 200px;
        max-height: calc(100vh - 240px);
    }

    .watcher-header {
        align-items: stretch;
        flex-direction: column;
    }

    .log-controls [role="tablist"] {
        gap: 6px;
    }

    .dev-input-wrap {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .dev-input,
    .dev-send {
        width: 100%;
        box-sizing: border-box;
    }
}

@media (max-width: 520px) {
    .log-output {
        min-height: 160px;
        max-height: none;
    }

    .watcher-metrics {
        grid-template-columns: 1fr;
    }

    .watcher-page {
        padding: var(--space-md);
    }
}

.log-output:empty::before {
    color: var(--text-soft);
    content: "No watcher logs yet.";
}

@media (max-width: 840px) {
    .watcher-page {
        padding: var(--space-md);
    }

    .watcher-header {
        align-items: stretch;
        flex-direction: column;
    }

    .watcher-actions {
        justify-content: stretch;
    }

    .search-input,
    .refresh-button {
        width: 100%;
    }

    .watcher-metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 520px) {
    .watcher-metrics {
        grid-template-columns: 1fr;
    }

    .watcher-title h1 {
        font-size: 24px;
    }

    .log-output {
        min-height: 360px;
        max-height: none;
    }
}
