:root {
    --brand: #0B1F3A;
    --brand-2: #16345E;
    --accent: #E53935;
    --blue: #1E88E5;
    --green: #2E9E5B;
    --amber: #F59E0B;
    --bg: #F2F5FA;
    --card: #FFFFFF;
    --text: #1A2433;
    --muted: #6B7A90;
    --border: #E3E8F0;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 32, 64, .06), 0 4px 16px rgba(16, 32, 64, .06);
    --header-h: 56px;
}

* {
    box-sizing: border-box;
}

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

body {
    /* safety net: nothing may push the page sideways on phones (clip keeps the sticky header working) */
    overflow-x: clip;
    background: var(--bg);
    color: var(--text);
    font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

/* ---------- Header (sits under the iPhone notch / status bar) ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: calc(var(--header-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) calc(16px + env(safe-area-inset-right)) 0 calc(16px + env(safe-area-inset-left));
    background: linear-gradient(90deg, var(--brand), var(--brand-2));
    color: #fff;
    border-bottom: 3px solid var(--accent);
}

.app-logo {
    width: 34px;
    height: 34px;
    border-radius: 8px;
}

.app-title {
    margin: 0;
    font-size: 18px;
    font-weight: 500;
    white-space: nowrap;
}

.net-status {
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--accent);
    font-size: 12px;
}

/* ---------- Menu button + side menu ---------- */
.menu-button {
    flex: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 40px;
    height: 40px;
    margin-left: -8px;
    padding: 0 9px;
    border: 0;
    border-radius: 10px;
    background: none;
    cursor: pointer;
}

.menu-button[hidden] {
    display: none;
}

.menu-button span {
    display: block;
    height: 2px;
    border-radius: 2px;
    background: #fff;
}

.menu-button:hover {
    background: rgba(255, 255, 255, .12);
}

.menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1990;
    background: rgba(11, 31, 58, .45);
}

.menu-backdrop[hidden] {
    display: none;
}

.side-menu {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    width: min(300px, 84vw);
    padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: var(--card);
    box-shadow: 4px 0 24px rgba(11, 31, 58, .25);
    transform: translateX(-105%);
    transition: transform .22s ease;
}

.side-menu.open {
    transform: none;
}

.menu-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 18px 18px;
    background: linear-gradient(135deg, var(--brand), var(--brand-2));
    border-bottom: 3px solid var(--accent);
    color: #fff;
}

.menu-user .avatar {
    border: 2px solid rgba(255, 255, 255, .85);
}

.menu-user-text {
    min-width: 0;
}

.menu-user-name {
    font-size: 16px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu-user-code {
    font-size: 12px;
    opacity: .75;
}

.menu-nav {
    flex: 1;
    padding: 10px 8px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 12px 14px;
    border: 0;
    border-radius: 10px;
    background: none;
    color: var(--text);
    font: inherit;
    font-size: 15px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.menu-item i {
    font-size: 20px;
    color: var(--muted);
}

.menu-item:hover {
    background: var(--bg);
}

.menu-item.active {
    background: #E6EEFB;
    color: var(--brand-2);
    font-weight: 500;
}

.menu-item.active i {
    color: var(--blue);
}

.menu-signout {
    width: auto;
    margin: 8px;
    border-top: 1px solid var(--border);
    border-radius: 0 0 10px 10px;
    color: var(--accent);
}

.menu-signout i {
    color: var(--accent);
}

/* Nothing is shown until the user has signed in */
/* (opacity, not visibility: DevExtreme charts set visibility on their own SVG text) */
body:not(.signed-in) .app-main {
    opacity: 0;
    pointer-events: none;
}

/* ---------- Layout ---------- */
.app-main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 16px calc(16px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.view {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.view[hidden] {
    display: none;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    min-width: 0;
}

.card h2 {
    margin: 0 0 10px;
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
}

/* ---------- Filters ---------- */
.filter-presets {
    margin-bottom: 12px;
    max-width: 100%;
}

/* The four preset buttons share the full width equally */
.filter-presets .dx-buttongroup-wrapper {
    display: flex;
    width: 100%;
}

.filter-presets .dx-buttongroup-item {
    flex: 1 1 0;
    min-width: 0;
}

.filter-presets .dx-button-content {
    padding-left: 4px;
    padding-right: 4px;
}

.filter-presets .dx-button-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (min-width: 600px) {
    .filter-presets { max-width: 520px; }
}

@media (max-width: 599px) {
    .filter-presets .dx-button-text { font-size: 12px; letter-spacing: 0; }
    .snap-thumb { width: 40px; height: 40px; }
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
}

.filter-item label {
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.filter-wide {
    grid-column: 1 / -1;
}

.filter-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

@media (min-width: 900px) {
    .filter-grid {
        grid-template-columns: 170px 170px minmax(220px, 1fr) 200px auto;
    }
    .filter-wide,
    .filter-actions {
        grid-column: auto;
    }
}

/* ---------- KPI cards ---------- */
.kpis {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

/* Phones: icon above the number so three cards fit side by side */
@media (max-width: 599px) {
    .kpis { gap: 8px; }
    .kpi { flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; }
    .kpi-icon { width: 34px; height: 34px; border-radius: 10px; }
    .kpi-icon i { font-size: 17px; }
    .kpi-value { font-size: 20px; }
}

.kpi {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 0;
}

.kpi-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    color: #fff;
}

.kpi-icon i {
    font-size: 20px;
}

.kpi-total .kpi-icon { background: var(--brand-2); }
.kpi-staff .kpi-icon { background: var(--blue); }
.kpi-last .kpi-icon  { background: var(--amber); }

.kpi-value {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kpi-label {
    font-size: 12px;
    color: var(--muted);
}

/* ---------- Charts ---------- */
.charts {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
}

/* Tablet: hours full width, then presence + type side by side, then devices full width */
@media (min-width: 900px) {
    .charts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .chart-hours,
    .chart-devices { grid-column: 1 / -1; }
}

/* Desktop: hours (wide) + presence + type on one row, devices below */
@media (min-width: 1300px) {
    .charts { grid-template-columns: 2fr 1fr 1fr; }
    .chart-hours { grid-column: auto; }
}

.chart-hint {
    margin-left: 6px;
    font-size: 12px;
    font-weight: 400;
    color: var(--muted);
}

/* ---------- Presence staff list ---------- */
.presence-list .dx-list-item-content {
    padding: 10px 12px;
}

.presence-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.presence-item .cell-person-text {
    flex: 1;
}

.presence-time {
    flex: none;
    text-align: right;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

.presence-time b {
    display: block;
    font-size: 14px;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.chart-card > div {
    height: 260px;
}

/* ---------- Records grid ---------- */
.grid-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.grid-head h2 {
    margin: 0;
}

.live {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--muted);
}

#grid {
    margin-top: 10px;
}

#grid .dx-datagrid-rowsview .dx-row > td {
    vertical-align: middle;
}

#grid .dx-data-row {
    cursor: pointer;
}

.cell-person {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.cell-person-text {
    min-width: 0;
}

.cell-person-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cell-person-code,
.cell-sub {
    font-size: 12px;
    color: var(--muted);
}

.avatar {
    flex: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    background: #DCE3EE;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--brand-2);
}

.snap-thumb {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    object-fit: cover;
    background: #EEF2F7;
    display: block;
}

.cell-time {
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.pill-in    { background: #E3F4EA; color: #1F7A45; }
.pill-out   { background: #E6EEFB; color: #1F5AB8; }
.pill-break { background: #FFF3DC; color: #9A6200; }
.pill-other { background: #EEF1F5; color: #4A5668; }

/* ---------- Detail popup ---------- */
.detail {
    display: grid;
    gap: 16px;
}

@media (min-width: 640px) {
    .detail { grid-template-columns: 260px 1fr; }
}

.detail-snap {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    border-radius: 12px;
    background: #EEF2F7;
}

@media (max-width: 639px) {
    .detail-snap { max-height: 48vh; }
}

.detail-no-snap {
    display: grid;
    place-items: center;
    color: var(--muted);
}

.detail-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 16px;
    margin: 0;
    align-content: start;
}

.detail-list dt {
    color: var(--muted);
    font-size: 13px;
}

.detail-list dd {
    margin: 0;
    font-weight: 500;
    word-break: break-word;
}

/* ---------- Live view ---------- */
.live-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.live-head h2 {
    margin-bottom: 4px;
}

.live-note {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
}

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

@media (min-width: 700px) {
    .device-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
}

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

@media (min-width: 1400px) {
    .device-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

.device-card {
    overflow: hidden;
    padding: 0;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease;
}

.device-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 32, 64, .12);
}

.device-media {
    position: relative;
    aspect-ratio: 3 / 4;
    background: #0E1A2C;
}

.device-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.device-media .no-snap {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #8FA0B8;
    font-size: 13px;
}

.device-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(11, 31, 58, .72);
    color: #fff;
    font-size: 11px;
    font-weight: 500;
    backdrop-filter: blur(4px);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9AA5B5;
}

.status-dot.recent { background: #34C759; box-shadow: 0 0 0 3px rgba(52, 199, 89, .25); }
.status-dot.today  { background: var(--amber); }

.device-who {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 24px 10px 8px;
    background: linear-gradient(transparent, rgba(0, 0, 0, .7));
    color: #fff;
    font-size: 12px;
    line-height: 1.35;
}

.device-who b {
    display: block;
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-info {
    padding: 10px 12px 12px;
}

.device-name {
    font-weight: 700;
    font-size: 15px;
}

.device-meta {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 2px;
    font-size: 12px;
    color: var(--muted);
}

.device-detail {
    display: grid;
    gap: 16px;
}

@media (min-width: 640px) {
    .device-detail { grid-template-columns: 300px 1fr; }
}

.device-detail .device-media {
    border-radius: 12px;
    overflow: hidden;
}

@media (max-width: 639px) {
    /* keep the 3:4 picture at most half the screen tall, centered */
    .device-detail .device-media { width: min(100%, 37.5vh); margin: 0 auto; }
}

/* ---------- Options ---------- */
.options-intro,
.options-help {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
}

.options-help {
    margin-top: 6px;
    font-size: 12px;
}

.options-readonly {
    margin: 12px 0 0;
    padding: 10px 12px;
    border-radius: 10px;
    background: #FFF3DC;
    color: #8A5A00;
    font-size: 13px;
}

.options-readonly[hidden] {
    display: none;
}

.options-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    margin-top: 16px;
}

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

.options-preview {
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--bg);
    font-size: 14px;
    line-height: 1.6;
}

.options-preview .warn {
    color: var(--accent);
    font-weight: 500;
}

.options-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

.options-info {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
}

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

/* ---------- Full-size image viewer ---------- */
img.zoomable {
    cursor: zoom-in;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
    background: rgba(5, 12, 24, .97);
    cursor: zoom-out;
}

.lightbox[hidden] {
    display: none;
}

.lightbox figure {
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    max-width: 100%;
    max-height: 100%;
}

/* whole picture, original proportions (no cropping), enlarged to fill the screen */
.lightbox img {
    display: block;
    width: calc(100vw - 32px);
    height: calc(100vh - 110px);
    object-fit: contain;
}

/* Phone held upright: full width, caption right under the picture */
@media (orientation: portrait) {
    .lightbox img {
        height: auto;
        max-height: calc(100vh - 110px);
    }
}

.lightbox figcaption {
    color: #E6EAF0;
    font-size: 14px;
    text-align: center;
}

.lightbox-close {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top));
    right: 12px;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

body.lightbox-open {
    overflow: hidden;
}

/* ---------- New version banner (assets/app.js) ---------- */
.update-banner {
    position: fixed;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    align-items: center;
    gap: 12px;
    width: max-content;
    max-width: calc(100vw - 32px);
    padding: 10px 10px 10px 16px;
    border-radius: 12px;
    background: var(--brand);
    color: #fff;
    font-size: 14px;
    box-shadow: 0 8px 24px rgba(11, 31, 58, .35);
    border-left: 4px solid var(--accent);
}

.update-banner button {
    border: 0;
    cursor: pointer;
    font: inherit;
}

.update-reload {
    padding: 6px 14px;
    border-radius: 8px;
    background: #fff;
    color: var(--brand);
    font-weight: 500;
}

.update-reload:disabled {
    opacity: .7;
    cursor: default;
}

.update-later {
    padding: 0 6px;
    background: none;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    opacity: .8;
}

/* ---------- Login ---------- */
.login-box {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-box p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.login-error {
    color: var(--accent);
    font-size: 13px;
    min-height: 1em;
}
