/* Efeta – shared styles (PLAN.md, chapter 8.1). Mobile first. */

:root {
    --bg: #edf1f5;
    --text: #263238;
    --card-bg: #ffffff;
    --label: #546e7a;
    --border: #cfd8dc;
    --box: #f4f6f8;
    --green: #269447;
    --red: #c62828;
    --blue: #1976d2;
    --orange-bg: #fff3e0;
    --orange-text: #a84300;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

[hidden] {
    display: none !important;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 12px;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

/* ---------- page layout ---------- */

.page-header,
.page-content,
.connection-lost {
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}

.page-header.medium,
.page-content.medium {
    max-width: 640px;
}

.page-header.wide,
.page-content.wide {
    max-width: 1400px;
}

.page-header {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    margin-bottom: 12px;
}

.page-header h1 {
    flex: 1;
    min-width: 0;
    margin: 0;
    font-size: 1.4rem;
}

.back-link {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 48px;
    height: 48px;
    margin-left: -10px;
    border-radius: 12px;
    color: inherit;
}

.login {
    margin-top: 8vh;
}

.login h1 {
    margin: 0 0 8px;
    font-size: 1.6rem;
    text-align: center;
}

.logo {
    display: block;
    margin: 0 auto 8px;
}

/* ---------- card ---------- */

.card {
    display: block;
    width: 100%;
    margin-bottom: 12px;
    padding: 18px 16px;
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.card h2 {
    margin: 0 0 12px;
    font-size: 1.2rem;
}

a.card {
    color: inherit;
    text-decoration: none;
    transition: box-shadow 0.15s ease, transform 0.1s ease;
}

a.card:hover,
a.card:focus-visible {
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
    outline: none;
}

a.card:active {
    transform: scale(0.98);
}

.card-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
}

.card-grid .card {
    margin-bottom: 0;
}

.row-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 2px 10px;
}

.row-head h2 {
    margin: 0;
    font-size: 1.15rem;
}

/* ---------- values and states ---------- */

.main-value {
    margin: 12px 0 4px;
    font-size: 3.2rem;
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -1px;
}

.status-line {
    margin: 8px 0 16px;
    font-size: 1.1rem;
    font-weight: 600;
}

.card-grid .main-value {
    font-size: 2.8rem;
}

.card-grid .status-line {
    margin-bottom: 0;
    font-size: 1rem;
    font-weight: normal;
}

.is-on {
    color: var(--green);
}

.is-off {
    color: var(--red);
}

/* last known values of a device that is offline */
.stale .main-value,
.stale .status-line {
    opacity: 0.45;
}

.connection {
    font-size: 0.85rem;
    color: var(--label);
    white-space: nowrap;
}

.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 6px;
    border-radius: 50%;
}

.dot.online {
    background: var(--green);
}

.dot.offline {
    background: var(--red);
}

.info-box {
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--box);
    border-radius: 10px;
    font-size: 0.9rem;
}

.info-box div {
    margin-bottom: 3px;
}

/* ---------- strips and messages ---------- */

.alert-strip,
.banner,
.connection-lost {
    margin-top: 0;
    margin-bottom: 12px;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
}

.alert-strip {
    list-style: none;
    background: #fdecea;
    color: var(--red);
}

.alert-strip li + li {
    margin-top: 4px;
}

.banner,
.connection-lost {
    background: var(--orange-bg);
    color: var(--orange-text);
}

.connection-lost {
    text-align: center;
}

.message {
    margin: 12px 0 0;
    font-size: 0.95rem;
    color: var(--label);
}

.message.error {
    color: var(--red);
    font-weight: 600;
}

.message.ok {
    color: var(--green);
    font-weight: 600;
}

.note,
.field-error {
    margin: 6px 0 0;
    font-size: 0.85rem;
    color: var(--label);
}

.note a {
    color: var(--blue);
    font-weight: 600;
}

.field-error {
    color: var(--red);
}

.badge {
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--green);
    white-space: nowrap;
}

/* ---------- forms ---------- */

label,
.field-label {
    display: block;
    margin-top: 12px;
    font-size: 0.88rem;
    font-weight: bold;
    color: var(--label);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input,
select {
    width: 100%;
    height: 48px;
    margin-top: 6px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fafafa;
    color: inherit;
    font: inherit;
    font-size: 1.1rem;
}

input {
    -webkit-appearance: none;
    appearance: none;
}

input:focus,
select:focus {
    border-color: var(--blue);
    outline: none;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.18);
}

input[aria-invalid="true"] {
    border-color: var(--red);
}

input[type="checkbox"] {
    -webkit-appearance: auto;
    appearance: auto;
    flex: none;
    width: 24px;
    height: 24px;
    margin: 0;
    padding: 0;
    accent-color: var(--blue);
}

/* a checkbox with its sentence and an optional number inside it, e.g. "offline longer than [5] min" */
.check-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    min-height: 48px;
    padding: 4px 0;
}

.check-row label {
    flex: 1 1 0;
    min-width: 130px;
    margin: 0;
    font-size: 1rem;
    font-weight: normal;
    color: inherit;
    text-transform: none;
    letter-spacing: 0;
}

.check-row input[type="number"] {
    flex: none;
    width: 84px;
    margin-top: 0;
    padding: 10px;
}

/* ---------- buttons ---------- */

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 50px;
    margin-top: 10px;
    padding: 0 14px;
    border: 0;
    border-radius: 12px;
    background: #455a64;
    color: #fff;
    font: inherit;
    font-size: 1rem;
    font-weight: bold;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn:active {
    transform: scale(0.98);
    opacity: 0.85;
}

.btn:focus-visible {
    outline: 3px solid rgba(25, 118, 210, 0.55);
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.btn-save   { background: #1976d2; margin-top: 16px; }
.btn-auto   { background: #455a64; }
.btn-manual { background: #7b1fa2; }
.btn-on     { background: #2e7d32; }
.btn-off    { background: #c62828; }

.btn-secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
}

/* the currently selected mode */
.btn-auto[aria-pressed="true"],
.btn-manual[aria-pressed="true"] {
    outline: 3px solid var(--text);
    outline-offset: 2px;
}

/* one of several choices in a row, e.g. the time range of a chart */
.btn-choice[aria-pressed="true"] {
    background: var(--text);
    border-color: var(--text);
    color: #fff;
}

.btn-triple {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.btn-small {
    width: auto;
    min-height: 48px;
    margin-top: 0;
    font-size: 0.95rem;
    white-space: nowrap;
}

.btn-icon {
    flex: none;
    width: 48px;
    padding: 0;
}

.btn-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
}

.btn-pair .btn {
    margin-top: 0;
}

/* ---------- lists on the admin page ---------- */

.list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.list-row {
    padding: 12px 0;
    border-top: 1px solid #e3e8ec;
}

.list-row:first-child {
    padding-top: 0;
    border-top: 0;
}

.row-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.actions .btn {
    flex: 1 1 auto;
    padding: 0 8px;
    font-size: 0.88rem;
}

pre,
.code-block {
    display: block;
    margin: 6px 0 0;
    padding: 12px;
    border-radius: 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

pre {
    max-height: 320px;
    overflow: auto;
    background: #263238;
    color: #eceff1;
    font-size: 0.8rem;
    line-height: 1.4;
    white-space: pre;
    overflow-wrap: normal;
}

.code-block {
    background: var(--box);
    font-size: 1rem;
    -webkit-user-select: all;
    user-select: all;
}

/* ---------- chart (js/chart.js) ---------- */

.chart {
    margin-top: 12px;
    transition: opacity 0.15s ease;
}

/* new data is being fetched; the previous drawing stays in place */
.chart.is-loading {
    opacity: 0.5;
}

.chart svg {
    display: block;
    width: 100%;
    touch-action: pan-y; /* a finger may inspect sideways, while vertical moves still scroll the page */
    -webkit-user-select: none;
    user-select: none;
}

.chart svg:focus {
    outline: none;
}

.chart svg:focus-visible {
    outline: 2px solid rgba(25, 118, 210, 0.55);
    border-radius: 6px;
}

.chart-grid {
    stroke: #e3e8ec;
    stroke-width: 1;
}

.chart-axis-text {
    fill: var(--label);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.chart-activity {
    fill: var(--green);
    opacity: 0.22;
}

.chart-activity.partial {
    opacity: 0.1;
}

.chart-band {
    fill: var(--blue);
    opacity: 0.14;
}

.chart-line {
    fill: none;
    stroke: var(--blue);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.chart-lone-point {
    fill: var(--blue);
}

.chart-reference {
    stroke: var(--text);
    stroke-width: 1;
    stroke-dasharray: 5 4;
}

.chart-reference-text {
    fill: var(--text);
    font-size: 11px;
    font-weight: 600;
    paint-order: stroke;
    stroke: #fff;
    stroke-width: 3px;
    stroke-linejoin: round;
}

.chart-marker line {
    stroke: var(--text);
    stroke-width: 1;
}

.chart-marker circle {
    fill: var(--blue);
    stroke: #fff;
    stroke-width: 2;
}

.chart-readout-row {
    position: relative;
    height: 26px;
}

.chart-readout {
    position: absolute;
    top: 0;
    display: flex;
    gap: 6px;
    padding: 3px 7px;
    transform: translateX(-50%);
    background: var(--text);
    border-radius: 6px;
    color: #fff;
    font-size: 0.78rem;
    white-space: nowrap;
    pointer-events: none;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--label);
}

.chart-legend span {
    white-space: nowrap;
}

.chart-key {
    display: inline-block;
    width: 16px;
    margin-right: 6px;
    vertical-align: middle;
}

.chart-key.line {
    border-top: 2px solid var(--blue);
}

.chart-key.activity {
    height: 12px;
    border-radius: 2px;
    background: var(--green);
    opacity: 0.35;
}

.chart-key.reference {
    border-top: 1px dashed var(--text);
}

/* ---------- dialog and toasts ---------- */

.dialog {
    width: min(420px, calc(100% - 24px));
    padding: 18px 16px;
    border: 0;
    border-radius: 16px;
    color: inherit;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.dialog::backdrop {
    background: rgba(38, 50, 56, 0.5);
}

.dialog p {
    margin: 0 0 6px;
    font-weight: 600;
}

.dialog .btn-pair {
    margin-top: 16px;
}

.toasts {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 16px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.toast {
    max-width: 420px;
    padding: 12px 16px;
    border-radius: 12px;
    background: #263238;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.toast.error {
    background: var(--red);
}

.toast.ok {
    background: #2e7d32;
}

/* ---------- tablet and desktop ---------- */

@media (min-width: 600px) {
    .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 960px) {
    .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 1280px) {
    .card-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
