/* XME Energy Gate — shared styles */
:root {
  --bg: #0b1220;
  --panel: #111a2e;
  --panel-2: #16223d;
  --border: #1f2d4d;
  --text: #e6edf7;
  --muted: #8a9ab5;
  --brand: #3b82f6;
  --brand-2: #60a5fa;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --gray: #64748b;
}
html, body { background: var(--bg); color: var(--text); }
body { font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
.input, .select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 0 12px; outline: none; width: 100%;
  height: 38px; box-sizing: border-box; line-height: 38px;
}
.input:focus, .select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(59,130,246,.2); }
.input:-webkit-autofill, .input:-webkit-autofill:hover, .input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 30px var(--panel-2) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text);
}
input[type="date"].input { color-scheme: dark; }
input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 1;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e6edf7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='4' width='18' height='18' rx='2' ry='2'/><line x1='16' y1='2' x2='16' y2='6'/><line x1='8' y1='2' x2='8' y2='6'/><line x1='3' y1='10' x2='21' y2='10'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px 16px;
  filter: none;
}
.btn { display:inline-flex; align-items:center; gap:6px; padding: 8px 14px; border-radius: 8px; font-weight: 500; transition: all .15s; cursor:pointer; border: 1px solid transparent; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--panel-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-icon { padding: 6px; }
.btn:disabled, .btn[disabled] {
  background: var(--panel-2) !important;
  color: var(--muted) !important;
  border-color: var(--border) !important;
  cursor: not-allowed;
  filter: none;
  opacity: .6;
}
.btn:disabled:hover, .btn[disabled]:hover {
  background: var(--panel-2) !important;
  filter: none;
}

.badge { display:inline-flex; align-items:center; gap:4px; font-size: 12px; padding: 2px 8px; border-radius: 999px; font-weight: 500; }
.badge-green { background: rgba(16,185,129,.15); color: #34d399; }
.badge-yellow { background: rgba(245,158,11,.15); color: #fbbf24; }
.badge-red { background: rgba(239,68,68,.15); color: #f87171; }
.badge-gray { background: rgba(100,116,139,.2); color: #94a3b8; }
.badge-blue { background: rgba(59,130,246,.15); color: #60a5fa; }
.badge-override-on  { background: rgba(251,146,60,.2); color: #fb923c; }
.badge-override-off { background: repeating-linear-gradient(45deg,rgba(251,146,60,.2) 0,rgba(251,146,60,.2) 5px,rgba(255,255,255,.1) 5px,rgba(255,255,255,.1) 10px); color: #fb923c; }
.badge-ctrl { cursor: pointer; border: 1px solid currentColor; box-shadow: 0 1px 4px rgba(0,0,0,.3); transition: filter .15s, box-shadow .15s; }
.badge-ctrl:hover:not(:disabled) { filter: brightness(1.2); box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.badge-ctrl:active:not(:disabled) { filter: brightness(.95); box-shadow: 0 0 2px rgba(0,0,0,.3); }
.badge-ctrl:disabled { cursor: default; opacity: .7; border: none; box-shadow: none; }

.dot { width: 8px; height: 8px; border-radius: 999px; display:inline-block; }
.dot-green { background: var(--success); }
.dot-yellow { background: var(--warning); }
.dot-red { background: var(--danger); }
.dot-gray { background: var(--gray); }

table.tbl { width: 100%; border-collapse: separate; border-spacing: 0; }
table.tbl th, table.tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
table.tbl th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--panel-2); position: sticky; top: 0; }
table.tbl tbody tr:hover { background: rgba(255,255,255,.02); }
table.tbl tbody tr:last-child td { border-bottom: none; }

/* Sidebar */
.sidebar { width: 240px; background: var(--bg); display: flex; flex-direction: column; }
.sidebar nav { flex: 1; margin: 8px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 4px; display: flex; flex-direction: column; }
.sidebar-xme { margin-top: auto; padding: 8px 4px 2px; text-align: center; }
.sidebar-xme a { font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; padding: 0; margin: 0; background: none !important; border-radius: 0; letter-spacing: .04em; }
.sidebar-xme a:hover { text-decoration: underline; background: none !important; color: var(--muted); }
.sidebar-xme-logo { width: 14px; height: 14px; border-radius: 3px; }
.sidebar a { display:flex; align-items:center; gap:10px; padding: 10px 14px; color: var(--muted); font-size: 14px; border-radius: 8px; margin: 1px 0; }
.sidebar a:hover { background: var(--panel-2); color: var(--text); }
.sidebar a.active { background: var(--panel-2); color: var(--brand-2); font-weight: 500; }
.sidebar .sub a { padding-left: 40px; font-size: 13px; }
/* Desktop: card floats aligned with main content (p-6 = 24px) */
@media (min-width: 769px) {
  .sidebar { display: flex; flex-direction: column; padding: 24px 0 24px 24px; align-self: stretch; }
  .sidebar nav { margin: 0; flex: 1; }
}
@media (max-width: 768px) { .sidebar { background: var(--panel); } }

/* Header */
.app-header { height: 56px; background: var(--panel); border-bottom: 1px solid var(--border); }
.mobile-proj-select {
  background: transparent; border: none; outline: none;
  color: var(--text); font-size: 14px; font-weight: 500;
  -webkit-appearance: none; appearance: none;
  cursor: pointer; max-width: 100%; text-align: center;
}
.date-nav { height: 48px; background: var(--panel); border-bottom: 1px solid var(--border); }

/* Date picker — hide native rendering, show dd/mm/yyyy button that opens the native picker */
.date-pick-wrap { position: relative; }
.date-pick-wrap input[type="date"] {
  position: absolute; inset: 0; opacity: 0; pointer-events: none; width: 100%; height: 100%;
}
.date-display {
  width: 140px; text-align: center; cursor: pointer; background: var(--panel-2);
  border: 1px solid var(--border); color: var(--text); font-size: 14px;
  padding: 0 12px; border-radius: 8px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.date-display:hover { border-color: var(--brand); }
.date-nav .btn-icon,
.date-nav .date-display,
.date-nav #date-today { height: 36px; box-sizing: border-box; }

/* Status counts: summary (mobile default) + detail (desktop default) */
.status-counts { position: relative; display: flex; align-items: center; }
.status-summary {
  display: none; align-items: center; gap: 6px; background: transparent;
  border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px;
  color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer;
  height: 36px; box-sizing: border-box;
}
.status-summary:hover { background: var(--panel-2); }
.status-detail { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.status-detail .sep { color: var(--muted); }
/* Compact status + hidden date-summary: phones (portrait) và landscape dưới 1024px */
@media (max-width: 1023px) {
  .status-summary { display: inline-flex; }
  .status-detail {
    display: none; position: absolute; top: calc(100% + 6px); right: 0;
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    padding: 10px 12px; gap: 8px; z-index: 20; box-shadow: 0 8px 24px rgba(0,0,0,.4);
    flex-direction: column; align-items: flex-start; white-space: nowrap;
  }
  .status-detail .sep { display: none; }
  .status-counts.expanded .status-detail { display: flex; }
  #status-extra label span { display: none; }
  #status-extra .sep { display: none; }
}
@media (max-width: 768px) {
  .date-display { width: 108px; padding: 8px 6px; font-size: 13px; }
  #date-today { padding: 4px 8px; }
  .date-summary { display: none !important; }
}

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; width: 100%; max-width: 720px; max-height: 90vh; overflow: auto; }
.modal-lg { max-width: 960px; }
.modal-xl { max-width: 1400px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display:flex; align-items:center; justify-content: space-between; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display:flex; justify-content: flex-end; gap: 8px; }

/* Timeline */
.timeline-wrap { overflow-x: auto; }
.timeline-grid { min-width: 900px; --col-left: 40px; --col-right: 92px; } /* cột gộp nhiệt độ | trạng thái */
.tl-body { position: relative; }
.tl-row { display: grid; grid-template-columns: 64px 1fr 92px; align-items: stretch; border-bottom: 1px solid var(--border); }
.tl-row:last-child { border-bottom: none; }
@keyframes tl-row-pulse { 0%,100%{background:rgba(234,88,12,.08)} 50%{background:rgba(234,88,12,.32)} }
.tl-row--highlight { animation: tl-row-pulse 0.75s ease-in-out 3; outline: 1px solid rgba(234,88,12,.9); outline-offset: -1px; }
@keyframes tl-hl-pulse { 0%,100%{background:rgba(239,68,68,.06)} 50%{background:rgba(239,68,68,.36)} }
.tl-highlight-band { position:absolute; top:2px; bottom:2px; border-left:2px solid #ef4444; border-right:2px solid #ef4444; background:rgba(239,68,68,.06); border-radius:2px; z-index:8; pointer-events:none; animation:tl-hl-pulse .65s ease-in-out 24; }
.tl-label { padding: 10px 6px; color: var(--muted); font-size: 13px; display:flex; align-items:center; gap: 4px; background: var(--panel-2); border-right: 1px solid var(--border); overflow: hidden; position: sticky; left: 0; z-index: 3; }
.tl-header-label { position: sticky; left: 0; z-index: 5; background: var(--panel-2); }
.tl-label-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-waste-bar {
  position: absolute; top: 9px; bottom: 9px;
  background: none;
  border: 2px solid rgba(239, 68, 68, .85);
  border-radius: 2px;
  z-index: 2; pointer-events: auto; cursor: help;
}
.rtc-err { cursor: help; font-size: 14px; line-height: 1; }
.tl-bar-area { position: relative; height: 40px; overflow: hidden; isolation: isolate; background-image: repeating-linear-gradient(to right, transparent 0, transparent calc(100%/24 - 1px), rgba(255,255,255,.04) calc(100%/24 - 1px), rgba(255,255,255,.04) calc(100%/24)); }
.tl-status-cell { border-left: 1px solid var(--border); display:flex; align-items:center; justify-content: center; font-size: 12px; font-weight: 500; }
.tl-status-cell .badge { font-size: 12px; }
.tl-bar {
  position: absolute;
  top: 9px;
  bottom: 9px;
  border-radius: 2px;
  cursor: pointer;
  min-width: 2px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* z-index keeps the hourly grid + now-line painted above the bars. */
  z-index: 1;
}
.tl-bar-done { background: rgb(238, 130, 238); color: #fff; }
.tl-bar-live { background: rgb(217, 57, 13); color: #fff; }
/* Live "on" span covering time after the ESP stopped heartbeating —
   we can't confirm the device is still on, so render it as gray. */
.tl-bar-offline {
  background: repeating-linear-gradient(
    45deg,
    #475569 0, #475569 3px,
    #64748b 3px, #64748b 4px
  );
  color: #fff;
}
/* Override bars — relay forced by remote command. Rendered via the same
   renderBar() path as power bars so positions are pixel-identical.
   z-index:2 keeps them above regular power bars (z-index:1). */
.tl-bar-override-on {
  background: rgba(249,115,22,1);
  color: #fff;
  z-index: 2;
}
.tl-bar-override-off {
  background: repeating-linear-gradient(
    45deg,
    rgba(249,115,22,1) 0, rgba(249,115,22,1) 3px,
    #fff8f0 3px, #fff8f0 4px
  );
  color: #7c2d12;
  z-index: 2;
}
.tl-bar:hover { filter: brightness(1.1); }
/* Chevron badges at the edges of a bar whose span crosses a day
   boundary. ◀ on the left means "started on a previous day"; ▶ on the
   right means "continues into a following day". Positioned absolutely
   so they sit over the bar's edge independently of the centered label. */
.tl-bar-cont-left::before,
.tl-bar-cont-right::after {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  opacity: .75;
  pointer-events: none;
}
.tl-bar-cont-left::before  { content: '←'; left: 2px; }
.tl-bar-cont-right::after  { content: '→'; right: 2px; }
/* Bar kéo qua nửa đêm: cạnh cắt (phía tiếp tục sang ngày khác) để vuông,
   không bo góc — thể hiện bar liền mạch qua ranh giới ngày. */
.tl-bar-cont-left  { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.tl-bar-cont-right { border-top-right-radius: 0; border-bottom-right-radius: 0; }
/* Booking overlay tint — background marking guest occupancy periods from
   the PMS. Sits BELOW power bars (z-index 0 vs bar's 1) so the bars stay
   readable on top. Inset 5% from top/bottom (≈2px on a 40px row) leaves
   a small breathing gap at both row edges so adjacent rows' tints don't
   visually merge into one continuous band — easier to scan device-by-
   device. Border on all four sides; the chevron rules below drop the
   left or right border when the booking continues into adjacent days.
   See specs/integrations-pms.md §6 for the full rationale. */
.tl-booking-bg {
  position: absolute;
  top: 5%; bottom: 5%;                     /* 90% row height, equal gaps */
  background: rgba(96, 165, 250, .12);     /* brand-2 @ 12% */
  border: 1px solid rgba(96, 165, 250, .45);
  border-radius: 2px;
  z-index: 0;
  cursor: help;
  pointer-events: auto;                    /* hover for tooltip */
}
.tl-booking-bg:hover { background: rgba(96, 165, 250, .20); }
/* When a booking is clipped at the day boundary, drop the border on
   that side so the tint visually flows off the edge instead of looking
   like a hard wall mid-stay. */
.tl-booking-bg.cont-left  { border-left:  none; border-top-left-radius: 0;  border-bottom-left-radius: 0;  }
.tl-booking-bg.cont-right { border-right: none; border-top-right-radius: 0; border-bottom-right-radius: 0; }
/* Tiny chevron at the day-boundary side to hint at continuation. Pure
   pseudo-element, doesn't change layout. */
.tl-booking-bg.cont-left::before,
.tl-booking-bg.cont-right::after {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  color: rgba(96, 165, 250, .85);
  pointer-events: none;
}
.tl-booking-bg.cont-left::before  { content: '◀'; left: 3px; }
.tl-booking-bg.cont-right::after  { content: '▶'; right: 3px; }
/* Toggle: when the timeline-grid carries `hide-bookings`, ALL booking
   tints disappear with no DOM cost (still in the tree, just display:none).
   Bringing them back is instant. */
.timeline-grid.hide-bookings .tl-booking-bg { display: none; }
/* Toolbar above the timeline grid (booking toggle lives here). */
.tl-toolbar {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 12px; padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 12px;
  color: var(--muted);
}
.tl-toolbar label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.tl-toolbar input[type="checkbox"] { accent-color: var(--brand); cursor: pointer; }
/* Inline label showing on/off time + duration. Two lines stacked
   vertically so narrow bars only need to accommodate the wider of the
   two strings (usually the HH:MM → HH:MM line). Padding lives on the
   label (not the bar) so the bar's outer box exactly matches widthPct%.
   Hidden by default, revealed by JS once the label's natural width
   fits inside the bar. */
.tl-bar-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
  font-size: 9px;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  letter-spacing: .01em;
  padding: 0 4px;
}
.tl-bar-label > span { white-space: nowrap; }
.tl-bar-label .tl-bar-label-dur { opacity: .85; font-weight: 500; }
.tl-bar.fits-label .tl-bar-label { opacity: 1; }
.tl-bar.fits-dur .tl-bar-label { opacity: 1; }
.tl-bar.fits-dur .tl-bar-label > span:not(.tl-bar-label-dur) { display: none; }
.tl-header { display: grid; grid-template-columns: 64px 1fr 92px; background: var(--panel-2); border-bottom: 1px solid var(--border); }
.tl-hours { display: grid; grid-template-columns: repeat(24, 1fr); }
.tl-hours > div { text-align: center; font-size: 11px; color: var(--muted); padding: 6px 0; border-right: 1px solid var(--border); }
.tl-hours > div:last-child { border-right: none; }
.tl-now-wrap { position: absolute; top: 0; bottom: 0; left: var(--col-left); right: var(--col-right); pointer-events: none; z-index: 10; }
.tl-now-line { position: absolute; top: 0; bottom: 0; width: 1px; background-image: linear-gradient(to bottom, var(--brand-2) 50%, transparent 50%); background-size: 1px 6px; background-repeat: repeat-y; }
.tl-now-label { position: absolute; top: 6px; transform: translateX(6px); padding: 2px 6px; font-size: 11px; font-weight: 600; background: var(--brand-2); color: #0b1220; border-radius: 4px; white-space: nowrap; }

.tl-group-header { background: var(--panel-2); border-bottom: 1px solid var(--border); }
.tl-group-name { display: inline-block; position: sticky; left: 0; z-index: 4; padding: 8px 12px; background: var(--panel-2); font-weight: 600; font-size: 13px; color: var(--brand-2); letter-spacing: .02em; text-transform: uppercase; }

/* Settings-devices: group header row inside unified table */
.sd-group-row > td { background: var(--panel-2) !important; padding: 6px 12px; border-bottom: 1px solid var(--border); }
.sd-group-row:hover > td { background: var(--panel-2) !important; }
.sd-group-row .sd-grp-label { font-weight: 600; font-size: 12px; color: var(--brand-2); letter-spacing: .04em; text-transform: uppercase; }

/* Tooltip */
.tt { position: fixed; background: #000; color: #fff; font-size: 12px; padding: 6px 10px; border-radius: 6px; z-index: 50; pointer-events: none; white-space: pre-line; box-shadow: 0 4px 16px rgba(0,0,0,.4); }

/* Drag handle */
.handle { cursor: grab; color: var(--muted); }
.handle:active { cursor: grabbing; }
.dragging { opacity: .5; }
.drop-target { outline: 2px dashed var(--brand); outline-offset: -2px; }

/* Utilities */
.muted { color: var(--muted); }
.link { color: var(--brand-2); cursor: pointer; }
.link:hover { text-decoration: underline; }
.divider { border-top: 1px solid var(--border); margin: 16px 0; }
.chip { display:inline-flex; align-items:center; gap:6px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: 12px; margin: 2px; }
.chip .x { cursor: pointer; color: var(--muted); }
.chip .x:hover { color: var(--danger); }

/* Mobile drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30; display:none; }
.drawer-backdrop.open { display:block; }
@media (max-width: 768px) {
  .sidebar { position: fixed; top: 0; right: 0; bottom: 0; left: 0; width: 100%; transform: translateX(100%); transition: transform .25s cubic-bezier(.4,0,.2,1); z-index: 35; display: flex; flex-direction: column; }
  .sidebar.open { transform: translateX(0); }
  .sidebar nav { flex: 1; margin: 8px; }
  .tl-row { grid-template-columns: 48px 1fr 92px; }
  .tl-header { grid-template-columns: 48px 1fr 92px; }
  .timeline-grid { --col-left: 40px; --col-right: 92px; } /* cột gộp nhiệt độ | trạng thái */
}

/* iOS-style toggle switch (relay control on timeline) */
.ios-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.ios-switch input { opacity: 0; width: 0; height: 0; margin: 0; }
.ios-switch .slider {
  position: absolute; inset: 0; background: #3a4764;
  border-radius: 24px; transition: background .2s; cursor: pointer;
}
.ios-switch .slider::before {
  content: ''; position: absolute; width: 20px; height: 20px; border-radius: 50%;
  top: 2px; left: 2px; background: #fff; transition: transform .2s, background .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.ios-switch input:checked + .slider { background: var(--success); }
.ios-switch input:checked + .slider::before { transform: translateX(20px); }
.ios-switch input:disabled + .slider { cursor: not-allowed; }
.ios-switch.disabled .slider { opacity: .35; cursor: not-allowed; }
.ios-switch.pending .slider { opacity: .7; cursor: wait; }
@keyframes ios-spin { to { transform: rotate(360deg); } }

/* Inline spinner + countdown shown next to the toggle while a relay
   command is in flight. The device acks via SSE (relay_status matches
   the target) which clears the pending state; this UI is the user's
   feedback that the command was sent and is being waited on. */
.tl-ctrl {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%;
}
.tl-temp-cell {
  border-left: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.tl-temp {
  font-size: 12px; font-weight: 500;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px; cursor: default;
}
.tl-temp-mat  { background: rgba(16,185,129,.15);  color: #34d399; } /* <32°C  — Mát mẻ */
.tl-temp-nong { background: rgba(239,68,68,.15);   color: #f87171; } /* ≥32°C  — Nóng   */

/* Cột gộp: nút điều khiển chia đôi [ nhiệt độ | trạng thái ]. Mọi nút cùng
   một chiều rộng cố định 80px, hai nửa chia đều (grid 1fr 1px 1fr) bất kể
   nội dung dài ngắn — nội dung tràn thì cắt gọn chứ không nong nút. */
.tl-ctrl-cell { border-left: 1px solid var(--border); display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.tl-split {
  box-sizing: border-box;
  display: grid; grid-template-columns: 1fr 1px 1fr;
  width: 80px; height: 26px;
  border: 1px solid #2a3d63; border-radius: 6px; overflow: hidden;
  background: transparent; padding: 0;
  font-family: inherit; font-size: 12px; font-weight: 500;
  font-variant-numeric: tabular-nums;
}
button.tl-split { cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.3); transition: filter .15s, box-shadow .15s; }
button.tl-split:hover:not(:disabled)  { filter: brightness(1.18); box-shadow: 0 2px 8px rgba(0,0,0,.4); }
button.tl-split:active:not(:disabled) { filter: brightness(.95);  box-shadow: 0 0 2px rgba(0,0,0,.3); }
button.tl-split:disabled { cursor: default; opacity: .75; }
.tl-split-temp, .tl-split-status {
  min-width: 0; height: 100%; overflow: hidden; white-space: nowrap;
  display: flex; align-items: center; justify-content: center;
}
.tl-split-div { background: #2a3d63; }
.tl-split-temp-none { background: rgba(100,116,139,.14); color: #5f6f8c; }
/* Mất kết nối: badge đỏ full-width, cùng kích thước nút để thẳng cột */
.tl-ctrl-full {
  box-sizing: border-box;
  display: flex; align-items: center; justify-content: center;
  width: 80px; height: 26px; border-radius: 6px; border: 1px solid transparent;
  font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden;
}
.tl-pending {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
  min-width: 44px;
}
.tl-override-count {
  display: inline-flex; align-items: center;
  font-size: 11px; color: #60a5fa; font-weight: 600;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  min-width: 44px;
}
.tl-spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.15); border-top-color: var(--brand-2);
  animation: ios-spin .8s linear infinite;
  flex: none;
}

/* Empty state */
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #2d3f66; }

/* ============================================================
   Tailwind utility fallback
   ============================================================
   We load Tailwind via cdn.tailwindcss.com (JIT in-browser).
   On long-running mobile sessions the JIT can stop running:
   - iOS Safari suspends scripts on idle tabs / memory pressure
   - flaky cellular network kills the script mid-load
   - the Play CDN explicitly says "not for production"
   When that happens, every utility class (`hidden`, `flex`,
   `w-8`, `md:hidden`, etc.) silently no-ops — sidebar pops
   into the document flow, `<img class="w-8 h-8">` renders at
   natural size, dropdown menus stop hiding. This block is a
   minimal redundancy layer: only the classes the codebase
   actually uses, kept compact so it costs ~3KB extra. If
   Tailwind CDN dies, the layout still holds.

   When Tailwind CDN is alive both rule sets apply; same
   declarations so no visual change. When it dies, this block
   is the only thing standing between you and the screenshot.
   ============================================================ */

/* Display */
.block { display: block; }
.inline-block { display: inline-block; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }
.hidden { display: none; }

/* Flex */
.flex-1 { flex: 1 1 0%; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.shrink-0 { flex-shrink: 0; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: .25rem; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }

/* Sizing */
.w-2 { width: .5rem; } .h-2 { height: .5rem; }
.w-8 { width: 2rem; } .h-8 { height: 2rem; }
.w-9 { width: 2.25rem; } .h-9 { height: 2.25rem; }
.w-14 { width: 3.5rem; } .h-14 { height: 3.5rem; }
.w-56 { width: 14rem; }
.w-full { width: 100%; } .h-full { height: 100%; }
.h-screen { height: 100vh; }
.min-w-0 { min-width: 0; }
.max-w-md { max-width: 28rem; }

/* Spacing — padding */
.p-1 { padding: .25rem; }
.p-4 { padding: 1rem; }
.p-8 { padding: 2rem; }
.px-1 { padding-left: .25rem; padding-right: .25rem; }
.px-3 { padding-left: .75rem; padding-right: .75rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.py-1 { padding-top: .25rem; padding-bottom: .25rem; }
.py-2 { padding-top: .5rem; padding-bottom: .5rem; }
.py-3 { padding-top: .75rem; padding-bottom: .75rem; }
.pb-2 { padding-bottom: .5rem; }
.pl-9 { padding-left: 2.25rem; }
.pt-4 { padding-top: 1rem; }

/* Spacing — margin */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mb-1 { margin-bottom: .25rem; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.my-1 { margin-top: .25rem; margin-bottom: .25rem; }
.ml-auto { margin-left: auto; }

/* Stacked spacing (Tailwind: space-y-N adds margin-top to all but first child) */
.space-y-2 > * + * { margin-top: .5rem; }
.space-y-3 > * + * { margin-top: .75rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }

/* Position */
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.top-1 { top: .25rem; }
.left-3 { left: .75rem; }
.right-0 { right: 0; }
.bottom-4 { bottom: 1rem; }
.right-4 { right: 1rem; }
.inset-0 { top: 0; right: 0; bottom: 0; left: 0; }
.z-50 { z-index: 50; }

/* Border */
.border { border-width: 1px; border-style: solid; }
.border-t { border-top-width: 1px; border-top-style: solid; }
.border-b { border-bottom-width: 1px; border-bottom-style: solid; }
.border-transparent { border-color: transparent; }
.rounded { border-radius: .25rem; }
.rounded-lg { border-radius: .5rem; }
.rounded-xl { border-radius: .75rem; }
.rounded-full { border-radius: 9999px; }

/* Text */
.text-xs { font-size: .75rem; line-height: 1rem; }
.text-sm { font-size: .875rem; line-height: 1.25rem; }
.text-lg { font-size: 1.125rem; line-height: 1.75rem; }
.text-xl { font-size: 1.25rem; line-height: 1.75rem; }
.text-white { color: #fff; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }
.tracking-wide { letter-spacing: .025em; }

/* Backgrounds */
.bg-transparent { background: transparent; }
.bg-gradient-to-br { background-image: linear-gradient(to bottom right, var(--tw-gradient-from, #6366f1), var(--tw-gradient-to, #a855f7)); }
.from-indigo-500 { --tw-gradient-from: #6366f1; }
.to-purple-500 { --tw-gradient-to: #a855f7; }

/* Misc */
.opacity-40 { opacity: .4; }
.pointer-events-none { pointer-events: none; }
.whitespace-nowrap { white-space: nowrap; }
.overflow-hidden { overflow: hidden; }
.overflow-x-auto { overflow-x: auto; }
.shadow-2xl { box-shadow: 0 25px 50px -12px rgba(0,0,0,.25); }

/* WiFi signal bars */
.wifi-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; vertical-align: middle; }
.wifi-bars span:not(.wifi-dbm) { display: block; width: 3px; border-radius: 1px; background: var(--border); }
.wifi-bars span:nth-child(1) { height: 25%; }
.wifi-bars span:nth-child(2) { height: 50%; }
.wifi-bars span:nth-child(3) { height: 75%; }
.wifi-bars span:nth-child(4) { height: 100%; }
.wifi-bars[data-lvl="1"] span:nth-child(1) { background: var(--danger); }
.wifi-bars[data-lvl="2"] span:nth-child(1), .wifi-bars[data-lvl="2"] span:nth-child(2) { background: var(--warning); }
.wifi-bars[data-lvl="3"] span:nth-child(1), .wifi-bars[data-lvl="3"] span:nth-child(2), .wifi-bars[data-lvl="3"] span:nth-child(3) { background: var(--brand); }
.wifi-bars[data-lvl="4"] span:not(.wifi-dbm) { background: var(--success); }
.wifi-dbm { font-size: 11px; color: var(--muted); margin-left: 3px; line-height: 1; align-self: center; }

/* Duration display — responsive full/short/truncated */
.dur-cell { container-type: inline-size; overflow: hidden; white-space: nowrap; text-align: left; }
.dur-wrap { white-space: nowrap; }
.dur-s { display: none; }
@container (max-width: 110px) {
  .dur-f { display: none; }
  .dur-s { display: inline; }
}

/* Grid */
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.col-span-2 { grid-column: span 2 / span 2; }

/* Responsive — sm: ≥ 640px */
@media (min-width: 640px) {
  .sm\:block { display: block; }
}

/* Responsive — md: ≥ 768px */
@media (min-width: 768px) {
  .md\:hidden { display: none; }
  .md\:p-6 { padding: 1.5rem; }
  .md\:px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
  .md\:gap-2 { gap: .5rem; }
  .md\:gap-3 { gap: .75rem; }
  .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .md\:col-span-2 { grid-column: span 2 / span 2; }
}
