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

/* ── Toast notifications ───────────────────────────────────── */
#toast-container {
    position: fixed; bottom: 1.25rem; right: 1.25rem;
    display: flex; flex-direction: column; gap: .55rem;
    z-index: 9999; pointer-events: none;
}
.toast {
    display: flex; align-items: flex-start; gap: .6rem;
    padding: .7rem 1rem; border-radius: 8px; max-width: 340px;
    box-shadow: 0 4px 18px rgba(0,0,0,.18); pointer-events: all;
    opacity: 0; transform: translateY(8px);
    transition: opacity .22s ease, transform .22s ease;
}
.toast.toast-show { opacity: 1; transform: translateY(0); }
.toast-error { background: #fef2f2; border: 1.5px solid #fca5a5; color: #991b1b; }
.toast-msg { font-size: .85rem; line-height: 1.45; flex: 1; }
.toast-close {
    flex-shrink: 0; background: none; border: none; cursor: pointer;
    color: inherit; opacity: .55; font-size: .85rem; padding: 0; line-height: 1;
    font-family: inherit;
}
.toast-close:hover { opacity: 1; }

:root {
    --primary:   #4f46e5;
    --primary-d: #4338ca;
    --bg:        #f0f2f5;
    --card:      #ffffff;
    --text:      #111827;
    --muted:     #6b7280;
    --border:    #e5e7eb;
    --danger:    #dc2626;
    --danger-bg: #fef2f2;
    --ok:        #16a34a;
    --ok-bg:     #f0fdf4;
    --ok-border: #86efac;
    --nav-h:     56px;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Login ──────────────────────────────────────────── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.login-card {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,.08);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}
.login-card h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 1.75rem; }

.field { margin-bottom: 1.1rem; }
.field label {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: .4rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.field input {
    width: 100%;
    padding: .65rem .9rem;
    border: 1.5px solid var(--border);
    border-radius: 7px;
    font-size: 1rem;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.field input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #fecaca;
    border-radius: 7px;
    padding: .6rem .9rem;
    font-size: .9rem;
    margin-bottom: 1rem;
}
.btn-primary {
    display: block;
    width: 100%;
    padding: .7rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 7px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
}
.btn-primary:hover { background: var(--primary-d); }

/* ── Navbar ─────────────────────────────────────────── */
.navbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--nav-h);
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 200;
    gap: .5rem;
}
.nav-home {
    display: flex;
    align-items: center;
    gap: .45rem;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 1rem;
    white-space: nowrap;
    flex-shrink: 0;
    padding: .35rem .65rem;
    border-radius: 7px;
    transition: background .15s;
}
.nav-home:hover { background: rgba(255,255,255,.15); }
.nav-home-icon { font-size: 1.25rem; line-height: 1; }
.nav-right {
    display: flex;
    align-items: center;
    gap: .6rem;
    overflow: hidden;
    flex-shrink: 1;
    min-width: 0;
}
.nav-time {
    font-size: .78rem;
    opacity: .85;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.nav-sep { opacity: .4; font-size: .8rem; flex-shrink: 0; }
.nav-username {
    font-weight: 600;
    font-size: .88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}
.nav-account {
    color: #fff;
    text-decoration: none;
    font-size: .85rem;
    font-weight: 600;
    white-space: nowrap;
    padding: .3rem .65rem;
    border: 1.5px solid rgba(255,255,255,.5);
    border-radius: 6px;
    transition: background .15s, border-color .15s;
    flex-shrink: 0;
}
.nav-account:hover { background: rgba(255,255,255,.15); border-color: #fff; }
.nav-logout {
    color: #fff;
    background: rgba(220,38,38,.2);
    border: 1.5px solid rgba(255,255,255,.4);
    font-size: .85rem;
    font-weight: 600;
    white-space: nowrap;
    padding: .3rem .65rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background .15s, border-color .15s;
    flex-shrink: 0;
    font-family: inherit;
}
.nav-logout:hover { background: rgba(220,38,38,.5); border-color: #fca5a5; }

/* ── Nav bell ──────────────────────────────────────── */
.nav-bell {
    position: relative; display: flex; align-items: center; justify-content: center;
    background: none; border: none; cursor: pointer; color: rgba(255,255,255,.6);
    padding: .3rem .35rem; border-radius: 6px; flex-shrink: 0; font-family: inherit;
    transition: background .15s, color .15s;
}
.nav-bell:hover { background: rgba(255,255,255,.15); color: #fff; }
.nav-bell-unread { color: #fca5a5; }
.nav-bell-unread:hover { color: #fecaca; }
.nav-bell-badge {
    position: absolute; top: 1px; right: 1px;
    background: #ef4444; color: #fff; font-size: .58rem; font-weight: 700;
    min-width: 13px; height: 13px; border-radius: 7px;
    display: flex; align-items: center; justify-content: center; padding: 0 2px; line-height: 1;
    pointer-events: none;
}

/* ── Notification panel ─────────────────────────────── */
.notif-panel {
    position: fixed; top: var(--nav-h); right: 1rem;
    width: 340px; max-height: 440px;
    background: var(--card); border: 1.5px solid var(--border);
    border-radius: 10px; box-shadow: 0 8px 32px rgba(0,0,0,.14);
    z-index: 900; display: flex; flex-direction: column; overflow: hidden;
}
.notif-panel.hidden { display: none; }
.notif-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: .7rem 1rem; border-bottom: 1.5px solid var(--border); flex-shrink: 0;
}
.notif-header-title { font-weight: 700; font-size: .92rem; }
.notif-ack-all {
    font-size: .78rem; color: var(--primary); background: none; border: none;
    cursor: pointer; font-weight: 600; padding: .2rem .45rem; border-radius: 4px; font-family: inherit;
}
.notif-ack-all:hover { background: var(--bg); }
.notif-list { overflow-y: auto; flex: 1; }
.notif-empty { padding: 1.5rem 1rem; text-align: center; color: var(--muted); font-size: .87rem; }
.notif-item {
    display: flex; gap: .6rem; align-items: flex-start;
    padding: .7rem 1rem; border-bottom: 1px solid var(--border);
}
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: #fef2f2; }
.notif-item-body { flex: 1; min-width: 0; }
.notif-item-msg { font-size: .82rem; color: var(--text); line-height: 1.45; word-break: break-word; }
.notif-item-time { font-size: .71rem; color: var(--muted); margin-top: .2rem; }
.notif-ack-btn {
    flex-shrink: 0; font-size: .78rem; padding: .2rem .5rem;
    border: 1px solid var(--border); border-radius: 5px;
    background: var(--card); color: var(--muted); cursor: pointer; font-family: inherit;
    transition: background .1s, color .1s, border-color .1s;
}
.notif-ack-btn:hover:not(:disabled) { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.notif-ack-btn:disabled { opacity: .3; cursor: default; }
@media (max-width: 400px) { .notif-panel { right: .25rem; left: .25rem; width: auto; } }

@media (max-width: 480px) {
    .nav-time { display: none; }
    .nav-sep { display: none; }
    .nav-account { display: none; }
    .nav-username { max-width: 90px; }
}

/* ── Page shell ─────────────────────────────────────── */
.page-wrap {
    padding-top: calc(var(--nav-h) + 1.5rem);
    padding-bottom: 3rem;
    min-height: 100vh;
}

/* ── Home tiles ─────────────────────────────────────── */
.tiles-heading {
    text-align: center;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--muted);
    padding: 0 1rem .25rem;
    letter-spacing: .02em;
}
.tiles {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    padding: 1rem;
    max-width: 860px;
    margin: 0 auto;
}
@media (min-width: 560px) {
    .tiles { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1.25rem; padding: 1.25rem; }
}
.tile {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,.07);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    text-decoration: none;
    color: var(--text);
    gap: .6rem;
    transition: transform .18s, box-shadow .18s;
}
.tile:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(79,70,229,.15); }
.tile:active { transform: none; }
.tile-icon { font-size: 2.4rem; line-height: 1; }
.tile-title { font-size: 1rem; font-weight: 700; }
.tile-sub { font-size: .8rem; color: var(--muted); }
.tile-logout { cursor: pointer; font-family: inherit; border: 2px solid transparent; }
.tile-logout:hover { box-shadow: 0 8px 24px rgba(220,38,38,.15); border-color: #fca5a5; }
.tile-logout .tile-icon { color: var(--danger); }
.tile-admin { border: 2px solid #fde68a; }
.tile-admin:hover { box-shadow: 0 8px 24px rgba(251,191,36,.18); border-color: #f59e0b; }
.tile-admin .tile-icon { color: #b45309; }
.tile-action { cursor: pointer; font-family: inherit; border: 2px solid #c7d2fe; }
.tile-action:hover { box-shadow: 0 8px 24px rgba(79,70,229,.15); border-color: var(--primary); }
.tile-action .tile-icon { color: var(--primary); }

/* home tile wrapper + edit button */
.home-tile-wrap {
    position: relative;
}
.home-tile-wrap .tile {
    width: 100%;
    height: 100%;
}
.home-tile-edit-btn {
    position: absolute;
    top: .3rem;
    left: .3rem;
    width: 22px;
    height: 22px;
    background: rgba(255,255,255,.85);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    font-size: .65rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    padding: 0;
    z-index: 2;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, background .15s, color .15s, border-color .15s;
    transition-delay: 0s, 0s, 0s, 0s;
}
.home-tile-wrap:hover .home-tile-edit-btn {
    opacity: 1;
    pointer-events: auto;
    transition-delay: 2s, 0s, 0s, 0s;
}
.home-tile-edit-btn:hover { background: #ede9fe; color: var(--primary); border-color: #a5b4fc; }
.tile-custom-icon {
    width: 2.4rem;
    height: 2.4rem;
    object-fit: contain;
    border-radius: 6px;
    flex-shrink: 0;
}

/* fetch result notice */
.fetch-notice {
    border-radius: 8px;
    padding: .65rem 1rem;
    font-size: .88rem;
    font-weight: 600;
    margin-bottom: 1.1rem;
}
.fetch-notice-ok    { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.fetch-notice-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ── Market page ─────────────────────────────────────── */

/* Unit toggle bar */
.market-unit-bar {
    display: flex;
    align-items: center;
    gap: .65rem;
    margin-bottom: .9rem;
}
.unit-opt {
    font-size: .88rem;
    font-weight: 700;
    color: var(--text);
    transition: opacity .2s;
    user-select: none;
}
.unit-opt-dim { opacity: .35; }

/* iOS-style toggle switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 24px;
    cursor: pointer;
    transition: background .2s;
}
.toggle-track::after {
    content: '';
    position: absolute;
    left: 3px; top: 3px;
    width: 18px; height: 18px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
    transition: transform .2s;
}
.toggle input:checked + .toggle-track { background: var(--primary); }
.toggle input:checked + .toggle-track::after { transform: translateX(20px); }

/* Chart wrapper */
.chart-wrap {
    position: relative;
    height: 320px;
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,.06);
    padding: 1rem 1rem .5rem;
    margin-bottom: .25rem;
}
@media (max-width: 480px) { .chart-wrap { height: 210px; padding: .65rem .5rem .35rem; } }

.market-meta {
    font-size: .85rem;
    color: var(--muted);
    margin-bottom: 1rem;
}
.market-meta strong { color: var(--text); }
.market-empty {
    text-align: center;
    color: var(--muted);
    padding: 3rem 1rem;
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,.06);
}

/* chart color threshold bar */
.chart-color-bar {
    display: flex;
    align-items: center;
    gap: .65rem;
    flex-wrap: wrap;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .6rem 1rem;
    margin-top: .5rem;
}
.chart-color-row {
    display: flex;
    align-items: center;
    gap: .4rem;
}
.chart-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.chart-color-lbl {
    font-size: .78rem;
    color: var(--muted);
    white-space: nowrap;
}
.chart-color-input {
    width: 76px;
    padding: .25rem .4rem;
    border: 1.5px solid var(--border);
    border-radius: 5px;
    font-size: .82rem;
    background: var(--bg);
    color: var(--text);
    text-align: right;
}
.chart-color-input:focus { outline: none; border-color: var(--primary); }
.chart-color-unit { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.chart-color-sep {
    width: 1px;
    height: 22px;
    background: var(--border);
    flex-shrink: 0;
}
.chart-color-btn {
    padding: .28rem .85rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    margin-left: auto;
}
.chart-color-btn:hover { background: var(--primary-d); }

/* ── Generic subpage ────────────────────────────────── */
.subpage { max-width: 900px; margin: 0 auto; padding: 0 1rem; }
.subpage-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1.25rem;
}
.subpage-icon { font-size: 2rem; line-height: 1; }
.subpage-custom-icon { width: 2rem; height: 2rem; object-fit: contain; border-radius: 6px; flex-shrink: 0; }
.subpage-title { font-size: 1.6rem; font-weight: 800; }
.subpage-subtitle { font-size: .9rem; color: var(--muted); margin-top: .1rem; }
.subpage-body {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,.06);
    padding: 2rem;
    color: var(--muted);
    font-size: .95rem;
    text-align: center;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Links page ─────────────────────────────────────── */
.links-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: .75rem;
    flex-wrap: wrap;
}
.links-count { font-size: .85rem; color: var(--muted); }

.btn-add {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: .5rem 1rem;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    white-space: nowrap;
}
.btn-add:hover { background: var(--primary-d); }

/* Link tiles grid */
.link-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: .85rem;
}
@media (min-width: 560px) {
    .link-tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
}

.link-tile-wrap { position: relative; }

.link-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    text-decoration: none;
    color: var(--text);
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,.07);
    padding: 1rem .75rem .85rem;
    gap: .55rem;
    transition: transform .18s, box-shadow .18s;
    width: 100%;
    min-height: 120px;
}
.link-tile:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(79,70,229,.13); }
.link-tile:active { transform: none; }

.link-tile-img {
    width: 56px;
    height: 56px;
    object-fit: contain;
    border-radius: 8px;
    flex-shrink: 0;
}
.link-tile-placeholder {
    width: 56px;
    height: 56px;
    background: var(--bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    flex-shrink: 0;
}
.link-tile-name {
    font-size: .8rem;
    font-weight: 600;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    width: 100%;
    word-break: break-word;
}
.link-tile-desc {
    font-size: .63rem;
    color: var(--muted);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    width: 100%;
    word-break: break-word;
    margin-top: -.1rem;
}

/* edit button — hidden by default, fades in after 2s of hovering the tile */
.link-edit-btn {
    position: absolute;
    top: .3rem;
    left: .3rem;
    width: 22px;
    height: 22px;
    background: rgba(255,255,255,.85);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    font-size: .65rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    padding: 0;
    z-index: 2;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, background .15s, color .15s, border-color .15s;
    transition-delay: 0s, 0s, 0s, 0s;
}
.link-tile-wrap:hover .link-edit-btn {
    opacity: 1;
    pointer-events: auto;
    transition-delay: 2s, 0s, 0s, 0s;
}
.link-edit-btn:hover { background: #ede9fe; color: var(--primary); border-color: #a5b4fc; }

/* delete button */
.link-del-btn {
    position: absolute;
    top: .3rem;
    right: .3rem;
    width: 22px;
    height: 22px;
    background: rgba(255,255,255,.85);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    font-size: .65rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    transition: background .15s, color .15s, border-color .15s;
    padding: 0;
    z-index: 2;
}
.link-del-btn:hover { background: #fecaca; color: var(--danger); border-color: #fca5a5; }

/* confirm overlay */
.link-confirm {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,.97);
    border-radius: 12px;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .75rem;
    z-index: 3;
    box-shadow: 0 0 0 2px #fca5a5;
}
.link-confirm.show { display: flex; }
.link-confirm-msg {
    font-size: .78rem;
    font-weight: 700;
    color: var(--text);
    text-align: center;
}
.link-confirm-name {
    font-size: .73rem;
    color: var(--muted);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}
.link-confirm-btns { display: flex; gap: .4rem; }
.btn-confirm-del {
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: .3rem .65rem;
    font-size: .78rem;
    font-weight: 700;
    cursor: pointer;
}
.btn-confirm-del:hover { background: #b91c1c; }
.btn-confirm-cancel {
    background: var(--border);
    color: var(--text);
    border: none;
    border-radius: 6px;
    padding: .3rem .65rem;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
}
.btn-confirm-cancel:hover { background: #d1d5db; }

/* empty state */
.links-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--muted);
    padding: 3rem 1rem;
    font-size: .95rem;
}
.links-empty-icon { font-size: 2.5rem; margin-bottom: .5rem; }

/* ── Add-link modal ─────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 400;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--card);
    border-radius: 14px;
    box-shadow: 0 12px 48px rgba(0,0,0,.22);
    padding: 1.75rem;
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 1.4rem;
}
.modal .field { margin-bottom: .9rem; }
.modal-actions {
    display: flex;
    gap: .6rem;
    margin-top: 1.25rem;
}
.btn-modal-submit {
    flex: 1;
    padding: .65rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 7px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.btn-modal-submit:hover { background: var(--primary-d); }
.btn-modal-cancel {
    padding: .65rem 1.1rem;
    background: var(--border);
    color: var(--text);
    border: none;
    border-radius: 7px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.btn-modal-cancel:hover { background: #d1d5db; }

/* paste zone */
.paste-zone {
    border: 2px dashed var(--border);
    border-radius: 10px;
    min-height: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    cursor: pointer;
    padding: 1rem;
    transition: border-color .2s, background .2s;
    outline: none;
    position: relative;
}
.paste-zone:focus,
.paste-zone.active {
    border-color: var(--primary);
    background: rgba(79,70,229,.04);
}
.paste-zone.has-image {
    border-style: solid;
    border-color: var(--ok-border);
    background: var(--ok-bg);
}
.paste-instructions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .25rem;
    pointer-events: none;
}
.paste-icon { font-size: 1.6rem; }
.paste-label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--text);
}
.paste-hint { font-size: .75rem; color: var(--muted); }

.paste-preview-wrap {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
}
.paste-preview-wrap.show { display: flex; }
.paste-preview {
    max-width: 140px;
    max-height: 80px;
    object-fit: contain;
    border-radius: 6px;
    border: 1px solid var(--ok-border);
}
.paste-clear {
    font-size: .72rem;
    color: var(--danger);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
}
.paste-clear:hover { color: #b91c1c; }

/* ── Log page ───────────────────────────────────────── */
.log-controls {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1.1rem;
    flex-wrap: wrap;
}
.log-month-label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.log-month-select {
    padding: .35rem .65rem;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: .88rem;
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    outline: none;
}
.log-month-select:focus { border-color: var(--primary); }
.log-filter-input {
    padding: .32rem .65rem;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: .88rem;
    background: var(--card);
    color: var(--text);
    outline: none;
    width: 180px;
}
.log-filter-input:focus { border-color: var(--primary); }
.log-count { font-size: .82rem; color: var(--muted); margin-left: auto; }

.log-table-wrap { overflow-x: auto; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,.06); }
.log-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    font-size: .88rem;
    min-width: 420px;
}
.log-table thead th {
    background: #f8f9fb;
    text-align: left;
    padding: .7rem 1rem;
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    border-bottom: 1.5px solid var(--border);
}
.log-table tbody tr { border-bottom: 1px solid var(--border); }
.log-table tbody tr:last-child { border-bottom: none; }
.log-table tbody tr:hover { background: #fafafa; }
.log-table td { padding: .65rem 1rem; vertical-align: middle; }
.log-table td:first-child {
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    white-space: nowrap;
    font-size: .82rem;
}
.log-table td:nth-child(2) { font-weight: 600; }

.log-badge {
    display: inline-block;
    padding: .18rem .55rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 700;
}
.log-badge-login        { background: #d1fae5; color: #065f46; }
.log-badge-logout       { background: #fee2e2; color: #991b1b; }
.log-badge-login_failed { background: #fef3c7; color: #92400e; }
.log-badge-other        { background: var(--border); color: var(--muted); }

.log-empty {
    text-align: center;
    color: var(--muted);
    padding: 3rem 1rem;
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,.06);
}

/* also accept file input fallback */
.paste-file-label {
    font-size: .72rem;
    color: var(--primary);
    cursor: pointer;
    text-decoration: underline;
}
.paste-file-input { display: none; }

/* ── Account page ───────────────────────────────────── */
.account-cards {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-width: 520px;
}
.account-card {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,.06);
    padding: 1.5rem;
}
.account-card-title {
    font-size: .95rem;
    font-weight: 700;
    margin-bottom: 1rem;
    padding-bottom: .65rem;
    border-bottom: 1.5px solid var(--border);
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.account-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .5rem 0;
    font-size: .9rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
}
.account-info-row:last-of-type { border-bottom: none; margin-bottom: .25rem; }
.account-info-label { color: var(--muted); font-weight: 500; flex-shrink: 0; }
.account-info-value { font-weight: 600; text-align: right; word-break: break-word; }

/* ── Push notification UI ──────────────────────────────── */
.push-row { display: flex; align-items: center; gap: .75rem; margin-bottom: .9rem; }
.push-label { font-size: .82rem; color: var(--muted); font-weight: 500; min-width: 48px; }
.push-status-val { font-size: .85rem; font-weight: 600; }
.push-status-on  { color: var(--ok); }
.push-status-off { color: var(--muted); }
.push-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.push-btn { font-size: .85rem; padding: .45rem 1rem; }
.btn-secondary {
    display: inline-flex; align-items: center; justify-content: center;
    padding: .55rem 1.1rem; background: var(--card);
    border: 1.5px solid var(--border); border-radius: 8px;
    font-size: .9rem; font-weight: 600; color: var(--text);
    cursor: pointer; transition: border-color .15s, color .15s;
    font-family: inherit;
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.push-result {
    margin-top: .85rem; padding: .5rem .85rem;
    border-radius: 7px; font-size: .83rem; font-weight: 500;
}
.push-result-ok  { background: var(--ok-bg);     color: var(--ok);     border: 1px solid var(--ok-border); }
.push-result-err { background: var(--danger-bg);  color: var(--danger); border: 1px solid #fecaca; }

/* ── Users page ─────────────────────────────────────── */
.users-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: .75rem;
}
.users-count { font-size: .85rem; color: var(--muted); }

.users-table-wrap { overflow-x: auto; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,.06); }
.users-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    font-size: .88rem;
    min-width: 540px;
}
.users-table thead th {
    background: #f8f9fb;
    text-align: left;
    padding: .7rem 1rem;
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    border-bottom: 1.5px solid var(--border);
}
.users-table tbody tr { border-bottom: 1px solid var(--border); }
.users-table tbody tr:last-child { border-bottom: none; }
.users-table tbody tr:hover { background: #fafafa; }
.users-table td { padding: .65rem 1rem; vertical-align: middle; }
.users-td-username { font-weight: 600; }
.users-td-date { font-size: .82rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.users-td-actions { white-space: nowrap; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; padding-top: .5rem; padding-bottom: .5rem; }

.badge-admin {
    display: inline-block;
    padding: .18rem .55rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    background: #ede9fe;
    color: #4f46e5;
}

.btn-user-action {
    padding: .28rem .65rem;
    border-radius: 6px;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    border: 1.5px solid var(--border);
    background: var(--card);
    color: var(--text);
    transition: background .15s, border-color .15s;
    font-family: inherit;
}
.btn-user-edit:hover { background: #ede9fe; border-color: #a5b4fc; color: var(--primary); }
.btn-user-del:hover  { background: #fee2e2; border-color: #fca5a5; color: var(--danger); }

.user-del-confirm {
    display: none;
    align-items: center;
    gap: .35rem;
    font-size: .78rem;
    color: var(--muted);
}
.user-del-confirm.show { display: inline-flex; }

.user-self-tag { font-size: .75rem; color: var(--muted); padding: .28rem .2rem; }

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
}

/* ── Control Scheduler ──────────────────────────────── */
.ctrl-view-bar {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin: .25rem 0 1rem;
    justify-content: flex-end;
}
.ctrl-simplified .ctrl-adv-only { display: none !important; }
.ctrl-scheduler { display: flex; flex-direction: column; gap: 1rem; margin-top: 1.5rem; }

.ctrl-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
}
.ctrl-card-title {
    font-size: .9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    margin-bottom: .65rem;
}
.ctrl-card-desc {
    font-size: .8rem;
    color: var(--muted);
    margin: -.2rem 0 .75rem;
    line-height: 1.5;
}

/* ── Top card: chart + device controls ─────────────────── */
.ctrl-top-card {
    display: flex;
    align-items: stretch;
    gap: 1.5rem;
    margin-bottom: 1rem;
}
.ctrl-top-chart { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ctrl-top-chart-inner { flex: 1; min-height: 160px; position: relative; }
.ctrl-top-devctl {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: .9rem;
    min-width: 110px; padding: .5rem 0;
    border-left: 1px solid var(--border);
    padding-left: 1.25rem;
}
@media (max-width: 540px) {
    .ctrl-top-card { flex-direction: column; }
    .ctrl-top-devctl { flex-direction: row; border-left: none; border-top: 1px solid var(--border); padding: .75rem 0 0; }
}

/* ── Large toggle variant ─────────────────────────────── */
.dev-toggle.dev-toggle-lg { width: 64px; height: 36px; }
.dev-toggle-lg .dev-toggle-slider { border-radius: 36px; }
.dev-toggle-lg .dev-toggle-slider::before { width: 26px; height: 26px; left: 5px; bottom: 5px; }
.dev-toggle-lg .dev-toggle-input:checked + .dev-toggle-slider::before { transform: translateX(28px); }

/* ── Force ON button ──────────────────────────────────── */
.ctrl-btn-force {
    padding: .45rem .9rem;
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: .82rem;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
    font-family: inherit;
    white-space: nowrap;
}
.ctrl-btn-force:hover { border-color: var(--primary); color: var(--primary); background: #ede9fe; }
.ctrl-btn-force.ctrl-btn-force-active { background: #fef3c7; border-color: #f59e0b; color: #92400e; }
.ctrl-btn-force.ctrl-btn-force-active:hover { background: #fde68a; }

/* 24-hour slot selector grid */
.ctrl-grid-outer { overflow-x: auto; }
.ctrl-hour-strip {
    display: grid;
    grid-template-columns: repeat(48, minmax(0, 1fr));
    min-width: 768px;
    margin-bottom: 2px;
}
.ctrl-hour-lbl {
    font-size: .62rem;
    color: var(--muted);
    padding-left: 1px;
    user-select: none;
}
.ctrl-hour-lbl.ctrl-midnight { color: var(--text); font-weight: 600; padding-left: 3px; }
.ctrl-grid {
    display: grid;
    grid-template-columns: repeat(192, minmax(0, 1fr));
    gap: 1px;
    min-width: 768px;
    cursor: pointer;
    user-select: none;
    touch-action: none;
}
.ctrl-cell {
    height: 34px;
    background: var(--border);
    border-radius: 2px;
    transition: background .07s;
}
.ctrl-cell.selected { background: var(--primary); }
.ctrl-cell:hover { filter: brightness(1.12); }
.ctrl-cell.ctrl-disabled { background: #9d1e24 !important; cursor: not-allowed; }
.ctrl-cell.ctrl-disabled:hover { filter: none; }
/* Every other hour (slots 4-7, 12-15, …) slightly darker */
.ctrl-grid .ctrl-cell:nth-child(8n+5),
.ctrl-grid .ctrl-cell:nth-child(8n+6),
.ctrl-grid .ctrl-cell:nth-child(8n+7),
.ctrl-grid .ctrl-cell:nth-child(8n+8) { background: #d1d5db; }
.ctrl-grid .ctrl-cell.selected:nth-child(8n+5),
.ctrl-grid .ctrl-cell.selected:nth-child(8n+6),
.ctrl-grid .ctrl-cell.selected:nth-child(8n+7),
.ctrl-grid .ctrl-cell.selected:nth-child(8n+8) { background: var(--primary-d); }
/* Hard boundary after every 4th cell to prevent colour bleed across hours */
.ctrl-grid .ctrl-cell:nth-child(4n) { border-right: 2px solid var(--card); }
.ctrl-zoom-btns { display: inline-flex; gap: .25rem; margin-left: auto; }
.ctrl-time-range {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-top: .6rem;
}
.ctrl-time-range input[type="time"] {
    padding: .3rem .5rem;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: .85rem;
    background: var(--card);
    color: var(--text);
    outline: none;
    width: 8rem;
}
.ctrl-time-range input[type="time"]:focus { border-color: var(--primary); }
.ctrl-tr-sep { color: var(--muted); font-size: .9rem; }
.ctrl-cell[data-slot="96"] { border-left: 2px solid rgba(0,0,0,0.18); }
.ctrl-span-warn { font-size: .8rem; color: var(--danger); margin-top: .35rem; }

.ctrl-grid-footer {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-top: .55rem;
    flex-wrap: wrap;
}
.ctrl-btn-sm {
    font-size: .75rem;
    padding: .22rem .65rem;
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
    font-family: inherit;
}
.ctrl-btn-sm:hover { background: var(--border); }
.ctrl-sel-count {
    font-size: .75rem;
    color: var(--muted);
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}

/* Device on/off toggle */
.dev-toggle { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.dev-toggle-input { opacity: 0; width: 0; height: 0; position: absolute; }
.dev-toggle-slider {
    position: absolute; cursor: pointer;
    inset: 0; background: #cbd5e1; border-radius: 22px; transition: background .2s;
}
.dev-toggle-slider::before {
    content: ''; position: absolute;
    width: 16px; height: 16px; left: 3px; bottom: 3px;
    background: #fff; border-radius: 50%; transition: transform .2s;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.dev-toggle-input:checked + .dev-toggle-slider { background: var(--ok); }
.dev-toggle-input:checked + .dev-toggle-slider::before { transform: translateX(16px); }
.dev-toggle-input:disabled + .dev-toggle-slider { opacity: .55; cursor: not-allowed; }
.dev-toggle.state-off .dev-toggle-slider { background: #b56060; }
.dev-toggle.state-querying .dev-toggle-slider { background: #b0b8c4; animation: toggle-pulse .8s ease-in-out infinite alternate; }
@keyframes toggle-pulse { from { opacity: 1; } to { opacity: .5; } }

/* Device status response row */
.dev-status-td { padding: .5rem 1rem; background: var(--bg); border-top: 1px solid var(--border); }
.dev-status-pre { margin: 0; font-size: .78rem; font-family: monospace; white-space: pre-wrap; word-break: break-all; max-height: 180px; overflow-y: auto; }
.dev-status-err { font-size: .82rem; color: var(--danger); }

/* Device query result box (in edit modal) */
.dev-query-result {
    flex-direction: column; gap: .3rem;
    margin-top: .75rem; padding: .75rem 1rem;
    background: var(--bg); border: 1.5px solid var(--border); border-radius: 7px;
    font-size: .85rem;
}
.dev-query-label { font-weight: 600; font-size: .73rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.dev-query-url { display: block; font-family: monospace; font-size: .8rem; word-break: break-all; color: var(--text); background: var(--card); padding: .3rem .55rem; border-radius: 5px; border: 1px solid var(--border); }
.dev-query-loading { font-size: .82rem; color: var(--muted); font-style: italic; }
.btn-dev-query { padding: .55rem .9rem; font-size: .85rem; font-weight: 600; border: 1.5px solid var(--border); border-radius: 7px; background: var(--card); color: var(--text); cursor: pointer; white-space: nowrap; flex-shrink: 0; transition: background .15s, border-color .15s; }
.btn-dev-query:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }

/* Device assignment card */
.ctrl-device-card { margin-top: 1rem; }
.ctrl-device-row {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    flex-wrap: wrap;
}
.ctrl-device-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: .25rem;
    min-width: 180px;
}
.ctrl-device-select {
    min-width: 200px;
    padding: .5rem .75rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: .9rem;
    background: var(--card);
    color: var(--text);
    outline: none;
    cursor: pointer;
}
.ctrl-device-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }
.ctrl-no-devices { font-size: .82rem; color: var(--muted); font-style: italic; }

/* Auto-selection rules */
.ctrl-rules { display: flex; flex-direction: column; gap: .9rem; margin-bottom: 1rem; }
.ctrl-rule-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding: .75rem;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}
.ctrl-rule-info { flex: 1; min-width: 180px; }
.ctrl-rule-name { display: block; font-size: .88rem; font-weight: 600; color: var(--text); }
.ctrl-rule-desc { display: block; font-size: .75rem; color: var(--muted); margin-top: .2rem; line-height: 1.4; }
.ctrl-rule-field { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }
.ctrl-input {
    width: 80px;
    padding: .35rem .5rem;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: .9rem;
    background: var(--card);
    color: var(--text);
    text-align: right;
}
.ctrl-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }
.ctrl-unit { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.ctrl-save-btn { width: auto; padding: .6rem 1.75rem; display: inline-block; }

/* Active periods preview */
.ctrl-preview-card { margin-top: 0; }
.ctrl-preview-outer { overflow-x: auto; }
.ctrl-preview-scroll { display: inline-block; }
.ctrl-prev-cell {
    width: 10px;
    height: 26px;
    border-radius: 2px;
    flex-shrink: 0;
    cursor: default;
}
.ctrl-ps   { background: #22c55e; }
.ctrl-pw   { background: #93c5fd; }
.ctrl-pn   { background: #e5e7eb; }
.ctrl-past { opacity: .38; }
.ctrl-preview-legend {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: .85rem;
}
.ctrl-legend-item {
    display: flex;
    align-items: center;
    gap: .35rem;
    font-size: .75rem;
    color: var(--muted);
}
.ctrl-legend-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}
.ctrl-past-swatch { background: #e5e7eb; opacity: .38; }

/* ── Multi-period controls ──────────────────────────── */
.ctrl-period-card { margin-bottom: 0; }

.ctrl-period-header {
    display: flex;
    align-items: center;
    gap: .75rem;
}
.ctrl-period-name {
    flex: 1;
    padding: .4rem .65rem;
    border: 1.5px solid var(--border);
    border-radius: 7px;
    font-size: .95rem;
    font-weight: 600;
    color: var(--text);
    background: var(--bg);
    outline: none;
    min-width: 0;
}
.ctrl-period-name:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }

.ctrl-period-del {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    background: transparent;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    color: var(--muted);
    cursor: pointer;
    font-size: .8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background .15s, border-color .15s, color .15s;
    font-family: inherit;
}
.ctrl-period-del:hover { background: #fee2e2; border-color: #fca5a5; color: var(--danger); }

.ctrl-bottom-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    flex-wrap: wrap;
    padding: .5rem 0;
}
.ctrl-bottom-actions { display: flex; gap: .6rem; }

.ctrl-btn-addperiod {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .5rem 1rem;
    background: var(--card);
    border: 1.5px dashed var(--primary);
    border-radius: 8px;
    font-size: .88rem;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    transition: background .15s;
    font-family: inherit;
}
.ctrl-btn-addperiod:hover { background: #ede9fe; }

.ctrl-btn-preview {
    padding: .55rem 1.1rem;
    background: var(--card);
    border: 1.5px solid var(--primary);
    border-radius: 8px;
    font-size: .88rem;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    transition: background .15s;
    font-family: inherit;
}
.ctrl-btn-preview:hover { background: #ede9fe; }

.ctrl-btn-savesched {
    padding: .55rem 1.4rem;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    font-size: .88rem;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
    transition: background .15s;
    font-family: inherit;
}
.ctrl-btn-savesched:hover { background: var(--primary-d); }

/* ── Slot price list ────────────────────────────────── */
.ctrl-pricelist-period { margin-bottom: 1.25rem; }
.ctrl-pricelist-period:last-child { margin-bottom: 0; }
.ctrl-pricelist-period-name {
    font-size: .78rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: .5rem;
}
.ctrl-pricelist-empty { font-size: .82rem; color: var(--muted); margin: 0; }
.ctrl-pricelist-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .82rem;
}
.ctrl-pricelist-table thead th {
    text-align: left;
    padding: .3rem .6rem;
    font-size: .72rem;
    font-weight: 600;
    color: var(--muted);
    border-bottom: 1.5px solid var(--border);
}
.ctrl-pricelist-table tbody tr td {
    padding: .28rem .6rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    white-space: nowrap;
}
.ctrl-pricelist-table tbody tr:last-child td { border-bottom: none; }
.ctrl-pricelist-table tbody tr.ctrl-pla { background: #f0fdf4; }
.ctrl-pricelist-table tbody tr.ctrl-plp td { color: var(--muted); }
.ctrl-pricelist-table tbody tr.ctrl-pla.ctrl-plp { background: #f0fdf4; }
.ctrl-pl-check {
    display: inline-block;
    font-size: .85rem;
    font-weight: 700;
    color: #16a34a;
}
.ctrl-pl-badge {
    display: inline-block;
    padding: .1rem .42rem;
    border-radius: 99px;
    font-size: .68rem;
    font-weight: 700;
    margin-right: .25rem;
    white-space: nowrap;
}
.ctrl-pricelist-table tbody tr.ctrl-pl-current { background: #f0fdf4; outline: 2px solid #22c55e; outline-offset: -2px; }
.ctrl-pricelist-table tbody tr.ctrl-pl-current.ctrl-plm { background: #dcfce7; }
.ctrl-pl-cheap     { background: #dbeafe; color: #1d4ed8; }
.ctrl-pl-threshold { background: #fef3c7; color: #92400e; }
.ctrl-pl-tolerance { background: #ede9fe; color: #5b21b6; }
.ctrl-pl-manual    { background: #fef9c3; color: #854d0e; }
.ctrl-pricelist-table tbody tr.ctrl-plm { background: #fef9c3; }
.ctrl-pricelist-table tbody tr.ctrl-pla.ctrl-plm { background: #dcfce7; }
.ctrl-pl-ov {
    font-size: .75rem;
    padding: .2rem .55rem;
    border: 1px solid var(--primary);
    border-radius: 4px;
    background: transparent;
    color: var(--primary);
    cursor: pointer;
    white-space: nowrap;
}
.ctrl-pl-ov:hover { background: var(--primary); color: #fff; }
.ctrl-pl-ov-cancel { border-color: #dc2626; color: #dc2626; }
.ctrl-pl-ov-cancel:hover { background: #dc2626; color: #fff; }
.ctrl-pl-ov-forceoff { border-color: #d97706; color: #d97706; }
.ctrl-pl-ov-forceoff:hover { background: #d97706; color: #fff; }
.ctrl-pl-ov-allow { border-color: #16a34a; color: #16a34a; }
.ctrl-pl-ov-allow:hover { background: #16a34a; color: #fff; }
.ctrl-pricelist-table tbody tr.ctrl-plfo td { color: var(--muted); text-decoration: line-through; opacity: .65; }

/* ── Files page ─────────────────────────────────────────────── */
.files-toolbar {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.btn-add-secondary { background: var(--card); color: var(--text); border: 1.5px solid var(--border); }
.btn-add-secondary:hover { background: var(--bg); }

.files-breadcrumbs {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .3rem;
    font-size: .85rem;
    margin-bottom: 1rem;
}
.files-crumb { color: var(--primary); text-decoration: none; }
.files-crumb:hover { text-decoration: underline; }
.files-crumb-current { color: var(--muted); font-weight: 600; pointer-events: none; }
.files-crumb-sep { color: var(--muted); }

.files-list-wrap { overflow-x: auto; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,.06); }
.files-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    font-size: .88rem;
    min-width: 420px;
}
.files-table thead th {
    background: #f8f9fb;
    text-align: left;
    padding: .7rem 1rem;
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    border-bottom: 1.5px solid var(--border);
}
.files-table tbody tr { border-bottom: 1px solid var(--border); }
.files-table tbody tr:last-child { border-bottom: none; }
.files-table tbody tr:hover { background: #fafafa; }
.files-table td { padding: .6rem 1rem; vertical-align: middle; }
.files-muted { color: var(--muted); white-space: nowrap; }

.files-row-name {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    color: var(--text);
    text-decoration: none;
    word-break: break-word;
}
.files-row-folder { color: var(--primary); font-weight: 600; }
.files-row-folder:hover { text-decoration: underline; }
.files-row-icon { font-size: 1.05rem; flex-shrink: 0; }

.files-row-actions {
    display: flex;
    align-items: center;
    gap: .4rem;
    justify-content: flex-end;
    white-space: nowrap;
}
.files-dl-btn, .files-del-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 1.5px solid var(--border);
    background: var(--card);
    color: var(--muted);
    cursor: pointer;
    text-decoration: none;
    font-size: .8rem;
    transition: background .15s, color .15s, border-color .15s;
}
.files-dl-btn:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.files-del-btn:hover { background: #dc2626; border-color: #dc2626; color: #fff; }

.files-delete-warning { font-size: .85rem; color: var(--muted); margin: -.3rem 0 1rem; }

.files-drop-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 350;
    background: rgba(79,70,229,.12);
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.files-drop-overlay.show { display: flex; }
.files-drop-overlay-inner {
    background: var(--card);
    border: 3px dashed var(--primary);
    border-radius: 16px;
    padding: 2.5rem 3rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    box-shadow: 0 8px 30px rgba(0,0,0,.15);
}
.files-drop-overlay-icon { font-size: 2rem; }

/* Sensors page */
.sensor-block {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,.06);
    padding: 1.25rem 1.4rem;
    margin-bottom: 1.25rem;
}
.sensor-block-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 1rem;
}
.sensor-card-name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    word-break: break-word;
}
.sensor-readings { display: flex; gap: 1.75rem; flex-wrap: wrap; }
.sensor-stat-value { font-size: 1.6rem; font-weight: 800; color: var(--text); line-height: 1.1; }
.sensor-stat-label {
    font-size: .72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-top: .2rem;
}
.sensor-card-updated { font-size: .78rem; color: var(--muted); margin-left: auto; }
.sensor-chart-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .4rem;
}
.sensor-chart-hint { font-size: .75rem; color: var(--muted); }
.sensor-range-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: .6rem;
    font-size: .8rem;
    color: var(--muted);
}
.sensor-range-toolbar label { display: flex; align-items: center; gap: .4rem; }
.sensor-range-toolbar input[type="datetime-local"] {
    padding: .35rem .5rem;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: .82rem;
    background: var(--card);
    color: var(--text);
}
.sensor-chart-wrap {
    height: 280px;
    min-height: 120px;
    max-height: 1200px;
    position: relative;
    touch-action: none; /* the zoom/pan plugin owns all touch gestures on the canvas */
    resize: vertical;   /* native drag handle, bottom-right corner; saved via ResizeObserver in app.js */
    overflow: hidden;   /* required by most browsers for the resize handle to render */
}
.sensor-chart-empty { font-size: .85rem; color: var(--muted); font-style: italic; }
.lora-color-swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(0,0,0,.15); }

/* Session expiry warning */
.session-warning {
    position: fixed;
    top: var(--nav-h); left: 0; right: 0;
    z-index: 500;
    background: #92400e;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: .6rem 1rem;
    font-size: .88rem;
    box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.session-warning.hidden { display: none; }
.session-warning-btn {
    background: #fff;
    color: #92400e;
    border: none;
    border-radius: 6px;
    padding: .35rem .8rem;
    font-size: .82rem;
    font-weight: 700;
    cursor: pointer;
}
.session-warning-dismiss {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 .25rem;
    opacity: .8;
}
.session-warning-dismiss:hover { opacity: 1; }

