/* ------------------------------------------------------------------ */
/* Base                                                                  */
/* ------------------------------------------------------------------ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --accent:      #00ff9f;
    --accent-dim:  #00b870;
    --bg:          #0d0d0d;
    --bg-card:     #1a1a1a;
    --bg-card-border: #2a2a2a;
    --text:        #e0e0e0;
    --text-muted:  #666;
    --font:        'JetBrains Mono', 'Courier New', Courier, monospace;
}

html, body {
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 2rem 1rem 5rem;
}

/* ------------------------------------------------------------------ */
/* Layout                                                               */
/* ------------------------------------------------------------------ */
.container {
    width: 100%;
    max-width: 640px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

/* ------------------------------------------------------------------ */
/* Header                                                               */
/* ------------------------------------------------------------------ */
header {
    text-align: center;
}

.site-title {
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.25em;
    color: var(--accent);
    text-transform: uppercase;
}

.subtitle {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 0.15em;
    margin-top: 0.3rem;
}

/* ------------------------------------------------------------------ */
/* Clock                                                                */
/* ------------------------------------------------------------------ */
.clock {
    font-size: clamp(3.5rem, 12vw, 6rem);
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.05em;
    /* subtle glow on the accent text */
    text-shadow: 0 0 20px rgba(0, 255, 159, 0.35);
    line-height: 1;
}

.date {
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 0.15em;
    margin-top: -0.5rem;
}

/* ------------------------------------------------------------------ */
/* Sensor cards                                                         */
/* ------------------------------------------------------------------ */
.cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    width: 100%;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    border-radius: 8px;
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
    text-align: center;
}

.card-label {
    font-size: 0.6rem;
    letter-spacing: 0.2em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.card-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
    text-shadow: 0 0 12px rgba(0, 255, 159, 0.25);
}

/* ------------------------------------------------------------------ */
/* ESP32 System section                                                  */
/* ------------------------------------------------------------------ */
.sys-section {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    border-radius: 8px;
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.sys-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.sys-item {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    align-items: center;
    text-align: center;
}

.sys-label {
    font-size: 0.55rem;
    letter-spacing: 0.18em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.sys-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent);
}

/* Smaller variant for longer strings like "Exception/panic" */
.sys-value--sm {
    font-size: 0.7rem;
}

.sys-sublabel {
    font-size: 0.6rem;
    color: var(--text-muted);
    letter-spacing: 0.1em;
}

/* Heap bar row */
.heap-row {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.heap-labels {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.heap-bar-track {
    width: 100%;
    height: 6px;
    background: #2a2a2a;
    border-radius: 3px;
    overflow: hidden;
}

.heap-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    box-shadow: 0 0 6px rgba(0, 255, 159, 0.4);
    transition: width 0.6s ease;
    /* width is set by JS as a percentage of heap used */
}

/* Stack sys-grid on narrow screens */
@media (max-width: 420px) {
    .sys-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ------------------------------------------------------------------ */
/* Status indicator (bottom right)                                      */
/* ------------------------------------------------------------------ */
.status-bar {
    position: fixed;
    bottom: 1rem;
    right: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
    transition: background 0.4s;
}

/* Connected state — toggled by JS */
.status-bar.connected .status-dot {
    background: var(--accent);
    box-shadow: 0 0 6px var(--accent);
}

.status-bar.connected #status-text {
    color: var(--accent-dim);
}

/* ------------------------------------------------------------------ */
/* Sleep buttons                                                        */
/* ------------------------------------------------------------------ */
.sleep-buttons {
    display: flex;
    gap: 1rem;
    width: 100%;
}

.btn {
    flex: 1;
    padding: 0.85rem 1rem;
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    border: 1px solid var(--bg-card-border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, box-shadow 0.2s;
}

.btn-bed:hover {
    border-color: #6a8fff;
    color: #6a8fff;
    box-shadow: 0 0 8px rgba(106, 143, 255, 0.25);
}

.btn-wake:hover {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 8px rgba(0, 255, 159, 0.25);
}

.btn:active {
    opacity: 0.7;
}

/* ------------------------------------------------------------------ */
/* Rating widget                                                        */
/* ------------------------------------------------------------------ */
.rating-widget {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    border-radius: 8px;
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.rating-widget.hidden {
    display: none;
}

.stars {
    display: flex;
    gap: 0.5rem;
}

.star {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s, text-shadow 0.15s;
    line-height: 1;
}

.star.active,
.star:hover {
    color: var(--accent);
    text-shadow: 0 0 8px rgba(0, 255, 159, 0.4);
}

.rating-msg {
    font-size: 0.65rem;
    letter-spacing: 0.15em;
    color: var(--accent-dim);
}

.rating-msg.hidden {
    display: none;
}

/* ------------------------------------------------------------------ */
/* Section label                                                        */
/* ------------------------------------------------------------------ */
.section-label {
    font-size: 0.6rem;
    letter-spacing: 0.25em;
    color: var(--text-muted);
    text-transform: uppercase;
    align-self: flex-start;
    width: 100%;
}

/* ------------------------------------------------------------------ */
/* History tables                                                       */
/* ------------------------------------------------------------------ */
.history-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    border-radius: 8px;
}

.readings-wrap {
    max-height: 220px;
    overflow-y: auto;
}

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

thead th {
    padding: 0.65rem 0.75rem;
    text-align: left;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    font-weight: 400;
    text-transform: uppercase;
    border-bottom: 1px solid var(--bg-card-border);
    white-space: nowrap;
}

tbody td {
    padding: 0.55rem 0.75rem;
    color: var(--text);
    border-bottom: 1px solid #1f1f1f;
    white-space: nowrap;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover td {
    background: #1f1f1f;
}

.empty-row {
    color: var(--text-muted);
    text-align: center;
    padding: 1rem !important;
}

.rating-stars {
    color: var(--accent);
    letter-spacing: 0.05em;
}

/* ------------------------------------------------------------------ */
/* Responsive — stack cards on narrow screens                           */
/* ------------------------------------------------------------------ */
@media (max-width: 420px) {
    .cards {
        grid-template-columns: 1fr;
    }

    .card-value {
        font-size: 2rem;
    }
}
