@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800;900&family=Roboto:wght@400;500;700&display=swap");

/* =========================
   I keep one single token system and map old vars -> new vars so nothing breaks.
   ========================= */
:root {
    /* Brand / status */
    --bar-1: #059669;
    --bar-2: #2563eb;
    --bar-3: #f97316;
    --bar-4: #e11d48;

    /* Spacing + radius */
    --radius: 12px;
    --radius-lg: 16px;
    --radius-max: 9999px;

    --s-1: 4px;
    --s-2: 8px;
    --s-3: 12px;
    --s-4: 16px;
    --s-5: 20px;
    --s-6: 24px;

    --fs-0: .82rem;
    --fs-1: .9rem;
    --fs-2: .95rem;
    --fs-3: 1.05rem;
    --fs-4: 1.25rem;

    /* UI tokens (dark default) */
    --ui-bg: #0e1218;
    --ui-panel: #141b25;
    --ui-panel-2: #111722;
    --ui-line: #2a384c;
    --ui-text: #e8eef6;
    --ui-muted: #a1aec2;
    --ui-accent: #f2b705;
    --ui-accent-2: #f6cf5a;
    --ui-shadow: 0 18px 36px rgba(0, 0, 0, .50);

    --focus: 0 0 0 2px color-mix(in oklab, var(--bar-2) 40%, white);
    --header-bg: #111418;
    --header-border: #1e2329;
    --header-text: #e6e6e6;
    --hc-bg: #0f1216;
    --hc-fg: #e6e6e6;
    --hc-border: #273244;
    --hc-hover: #161c26;
    --hc-focus: rgba(96, 165, 250, .45);
    --btn-h: 36px;
    --btn-radius: 10px;
    --btn-pad-x: 16px;
    --btn-bg: #1f2937;
    --btn-fg: #f8fafc;
    --btn-border: rgba(255, 255, 255, .14);
    --btn-hover: #2b3442;
    --btn-shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 10px rgba(0, 0, 0, .22);
    --btn-ghost-fg: #e6edf6;
    --btn-ghost-border: rgba(255, 255, 255, .2);
    --btn-ghost-hover: rgba(255, 255, 255, .08);

    /* Skeleton */
    --sk-base: #1b2330;
    --sk-hi: #273246;

    /* Compatibility mapping (old vars still used in some places) */
    --bg: var(--ui-bg);
    --bg-soft: var(--ui-bg);
    --surface: var(--ui-panel);
    --surface-2: var(--ui-panel-2);
    --text: var(--ui-text);
    --text-dim: var(--ui-muted);
    --grid: var(--ui-line);
    --muted: color-mix(in srgb, var(--ui-panel) 80%, #000 20%);
    --catHeaderBg: color-mix(in srgb, var(--ui-panel) 75%, #000 25%);
    --shadow-lg: var(--ui-shadow);
}

:root[data-theme="light"] {
    --ui-bg: #f4f6f9;
    --ui-panel: #ffffff;
    --ui-panel-2: #f8fafc;
    --ui-line: #d7dee8;
    --ui-text: #1f2937;
    --ui-muted: #6b778c;
    --ui-accent: #f2b705;
    --ui-accent-2: #f9da74;
    --ui-shadow: 0 14px 26px rgba(15, 23, 42, .12);

    --focus: 0 0 0 2px color-mix(in oklab, var(--bar-2) 55%, white);
    --header-bg: #eef2f7;
    --header-border: #d7dee8;
    --header-text: #1f2937;
    --hc-bg: #e9eef4;
    --hc-fg: #1f2937;
    --hc-border: #d7dee8;
    --hc-hover: #eef2f7;
    --hc-focus: rgba(37, 99, 235, .35);
    --btn-bg: #111827;
    --btn-fg: #ffffff;
    --btn-border: #0f172a;
    --btn-hover: #0f172a;
    --btn-shadow: 0 1px 2px rgba(15, 23, 42, .16), 0 6px 12px rgba(15, 23, 42, .12);
    --btn-ghost-fg: #1f2937;
    --btn-ghost-border: #cbd5e1;
    --btn-ghost-hover: #e5edf7;

    /* Skeleton */
    --sk-base: #e2e8f0;
    --sk-hi: #f1f5f9;
}

/* ===== Skeleton (reporte incidencias) ===== */
.ri-skeleton {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--ui-bg);
    display: block;
    padding: 0;
    opacity: 1;
    visibility: visible;
    pointer-events: all;
    overflow: auto;
}

.ri-skeleton-inner {
    max-width: 2000px;
    margin: 0 auto;
    padding: 0 0 24px;
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 12px;
}

html[data-ri-ready="1"] .ri-skeleton {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .2s ease, visibility 0s linear .2s;
}

html:not([data-ri-ready="1"]) .ri-wrap {
    opacity: 0;
    pointer-events: none;
}
html[data-ri-ready="1"] .ri-wrap {
    opacity: 1;
    transition: opacity .2s ease;
}

.ri-sk-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    border-radius: 0;
}
.ri-sk-tabs,
.ri-sk-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}
.ri-sk-card {
    background: var(--ui-panel);
    border: 1px solid var(--ui-line);
    border-radius: var(--radius-lg);
    padding: 12px;
    box-shadow: var(--ui-shadow);
    margin: 0 16px;
}
.ri-sk-main {
    display: grid;
    gap: 12px;
}
.ri-sk-pane { display: grid; gap: 12px; }
html[data-ri-tab="search"] .ri-sk-pane[data-ri-skeleton="dash"] { display: none; }
html:not([data-ri-tab="search"]) .ri-sk-pane[data-ri-skeleton="search"] { display: none; }
html[data-ri-tab="search"][data-ri-filters="closed"] .ri-sk-pane[data-ri-skeleton="search"] .ri-sk-filters {
    display: none;
}
.ri-sk-filters {
    display: grid;
    grid-template-columns: repeat(3, minmax(160px, 1fr));
    gap: 10px;
    margin-top: 12px;
}
.ri-sk-filters-search {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
}
.ri-sk-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.ri-sk-line,
.ri-sk-tab,
.ri-sk-btn,
.ri-sk-title,
.ri-sk-sub,
.ri-sk-field {
    background: linear-gradient(90deg, var(--sk-base), var(--sk-hi), var(--sk-base));
    background-size: 200% 100%;
    animation: ri-shimmer 1.2s ease-in-out infinite;
    border-radius: 10px;
}
.ri-sk-line { height: 12px; }
.ri-sk-tab { height: 28px; width: 120px; border-radius: 999px; }
.ri-sk-tab.sm { width: 90px; }
.ri-sk-btn { height: 36px; width: 120px; border-radius: 10px; }
.ri-sk-btn.md { width: 140px; }
.ri-sk-btn.sm { width: 90px; }
.ri-sk-title { height: 16px; width: 220px; }
.ri-sk-sub { height: 12px; width: 280px; margin-top: 6px; }
.ri-sk-field { height: 36px; }
.ri-sk-table {
    height: 220px;
    border-radius: 12px;
    border: 1px solid var(--ui-line);
    background: var(--ui-panel-2);
    position: relative;
    overflow: hidden;
}
.ri-sk-table-tall { height: 320px; }
.ri-sk-table::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        repeating-linear-gradient(180deg, transparent 0 34px, rgba(255,255,255,.05) 34px 35px);
    opacity: .5;
}

/* Dash table skeleton (Top 10) */
.dash-skel {
    border: 1px solid var(--ui-line);
    border-radius: 12px;
    padding: 12px;
    background: var(--ui-panel-2);
    margin-bottom: 8px;
}
.dash-skel-head {
    height: 20px;
    margin-bottom: 14px;
    width: 980px;
    max-width: 100%;
    background: linear-gradient(90deg, var(--sk-base), var(--sk-hi), var(--sk-base));
    background-size: 200% 100%;
    animation: ri-shimmer 1.2s ease-in-out infinite;
    border-radius: 10px;
}
.dash-skel-table {
    display: grid;
    gap: 10px;
}
.dash-skel-row {
    display: grid;
    grid-template-columns: minmax(600px, 1fr) repeat(3, 180px);
    gap: 10px;
    align-items: center;
}
.dash-skel-cell {
    height: 22px;
    background: linear-gradient(90deg, var(--sk-base), var(--sk-hi), var(--sk-base));
    background-size: 200% 100%;
    animation: ri-shimmer 1.2s ease-in-out infinite;
    border-radius: 10px;
}
.dash-skel-row.head .dash-skel-cell {
    height: 18px;
}
.dash-skel-cell.wide { width: 100%; }
.dash-skel-cell.sm { width: 100%; }

#dashWrap[data-loading="1"] .table-scroll {
    opacity: 0;
    pointer-events: none;
}

#dashWrap[data-loading="1"] .ri-plant-head {
    opacity: 0;
    pointer-events: none;
}

@media (max-width: 900px) {
    .ri-sk-filters { grid-template-columns: 1fr; }
    .ri-sk-actions { justify-content: flex-start; }
}

@keyframes ri-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* =========================
   Base / reset
   ========================= */
* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    min-height: 100dvh;
    margin: 0;
    font: 14px/1.45 "Montserrat", "Roboto", sans-serif;
    background: var(--ui-bg);
    color: var(--ui-text);
}

body {
    background: radial-gradient(1100px 600px at 10% -10%, rgba(242, 183, 5, .12), transparent 55%),
    var(--ui-bg);
    overflow-x: hidden;
}

img {
    max-width: 100%;
    display: block;
}

button, select, input, textarea {
    font: inherit;
    color: inherit;
}

:disabled {
    opacity: .55;
    cursor: not-allowed !important;
}

a, button, [role="button"], .dropzone {
    outline-offset: 2px;
}

a:focus-visible, button:focus-visible, [role="button"]:focus-visible, .dropzone:focus-visible {
    outline: 2px solid #60a5fa;
}

/* =========================
   Layout wrapper
   ========================= */
.ri-wrap {
    max-width: 2000px;
    margin: 0 auto;
    padding: 0 0 24px;
}

.ri-card {
    margin: 12px 16px;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line);
    border-radius: var(--radius-lg);
    box-shadow: var(--ui-shadow);
    overflow: hidden;
}

.ri-card-head {
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px solid var(--ui-line);
    background: linear-gradient(180deg, rgba(255, 255, 255, .03), rgba(0, 0, 0, .10));
}

:root[data-theme="light"] .ri-card-head {
    background: linear-gradient(180deg, #f8fafc, #eef2f7);
}

.ri-card-title {
    font-weight: 800;
    letter-spacing: .3px;
    font-size: var(--fs-3);
}

.ri-card-sub {
    color: var(--ui-muted);
    font-size: var(--fs-1);
}

/* =========================
   Buttons / inputs
   ========================= */
.btn {
    background: var(--ui-panel);
    color: var(--ui-text);
    border: 1px solid var(--ui-line);
    border-radius: 10px;
    padding: 10px 14px;
    min-height: 28px;
    line-height: 1;
    font-weight: 700;
    cursor: pointer;
    transition: transform .04s ease, filter .15s ease;
}
.btn.sm {
    padding: 6px 10px;
    min-height: 28px;
    font-size: var(--fs-0);
    font-weight: 600;
}

.btn:hover {
    filter: brightness(1.05);
}

.btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px #60a5fa66;
}

.btn.ghost {
    background: transparent;
    color: var(--ui-text);
    border-color: var(--ui-line);
}

.btn.danger {
    background: #b91c1c;
    border-color: #7f1d1d;
    color: #fff;
}

.input, select, textarea {
    background: var(--ui-panel-2);
    color: var(--ui-text);
    border: 1px solid var(--ui-line);
    border-radius: 10px;
    padding: 8px 12px;
    min-height: 38px;
    outline: none;
}

.input:focus, select:focus, textarea:focus {
    box-shadow: 0 0 0 2px rgba(242, 183, 5, .25);
    border-color: var(--ui-accent);
}

.input::placeholder, textarea::placeholder {
    color: color-mix(in srgb, var(--ui-muted) 80%, transparent);
}

.field {
    display: grid;
    gap: var(--s-1);
}

.field label {
    font-size: var(--fs-1);
    color: var(--ui-muted);
    font-weight: 700;
}

/* =========================
   Header + tabs + controls
   ========================= */
.app-header {
    width: 100%;
    padding: 14px 18px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    box-shadow: 0 8px 18px rgba(0, 0, 0, .2);
    margin-bottom: var(--s-3);
}

/* I keep the 'hdr-controls' header deterministic using CSS Grid. */
.app-header.hdr-controls {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
    "title controls"
    "tabs  controls";
    align-items: center;
    gap: 10px 12px;
}

.app-header.hdr-controls .page-title {
    grid-area: title;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    white-space: normal;
    overflow: hidden;
    font-weight: 800;
    letter-spacing: .3px;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}
.app-header.hdr-controls .page-title .title {
    font-size: 1.1rem;
    font-weight: 800;
}
.app-header.hdr-controls .page-title .subtitle {
    font-size: .85rem;
    color: var(--ui-muted);
    font-weight: 600;
}

.app-header.hdr-controls .hdr-tabs {
    grid-area: tabs;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.app-header.hdr-controls .controls {
    grid-area: controls;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
}

/* Header buttons + tabs (match Bitacora header) */
.app-header.hdr-controls .controls .btn,
.app-header.hdr-controls .controls button,
.app-header.hdr-controls .hdr-tabs .tab {
    height: var(--btn-h);
    padding: 0 var(--btn-pad-x);
    border-radius: var(--btn-radius);
    background: var(--btn-bg);
    color: var(--btn-fg);
    border: 1px solid var(--btn-border);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--btn-shadow);
    transition: background .12s ease, box-shadow .12s ease, border-color .12s ease, color .12s ease, transform .04s ease;
}

.app-header.hdr-controls .controls .btn:hover,
.app-header.hdr-controls .controls button:hover,
.app-header.hdr-controls .hdr-tabs .tab:hover {
    background: var(--btn-hover);
}

.app-header.hdr-controls .controls .btn:active,
.app-header.hdr-controls .controls button:active,
.app-header.hdr-controls .hdr-tabs .tab:active {
    transform: translateY(1px);
    box-shadow: none;
}

.app-header.hdr-controls .controls .btn:focus-visible,
.app-header.hdr-controls .controls button:focus-visible,
.app-header.hdr-controls .hdr-tabs .tab:focus-visible {
    outline: 2px solid var(--hc-focus);
    outline-offset: 2px;
}

.app-header.hdr-controls .hdr-tabs .tab.is-active {
    background: var(--btn-hover);
    border-color: var(--btn-border);
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, .25), inset 0px 0px 0 2px var(--ui-accent)
}

.attach-ico,
.icon-ico {
    width: 16px;
    height: 16px;
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
    color: currentColor;
}

:root[data-theme="light"] .hdr-tabs .tab.is-active {
    background: #111827;
    color: #fff;
    border-color: #111827;
    box-shadow: 0 6px 14px rgba(0, 0, 0, .25), inset 0px 0px 0 2px var(--ui-accent);
}

/* =========================
   Filters + legend
   ========================= */
.filters {
    display: grid;
    gap: var(--s-3);
    grid-template-columns: repeat(6, 1fr);
    align-items: end;
    margin: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 14px;
    box-shadow: none;
}
.filters.is-collapsed {
    display: none;
}

.filters .col-3 {
    grid-column: span 3;
}

.filters .col-full {
    grid-column: 1/-1;
}

#filters .field input, #filters .field select {
    width: 100%;
}

.legend.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 10px;
    align-items: center;
    margin: 6px 16px 10px;
}

.legend.chips .legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--fs-0);
    padding: 6px 10px;
    border-radius: var(--radius-max);
    background: var(--ui-panel);
    border: 1px solid var(--ui-line);
    color: var(--ui-text);
    box-shadow: var(--ui-shadow);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .18);
}

.legend-dot[data-color="ok"] {
    background: var(--bar-1);
}

.legend-dot[data-color="nok"] {
    background: var(--bar-3);
}

.legend-dot[data-color="q-on"] {
    background: #22c55e;
}

.legend-dot[data-color="q-late"] {
    background: #ef4444;
}

.hint {
    display: inline-grid;
    place-items: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 800;
    margin-left: 4px;
    background: var(--ui-panel-2);
    color: var(--ui-text);
    border: 1px solid var(--ui-line);
    cursor: help;
}

/* =========================
   Panels + tables
   ========================= */
.ri-plant {
    margin: 12px 16px;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--ui-shadow);
}

.ri-plant.is-loading {
    padding: 10px 12px 12px;
}
.ri-plant.is-loading .dash-skel {
    margin: 0;
}

.ri-plant .ri-plant-head {
    background: linear-gradient(180deg, #1f2937, #111827);
    color: #fff;
    font-weight: 800;
    letter-spacing: .3px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--ui-line);
}

:root[data-theme="light"] .ri-plant .ri-plant-head {
    background: linear-gradient(180deg, #f8fafc, #eef2f7);
    color: #111827;
}

.table-scroll {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    cursor: grab;
    user-select: none;
}
.table-scroll.is-dragging {
    cursor: grabbing;
    user-select: none;
}

.inc-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.inc-table th, .inc-table td {
    border-bottom: 1px solid var(--ui-line);
    border-right: 1px solid var(--ui-line);
    padding: 8px 10px;
    vertical-align: top;
    background: transparent;
    font-size: var(--fs-2);
    line-height: 1.35;
}
.inc-table th:first-child,
.inc-table td:first-child {
    border-left: 1px solid var(--ui-line);
}
.inc-table th:last-child,
.inc-table td:last-child {
    border-right: 1px solid var(--ui-line);
}

.inc-table thead th {
    background: var(--ui-panel-2);
    color: var(--ui-text);
    font-weight: 800;
    text-align: center;
    font-size: .9rem;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
    box-shadow: 0 2px 0 var(--ui-line);
}

.inc-table thead th:first-child,
.inc-table tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    min-width: 170px;
}

.inc-table thead th:nth-child(2),
.inc-table tbody td:nth-child(2) {
    position: sticky;
    left: 170px;
    z-index: 3;
    min-width: 140px;
}

.inc-table thead th:first-child {
    background: var(--ui-panel-2);
    z-index: 4;
}

.inc-table thead th:nth-child(2) {
    background: var(--ui-panel-2);
    z-index: 4;
}

.inc-table tbody td:first-child {
    background: var(--ui-panel);
}

.inc-table tbody td:nth-child(2) {
    background: var(--ui-panel);
}

.inc-table tbody tr:hover td {
    background: color-mix(in srgb, var(--ui-panel) 85%, #000 15%);
}

.inc-table td.perm-clickable {
    cursor: pointer;
}

:root[data-theme="light"] .inc-table tbody tr:hover td {
    background: #f7f9fc;
}

.ri-plant .inc-table:not(.sum-table) tbody tr:nth-child(even) td {
    background: color-mix(in srgb, var(--ui-panel) 92%, #000 8%);
}

:root[data-theme="light"] .ri-plant .inc-table:not(.sum-table) tbody tr:nth-child(even) td {
    background: #f3f6fb;
}

/* Fixed columns (desktop) */
.inc-table tbody td:nth-child(8) {
    width: 260px;
    min-width: 160px;
}

.inc-table tbody td:nth-child(10) {
    width: 70px;
    text-align: center;
    font-weight: 650;
    color: #fff;
}

/* light mode */
html[data-theme="light"] .inc-table tbody td:nth-child(10){
  color: #000000;
}

.state-ok {
    background: #065f46 !important;
    color: #e7ffef !important;
}

.state-nok {
    background: #7f1d1d !important;
    color: #fff1f2 !important;
}

.elapsed {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: .8rem;
    font-weight: 700;
    border: 1px solid transparent;
    white-space: nowrap;
}

.elapsed-green {
    background: #14532d;
    color: #bbf7d0;
    border-color: #166534;
}

.elapsed-red {
    background: #7f1d1d;
    color: #fecaca;
    border-color: #991b1b;
}

.elapsed-ok {
    background: #0f172a;
    color: #e2e8f0;
    border-color: #334155;
}

.elapsed-na {
    background: #111827;
    color: #94a3b8;
    border-color: #334155;
}

.evidence {
    display: grid;
    gap: 6px;
    grid-template-columns: repeat(2, 1fr);
}

.evidence img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border: 1px solid var(--ui-line);
    border-radius: 6px;
}

.empty {
    padding: 22px;
    text-align: center;
    border: 1px dashed var(--ui-line);
    border-radius: 12px;
    color: var(--ui-text);
    background: var(--ui-panel-2);
}

/* =========================
   Dropzone + previews
   ========================= */
.dropzone {
    border: 2px dashed #3b82f6;
    background: var(--ui-panel-2);
    border-radius: 12px;
    padding: 14px;
    text-align: center;
    outline: none;
    color: var(--ui-text);
}

.dropzone.dragover {
    background: color-mix(in srgb, #0b1b35 65%, var(--ui-panel-2) 35%);
    border-color: #93c5fd;
}

.ev-previews {
    margin-top: 10px;
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(4, 1fr);
}


.ev-item {
    position: relative;
    border: 1px solid var(--ui-line);
    border-radius: 10px;
    overflow: hidden;
    background: var(--ui-panel-2);
}

.ev-item img {
    width: 100%;
    height: clamp(140px, 24vh, 240px);
    object-fit: cover;
}

.ev-remove {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(14, 18, 25, .85);
    border: 1px solid rgba(255, 255, 255, .18);
    color: #fff;
    border-radius: var(--radius-max);
    font-size: 12px;
    padding: 4px 8px;
    cursor: pointer;
}

/* =========================
   Modal
   ========================= */
.modal {
    position: fixed;
    inset: 0;
    display: none;
    background: rgba(7, 10, 15, .7);
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
    z-index: 2147483646;
}

:root[data-theme="light"] .modal {
    background: rgba(15, 23, 42, .35);
}

.modal.show {
    display: flex;
}

.modal-card {
    width: 100vw;
    height: 100dvh;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line);
    border-radius: 0;
    box-shadow: var(--ui-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 2147483647;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.modal-head, .modal-foot {
    padding: var(--s-3);
    background: var(--ui-panel);
    border-bottom: 1px solid var(--ui-line);
    display: flex;
    align-items: center;
    gap: var(--s-3);
    position: sticky;
    left: 0;
    right: 0;
    z-index: 2;
}

.modal-head {
    top: 0;
}

.modal-foot {
    border-top: 1px solid var(--ui-line);
    border-bottom: 0;
    justify-content: flex-end;
    bottom: 0;
    box-shadow: 0 -6px 18px rgba(6, 10, 16, 0.18);
}

.modal-foot-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: clamp(12px, 2vw, 16px);
    display: grid;
    gap: var(--s-3);
    grid-template-columns: 1fr 1fr;
    background: var(--ui-panel-2);
}

.modal-skel {
    position: sticky;
    top: 0;
    grid-column: 1 / -1;
    z-index: 3;
    background: var(--ui-panel-2);
    border: 1px solid var(--ui-line);
    border-radius: 12px;
    padding: 12px;
    display: grid;
    gap: 10px;
    animation: skel-fade 0.2s ease-in;
}

.modal-skel[hidden] {
    display: none !important;
}

/* =========================
   Asignacion picker (incidencias)
   ========================= */
.assign-picker {
    display: flex;
    gap: 8px;
    align-items: center;
}
.assign-picker input {
    flex: 1 1 auto;
}
.assign-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    backdrop-filter: blur(2px);
    z-index: 2147483650;
    display: none;
}
.assign-modal {
    position: fixed;
    inset: 0;
    display: none;
    place-items: center;
    z-index: 2147483651;
}
.assign-modal.show,
.assign-backdrop.show {
    display: grid;
}
.ri-assign-open .modal-body {
    overflow: hidden;
}
.ri-assign-open .modal-card {
    overscroll-behavior: contain;
}
.assign-dialog {
    width: min(860px, 92vw);
    max-height: 86vh;
    background: var(--ui-panel);
    border: 1px solid var(--ui-line);
    border-radius: 14px;
    box-shadow: var(--ui-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.assign-title,
.assign-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    background: var(--ui-panel-2);
    border-bottom: 1px solid var(--ui-line);
}
.assign-foot {
    border-top: 1px solid var(--ui-line);
    border-bottom: 0;
}
.assign-foot .btn {
    font-weight: 700;
}
.assign-foot .assign-pager {
    margin-right: auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.assign-page {
    font-size: var(--fs-0);
    color: var(--ui-muted);
    min-width: 120px;
    text-align: center;
}
.assign-content {
    overflow: auto;
    flex: 1 1 auto;
    padding: 12px;
}
.assign-search {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.assign-row {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr;
}
.assign-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.assign-search label {
    font-size: 12px;
    color: var(--ui-muted);
}
.assign-search input,
.assign-search select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--ui-line);
    background: var(--ui-panel-2);
    color: var(--ui-text);
    outline: none;
}
.assign-list {
    display: grid;
    gap: 8px;
    margin-top: 10px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
.assign-item {
    display: grid;
    gap: 4px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--ui-line);
    background: var(--ui-panel-2);
    cursor: pointer;
}
.assign-item .t {
    font-weight: 600;
}
.assign-item .assign-line {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 12px;
    color: var(--ui-muted);
}
.assign-item .sub {
    font-size: 12px;
    color: var(--ui-muted);
}
.assign-item .sub strong {
    color: var(--ui-text);
    font-weight: 600;
}
.assign-item:hover {
    border-color: color-mix(in oklab, var(--ui-accent) 35%, var(--ui-line));
    background: color-mix(in oklab, var(--ui-panel-2) 80%, var(--ui-accent));
}
.assign-empty {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px dashed var(--ui-line);
    color: var(--ui-muted);
    grid-column: 1 / -1;
}
@media (min-width: 720px) {
    .assign-row.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .assign-row.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
    .assign-list { grid-template-columns: 1fr; }
}

.modal-skel-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr 1fr;
}

.modal-skel-row,
.modal-skel-line,
.modal-skel-block {
    border-radius: 9999px;
    background: linear-gradient(90deg,
        rgba(255,255,255,0.06) 0%,
        rgba(255,255,255,0.14) 50%,
        rgba(255,255,255,0.06) 100%);
    background-size: 200% 100%;
    animation: skel-shimmer 1.2s linear infinite;
}

.modal-skel-line {
    height: 12px;
}

.modal-skel-block {
    height: 40px;
    border-radius: 10px;
}

.skel-w-30 { width: 30%; }
.skel-w-35 { width: 35%; }
.skel-w-40 { width: 40%; }
.skel-w-45 { width: 45%; }
.skel-h-36 { height: 36px; }
.skel-h-44 { height: 44px; }
.skel-h-56 { height: 56px; }
.skel-h-72 { height: 72px; }

:root[data-theme="light"] .modal-skel-row,
:root[data-theme="light"] .modal-skel-line,
:root[data-theme="light"] .modal-skel-block {
    background: linear-gradient(90deg,
        rgba(15,23,42,0.08) 0%,
        rgba(15,23,42,0.16) 50%,
        rgba(15,23,42,0.08) 100%);
}

@media (max-width: 700px) {
    .modal-skel-grid {
        grid-template-columns: 1fr;
    }
}

@keyframes skel-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes skel-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (max-width: 900px) {
    .modal-body {
        grid-template-columns:1fr;
    }
}

@media (max-width: 640px) {
    .modal-foot {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .modal-foot-actions {
        justify-content: stretch;
    }
    .modal-foot-actions .btn {
        flex: 1 1 auto;
    }
}

.comments-wrap {
    padding: 6px 0;
}

.ri-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.input-compact {
    min-height: 38px !important;
    height: auto !important;
    padding: 8px 12px !important;
    line-height: 1.2 !important;
    font-size: inherit !important;
}

.ri-row .input {
    flex: 1 1 160px;
    min-width: 160px;
    min-height: 0 !important;
    height: auto !important;
}

.ri-row .btn {
    flex: 0 0 auto;
}

#modal .comments.is-readonly .comments-compose,
#modal .comments.is-readonly .attach-previews {
    display: none;
}

/* =========================
   Loading overlay
   ========================= */
#listWrap.ri-card {
    padding: 0;
}

#grouped {
    display: grid;
    gap: 12px;
}

#listWrap, #dashWrap {
    position: relative;
}

#listWrap .loading, #dashWrap .loading {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .35);
    backdrop-filter: saturate(.8) blur(1px);
    font-weight: 700;
    letter-spacing: .3px;
    z-index: 3;
}

/* is-loading spinner removed */

/* =========================
   Badges + quick range
   ========================= */
.badge {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 9999px;
    background: var(--ui-panel-2);
    border: 1px solid var(--ui-line);
    font-size: .8rem;
    color: var(--ui-text);
}

.quick-range {
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--ui-panel-2);
    border: 1px dashed var(--ui-line);
    padding: 8px 10px;
    border-radius: 12px;
}

.quick-range .btn {
    padding: 6px 15px;
    min-height: 32px;
    font-weight: 700;
}

button.btn.ghost.range {
    font-size: .8rem;
}

/* =========================
   Dashboard bits
   ========================= */
.dash-filters {
    display: grid;
    gap: 12px;
    grid-template-columns: 320px 200px 200px 1fr;
    align-items: end;
    margin: 0;
    padding: 14px;
}

@media (max-width: 900px) {
    .dash-filters {
        grid-template-columns: 1fr 1fr;
    }
}

.sum-table td:nth-child(2),
.sum-table td:nth-child(3),
.sum-table td:nth-child(4) {
    text-align: center;
    font-weight: 800;
}

.sum-cell {
    cursor: pointer;
}

.sum-cell:hover {
    filter: brightness(1.15);
}

.sum-ok {
    background: #065f46 !important;
    color: #e7ffef !important;
}

.sum-nok {
    background: #7f1d1d !important;
    color: #fff1f2 !important;
}

.sum-total {
    background: #1f2937 !important;
    color: #f8fafc !important;
}
:root[data-theme="light"] .sum-total {
    background: #e2e8f0 !important;
    color: #111827 !important;
}

.sum-plant {
    cursor: pointer;
    text-decoration: none;
}

.sum-plant:hover,
.sum-plant:focus-visible {
    text-decoration: underline;
    text-underline-offset: 1px;
    text-decoration-thickness: 1px;
}

/* =========================
   Responsive
   ========================= */
@media (max-width: 1100px) {
    .ri-wrap {
        padding: 0 0 20px;
    }

    .filters {
        grid-template-columns: repeat(3, 1fr);
    }

    .filters .col-3 {
        grid-column: span 1;
    }
}

@media (max-width: 640px) {
    .ri-wrap {
        padding: 0 0 18px;
    }

    .filters {
        grid-template-columns: 1fr 1fr;
    }

    .filters .col-full {
        grid-column: 1/-1;
    }
}

@media (max-width: 900px) {
    .inc-table th, .inc-table td {
        padding: 6px 8px;
        font-size: var(--fs-1);
    }

    .evidence img {
        height: 90px;
    }

    .ev-previews {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Mobile: I keep buttons compact (no full width) and tabs scroll horizontally. */
@media (max-width: 720px) {
    .app-header {
        padding: 12px 14px;
    }

    .app-header.hdr-controls {
        grid-template-columns: 1fr;
        grid-template-areas:
      "title"
      "tabs"
      "controls";
    }

    .app-header.hdr-controls .hdr-tabs {
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 2px;
    }

    .app-header.hdr-controls .hdr-tabs::-webkit-scrollbar {
        display: none;
    }

    .app-header.hdr-controls .hdr-tabs .tab {
        flex: 0 0 auto !important;
        white-space: nowrap;
        padding: 8px 12px;
    }

    .app-header.hdr-controls .controls {
        justify-content: flex-start;
    }

    .app-header.hdr-controls .controls .btn {
        flex: 0 0 auto !important;
        width: auto !important;
        min-width: 0 !important;
        white-space: nowrap;
        padding: 8px 12px;
    }

    .filters {
        grid-template-columns: 1fr;
    }

    .ri-card,
    .ri-plant {
        margin-left: 12px;
        margin-right: 12px;
    }

    .quick-range {
        flex-wrap: wrap;
        row-gap: 6px;
    }

    /* Table -> cards */
    .inc-table, .inc-table thead, .inc-table tbody, .inc-table tr, .inc-table th, .inc-table td {
        display: block;
    }

    .inc-table thead {
        display: none;
    }

    .inc-table tr {
        border: 1px solid var(--ui-line);
        border-radius: 10px;
        margin: 10px 0;
        overflow: hidden;
        background: var(--ui-panel);
    }

    .inc-table td {
        border: 0;
        border-bottom: 1px solid var(--ui-line);
        display: grid;
        grid-template-columns: 110px 1fr;
        gap: 8px;
        padding: 10px 12px;
    }

    .inc-table td.state-ok,
    .inc-table td.state-nok {
        grid-template-columns: 1fr;
        text-align: left;
        padding: 10px 12px;
    }

    .inc-table td.state-ok::before,
    .inc-table td.state-nok::before {
        margin-bottom: 6px;
    }

    .inc-table td:last-child {
        border-bottom: 0;
    }

    .inc-table td::before {
        content: attr(data-th);
        font-weight: 700;
        color: color-mix(in srgb, var(--ui-muted) 85%, transparent);
    }

    /* Wide columns lose fixed width on mobile */
    .inc-table tbody td:nth-child(8),
    .inc-table tbody td:nth-child(9) {
        width: auto;
        min-width: 0;
    }

    .evidence {
        grid-template-columns:1fr;
    }

    .evidence img {
        height: 140px;
    }

    .ev-previews {
        grid-template-columns: 1fr;
    }
}

/* Extra tiny phones */
@media (max-width: 420px) {
    .inc-table td {
        grid-template-columns: 92px 1fr;
    }

    .ri-plant .ri-plant-head {
        font-size: .9rem;
        padding: 6px 10px;
    }

    .app-header.hdr-controls .controls .btn {
        padding: 8px 10px;
    }
}

/* =========================
   Motion accessibility
   ========================= */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
        scroll-behavior: auto !important;
    }
}
