/* Manchester Labs - components: the parts of a bench instrument */

/* ---------------------------------------------------------------------------
   Group box: a silkscreened outline with its label breaking the top line,
   the way an instrument groups related controls ("TRIGGER", "MEASURE").
   Set --group-bg to the colour behind the group so the label can mask the line.
--------------------------------------------------------------------------- */
.group {
    --group-bg: var(--panel);
    position: relative;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: var(--s6) var(--s5) var(--s5);
}

.group-label {
    position: absolute;
    top: 0;
    left: var(--s4);
    transform: translateY(-50%);
    padding: 0 var(--s2);
    background: var(--group-bg);
    font-family: var(--font-label);
    font-weight: 600;
    font-size: var(--text-xs);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: var(--ink-dim);
    line-height: 1;
}

/* Raised plate: a card sitting proud of the panel */
.plate {
    background: var(--bezel);
    border-radius: var(--radius-lg);
    box-shadow: var(--relief-raised);
}

/* Recessed screen: where data is displayed */
.screen {
    background: var(--screen);
    border-radius: var(--radius);
    box-shadow: var(--relief-recessed);
}

/* ---------------------------------------------------------------------------
   Keys (buttons)
--------------------------------------------------------------------------- */
.key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s2);
    min-height: 36px;
    padding: 0 var(--s4);
    background: var(--bezel);
    color: var(--ink);
    border: 0;
    border-radius: var(--radius);
    box-shadow: var(--relief-raised);
    font-family: var(--font-label);
    font-weight: 600;
    font-size: var(--text-sm);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
    transition: background-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.key:hover {
    background: var(--bezel-hover);
}

.key:active,
.key.is-pressed,
.key[aria-pressed="true"],
.key[aria-selected="true"],
.key[aria-current="page"] {
    transform: translateY(1px);
    box-shadow: var(--relief-pressed);
}

.key:disabled,
.key[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: var(--relief-raised);
}

.key svg {
    width: 16px;
    height: 16px;
    flex: none;
}

.key--primary {
    background: var(--amber);
    color: var(--on-amber);
}

.key--primary:hover {
    background: var(--amber);
    filter: brightness(1.07);
}

.key--danger {
    color: var(--fault-ink);
}

.key--danger:hover {
    color: var(--fault-ink-hi);
}

.key--ok {
    color: var(--ok-ink);
}

.key--ghost {
    background: transparent;
    box-shadow: none;
}

.key--ghost:hover {
    background: var(--bezel);
}

.key--sm {
    min-height: 28px;
    padding: 0 var(--s3);
    font-size: var(--text-xs);
}

.key--icon {
    width: 36px;
    padding: 0;
}

.key--icon.key--sm {
    width: 28px;
}

.key--block {
    width: 100%;
}

/* A latched key shows its state with an LED, not just colour */
.key .led {
    margin-right: -2px;
}

/* ---------------------------------------------------------------------------
   LEDs - always paired with a text label
--------------------------------------------------------------------------- */
.led {
    display: inline-block;
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--line);
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.35);
}

.led--on {
    background: var(--amber);
    box-shadow: 0 0 6px rgba(242, 169, 59, 0.55);
}

.led--ok {
    background: var(--ok);
    box-shadow: 0 0 6px rgba(91, 212, 106, 0.45);
}

.led--warn {
    background: var(--warn);
    box-shadow: 0 0 6px rgba(242, 201, 76, 0.45);
}

.led--fault {
    background: var(--fault);
    box-shadow: 0 0 6px rgba(240, 100, 90, 0.5);
}

[data-theme="light"] .led--on,
[data-theme="light"] .led--ok,
[data-theme="light"] .led--warn,
[data-theme="light"] .led--fault {
    box-shadow: inset 0 -1px 1px rgba(0, 0, 0, 0.2);
}

.led--blink {
    animation: led-blink 1.4s steps(1, end) infinite;
}

@keyframes led-blink {
    50% { opacity: 0.25; }
}

/* ---------------------------------------------------------------------------
   Fields
--------------------------------------------------------------------------- */
.field,
.select,
.textarea {
    display: block;
    width: 100%;
    min-height: 38px;
    padding: var(--s2) var(--s3);
    background: var(--screen);
    color: var(--ink);
    border: 0;
    border-radius: var(--radius);
    box-shadow: var(--relief-recessed);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    line-height: 1.4;
    transition: box-shadow var(--dur-fast) var(--ease);
}

.field::placeholder,
.textarea::placeholder {
    color: var(--ink-faint);
}

.field:focus-visible,
.select:focus-visible,
.textarea:focus-visible,
.field:focus,
.select:focus,
.textarea:focus {
    outline: none;
    box-shadow: var(--relief-recessed), 0 0 0 2px var(--amber);
    border-radius: var(--radius);
}

.field--mono {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
}

.select {
    appearance: none;
    padding-right: var(--s6);
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%2396928A' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.textarea {
    min-height: 96px;
    resize: vertical;
}

.field-label {
    display: block;
    margin-bottom: var(--s1);
}

.field[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
    box-shadow: var(--relief-recessed), 0 0 0 2px var(--fault);
}

.field-error {
    margin-top: var(--s1);
    color: var(--fault-ink);
    font-size: var(--text-xs);
}

input[type="checkbox"],
input[type="radio"],
input[type="range"] {
    accent-color: var(--amber);
}

/* ---------------------------------------------------------------------------
   Tables - live inside a .screen
--------------------------------------------------------------------------- */
.table-wrap {
    overflow: auto;
    border-radius: var(--radius);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.table th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: var(--s2) var(--s3);
    background: var(--screen);
    border-bottom: 1px solid var(--line);
    text-align: left;
    font-family: var(--font-label);
    font-weight: 600;
    font-size: var(--text-xs);
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--ink-dim);
    white-space: nowrap;
}

.table td {
    padding: var(--s2) var(--s3);
    border-top: 1px solid var(--graticule);
    vertical-align: middle;
}

.table tbody tr:first-child td {
    border-top: 0;
}

.table tbody tr:hover {
    background: var(--screen-hover);
}

.table .num,
.table td.mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--text-xs);
}

.table .num {
    text-align: right;
}

/* ---------------------------------------------------------------------------
   Tags and status badges (text + optional LED, never colour alone)
--------------------------------------------------------------------------- */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px var(--s2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-family: var(--font-label);
    font-weight: 600;
    font-size: var(--text-2xs);
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--ink-dim);
    white-space: nowrap;
    line-height: 1.5;
}

.tag--ok { color: var(--ok-ink); border-color: currentColor; }
.tag--warn { color: var(--warn-ink); border-color: currentColor; }
.tag--fault { color: var(--fault-ink); border-color: currentColor; }
.tag--on { color: var(--amber-ink); border-color: currentColor; }

/* ---------------------------------------------------------------------------
   Readout: an instrument display value
--------------------------------------------------------------------------- */
.readout {
    display: flex;
    flex-direction: column;
    gap: var(--s1);
    min-width: 0;
}

.readout-value {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: var(--text-xl);
    line-height: 1.1;
    color: var(--ink);
    white-space: nowrap;
}

.readout-unit {
    margin-left: 0.25em;
    font-size: 0.55em;
    color: var(--ink-dim);
}

.readout-note {
    font-size: var(--text-xs);
    color: var(--ink-faint);
}

/* Meter: a bar gauge; the fill carries severity */
.meter {
    height: 6px;
    background: var(--screen);
    border-radius: 3px;
    box-shadow: var(--relief-recessed);
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    width: 0;
    background: var(--amber);
    border-radius: 3px;
    transition: width var(--dur) var(--ease);
}

.meter-fill.is-warn { background: var(--warn); }
.meter-fill.is-fault { background: var(--fault); }

/* ---------------------------------------------------------------------------
   Softkey row: tabs and segmented choices
--------------------------------------------------------------------------- */
.softkeys {
    display: inline-flex;
    flex-wrap: wrap;
    gap: var(--s2);
}

.softkeys .key[aria-selected="true"],
.softkeys .key[aria-pressed="true"],
.softkeys .key.is-active {
    color: var(--amber-ink);
    transform: translateY(1px);
    box-shadow: var(--relief-pressed);
}

/* ---------------------------------------------------------------------------
   Modal
--------------------------------------------------------------------------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--s4);
    background: rgba(10, 11, 13, 0.6);
    backdrop-filter: blur(2px);
}

.modal {
    width: min(560px, 100%);
    max-height: calc(100vh - 2 * var(--s5));
    display: flex;
    flex-direction: column;
    background: var(--bezel);
    border-radius: var(--radius-lg);
    box-shadow: var(--relief-raised), 0 24px 60px rgba(0, 0, 0, 0.45);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s3);
    padding: var(--s3) var(--s4);
    border-bottom: 1px solid var(--line);
}

.modal-title {
    font-family: var(--font-label);
    font-weight: 600;
    font-size: var(--text-md);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.modal-body {
    padding: var(--s4);
    overflow: auto;
}

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: var(--s2);
    padding: var(--s3) var(--s4);
    border-top: 1px solid var(--line);
}

/* ---------------------------------------------------------------------------
   Toasts - also styles the portal's existing .notification markup
--------------------------------------------------------------------------- */
.toast,
.notification {
    position: fixed;
    right: var(--s4);
    bottom: var(--s4);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: var(--s3);
    max-width: min(420px, calc(100vw - 2 * var(--s4)));
    padding: var(--s3) var(--s4);
    background: var(--bezel);
    color: var(--ink);
    border-radius: var(--radius);
    box-shadow: var(--relief-raised), 0 12px 30px rgba(0, 0, 0, 0.35);
    font-size: var(--text-sm);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.toast::before,
.notification::before {
    content: '';
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--amber);
}

.toast .toast-text {
    flex: 1;
}

.toast .toast-action {
    flex: none;
}

.toast.show,
.notification.show {
    opacity: 1;
    transform: none;
}

.toast--ok::before,
.notification-success::before { background: var(--ok); }
.toast--fault::before,
.notification-error::before { background: var(--fault); }
.toast--warn::before,
.notification-warning::before { background: var(--warn); }

/* ---------------------------------------------------------------------------
   Empty state, loading, tooltip
--------------------------------------------------------------------------- */
.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s3);
    padding: var(--s6) var(--s4);
    text-align: center;
    color: var(--ink-dim);
    font-size: var(--text-sm);
}

.spinner {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--line);
    border-top-color: var(--amber);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--s3);
    padding: var(--s5);
    color: var(--ink-dim);
    font-size: var(--text-sm);
}

.tooltip {
    position: fixed;
    z-index: 1100;
    pointer-events: none;
    padding: var(--s2) var(--s3);
    background: var(--bezel);
    color: var(--ink);
    border-radius: var(--radius-sm);
    box-shadow: var(--relief-raised), 0 8px 20px rgba(0, 0, 0, 0.35);
    font-size: var(--text-xs);
    white-space: nowrap;
}

/* Hairline divider in silkscreen */
.rule {
    height: 1px;
    border: 0;
    margin: var(--s4) 0;
    background: var(--line);
}
