/* XME Tech — 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: 8px 12px; outline: none; width: 100%;
}
.input:focus, .select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(59,130,246,.2); }
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; }

.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; }

.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(--panel); border-right: 1px solid var(--border); }
.sidebar a { display:flex; align-items:center; gap:10px; padding: 10px 16px; color: var(--muted); font-size: 14px; border-left: 3px solid transparent; }
.sidebar a:hover { background: var(--panel-2); color: var(--text); }
.sidebar a.active { background: var(--panel-2); color: var(--brand-2); border-left-color: var(--brand); font-weight: 500; }
.sidebar .sub a { padding-left: 44px; font-size: 13px; }

/* Header */
.app-header { height: 56px; background: var(--panel); border-bottom: 1px solid var(--border); }
.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: 8px 12px; border-radius: 8px;
}
.date-display:hover { border-color: var(--brand); }

/* 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: var(--panel-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px;
  color: var(--text); font-size: 13px; cursor: pointer;
}
.status-summary:hover { border-color: var(--brand); }
.status-detail { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.status-detail .sep { color: var(--muted); }
@media (max-width: 768px) {
  .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; }
  .date-display { width: 108px; padding: 8px 6px; font-size: 13px; }
  #date-today { padding: 4px 8px; }
}

/* 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: 1180px; --col-left: 140px; --col-right: 180px; }
.tl-body { position: relative; }
.tl-row { display: grid; grid-template-columns: 140px 1fr 90px 90px; align-items: stretch; border-bottom: 1px solid var(--border); }
.tl-row:last-child { border-bottom: none; }
.tl-label { padding: 10px 12px; color: var(--muted); font-size: 13px; display:flex; align-items:center; gap: 6px; background: var(--panel-2); border-right: 1px solid var(--border); }
.rtc-err { cursor: help; font-size: 14px; line-height: 1; }
.tl-bar-area { position: relative; height: 40px; 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-bar { position: absolute; top: 6px; bottom: 6px; border-radius: 2px; cursor: pointer; min-width: 2px; box-sizing: border-box; }
.tl-bar-done { background: #f59e0b; }
.tl-bar-live { background: #10b981; color: #052e1a; }
.tl-bar:hover { filter: brightness(1.1); }
.tl-header { display: grid; grid-template-columns: 140px 1fr 90px 90px; 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: 5; }
.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: linear-gradient(90deg, var(--panel-2), transparent); padding: 8px 16px; font-weight: 600; font-size: 13px; color: var(--brand-2); border-bottom: 1px solid var(--border); letter-spacing: .02em; text-transform: uppercase; }

/* Tooltip */
.tt { position: absolute; 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; left: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s; z-index: 35; }
  .sidebar.open { transform: translateX(0); }
  .tl-row { grid-template-columns: 100px 1fr 70px 70px; }
  .tl-header { grid-template-columns: 100px 1fr 70px 70px; }
  .timeline-grid { --col-left: 100px; --col-right: 140px; }
}

/* 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; }
.ios-switch.pending .slider::after {
  content: ''; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 12px; height: 12px;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  border-radius: 50%; animation: ios-spin .8s linear infinite;
}
@keyframes ios-spin { to { transform: translate(-50%, -50%) rotate(360deg); } }

/* 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; }
