/* VARIABLES & THEME SETUP */
:root {
    /* Base Colors */
    --bg-body: #2d2d2d;
    --bg-card: #212529;
    --bg-card-header: #2c3034;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --border-color: #373b3e;

    /* Status Colors */
    --color-running: #4caf50;
    --color-off: #ffc107;
    --color-alarm: #d50000;
    --color-mainten: #0dcaf0;
    --color-breakdown: #000000;
    --color-disconnect: #6c757d;
}

/* GLOBAL RESET & BASIC SETUP */
html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-family: "Poppins", sans-serif;
}

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

a {
    text-decoration: none;
    color: inherit;
}

/* DASHBOARD GRID LAYOUT */
.dashboard-container {
    display: grid;
    width: 100%;
    height: calc(100vh - 60px);
    /* Adjust based on navbar height */
    padding: 8px;
    gap: 8px;
    /* grid-template-rows: 45fr 55fr; */
    /* 45% Top, 55% Bottom */
    overflow: hidden;
}

.top-section {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    height: 100%;
    width: 100%;
    min-height: 0;
}

/* Left Panel (Stats) */
.left-stats-panel {
    grid-column: span 1;
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: 8px;
    height: 100%;
    overflow: hidden;
}

/* Right Panel (Visuals) */
.right-visual-panel {
    grid-column: span 2;
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* 2 cols */
    grid-template-rows: 1fr 1fr;
    /* 2 rows */
    gap: 8px;
    height: 100%;
    overflow: hidden;
}

/* GAUGE & CYCLE TIME */
.availability-grid,
.cycletime-grid {
    display: grid;
    grid-auto-flow: column;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 5px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 5px;
    height: 100%;
    overflow: hidden;
}

/* Gauge specific */
.gauge-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid #8d8d8d;
    padding-top: 5px;
    font-weight: bold;
}

.gauge-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    z-index: 2;
    margin-bottom: -5px;
    text-align: center;
    white-space: nowrap;
    width: 100%;
}

.gauge-chart-container {
    width: 100%;
    height: 100%;
    margin-top: -8px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* CYCLE TIME CARD DESIGN */
.ct-card {
    background: linear-gradient(30deg, #2f2f32 0%, #443e1c 100%);
    border-radius: 4px;
    padding: 5px;
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    position: relative;
    overflow: hidden;
    border: 1px solid #444;
}

/* Container Kiri */
.cyc-left {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    padding-top: 2px;
    padding-bottom: 2px;
}

/* Container Kanan */
.cyc-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

/* Title (Cycle Time Line X) */
.ct-title {
    font-size: 1rem;
    color: #ffffff;
    margin-bottom: 5px;
    font-weight: 400;
    letter-spacing: 0.5px;
}

/* Angka Besar (27.5) */
.ct-value {
    font-size: 5rem;
    color: #ffffff;
    font-weight: bold;
    font-family: "Poppins";
}

/* Wrapper Target Hijau */
.ct-target-wrapper {
    padding-top: 5px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

/* Angka Target (28 SEC) */
.ct-target-val {
    font-size: 0.9rem;
    color: #4caf50;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 3px;
    line-height: 1.1;
    font-family: "Oswald", "Arial Narrow", sans-serif;
}

/* Label Kecil (Target Cycle Time) */
.ct-target-label {
    font-size: 0.5rem;
    color: #4caf50;
    font-weight: normal;
}

/* MACHINE STATUS  */
.machine-status-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
    min-height: 0;
    position: relative;
}

.machine-header {
    background: var(--bg-card-header);
    padding: 5px;
    font-size: 0.8rem;
    font-weight: bold;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    z-index: 20;
}

.machine-body {
    flex: 1;
    width: 100%;
    background: #000;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Legend - Rata Kiri (Flex Start) */
.machine-legend {
    display: flex;
    gap: 15px;
    padding: 4px 15px;
    background: #1a1a1a;
    font-size: 0.65rem;
    border-top: 1px solid #333;
    justify-content: flex-start;
    flex-wrap: wrap;
    z-index: 20;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    color: #ccc;
}

.box-indicator {
    width: 8px;
    height: 8px;
    border-radius: 2px;
}

/* SCHEMATIC CONTAINER */
.abs-schematic {
    position: relative;
    width: 100%;
    height: 100%;
    padding: 2%;
    /* Safe area padding */
}

/* TRACK LAYER BACKGROUND  */
.track-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    /* Layer paling bawah */
    pointer-events: none;
}

.track-svg1 {
    position: absolute;
    width: 80%;
    height: 100%;
    object-fit: fill;
    opacity: 0.9;
    top: -5%;
    left: 15%;
}

.track-svg3 {
    position: absolute;
    width: 68%;
    height: 100%;
    object-fit: fill;
    opacity: 0.9;
    top: 6%;
    left: 19.5%;
}

.track-svg2 {
    position: absolute;
    width: 80%;
    height: 100%;
    object-fit: fill;
    opacity: 0.9;
    top: -8%;
    left: 15%;
}

.track-svg4 {
    position: absolute;
    width: 68%;
    height: 100%;
    object-fit: fill;
    opacity: 0.9;
    top: -20%;
    left: 19.5%;
}

/* MACHINE BOXES */
.sch-box {
    position: absolute;
    z-index: 10;
    background-color: #636363;
    border-radius: 2px;
    color: #ffffff;
    font-size: 0.45rem;
    font-weight: 700;
    line-height: 1.1;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none !important;
    transition: all 0.3s ease;
    cursor: pointer;
    border: 1px solid transparent;
}

/* Hover Effect */
.sch-box:hover {
    transform: scale(1.05);
    border-color: #fff;
    color: #ffffff;
    z-index: 15;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

/* DYNAMIC STATUS COLORS AJAX HANDLER */
.sch-box[data-status="st0"] {
    background: #6c757d;
    border: 1px solid #555;
    color: #eee;
}

.sch-box[data-status="st1"] {
    background: #2e7d32;
    border: 2px solid #4caf50;
    color: #fff;
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.6);
}

.sch-box[data-status="st3"] {
    background: #c62f27;
    border: 2px solid #ef5b53;
    color: #fff;
    animation: blink-red 1s infinite alternate;
}

.sch-box[data-status="st2"] {
    background: #ffb300;
    border: 2px solid #ffca28;
    color: #000 !important;
    font-weight: 800;
}

.sch-box[data-status="st4"] {
    background: #0277bd;
    border: 2px solid #29b6f6;
    color: #fff;
}

.sch-box[data-status="st5"] {
    background: #212121;
    border: 2px solid #9e9e9e;
    color: #fff;
}

@keyframes blink-red {
    from {
        opacity: 1;
        box-shadow: 0 0 5px #ef5b53;
    }

    to {
        opacity: 0.7;
        box-shadow: 0 0 15px #ef5b53;
    }
}

/* EXACT POSITIONING LAYOUT*/
/* LEFT SECTION */
.box-pasu {
    top: 5%;
    left: 2%;
    width: 7%;
    height: 12%;
}

.box-repair {
    top: 28%;
    left: 2%;
    width: 6.5%;
    height: 15%;
}

.box-jig {
    top: 28%;
    left: 9%;
    width: 7%;
    height: 15%;
}

.box-polish {
    top: 48%;
    left: 2%;
    width: 10%;
    height: 20%;
    z-index: 12;
}

.box-sludgepool {
    top: 85%;
    left: 2%;
    width: 12%;
    height: 12%;
}

.box-basu {
    top: 85%;
    left: 14.5%;
    width: 7%;
    height: 12%;
}

/* CENTER SECTION  */
.box-rbt {
    top: 28%;
    left: 21.5%;
    width: 5%;
    height: 12%;
    font-size: 0.35rem;
}

.box-dry {
    top: 25%;
    left: 35%;
    width: 20%;
    height: 10%;
}

.box-bake {
    top: 36%;
    left: 35%;
    width: 20%;
    height: 10%;
}

.box-spray {
    top: 47%;
    left: 32%;
    width: 50%;
    height: 10%;
}

.box-auto {
    top: 58%;
    left: 32%;
    width: 50%;
    height: 12%;
}

/* RIGHT SECTION */
.box-pretreat {
    top: 25%;
    left: 62%;
    width: 20%;
    height: 10%;
}

.box-conveyor {
    top: 18%;
    right: 3.5%;
    width: 3%;
    height: 55%;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    letter-spacing: 2px;
}

/* BOTTOM CHARTS SECTION */
.bottom-charts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: 1fr 1fr;
    gap: 8px;
    height: 100%;
    min-height: 0;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
    min-height: 0;
    position: relative;
}

.chart-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 8px;
    border-bottom: 1px solid #333;
    background: var(--bg-card-header);
    height: 32px;
    flex-shrink: 0;
}

.chart-title {
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.btn-drpdown {
    background: #444;
    border: 1px solid #555;
    color: white;
    font-size: 0.65rem;
    padding: 1px 8px;
    border-radius: 3px;
    cursor: pointer;
}

.chart-body {
    display: flex;
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

.carousel {
    display: flex;
}

.carousel,
.carousel .carousel-inner,
.carousel .carousel-item {
    height: 100% !important;
    min-height: 0 !important;
}

.carousel .chart-body {
    height: 100% !important;
    min-height: 0;
    padding: 0;
}

.carousel .chart-body > div {
    width: 100% !important;
    height: 100% !important;
}

.carousel-indicators {
    bottom: -20px !important;
    opacity: 0.3;
}

/* Highcharts Overrides */
.highcharts-background {
    fill: transparent;
}

.highcharts-root {
    font-family: "Kanit", sans-serif !important;
}

/* LAYOUT OVERRIDES FOR LINE 2 & 4 (STACKED LAYOUT) */
#layout_line_2 .box-polish,
#layout_line_4 .box-polish {
    top: 30%;
    left: 2%;
    width: 11%;
    height: 18%;
    z-index: 15;
}

#layout_line_2 .box-repair,
#layout_line_4 .box-repair {
    top: 53%;
    left: 2%;
    width: 6.5%;
    height: 15%;
}

#layout_line_2 .box-jig,
#layout_line_4 .box-jig {
    top: 53%;
    left: 9%;
    width: 7%;
    height: 15%;
}

#layout_line_2 .box-rbt,
#layout_line_4 .box-rbt {
    top: 47%;
    left: 21.5%;
    width: 5%;
    height: 12%;
    font-size: 0.35rem;
}

#layout_line_2 .box-auto,
#layout_line_4 .box-auto {
    top: 12.5%;
    left: 32%;
    width: 50%;
    height: 12%;
    z-index: 20;
}

#layout_line_2 .box-spray,
#layout_line_4 .box-spray {
    top: 25%;
    left: 32%;
    width: 50%;
    height: 12%;
}

#layout_line_2 .box-dry,
#layout_line_4 .box-dry {
    top: 50%;
    left: 35%;
    width: 20%;
    height: 10%;
}

#layout_line_2 .box-bake,
#layout_line_4 .box-bake {
    top: 39%;
    left: 35%;
    width: 20%;
    height: 10%;
}

#layout_line_2 .box-pretreat,
#layout_line_4 .box-pretreat {
    top: 50%;
    left: 62%;
    width: 20%;
    height: 10%;
}

#layout_line_2 .box-conveyor,
#layout_line_4 .box-conveyor {
    top: 20%;
    right: 3.5%;
    width: 3%;
    height: 50%;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    letter-spacing: 2px;
}

#layout_line_2 .box-sludgepool,
#layout_line_4 .box-sludgepool {
    top: 85%;
    left: 2%;
    width: 12%;
    height: 12%;
}

#layout_line_2 .box-basu,
#layout_line_4 .box-basu {
    top: 85%;
    left: 14.5%;
    width: 7%;
    height: 12%;
}

#layout_line_2 .box-pasu,
#layout_line_4 .box-pasu {
    display: none;
}

/* CUSTOM MODAL SETTING CHART */
.modal-header-custom {
    background-color: #495057;
    color: white;
    border-bottom: none;
    display: flex;
    justify-content: center;
    padding: 10px 15px;
}

.modal-header-custom .modal-title {
    font-weight: 600;
    font-family: "Kanit", sans-serif;
}

.label-setting {
    font-weight: 600;
    font-size: 0.85rem;
    color: #333;
    text-transform: uppercase;
    margin-bottom: 5px;
    display: block;
}

.form-control-custom {
    border: 1px solid #ced4da;
    border-radius: 4px;
    padding: 0.375rem 0.75rem;
}

.input-group-text-custom {
    background-color: #e9ecef;
    border: 1px solid #ced4da;
    color: #495057;
    font-size: 0.85rem;
    font-weight: 500;
}

.input-color-bar {
    padding: 2px;
    height: 38px;
    border: 1px solid #ced4da;
    border-left: none;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    width: 100%;
}

.input-color-bar::-webkit-color-swatch-wrapper {
    padding: 0;
}

.input-color-bar::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.btn-custom-close {
    background-color: #969696;
    color: white;
    border: none;
    padding: 6px 20px;
    font-weight: 500;
}

.btn-custom-close:hover {
    background-color: #7a7a7a;
    color: white;
}

.btn-custom-save {
    background-color: #495057;
    color: white;
    border: none;
    padding: 6px 20px;
    font-weight: 500;
}

.btn-custom-save:hover {
    background-color: #343a40;
    color: white;
}

.setting {
    padding: 3px;
    border-radius: 4px;
    border: 1px solid #ffffff;
    color: #c7c7c7;
    margin-right: 0.4rem;
    background: transparent;
}

.setting:hover {
    background: #c7c7c7;
    color: #2f3231;
}

.icon-setting-custom {
    width: 19px;
    height: 19px;
    vertical-align: middle;
    opacity: 0.7;
    transition: opacity 0.3s;
    background-color: #3c3c3c;
}

.setting:hover .icon-setting-custom {
    opacity: 1;
    transform: scale(1.1);
}

.dropdown-toggle.show::after {
    display: inline-block;
    margin-left: 0.255em;
    vertical-align: 0.255em;
    content: "";
    border-top: 0;
    border-right: 0.3em solid transparent;
    border-bottom: 0.3em solid;
    border-left: 0.3em solid transparent;
}

.but-drop {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    margin-bottom: 0.5rem;
}

.but-drop:hover {
    background: #3c3c3c;
    color: #ffffff;
}

/* GLOBAL OVERRIDES DATEPICKER & DATERANGEPICKER */
body .datepicker-dropdown,
body .daterangepicker {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    z-index: 9999 !important;
    border: none !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    font-family: "Poppins", sans-serif;
    background-color: #ffffff !important;
    border-radius: 12px !important;
    overflow: hidden;
}

/* Backdrop effect */
body .datepicker-dropdown::before,
body .daterangepicker::before {
    content: "";
    position: fixed;
    top: -5000px;
    left: -5000px;
    right: -5000px;
    bottom: -5000px;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
    pointer-events: none;
}

/* Datepicker (Bootstrap) specific */
body .datepicker-dropdown {
    padding: 20px !important;
    color: black;
}

body .datepicker-panel > ul > li.disabled {
    color: rgb(58, 58, 58);
}

body .datepicker-panel > ul > li.disabled:hover {
    color: rgb(0, 0, 0);
}

body .datepicker table tr td,
body .datepicker table tr th {
    border-radius: 4px;
    width: 40px;
    height: 40px;
    font-size: 1rem;
    font-weight: 500;
}

body .datepicker table tr th.datepicker-switch {
    font-size: 1.2rem;
    font-weight: 700;
    color: #333;
    width: 200px;
}

body .datepicker table tr th.prev,
body .datepicker table tr th.next {
    color: #333;
    font-size: 1.2rem;
    cursor: pointer;
}

body .datepicker table tr th.prev:hover,
body .datepicker table tr th.next:hover,
body .datepicker table tr th.datepicker-switch:hover {
    background: #f0f0f0;
    border-radius: 8px;
}

body .datepicker table tr td span {
    height: 60px !important;
    line-height: 60px !important;
    width: 30% !important;
    margin: 1.5%;
    border-radius: 8px !important;
    font-size: 1rem;
    color: #333;
    font-weight: 500;
}

body .datepicker table tr td span:hover {
    background: #f0f0f0 !important;
}

body .datepicker table tr td span.active,
body .datepicker table tr td span.active:hover {
    background-color: #e3f2fd !important;
    color: #1976d2 !important;
    font-weight: 700;
    border: 1px solid #1976d2;
    text-shadow: none;
    background-image: none;
}

/* Daterangepicker specific */
body .daterangepicker {
    font-size: 14px;
    color: #333;
    width: auto !important;
    max-width: 95vw;
}

body .daterangepicker .calendar-table th {
    color: #333;
    font-weight: 700;
    font-size: 0.9rem;
    padding: 10px 0;
}

body .daterangepicker td.active,
body .daterangepicker td.active:hover {
    background-color: #2c8eff !important;
    color: #fff;
    border-radius: 4px;
}

body .daterangepicker .applyBtn {
    background-color: #16a086 !important;
    border-color: #16a086 !important;
    color: white !important;
}

body .daterangepicker .cancelBtn {
    background-color: #dc3545 !important;
    border-color: #dc3545 !important;
    color: white !important;
}

/* Hapus panah bawaan */
body .datepicker-dropdown:after,
body .datepicker-dropdown:before,
body .daterangepicker:after,
body .daterangepicker:before {
    display: none !important;
}

.daterangepicker.dropdown-menu.ltr.show-calendar.opensright {
    top: 15%;
    left: 25%;
    right: 25%;
    width: 50%;
}

.grid-daterangepicker {
    display: grid;
    padding: 0.5rem;
    grid-template-areas:
        "left right"
        "ranges ranges";
    grid-template-columns: 50% 50%;
    grid-template-rows: auto auto;
    grid-gap: 0.5rem;
}

.left {
    grid-area: left;
}

.right {
    grid-area: right;
}

.ranges {
    grid-area: ranges;
    margin-top: 1rem;
}
