/* =========================================================
    COMMON
    Shared styles and CSS variables used across all pages
    ========================================================= */

:root {
    --bg: #0f1117;
    --panel: #25292f;
    --panel2: #1f2328;
    --text: #e8ecef;
    --muted: #7f8a92;
    --border: #363c42;
    --border2: #3c4248;
    --border3: #353b41;
    --green: #3fa878;
    --green-light: #58b989;
    --green-bg: #25332d;
    --good: #2ecc71;
    --warn: #f1c40f;
    --bad: #e74c3c;
    --grid: rgba(255,255,255,0.08);

    /* Event severities */
    --sev-info: #5dade2;
    --sev-warning: #f1c40f;
    --sev-fault: #e67e22;
    --sev-critical: #e74c3c;
}

*{box-sizing:border-box}

/* Form controls don't inherit the page font by default */
button,
input,
select,
textarea {
    font-family: inherit;
}

/* Visible keyboard focus everywhere, without changing mouse clicks */
:focus-visible {
    outline: 2px solid var(--green);
    outline-offset: 2px;
}

/* Thin dark scrollbars for scrolling panels and tables */
* {
    scrollbar-width: thin;
    scrollbar-color: #454b52 transparent;
}

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

body {
    min-height: 100vh;
    font-family: Inter, Segoe UI, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

h1 {
    margin: 0 0 4px;
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}

h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.wrap {
    max-width: 1500px;
    margin: auto;
}

/* =========================================================
    SECTION HEADERS
    ========================================================= */

.section-header {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 5px 0 9px;
}

.section-eyebrow {
    flex-shrink: 0;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1.8px;
    color: var(--green);
}

.section-line {
    flex: 1;
    height: 1px;
    background: #30363c;
}

/* =========================================================
    CARDS & PANELS
    ========================================================= */

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 7px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 18px;
}

.panel h2 {
    font-size: 17px;
    margin: 0 0 4px;
}

.panel-sub {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 12px;
}

/* =========================================================
    BADGES
    ========================================================= */

.badge {
    padding: 9px 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: #aeb7bd;
    font-size: 11px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

/* =========================================================
   LABEL / VALUE / SMALL
   ========================================================= */

.label {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--muted);
}

.value {
    font-size: clamp(20px, 2.5vw, 25px);
    font-weight: 700;
    line-height: 1.2;
    color: var(--text);
}

.small {
    font-size: 13px;
    color: var(--muted);
    margin-top: 5px;
}

/* =========================================================
    FILTER GROUP (inputs, selects)
    ========================================================= */

.filter-group {
    min-width: 0;
}

.filter-group > label {
    display: block;
    margin-bottom: 5px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #818c94;
}

.filter-group input,
.filter-group select {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #23272d;
    color: #dce2e6;
    font-family: inherit;
    font-size: 11px;
    outline: none;
}

.filter-group input:focus,
.filter-group select:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 2px rgba(63,168,120,0.12);
}

/* =========================================================
    TOGGLE SWITCH
    ========================================================= */

.toggle {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #454b52;
    border-radius: 22px;
    transition: background 0.2s ease;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: #aeb7bd;
    border-radius: 50%;
    transition: transform 0.2s ease, background 0.2s ease;
}

.toggle input:checked + .toggle-slider {
    background: var(--green);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(18px);
    background: #fff;
}

.toggle-sm {
    width: 32px;
    height: 18px;
}

.toggle-sm .toggle-slider {
    height: 18px;
    border-radius: 18px;
}

.toggle-sm .toggle-slider::before {
    height: 12px;
    width: 12px;
    left: 3px;
    bottom: 3px;
}

.toggle-sm input:checked + .toggle-slider::before {
    transform: translateX(14px);
}

/* =========================================================
    STATUS DOTS
    ========================================================= */

.status-dot {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
    border-radius: 50%;
}

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

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

.status-dot.warning {
    background: var(--warn);
}

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

.status-dot-small.online {
    background: var(--good);
}

.status-dot-small.offline {
    background: var(--bad);
}

/* =========================================================
    STAT
    ========================================================= */

.stat {
    min-width: 0;
    padding: 15px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 7px;
}

.stat-label {
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.8px;
    text-transform: uppercase;
}

.stat-value {
    color: var(--text);
    font-size: clamp(20px, 2.5vw, 25px);
    font-weight: 700;
    line-height: 1.2;
}

.success, .success-good { color: var(--good); }
.muted-value { color: var(--muted); }
.success-warning { color: var(--warn); }
.success-bad { color: var(--bad); }
.stale { color: var(--warn); }

/* =========================================================
    TABLE
    ========================================================= */

.table-container {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border2);
    border-radius: 7px;
}

#robot-history-table,
#cleaning-history-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    min-width: 500px;
}

.table-container table thead {
    background: var(--panel2);
}

.table-container table th {
    height: 38px;
    padding: 0 15px;
    text-align: left;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: #818c94;
    border-bottom: 1px solid var(--border2);
    white-space: nowrap;
}

.table-container table td {
    height: 40px;
    padding: 0 15px;
    font-size: 12px;
    color: #c2c9ce;
    border-bottom: 1px solid var(--border3);
    white-space: nowrap;
}

.table-container table tbody tr {
    background: var(--panel) !important;
    transition: background 0.12s ease;
}

.table-container table tbody tr:hover {
    background: #2c3238 !important;
}

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

.table-container table td:last-child {
    font-weight: 600;
}

/* =========================================================
    STATUS PILL (result codes in tables)
    ========================================================= */

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 3px 9px 3px 8px;
    border: 1px solid var(--border2);
    border-radius: 999px;
    background: var(--panel2);
    color: #d5dbdf;
    font-size: 11px;
    font-weight: 600;
}

.status-pill::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--pill-colour, var(--muted));
}

.empty-row td {
    height: 64px !important;
    text-align: center;
    color: var(--muted) !important;
    font-weight: 500 !important;
}

/* =========================================================
    BUTTONS
    ========================================================= */

.page-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 32px;
    padding: 0 10px;
    border: 1px solid #454b52;
    border-radius: 6px;
    background: #292e34;
    color: #aeb7bd;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.page-btn:hover:not(:disabled) {
    background: #31383e;
    border-color: var(--green);
    color: #ffffff;
}

.page-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

/* =========================================================
   PAGE TOP
   Every page starts with this: the header on the left (eyebrow
   = the menu group, title = the menu name, a line on what the
   page is for) and the page's controls on the right.
   ========================================================= */

.page-top {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px 20px;
    margin-bottom: 22px;
}

.page-top .page-header {
    min-width: 0;
    margin-bottom: 0;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
}

.page-header p:empty {
    display: none;
}

/* =========================================================
   PAGE HEADER
   ========================================================= */

.page-header {
    margin-bottom: 22px;
}

.page-eyebrow {
    margin-bottom: 5px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--green);
}

.page-header h1 {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}

.page-header p {
    margin: 6px 0 0;
    font-size: 13px;
    color: #89949c;
}

/* =========================================================
    SINGLE-FARM USERS
    ========================================================= */

/* A farmer only sees their own farm, so the farm column is noise */
body.farm-user .col-farm {
    display: none;
}

/* The farm chip in the top bar picks the farm for every page */
body.has-nav .robot-picker {
    display: none;
}

/* =========================================================
    RESPONSIVE
    ========================================================= */

@media (max-width: 700px) {
    .wrap { padding: 12px; }
}

@media (max-width: 400px) {
    .wrap { padding: 8px; }
}


/* =========================================================
   EVENTS (robot faults, PLC alarms, e-stops, guards)
   Shared by the overview, the Events page and the robot page.
   ========================================================= */

.sev-info     { --sev-colour: var(--sev-info); }
.sev-warning  { --sev-colour: var(--sev-warning); }
.sev-fault    { --sev-colour: var(--sev-fault); }
.sev-critical { --sev-colour: var(--sev-critical); }

.sev-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border: 1px solid color-mix(in srgb, var(--sev-colour) 45%, transparent);
    border-radius: 999px;
    background: color-mix(in srgb, var(--sev-colour) 13%, transparent);
    color: var(--sev-colour);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.event-list {
    display: grid;
    gap: 8px;
}

/* One active event: icon, what and where, how long */
.event-item {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-left: 3px solid var(--sev-colour);
    border-radius: 7px;
    background: var(--panel);
    color: inherit;
    text-decoration: none;
}

a.event-item:hover {
    background: #2c3238;
}

.event-item-icon {
    flex-shrink: 0;
    font-size: 24px;
    color: var(--sev-colour);
}

.event-item-body {
    flex: 1;
    min-width: 0;
}

.event-item-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
}

.event-item-meta {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.event-item-time {
    flex-shrink: 0;
    text-align: right;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.event-item-time small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
}

/* "Nothing active" */
.event-clear {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--panel);
    color: #aeb7bd;
    font-size: 13px;
}

.event-clear .material-symbols-outlined {
    font-size: 21px;
    color: var(--good);
}

/* Link at the right-hand end of a section header */
.section-link {
    flex-shrink: 0;
    color: var(--green-light);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
}

.section-link:hover,
.table-link:hover {
    text-decoration: underline;
}

/* Link inside a table cell */
.table-link {
    color: inherit;
    text-decoration: none;
}

/* Event history table cells */

/* Type: icon and name */
.event-type {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.event-type .material-symbols-outlined {
    font-size: 17px;
    color: var(--muted);
}

.event-description {
    color: var(--text);
    font-weight: 600;
}

.event-code {
    margin-left: 6px;
    color: var(--muted);
    font-size: 11px;
}

/* Knock-ons (see Admin > Event codes): faults raised by another one */
.event-knock-ons {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    margin-top: 5px;
    color: var(--muted);
    font-size: 11.5px;
    line-height: 1.4;
}

.event-knock-ons .material-symbols-outlined {
    flex-shrink: 0;
    font-size: 15px;
}

.event-knock-on-of {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 11px;
}

/* Still going */
.event-active {
    color: var(--sev-colour, var(--warn));
    font-weight: 700;
}

/* Not an alarm: kept in the history only */
.event-logged {
    margin-left: 8px;
    padding: 1px 6px;
    border: 1px solid var(--border2);
    border-radius: 999px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
}

/* Small grey note after a value in a table cell */
.cell-note {
    margin-left: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
}
