/* dashboard.css - สไตล์หลักที่ใช้ร่วมกันในหน้า Dashboard (OPD/IPD) */
:root {
    --bg: #f6f8fb;
    --card: #ffffff;
    --accent: #1f3c88;
    --accent-2: #2b8fb0;
    --muted: #6c7b97;
    --glass: rgba(255,255,255,0.6);
    --radius: 14px;
    --shadow-lg: 0 26px 60px rgba(31,60,136,0.14);
    --shadow-sm: 0 12px 24px rgba(31,60,136,0.1);
}

body {
    background: radial-gradient(circle at top, #f4f7ff 0%, var(--bg) 45%, #e1e8f5 100%);
    font-family: 'Sarabun', Tahoma, sans-serif;
    color: #243247;
}

.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: linear-gradient(180deg,var(--accent), #163563);
    color: #fff;
    padding: 40px 20px 28px 20px;
    box-shadow: 6px 0 40px rgba(16,36,78,0.14);
    transition: width 260ms ease, padding 260ms ease, background 260ms ease;
    border-top-right-radius: 18px;
    border-bottom-right-radius: 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.sidebar-top { display: block; }
.logo { height: 44px; margin-right: 12px; vertical-align: middle; object-fit: contain; }

.sidebar h2 {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 34px;
    display: flex;
    gap: 12px;
    align-items: center;
}

.sidebar .brand-text {
    display: inline-flex;
    align-items: center;
    transition: opacity 160ms ease;
    white-space: nowrap;
    color: #fff;
    font-weight: 800;
    font-size: 20px;
    letter-spacing: 0.2px;
}

.sidebar .menu-section { margin-bottom: 18px; margin-top: 8px; padding-top: 6px; }
.sidebar .section-title {
    display: block;
    margin-bottom: 10px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    font-size: 12px;
    color: rgba(255,255,255,0.75);
}

.sidebar a {
    display: flex;
    gap: 12px;
    align-items: center;
    color: #eef6ff;
    padding: 12px 14px;
    border-radius: 12px;
    text-decoration: none;
    margin-bottom: 14px;
    transition: all 180ms ease;
    font-size: 14px;
}

.sidebar a i {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: rgba(255,255,255,0.06);
    color: #fff;
    font-size: 18px;
    flex: 0 0 44px;
}

.sidebar a .link-text { font-weight: 700; color: #f3f9ff; }
.sidebar a:hover { transform: translateX(6px); background: rgba(255,255,255,0.06); box-shadow: 0 8px 18px rgba(2,6,23,0.18); }
.sidebar a.active {
    background: #ffffff;
    color: var(--accent);
    box-shadow: 0 12px 30px rgba(31,60,136,0.12);
    transform: none;
    padding: 14px 18px;
    border-radius: 14px;
}

.sidebar a.active .link-text { color: var(--accent); font-weight: 800; }
.sidebar a.active i { background: linear-gradient(135deg,var(--accent),var(--accent-2)); color: #fff; }

.sidebar .link-text { transition: opacity 160ms ease, transform 160ms ease; white-space: nowrap; }
.sidebar.collapsed { width: 76px; padding: 28px 12px; }
.sidebar.collapsed .brand-text { opacity: 0; pointer-events: none; width: 0; margin: 0; overflow: hidden; }
.sidebar.collapsed .section-title { opacity: 0; height: 0; margin: 0; overflow: hidden; }
.sidebar.collapsed .menu-section { margin-bottom: 16px; }
.sidebar.collapsed .logo { margin-right: 0; }
.sidebar.collapsed h2 { justify-content: center; }
.sidebar.collapsed a { justify-content: center; gap: 0; padding: 12px 0; }
.sidebar.collapsed a i { margin: 0; }
.sidebar.collapsed a .link-text {
    opacity: 0;
    transform: translateX(-8px);
    width: 0;
    margin: 0;
    overflow: hidden;
    pointer-events: none;
}

.sidebar .user-footer {
    margin-top: 12px;
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
}

.sidebar .user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: linear-gradient(135deg,#ffffff22,#ffffff11);
    display: inline-grid;
    place-items: center;
    color: #fff;
    font-weight: 700;
}

.sidebar .user-info { font-size: 13px; color: rgba(255,255,255,0.95); }
.sidebar .user-info .name { font-weight: 700; }
.sidebar.collapsed .user-footer { flex-direction: column; gap: 6px; padding: 12px 6px; background: transparent; border-radius: 12px; }
.sidebar.collapsed .user-info { display: none; }
.sidebar.collapsed .user-avatar { width: 44px; height: 44px; border-radius: 12px; }

.main-content {
    flex: 1;
    padding: clamp(24px, 3vw, 48px) clamp(20px, 4vw, 56px) clamp(36px, 4vw, 60px);
    transition: padding 220ms ease;
    max-width: clamp(1100px, 96vw, 1680px);
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: clamp(24px, 3vw, 36px);
}

.dashboard-layout.collapsed .main-content { padding: 30px 32px; }

.filter-panel {
    background: var(--card);
    border-radius: 18px;
    padding: 22px 24px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 26px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: clamp(16px, 2.4vw, 28px);
    flex-wrap: wrap;
    border: 1px solid rgba(31,60,136,0.05);
}

.page-title { margin-bottom: 0; }
.page-title h1 {
    margin: 0 0 6px 0;
    font-size: 32px;
    font-weight: 800;
    line-height: 1.05;
    color: #1f3c88;
    background: none !important;
    box-shadow: none;
    border: none;
    padding: 0;
    display: block;
}

.page-title p {
    margin: 0;
    color: #4c5a73;
    font-size: 14px;
}

#filterForm { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
#filterForm label { margin: 0; font-weight: 600; color: #243247; }

.filter-panel .info { font-weight: 600; color: #243247; line-height: 1.4; }
.filter-panel .info span { display: block; color: var(--accent); font-weight: 700; margin-top: 4px; }

.date-input-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(180deg,#fff,#f4f8ff);
    border: 1px solid rgba(31,60,136,0.1);
    padding: 10px 14px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    min-width: 180px;
    position: relative;
}

.date-input-wrapper .date-text { font-weight: 700; color: var(--accent); font-size: 14px; }
.date-input-wrapper input[type="date"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border-radius: 12px; }
.date-input-wrapper .calendar-icon { color: #1f3c88; font-size: 16px; margin-left: auto; }

.date-range-group { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.date-range-separator { font-weight: 700; color: var(--muted); }

.cards-grid {
    display: grid;
    gap: clamp(18px, 2.5vw, 28px);
    grid-template-columns: repeat(auto-fit,minmax(260px,1fr));
    margin: 0;
    align-items: stretch;
}

.cards-grid--compact { grid-template-columns: repeat(auto-fit,minmax(220px,1fr)); margin-top: -6px; }
.cards-grid--compact .summary-card { min-height: 150px; padding: 22px 20px; }

.summary-card {
    background: linear-gradient(180deg,#ffffff,#f4f8ff);
    border-radius: 18px;
    padding: 26px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    justify-content: center;
    text-align: center;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(31,60,136,0.05);
    min-height: 184px;
    transition: transform 220ms ease, box-shadow 220ms ease, background 220ms ease, border 220ms ease;
}

.icon-wrapper {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 20px;
    box-shadow: 0 12px 24px rgba(0,0,0,0.12);
}

.summary-card .value {
    display: inline-block;
    background: #ffffff;
    color: #243247;
    font-weight: 800;
    font-size: 26px;
    padding: 10px 18px;
    border-radius: 16px;
    box-shadow: 0 10px 24px rgba(36,50,71,0.12);
}

.summary-card .label { margin: 4px 0 0 0; color: #6c7b97; font-size: 15px; line-height: 1.4; }
.summary-card > div { text-align: center; }
.summary-card:hover { transform: translateY(-6px); box-shadow: 0 24px 48px rgba(31,60,136,0.15); background: linear-gradient(180deg,#ffffff,#f7fbff); border-color: rgba(43,143,176,0.24); }

.content-sections {
    display: grid;
    gap: clamp(22px, 3vw, 32px);
    grid-template-columns: repeat(auto-fit,minmax(360px,1fr));
}

.panel {
    background: linear-gradient(180deg,var(--card), #fbfdff);
    border-radius: 16px;
    padding: 24px 26px;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(31,60,136,0.06);
    transition: transform 200ms ease, box-shadow 200ms ease, background 200ms ease;
    display: flex;
    flex-direction: column;
    min-height: 420px;
}

.panel:hover { transform: translateY(-4px); box-shadow: 0 26px 54px rgba(31,60,136,0.12); background: linear-gradient(180deg,#ffffff,#f5f9ff); border-color: rgba(31,60,136,0.12); }

.panel h3 {
    margin: 8px 0 20px 0;
    padding-left: 12px;
    font-size: 1.35rem;
    font-weight: 800;
    color: #243247;
    display: flex;
    align-items: center;
    gap: 6px;
}

.panel h3 i {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    color: #fff;
    font-size: 1.05rem;
    margin-right: 12px;
    box-shadow: 0 8px 20px rgba(31,60,136,0.12);
    border: 2px solid rgba(0,0,0,0.04);
    transition: transform 180ms ease, box-shadow 180ms ease;
    background: linear-gradient(180deg,#4c7dfe,#3b6df2);
}

.panel h3 i:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(31,60,136,0.14); }

.panel.dept h3 i { background: linear-gradient(180deg,#2bc4ad,#18a68f); }
.panel.rights h3 i { background: linear-gradient(180deg,#4c7dfe,#3b6df2); }
.panel.dept-list h3 i { background: linear-gradient(180deg,#845ec2,#6f45b8); }
.panel.rights-list h3 i { background: linear-gradient(180deg,#ef476f,#e03b61); }
.panel.wards h3 i { background: linear-gradient(180deg,#2bc4ad,#18a68f); }
.panel.flow h3 i { background: linear-gradient(180deg,#ff9f43,#ff7b25); }
.panel.ward-details h3 i { background: linear-gradient(180deg,#00bbf9,#118ab2); }
.panel.ward-history h3 i { background: linear-gradient(180deg,#1f3c88,#2b8fb0); }
.panel.rights .chart-container { height: 360px; }
.panel.dept .chart-container { height: 360px; }
.panel-footnote { margin-top: 18px; font-size: 13px; color: var(--muted); }

.chart-container {
    position: relative;
    flex: 1;
    height: 380px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 6px 6px;
}

.chart-container canvas {
    max-width: 100%;
    width: 100% !important;
    height: 100% !important;
    display: block;
    margin: 0 auto;
}

.panel .chart-container { margin-top: 28px; }
.panel .table-responsive { margin-top: 28px; }

.table-custom thead { background: #f1f5ff; }
.table-custom thead th { color: #1f3c88; }
.table-custom tbody tr { transition: background-color 180ms ease; }
.table-custom tbody tr:nth-child(even) { background: rgba(76,125,254,0.06); }
.table-custom tbody tr:hover { background: rgba(43,143,176,0.12); }

.table-total-row td {
    background: linear-gradient(180deg, #fbfdff 0%, #f3f8ff 100%);
    font-weight: 700;
    border-top: 2px solid rgba(31,60,136,0.06);
    color: #243247;
}

.table-total-row td.colspan-left { color: #243247; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    padding: clamp(16px, 2vw, 26px) clamp(20px, 4vw, 44px) 0;
    background: transparent;
    margin-bottom: clamp(18px, 2.4vw, 28px);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: clamp(16px,3vw,36px);
    background: linear-gradient(135deg, rgba(255,255,255,0.88), rgba(244,248,255,0.96));
    backdrop-filter: blur(14px);
    border-radius: 24px;
    padding: clamp(16px, 2vw, 24px) clamp(18px, 3vw, 32px);
    box-shadow: 0 26px 60px rgba(31,60,136,0.18);
    border: 1px solid rgba(255,255,255,0.55);
}

.topbar-left { display: flex; align-items: center; gap: clamp(12px,2.4vw,22px); min-width: 0; }
.topbar-toggle {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    border: none;
    background: linear-gradient(135deg,#4c7dfe,#2b8fb0);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    box-shadow: 0 16px 30px rgba(76,125,254,0.28);
    transition: transform 180ms ease, box-shadow 180ms ease;
}

a.topbar-toggle:hover,
.topbar-toggle:hover { transform: translateY(-2px); box-shadow: 0 20px 36px rgba(76,125,254,0.32); }
.topbar-toggle:focus-visible { outline: 2px solid rgba(255,255,255,0.9); outline-offset: 3px; }
.topbar-toggle i { transition: transform 200ms ease; }
.topbar-toggle.is-collapsed i { transform: rotate(180deg); }

.topbar-brand { display: flex; flex-direction: column; gap: 6px; color: #243247; min-width: 0; }
.topbar-brand-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar-brand .brand-label { font-size: 0.78rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; color: rgba(31,60,136,0.76); }
.topbar-brand .brand-title { font-size: clamp(1.1rem, 2.2vw, 1.45rem); font-weight: 800; color: var(--accent); letter-spacing: 0.02em; }
.topbar-logo { width: 40px; height: 40px; object-fit: contain; filter: drop-shadow(0 8px 16px rgba(31,60,136,0.16)); }

.topbar-right { display: flex; align-items: center; gap: clamp(14px,2.6vw,28px); flex-wrap: wrap; justify-content: flex-end; }
.topbar-actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: flex-end; }

.btn-soft {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    background: rgba(31,60,136,0.08);
    color: var(--accent);
    padding: 10px 18px;
    border-radius: 16px;
    font-weight: 700;
    font-size: 0.95rem;
    transition: background 180ms ease, transform 180ms ease, box-shadow 180ms ease;
    box-shadow: 0 12px 26px rgba(31,60,136,0.14);
}

.btn-soft i { font-size: 1rem; }
.btn-soft:hover { background: rgba(76,125,254,0.2); transform: translateY(-2px); box-shadow: 0 18px 34px rgba(31,60,136,0.2); }
.btn-soft:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.status-pill {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(43,143,176,0.18), rgba(31,60,136,0.1));
    border: 1px solid rgba(43,143,176,0.28);
    box-shadow: 0 14px 30px rgba(31,60,136,0.14);
}

.status-pill.is-online { background: linear-gradient(135deg, rgba(43,143,176,0.24), rgba(31,60,136,0.12)); border-color: rgba(43,143,176,0.4); box-shadow: 0 18px 36px rgba(31,60,136,0.18); }
.status-pill.is-offline { background: linear-gradient(135deg, rgba(239,71,111,0.18), rgba(31,60,136,0.1)); border-color: rgba(239,71,111,0.32); }

.status-pill .status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #2bc4ad;
    box-shadow: 0 0 0 6px rgba(43,196,173,0.18);
}

.status-pill.is-online .status-dot { background: #2bc4ad; box-shadow: 0 0 0 6px rgba(43,196,173,0.24); }
.status-pill.is-offline .status-dot { background: #ef476f; box-shadow: 0 0 0 6px rgba(239,71,111,0.2); }

.status-pill .status-text { display: flex; flex-direction: column; line-height: 1.2; color: #243247; font-weight: 600; font-size: 0.9rem; }
.status-pill .status-text strong { color: var(--accent); font-size: 0.95rem; font-weight: 800; }
.status-pill .status-text span { color: rgba(36,50,71,0.72); }

.muted { color: var(--muted); }

.room-breakdown-panel { min-height: auto; }
.room-breakdown { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.room-breakdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(255,255,255,0.95), rgba(244,248,255,0.98));
    border: 1px solid rgba(31,60,136,0.08);
    box-shadow: 0 18px 34px rgba(31,60,136,0.1);
    transition: transform 180ms ease, box-shadow 180ms ease;
}

.room-breakdown-item:hover { transform: translateY(-2px); box-shadow: 0 22px 40px rgba(31,60,136,0.14); }
.room-breakdown-item .label { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #243247; letter-spacing: 0.2px; }
.room-breakdown-item .value { font-weight: 800; color: var(--accent); font-size: 1.15rem; display: flex; align-items: baseline; gap: 6px; }
.room-breakdown-item .unit { font-size: 0.85rem; color: #6c7b97; font-weight: 600; }

.room-breakdown-total {
    margin-top: 10px;
    padding-top: 12px;
    border-top: 1px dashed rgba(31,60,136,0.18);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    color: #243247;
}

.room-breakdown-total .value { color: var(--accent); font-size: 1.2rem; display: flex; align-items: baseline; gap: 6px; }
.room-breakdown-empty { text-align: center; padding: 18px; border-radius: 14px; background: rgba(76,125,254,0.08); color: #6c7b97; font-weight: 600; }

.room-badge { width: 14px; height: 14px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 6px rgba(31,60,136,0.06); }
.room-badge--general { background: #2bc4ad; box-shadow: 0 0 0 6px rgba(43,196,173,0.18); }
.room-badge--special_fan { background: #ff9f43; box-shadow: 0 0 0 6px rgba(255,159,67,0.2); }
.room-badge--special_air { background: #4c7dfe; box-shadow: 0 0 0 6px rgba(76,125,254,0.2); }
.room-badge--other { background: #845ec2; box-shadow: 0 0 0 6px rgba(132,94,194,0.2); }

.room-detail-cell { min-width: 220px; vertical-align: top; }
.room-detail-list { display: flex; flex-wrap: wrap; gap: 8px; }
.room-detail-list.is-empty { color: #6c7b97; font-style: italic; padding: 4px 0; }
.room-detail-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 12px;
    background: rgba(31,60,136,0.08);
    color: #243247;
    font-weight: 600;
    font-size: 0.85rem;
}

.room-detail-chip .chip-label { font-weight: 600; }
.room-detail-chip .chip-count { color: var(--accent); font-weight: 700; font-size: 0.82rem; }

.content-sections.room-breakdown-grid { grid-template-columns: repeat(auto-fit,minmax(280px,1fr)); gap: clamp(18px, 2.6vw, 30px); }
.room-breakdown-panel h3 { margin-bottom: 12px; }
.room-breakdown-panel--current h3 i { background: linear-gradient(180deg,#2bc4ad,#169c86); }
.room-breakdown-panel--past h3 i { background: linear-gradient(180deg,#845ec2,#5f3ea6); }
.room-breakdown-panel--admit h3 i { background: linear-gradient(180deg,#ff9f43,#ff7b25); }
.room-breakdown-panel--discharge h3 i { background: linear-gradient(180deg,#ef476f,#d72658); }

/* Responsive behaviour */
@media (min-width: 1600px) {
    .content-sections { grid-template-columns: repeat(auto-fit,minmax(420px,1fr)); }
    .content-sections.room-breakdown-grid { grid-template-columns: repeat(auto-fit,minmax(320px,1fr)); }
}

@media (min-width: 1900px) {
    .main-content { max-width: 1800px; }
}

@media (max-width: 1200px) {
    .cards-grid--compact { grid-template-columns: repeat(auto-fit,minmax(200px,1fr)); }
    .content-sections.room-breakdown-grid { grid-template-columns: repeat(auto-fit,minmax(240px,1fr)); }
}

@media (max-width: 992px) {
    .main-content { padding: 26px 28px 40px; }
    .chart-container { height: 320px; }
    .panel.rights .chart-container { height: 300px; }
    .panel.dept .chart-container { height: 300px; }
}

@media (max-width: 768px) {
    .topbar-inner { flex-direction: column; align-items: stretch; }
    .topbar-left, .topbar-right { width: 100%; justify-content: space-between; }
    .topbar-actions { justify-content: flex-start; }
}

@media (max-width: 576px) {
    .main-content { padding: 22px 18px 36px; }
    .filter-panel { padding: 18px; }
    .chart-container { height: 280px; }
    .panel.rights .chart-container { height: 260px; }
    .panel.dept .chart-container { height: 260px; }
    .cards-grid { grid-template-columns: repeat(auto-fit,minmax(180px,1fr)); }
    .cards-grid--compact { grid-template-columns: repeat(auto-fit,minmax(180px,1fr)); }
    .content-sections.room-breakdown-grid { grid-template-columns: 1fr; }
    .room-detail-list { gap: 6px; }
    .room-detail-chip { font-size: 0.8rem; padding: 6px 8px; }
}
