/* =========================================================
   Heat Pump Dryer Platform Mobile Patch
   - PC 레이아웃은 기존 CSS 유지
   - 768px 이하에서 모바일 세로 스택형 레이아웃으로 전환
   - 반드시 기존 페이지 CSS보다 나중에 로드
========================================================= */

@media screen and (max-width: 768px) {
    /* =====================================================
       1. Global
    ===================================================== */
    html,
    body {
        width: 100%;
        height: auto;
        min-height: 100%;
        margin: 0;
        padding: 0;
        overflow-x: hidden;
        overflow-y: auto;
        background-color: #b8e2ff;
    }

    body {
        display: flex !important;
        flex-direction: column;
        grid-template-columns: none !important;
        grid-template-rows: none !important;
    }

    *,
    *::before,
    *::after {
        box-sizing: border-box;
    }

    img,
    svg,
    canvas,
    video,
    iframe {
        max-width: 100%;
    }

    input,
    select,
    textarea,
    button {
        max-width: 100%;
        font-family: inherit;
    }

    .m_r,
    .m_c,
    .m {
        min-width: 0;
    }

    .m_r {
        flex-wrap: wrap;
    }

    .space20,
    .space50,
    .space100 {
        display: none !important;
    }

    /* =====================================================
       2. Header
       - 기존 2열 헤더를 모바일 상단 카드형으로 전환
    ===================================================== */
    header {
        width: 100% !important;
        height: auto !important;
        min-height: auto !important;
        display: grid !important;
        grid-template-columns: 76px minmax(0, 1fr) !important;
        grid-template-rows: auto auto !important;
        border-bottom: 1px solid #ffffff;
        background: #298acd;
    }

    #dry_header {
        width: 76px !important;
        height: 58px !important;
        grid-column: 1;
        grid-row: 1;
        background: #298acd;
    }

    .header_img {
        width: 64px !important;
        height: 48px !important;
        object-fit: contain;
    }

    .title_css {
        grid-column: 2;
        grid-row: 1;
        min-height: 58px !important;
        height: auto !important;
        padding: 10px 12px;
        display: flex !important;
        align-items: center;
        justify-content: flex-start;
        color: #ffffff;
        font-size: 17px !important;
        font-weight: 800;
        line-height: 1.35;
        word-break: keep-all;
        background: #298acd;
    }

    header > h1 {
        grid-column: 1;
        grid-row: 2;
        height: auto !important;
        min-height: 42px;
        padding: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        border-right: 1px solid #ffffff;
        color: #ffffff;
        background: #206fa6;
        font-size: 14px !important;
    }

    #now_date_time_con {
        grid-column: 2;
        grid-row: 2;
        min-height: 42px;
        padding: 6px 10px;
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-start;
        align-items: center;
        gap: 8px;
        background: #eaf7ff;
    }

    #now_date_time_con > * {
        margin: 0 !important;
    }

    #now_date_time_con > h3 {
        display: none;
    }

    #now_date_time_con > p {
        font-size: 12px;
        color: #1b4c6f;
        white-space: nowrap;
    }

    #now_date_time_con > p::before {
        width: 16px;
        height: 16px;
        margin-right: 4px;
    }

    /* =====================================================
       3. Sidebar
       - 좌측 메뉴를 상단 가로 스크롤 메뉴로 전환
    ===================================================== */
    aside {
        width: 100% !important;
        height: auto !important;
        min-height: auto !important;
        border-right: 0;
        border-bottom: 1px solid #ffffff;
        background: #b8e2ff;
        overflow-x: auto;
    }

    aside ul {
        width: 100%;
        display: flex;
        gap: 8px;
        padding: 10px;
        overflow-x: auto;
        white-space: nowrap;
        scrollbar-width: thin;
    }

    aside ul::-webkit-scrollbar {
        height: 4px;
    }

    aside ul::-webkit-scrollbar-thumb {
        background: #7ecaff;
        border-radius: 999px;
    }

    aside li {
        flex: 0 0 auto;
        min-width: auto;
        height: 38px;
        padding: 0 14px !important;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 999px;
        color: #1f4f70;
        background: rgba(255, 255, 255, 0.58);
        font-size: 13px !important;
        font-weight: 800;
        border: 1px solid rgba(41, 138, 205, 0.18);
    }

    aside li:hover {
        background: rgba(255, 255, 255, 0.85);
    }

    aside li.focused {
        background: #ffffff;
        color: #298acd;
        box-shadow: 0 4px 12px rgba(41, 138, 205, 0.16);
    }

    aside li.focused::before {
        display: none;
    }

    /* =====================================================
       4. Main Common
    ===================================================== */
    main {
        width: 100% !important;
        height: auto !important;
        min-height: auto !important;
        max-height: none !important;
        padding: 10px !important;
        display: grid !important;
        grid-template-columns: 1fr !important;
        grid-template-rows: none !important;
        grid-auto-rows: auto !important;
        gap: 10px !important;
        overflow: visible !important;
        background: #b8e2ff;
    }

    main > article,
    main > div,
    main > section {
        width: 100% !important;
        height: auto !important;
        min-height: 120px;
        max-height: none !important;
        grid-column: auto !important;
        grid-row: auto !important;
        overflow: visible !important;
    }

    main > article:not(.alarm_btn),
    main > div > article {
        display: grid !important;
        grid-template-columns: 1fr !important;
        grid-template-rows: auto minmax(0, auto) !important;
    }

    main > div {
        display: grid !important;
        grid-template-columns: 1fr !important;
        grid-template-rows: none !important;
        grid-auto-rows: auto !important;
        gap: 10px !important;
        min-height: auto !important;
    }

    .a_header {
        width: 100% !important;
        height: auto !important;
        min-height: 42px;
        padding: 10px 14px !important;
    }

    .a_header h5 {
        font-size: 15px !important;
        font-weight: 800;
        line-height: 1.2;
    }

    .a_header p {
        margin-top: 2px;
        font-size: 11px !important;
        line-height: 1.2;
    }

    main > article > section {
        height: auto !important;
        min-height: 120px;
    }

    .scrollCon {
        overflow: auto !important;
        max-height: 320px;
    }

    table,
    .pg_table,
    .tb_row,
    .dry_hist_row,
    .thb_rows,
    .hch_rows {
        min-width: 520px;
    }

    #dry_prog_con {
        height: 420px !important;
    }

    #dry_progress_data {
        position: absolute !important;
        margin: 0;
        top: calc(50% - 11px);
        left: calc(50% - 20px);
    }

    #weather_5_day_container > article:first-of-type {
        height: 200px;
    }

    #weather_5_day_container > article:first-of-type > p:before {
        width: 100%;
        padding: 0;
        display: grid;
        place-content: center;
        height: 40px;
        border-bottom-right-radius: 0;
    }
    #weather_5_day_container > article:first-of-type > div:after {
        height: 40px;
    }

    #weather_5_day_container > article:last-of-type {
        width: 100%;
    }

    #weather_5_day_container > article:last-of-type > div > p {
        letter-spacing: -1px;
    }

    #sys_res_con {
        height: 400px !important;
    }

    #conn_status_container {
        min-height: 300px !important;
    }

    #conn_status_container > div > div > canvas {
        position: absolute !important;
        top: auto !important;
        left: auto !important;
    }

    #conn_status_container > div > div > {
        position: absolute;
    }
    /* =====================================================
       5. Alarm Buttons
    ===================================================== */
    .alarm_btn {
        width: 100% !important;
        height: auto !important;
        min-height: 86px;
        padding: 14px !important;
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        border-radius: 10px;
    }

    .alarm_btn::before,
    .alarm_btn::after {
        width: 24px;
        height: 24px;
    }

    .alarm_btn > div > h4 {
        font-size: 20px;
    }

    .alarm_btn > div > p {
        margin-top: 4px;
        font-size: 14px;
    }

    /* =====================================================
       6. Dryer Slider / Dryer List
    ===================================================== */
    .swiper,
    #dryer_list_slider {
        width: 100% !important;
        min-height: 78px;
        height: auto !important;
        overflow: hidden;
    }

    .swiper-wrapper {
        min-height: 58px;
        align-items: stretch;
    }

    .swiper-slide {
        min-height: 48px;
    }

    #dryer_list_slider label {
        height: 44px !important;
        min-height: 44px;
        margin: 6px !important;
        padding: 0 12px;
        font-size: 13px;
        border-radius: 8px;
        word-break: keep-all;
    }

    .swiper-button-prev,
    .swiper-button-next {
        transform: scale(0.72);
    }

    #dryer_list_container {
        max-height: 320px;
        overflow-y: auto;
    }

    #dryer_list_container > label {
        width: calc(100% - 24px) !important;
        height: auto;
        min-height: 42px;
        margin: 8px 12px;
        padding: 10px 32px 10px 34px;
        font-size: 13px;
    }

    /* =====================================================
       7. Main Page
    ===================================================== */
    .ES_box {
        width: 100%;
        min-height: 36px;
        margin: 4px 0;
        padding: 8px 10px;
        justify-content: flex-start;
        border-radius: 8px;
        background: #f4fbff;
    }

    .power {
        width: 100% !important;
        min-height: 72px;
        display: flex !important;
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px;
    }

    .power label,
    .power2 label {
        min-width: 96px;
        height: 36px;
        padding: 0 12px;
        border-radius: 18px;
        font-size: 13px;
        display: grid;
        place-content: center;
    }

    .a_header + #sel_dryer_data_container {
        width: calc(100% - 20px) !important;
        height: auto !important;
        min-height: 280px;
        margin: 0 10px 10px !important;
        padding: 12px !important;
        display: grid !important;
        grid-template-columns: 1fr !important;
        grid-template-rows: none !important;
        gap: 8px;
    }

    #sel_dryer_data_container > * {
        width: 100% !important;
        min-height: 34px;
    }

    #sel_dryer_data_container > p:nth-of-type(2n) {
        display: grid;
        place-content: center;
    }

    #flow_art_container {
        min-height: 300px;
        overflow: auto;
    }

    .flow-art-fallback,
    #flow_art_container svg {
        min-width: 400px;
    }

    #weather_5_day_container,
    #sensor_info_container,
    #conn_status_container,
    #alarm_container {
        width: 100% !important;
        min-height: 180px;
        overflow: auto;
    }

    #cpuUsageChart,
    #gpuUsageChart,
    #memUsageChart {
        width: 100% !important;
        height: 180px !important;
    }

    /* =====================================================
       8. PV Generation Page
    ===================================================== */
    .ess_box {
        width: 100% !important;
        height: auto !important;
        min-height: 280px;
        padding: 12px;
    }

    .ess_status {
        min-width: 74px;
        height: 34px;
        margin: 4px;
        font-size: 12px;
    }

    .ess_soc {
        width: 100% !important;
    }

    .ess_data {
        min-width: 110px;
        min-height: 44px;
        font-size: 16px !important;
    }

    #acc_gen_data_container {
        width: calc(100% - 100px) !important;
        height: auto !important;
        min-height: 170px;
        margin: 10px auto !important;
        padding: 12px;
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    #acc_gen_data_container > div {
        width: 130px !important;
        height: 130px !important;
        margin: 0 auto;
    }

    #rt_gen_data_container,
    #week_power_comp_container,
    #monthly_power_comp_container,
    #net_conn_st_container {
        width: 100% !important;
        min-height: 240px;
        overflow: auto;
    }

    #rt_gen_chart,
    #week_comp_chart,
    #monthly_comp_chart {
        width: 100% !important;
        height: 220px !important;
    }

    .pg_table {
        width: 100%;
        overflow-x: auto;
    }

    .tb_row {
        min-height: 38px;
    }

    .a_header + section > canvas#rt_gen_chart {
        width: 80% !important;
    }

    #ins_pw_con {
        height: 300px !important;
    }

    #pv_power_realtime_info {
        display: none;
    }

    #week_power_comp_container,
    #week_comp_chart {
        width: 100% !important;
    }

    #w_comp_chart_columns {
        display: none !important;
    }

    .pg_table,
    .tb_row {
        width: 100% !important;
        min-width: 0 !important;
        margin: 0 !important;
    }

    /* =====================================================
       9. Control Page
    ===================================================== */
    main > article#sub_grid_con {
        width: 100% !important;
        height: auto !important;
        min-height: auto;
        display: block !important;
        overflow: visible !important;
    }

    .sub-grid {
        width: 100% !important;
        height: auto !important;
        display: grid !important;
        grid-template-columns: 1fr !important;
        grid-template-rows: none !important;
        gap: 10px !important;
    }

    .sub-grid > article,
    .controller_pack_container,
    #dry_history_article,
    #sub_controller_and_ai_feedback {
        width: 100% !important;
        height: auto !important;
        min-height: 220px;
        grid-column: auto !important;
        grid-row: auto !important;
        overflow: visible !important;
    }

    #dry_history_article section,
    #test_history_board {
        width: 100%;
        max-height: 260px;
        overflow: auto;
    }

    .dry_hist_row,
    .thb_rows {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr);
    }

    .thb_rows {
        grid-template-columns: 0.8fr 1.2fr 1fr 1fr 1.4fr;
    }

    #dryer_power_con,
    #cate_sel_con,
    #dryer_ctrl_con,
    #dryer_op_set_con {
        width: 100% !important;
        height: auto !important;
        min-height: 120px;
        padding: 12px;
        display: flex !important;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
        align-items: center;
    }

    #cate_sel_con {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        grid-auto-rows: minmax(1fr, auto) !important;
    }

    #cate_sel_con label {
        padding: 0 10px;
        font-size: 12px;
    }

    #dryer_ctrl_con {
        display: grid !important;
    }

    .write_box,
    .write_box2,
    .write_box3,
    .write_box_bottom {
        width: 100% !important;
        height: auto !important;
        min-height: 42px;
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 8px;
    }

    .write_box input,
    .write_box2 input,
    .write_box3 input,
    .write_box_bottom input {
        width: 100% !important;
        height: 34px;
    }

    .ai_box {
        width: 100% !important;
        height: auto !important;
        min-height: 260px;
    }

    .ai_menu_box {
        width: 100% !important;
        height: auto !important;
        display: flex !important;
        overflow-x: auto;
        gap: 8px;
        padding: 8px;
    }

    .ai_menu {
        flex: 0 0 auto;
        min-width: 120px;
        height: 38px;
        font-size: 12px;
    }

    .ai_contents_box {
        width: 100% !important;
        height: auto !important;
        min-height: 220px;
        padding: 12px;
        overflow: auto;
    }

    .optimize_box0_1,
    .optimize_box0_2,
    .optimize_box1,
    .optimize_box2 {
        width: 100% !important;
        height: auto !important;
        min-height: 120px;
    }

    .optimize_img,
    .optimize_img_left,
    .optimize_img_right {
        width: 100% !important;
        height: auto !important;
        min-height: 160px;
        object-fit: contain;
    }

    #img_chart {
        width: 100% !important;
        height: 220px !important;
    }

    /* =====================================================
       10. Heat Pump Page
    ===================================================== */
    #hp_info_data_container,
    #pipe_info_data_container,
    #hst_info_data_container,
    #hp_controller_container,
    #hp_cont_hist_container {
        width: 100% !important;
        height: auto !important;
        min-height: 220px;
        padding: 12px;
        overflow: auto;
    }

    .c_con {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    .c_con > div,
    .c_con > div > div {
        width: 100% !important;
        height: auto !important;
        min-height: 42px;
    }

    .border {
        width: 100% !important;
        min-height: 38px;
        padding: 8px;
        font-size: 13px;
    }

    #hp_info_chart,
    #pipe_info_chart,
    #storage_info_chart {
        width: 100% !important;
        height: 220px !important;
    }

    .container,
    .row,
    .row2,
    .row3,
    .row4,
    .row5,
    .row6,
    .row7,
    .row8,
    .row9,
    .rowc {
        width: 100% !important;
        height: auto !important;
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 8px;
    }

    .circle {
        width: 86px !important;
        height: 86px !important;
        margin: 8px auto;
    }

    .big {
        width: 100% !important;
        height: auto !important;
    }

    .power2 {
        width: 100% !important;
        height: auto !important;
        display: flex !important;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
        padding: 12px;
    }

    #energy_settings_waiting,
    #energy_settings_waiting2,
    #energy_settings_waiting3 {
        width: 100% !important;
        min-height: 80px;
        padding: 10px;
    }

    #dryer_heat_controll,
    #big_dryer_heat_controll {
        width: 100% !important;
        height: auto !important;
        min-height: 140px;
    }

    #heatpump_stop_btn,
    #heatpump_start_btn,
    #heatpump_pump1_btn,
    #heatpump_pump2_btn,
    #heatpump_pump3_btn {
        min-width: 92px;
        height: 36px;
        margin: 4px;
    }

    #pump1_controll_set_in,
    #pump1_controll_set_out,
    #pump2_controll_set_in,
    #pump2_controll_set_out,
    #pump3_controll_set_in,
    #pump3_controll_set_out {
        width: 100% !important;
        height: auto !important;
        min-height: 60px;
    }

    .hch_rows {
        min-height: 38px;
    }

    /* =====================================================
       11. Digital Dryer Page
    ===================================================== */
    #digi_id,
    #digi_id_article,
    #digi_id_unity_con,
    #digi_dryer_info {
        width: 100% !important;
        height: auto !important;
        min-height: 260px;
        grid-column: auto !important;
        grid-row: auto !important;
        display: grid !important;
        grid-template-columns: 1fr !important;
    }

    #digi_id_unity_con {
        min-height: 360px;
    }

    #digi_id_unity_con iframe,
    #digi_id_unity_con canvas {
        width: 100% !important;
        height: 320px !important;
    }

    /* digi_dryer.ejs 안의 인라인 데모 영역 대응 */
    main > article[style] {
        min-height: 360px !important;
        padding: 12px;
    }

    main > article[style] > section[style] {
        width: 100% !important;
        height: auto !important;
        min-height: 320px !important;
        padding: 28px 16px;
    }

    main > article[style] h2 {
        font-size: 24px !important;
        line-height: 1.35;
    }

    main > article[style] p {
        font-size: 15px !important;
    }

    main > article[style] div[style] {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px !important;
    }

    main > article[style] span[style] {
        padding: 9px 14px !important;
        font-size: 13px;
    }

    /* =====================================================
       12. Alert Modal
    ===================================================== */
    main > section#alert_info_window {
        position: fixed !important;
        inset: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        padding: 12px;
        z-index: 2000;
        align-items: flex-start !important;
        overflow-y: auto;
    }

    main > section#alert_info_window > article {
        width: 100% !important;
        max-width: 560px;
        height: auto !important;
        min-height: 70vh;
        margin: 24px auto;
        padding: 16px;
    }

    .alert_title {
        padding: 9px 28px;
        font-size: 22px !important;
    }

    main > section#alert_info_window > article > section {
        height: auto !important;
        min-height: 300px;
    }

    main > section#alert_info_window > article > section:empty {
        font-size: 20px;
        text-align: center;
        word-break: keep-all;
    }

    /* =====================================================
       13. Demo Watermark
    ===================================================== */
    #ultra_popup {
        position: fixed !important;
        pointer-events: none;
    }

    #ultra_popup::before {
        font-size: clamp(42px, 14vw, 120px) !important;
        line-height: 1.1;
        text-align: center;
        letter-spacing: 2px !important;
    }
}

/* =========================================================
   Small Mobile Patch
========================================================= */
@media screen and (max-width: 480px) {
    header {
        grid-template-columns: 64px minmax(0, 1fr) !important;
    }

    #dry_header {
        width: 64px !important;
        height: 54px !important;
    }

    .header_img {
        width: 54px !important;
        height: 42px !important;
    }

    .title_css {
        min-height: 54px !important;
        padding: 8px 10px;
        font-size: 15px !important;
    }

    header > h1 {
        min-height: 38px;
        font-size: 12px !important;
    }

    #now_date_time_con {
        min-height: 38px;
        gap: 6px;
    }

    #now_date_time_con > p {
        font-size: 11px;
    }

    aside ul {
        padding: 8px;
        gap: 6px;
    }

    aside li {
        height: 34px;
        padding: 0 12px !important;
        font-size: 12px !important;
    }

    main {
        padding: 8px !important;
        gap: 8px !important;
    }

    main > article,
    main > div,
    main > section {
        min-height: 110px;
    }

    .a_header {
        min-height: 38px;
        padding: 9px 12px !important;
    }

    .a_header h5 {
        font-size: 14px !important;
    }

    .a_header p {
        font-size: 10px !important;
    }

    .alarm_btn {
        min-height: 78px;
    }

    .alarm_btn > div > h4 {
        font-size: 18px;
    }

    .alarm_btn > div > p {
        font-size: 13px;
    }

    #acc_gen_data_container > div {
        width: 112px !important;
        height: 112px !important;
    }

    #rt_gen_chart,
    #week_comp_chart,
    #monthly_comp_chart,
    #hp_info_chart,
    #pipe_info_chart,
    #storage_info_chart,
    #img_chart {
        height: 200px !important;
    }

    article.nl > canvas,
    canvas {
        max-height: 220px;
    }

    .dry_hist_row,
    .thb_rows,
    .hch_rows,
    .tb_row,
    .pg_table,
    table {
        min-width: 500px;
    }

    #is_cctv_con,
    .sub-grid,
    .c_con {
        grid-template-columns: 1fr !important;
    }

    .circle {
        width: 74px !important;
        height: 74px !important;
    }

    main > article[style] > section[style] {
        min-height: 280px !important;
        padding: 24px 12px;
    }

    main > article[style] h2 {
        font-size: 21px !important;
    }

    main > article[style] p {
        font-size: 14px !important;
    }

    #ultra_popup::before {
        font-size: clamp(44px, 15vw, 120px) !important;
        text-align: center;
        letter-spacing: 2px;
    }
}
