* {
    box-sizing: border-box;
}

:root {
    --header-bg: #08283f;
    --header-mid: #0b3552;
    --header-soft: #124765;

    --header-secondary: #e4f0f6;
    --tmd-gold: #f0c63f;

    --page-bg: #e8eef2;
    --panel-bg: #ffffff;

    --border: #ced9df;

    --text: #111b21;
    --secondary: #526a76;

    --accent: #176e98;
    --accent-dark: #0d577a;

    --viewer-bg: #10232c;
}


html,
body {
    margin: 0;
    width: 100%;
    height: 100%;

    font-family:
        "Noto Sans Thai",
        Tahoma,
        Arial,
        sans-serif;

    background: var(--page-bg);
}


body {
    min-height: 100vh;

    display: flex;
    flex-direction: column;

    overflow: hidden;
}


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

.top-header {
    height: 64px;
    flex: 0 0 64px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 20px;

    padding: 0 24px 0 18px;

    color: #fff;

    background:
        linear-gradient(
            110deg,
            var(--header-bg) 0%,
            var(--header-mid) 58%,
            var(--header-soft) 100%
        );

    border-bottom: 3px solid var(--tmd-gold);
}


.header-brand {
    min-width: 295px;

    display: flex;
    align-items: center;

    gap: 10px;
}


.header-logo {
    width: 44px;
    height: 44px;

    object-fit: contain;
}


.header-agency {
    display: flex;
    flex-direction: column;

    line-height: 1.15;
    white-space: nowrap;
}


.header-agency strong {
    font-size: 20px;
    font-weight: 800;
}


.header-agency span {
    margin-top: 3px;

    color: var(--header-secondary);

    font-size: 14px;
    font-weight: 600;
}


.main-nav {
    height: 100%;

    display: flex;
    align-items: stretch;

    gap: 3px;

    white-space: nowrap;
}


.main-nav a {
    display: flex;
    align-items: center;

    padding: 0 15px;

    color: #fff;

    text-decoration: none;

    font-size: 18px;
    font-weight: 600;

    border-bottom: 3px solid transparent;
}


.main-nav a:hover {
    background: rgba(255,255,255,.11);
}


.main-nav a.active {
    background: rgba(255,255,255,.15);

    border-bottom-color: #74d2ff;

    font-weight: 800;
}


/* =========================================================
   WORKSPACE
========================================================= */

.report-workspace {
    flex: 1 1 auto;

    min-height: 0;

    display: grid;

    grid-template-rows:
        auto
        auto
        minmax(0,1fr)
        auto;

    overflow: hidden;
}


/* =========================================================
   CONTROL BAR
========================================================= */

.report-controls {
    min-height: 59px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 20px;

    padding: 8px 18px;

    background: #fff;

    border-bottom: 1px solid var(--border);
}


.report-title {
    display: flex;
    align-items: baseline;

    gap: 12px;

    min-width: 0;
}


.report-title strong {
    color: var(--text);

    font-size: 19px;
    font-weight: 900;

    white-space: nowrap;
}


.report-title span {
    color: var(--secondary);

    font-size: 13px;
    font-weight: 700;

    white-space: nowrap;
}


.report-actions {
    display: flex;
    align-items: center;

    gap: 10px;
}


.latest-button {
    min-height: 36px;

    padding: 6px 14px;

    border: 1px solid var(--accent);
    border-radius: 5px;

    background: var(--accent);

    color: #fff;

    font-family: inherit;
    font-size: 14px;
    font-weight: 800;

    cursor: pointer;
}


.latest-button:hover {
    background: var(--accent-dark);
}


.archive-control {
    min-height: 36px;

    display: flex;
    align-items: center;

    gap: 7px;

    padding-left: 10px;

    border: 1px solid var(--border);
    border-radius: 5px;

    background: #f7fafb;
}


.archive-control > span {
    color: #3d555f;

    font-size: 13px;
    font-weight: 800;
}


.archive-control select {
    height: 34px;

    max-width: 175px;

    padding: 0 9px;

    border: 0;
    border-left: 1px solid var(--border);

    outline: none;

    background: #fff;

    color: #17262d;

    font-family: inherit;
    font-size: 13px;
    font-weight: 700;

    cursor: pointer;
}


/* =========================================================
   REPORT CYCLE
========================================================= */

.cycle-panel {
    padding: 7px 14px;

    background: #f3f7f9;

    border-bottom: 1px solid var(--border);
}


.cycle-buttons {
    display: flex;
    align-items: stretch;
    justify-content: center;

    flex-wrap: wrap;

    gap: 6px;
}


.cycle-day {
    display: flex;
    align-items: center;

    gap: 5px;

    padding: 3px 5px;
}


.cycle-date {
    min-width: 73px;

    color: #445d68;

    font-size: 12px;
    font-weight: 900;

    text-align: right;
}


.cycle-date.active {
    padding: 7px 9px;

    border-radius: 4px;

    background: var(--accent);
    color: #fff;

    box-shadow:
        inset 3px 0 0 rgba(255, 255, 255, .30),
        0 1px 3px rgba(0, 0, 0, .15);
}


.time-button {
    min-width: 62px;
    height: 32px;

    padding: 4px 9px;

    border: 1px solid #b9cbd3;
    border-radius: 4px;

    background: #fff;

    color: #17262d;

    font-family: inherit;
    font-size: 13px;
    font-weight: 800;

    cursor: pointer;
}


.time-button:hover:not(:disabled) {
    border-color: #438cac;

    background: #edf7fb;
}


.time-button.active {
    border-color: var(--accent);

    background: var(--accent);

    color: #fff;
}


.time-button:disabled {
    opacity: .35;
    cursor: default;
}


/* =========================================================
   VIEWER
========================================================= */

.report-viewer {
    position: relative;

    min-width: 0;
    min-height: 0;

    overflow: hidden;

    background:
        radial-gradient(
            circle at center,
            #29434f 0%,
            var(--viewer-bg) 75%
        );
}


.image-stage {
    position: absolute;

    inset: 7px;

    display: flex;
    align-items: center;
    justify-content: center;

    overflow: hidden;

    cursor: zoom-in;

    touch-action: none;
}


.image-stage.zoomed {
    cursor: grab;
}


.image-stage.dragging {
    cursor: grabbing;
}


#reportImage {
    display: none;

    width: auto;
    height: auto;

    max-width: 100%;
    max-height: 100%;

    object-fit: contain;

    transform-origin: center center;

    will-change: transform;

    user-select: none;
    -webkit-user-drag: none;
}


#reportImage.ready {
    display: block;
}


.viewer-message {
    position: absolute;

    z-index: 20;

    left: 50%;
    top: 50%;

    transform: translate(-50%, -50%);

    color: #e2edf2;

    font-size: 15px;
    font-weight: 700;

    text-align: center;

    pointer-events: none;
}


.viewer-message.hidden {
    display: none;
}


/* =========================================================
   ZOOM TOOLBAR
========================================================= */

.zoom-toolbar {
    position: absolute;

    z-index: 30;

    right: 16px;
    bottom: 16px;

    display: flex;
    align-items: center;

    gap: 5px;

    padding: 6px;

    border: 1px solid rgba(255,255,255,.25);
    border-radius: 7px;

    background: rgba(4,24,34,.88);

    box-shadow: 0 3px 14px rgba(0,0,0,.25);

    backdrop-filter: blur(4px);
}


.zoom-toolbar button {
    height: 34px;

    min-width: 38px;

    padding: 0 10px;

    border: 1px solid rgba(255,255,255,.22);
    border-radius: 5px;

    background: rgba(255,255,255,.09);

    color: #fff;

    font-family: inherit;
    font-size: 18px;
    font-weight: 900;

    cursor: pointer;
}


.zoom-toolbar button:hover {
    background: rgba(255,255,255,.18);
}


.zoom-toolbar .zoom-level {
    min-width: 64px;

    font-size: 13px;
}


.zoom-toolbar .fit-button {
    min-width: 98px;

    font-size: 13px;
}


.zoom-separator {
    width: 1px;
    height: 24px;

    margin: 0 2px;

    background: rgba(255,255,255,.25);
}


.zoom-hint {
    position: absolute;

    z-index: 25;

    left: 16px;
    bottom: 17px;

    padding: 6px 10px;

    border-radius: 5px;

    background: rgba(4,24,34,.72);

    color: #e4eef3;

    font-size: 12px;
    font-weight: 700;

    pointer-events: none;

    transition:
        opacity .25s ease,
        visibility .25s ease;
}


.zoom-hint.hidden {
    opacity: 0;
    visibility: hidden;
}


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

.report-status {
    min-height: 42px;

    display: flex;
    align-items: center;
    justify-content: center;

    gap: 15px;

    padding: 5px 15px;

    background: #fff;

    border-top: 1px solid var(--border);
}


.status-item {
    display: flex;
    align-items: baseline;

    gap: 6px;
}


.status-item span {
    color: #617781;

    font-size: 12px;
    font-weight: 700;
}


.status-item strong {
    color: #16272f;

    font-size: 13px;
    font-weight: 900;
}


.status-divider {
    width: 1px;
    height: 18px;

    background: #d0dce1;
}


/* =========================================================
   SHORT DESKTOP
========================================================= */

@media (min-width: 1001px) and (max-height: 850px) {

    .top-header {
        height: 60px;
        flex-basis: 60px;
    }

    .header-logo {
        width: 42px;
        height: 42px;
    }

    .header-agency strong {
        font-size: 19px;
    }

    .main-nav a {
        font-size: 17px;
    }

    .report-controls {
        min-height: 52px;
    }

    .cycle-panel {
        padding-top: 5px;
        padding-bottom: 5px;
    }

    .report-status {
        min-height: 38px;
    }

}


/* =========================================================
   TABLET
========================================================= */

@media (max-width: 1100px) {

    .main-nav a {
        padding-left: 8px;
        padding-right: 8px;

        font-size: 15px;
    }

}


/* =========================================================
   MOBILE / SMALL TABLET
========================================================= */

@media (max-width: 850px) {

    body {
        overflow: auto;
    }

    .top-header {
        height: auto;
        flex-basis: auto;

        flex-wrap: wrap;

        padding: 7px 12px 0;
    }

    .main-nav {
        width: 100%;
        height: 40px;

        overflow-x: auto;
    }

    .main-nav a {
        flex: 0 0 auto;
    }

    .report-workspace {
        display: flex;
        flex-direction: column;

        overflow: visible;
    }

    .report-controls {
        align-items: flex-start;
        flex-direction: column;

        gap: 8px;
    }

    .report-title {
        align-items: flex-start;
        flex-direction: column;

        gap: 1px;
    }

    .report-actions {
        width: 100%;

        justify-content: space-between;
    }

    .cycle-buttons {
        justify-content: flex-start;
    }

    .report-viewer {
        height: 65vh;
        min-height: 430px;
    }

}


/* =========================================================
   MOBILE
========================================================= */

@media (max-width: 560px) {

    .header-brand {
        min-width: 0;
    }

    .header-logo {
        width: 40px;
        height: 40px;
    }

    .header-agency strong {
        font-size: 18px;
    }

    .header-agency span {
        font-size: 12px;
    }

    .report-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .archive-control {
        justify-content: space-between;
    }

    .archive-control select {
        flex: 1;
        max-width: none;
    }

    .cycle-day {
        width: 100%;

        flex-wrap: wrap;
    }

    .cycle-date {
        width: 100%;

        text-align: left;
    }

    .report-status {
        flex-wrap: wrap;

        gap: 7px 12px;
    }

    .zoom-toolbar {
        right: 8px;
        bottom: 8px;
    }

    .zoom-toolbar .fit-button {
        min-width: 75px;

        font-size: 11px;
    }

    .zoom-hint {
        display: none;
    }

}
