/* ── Apollo Dark / Light – UiPath Design System ──────────────────────────────
   Token map: --c-bg · --c-surface · --c-border · --c-bh · --c-text
              --c-muted · --c-flabel · --c-ph · --c-blue · --c-skel
   Orange #FA4616 is a brand constant — not tokenised.
   ─────────────────────────────────────────────────────────────────────────── */

/* ── Design tokens ────────────────────────────────────────────────────────── */
:root {
  --c-bg:         #040E19;
  --c-surface:    #0B1929;
  --c-elevated:   #162536;
  --c-border:     #1E293B;
  --c-bh:         #2A3F5A;
  --c-text:       #C8D8E8;
  --c-muted:      #5A7A9A;
  --c-flabel:     #7A9AB8;
  --c-ph:         #3A5470;
  --c-blue:       #00AEEF;
  --c-skel:       #1E293B;
  --c-today-tint: rgba(250,70,22,.018);
  --c-half-line:  rgba(30,41,59,.6);
  --c-glow:       rgba(255,255,255,.03);
  --c-hglow:      rgba(255,255,255,.04);
  --c-tt-shadow:  rgba(0,0,0,.65);
  --c-tst-shadow: rgba(0,0,0,.55);
}

[data-theme="light"] {
  --c-bg:         #FFFFFF;
  --c-surface:    #F4F5F7;
  --c-border:     #E2E8F0;
  --c-bh:         #CBD5E1;
  --c-text:       #1A2332;
  --c-muted:      #6B7280;
  --c-flabel:     #4B5563;
  --c-ph:         #9CA3AF;
  --c-blue:       #0080C9;
  --c-skel:       #E2E8F0;
  --c-today-tint: rgba(250,70,22,.05);
  --c-half-line:  rgba(226,232,240,.9);
  --c-glow:       rgba(0,0,0,.02);
  --c-hglow:      rgba(0,0,0,.06);
  --c-tt-shadow:  rgba(0,0,0,.15);
  --c-tst-shadow: rgba(0,0,0,.12);
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbars ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--c-bg); }
::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--c-bh); }

/* ── Skeleton pulse ──────────────────────────────────────────────────────── */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.35; }
  50%       { opacity: 0.75; }
}
.skeleton {
  background: var(--c-skel);
  border-radius: 4px;
  animation: skeleton-pulse 1.6s ease-in-out infinite;
}

/* ── Range slider ────────────────────────────────────────────────────────── */
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: var(--c-border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #FA4616;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
input[type=range]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 0 4px rgba(250,70,22,.2);
}
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #FA4616;
  cursor: pointer;
  border: none;
}

/* ── Calendar grid ───────────────────────────────────────────────────────── */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
}

.cal-day {
  min-height: 90px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 5px;
  overflow: hidden;
  transition: border-color .15s;
}
.cal-day:hover        { border-color: var(--c-bh); }
.cal-day.today        { border-color: #FA4616; }
.cal-day.other-month  { opacity: 0.38; }

.cal-day-num {
  font-size: 11px;
  font-weight: 600;
  color: var(--c-muted);
  margin-bottom: 4px;
  letter-spacing: .02em;
}
.cal-day.today .cal-day-num { color: #FA4616; }

/* ── Event chips ─────────────────────────────────────────────────────────── */
.event-chip {
  font-size: 10px;
  font-weight: 600;
  font-family: 'Inter', system-ui, sans-serif;
  padding: 2px 5px;
  border-radius: 3px;
  margin-bottom: 2px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: filter .1s;
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  letter-spacing: .01em;
}
.event-chip:hover { filter: brightness(1.15); }

/* ── Tooltip ─────────────────────────────────────────────────────────────── */
.tooltip {
  position: fixed;
  z-index: 9999;
  background: var(--c-elevated);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  padding: 10px 14px;
  min-width: 240px;
  max-width: 320px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5), 0 8px 32px var(--c-tt-shadow), 0 0 0 1px rgba(255,255,255,0.04);
  pointer-events: none;
  font-size: 12px;
  line-height: 1.6;
}
.tooltip-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--c-blue);
  margin-bottom: 6px;
  word-break: break-word;
}
.tooltip-row   { display: flex; justify-content: space-between; gap: 12px; }
.tooltip-label { color: var(--c-muted); white-space: nowrap; font-weight: 500; }
.tooltip-value { color: var(--c-text); text-align: right; word-break: break-all; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 284px;
  min-width: 240px;
  flex-shrink: 0;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  overflow-y: auto;
  padding: 16px;
}

/* ── Inputs / selects ────────────────────────────────────────────────────── */
input[type=text],
input[type=password],
input[type=number],
select,
textarea {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  color: var(--c-text);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 400;
  width: 100%;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' stroke='%235A7A9A' stroke-width='2.5' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 14px;
  padding-right: 28px;
  cursor: pointer;
}
input[type=text]:focus,
input[type=password]:focus,
input[type=number]:focus,
select:focus,
textarea:focus {
  border-color: var(--c-blue);
  box-shadow: 0 0 0 2px rgba(0,174,239,.12);
}
input::placeholder { color: var(--c-ph); }

/* ── Form labels ─────────────────────────────────────────────────────────── */
.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--c-flabel);
  margin-bottom: 4px;
  letter-spacing: .01em;
}

/* ── Checkboxes ──────────────────────────────────────────────────────────── */
input[type=checkbox] {
  accent-color: #FA4616;
  width: 14px; height: 14px;
  cursor: pointer;
}

/* ── Primary button ──────────────────────────────────────────────────────── */
.btn-primary {
  background: #FA4616;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 8px 18px;
  font-size: 12px;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .1s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn-primary:hover {
  background: #d63c10;
  box-shadow: 0 2px 10px rgba(250,70,22,.35);
}
.btn-primary:active  { transform: scale(.97); }
.btn-primary:disabled { background: #4A2510; color: #7A4030; cursor: not-allowed; box-shadow: none; }

/* ── Ghost button ────────────────────────────────────────────────────────── */
.btn-ghost {
  background: transparent;
  color: var(--c-muted);
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 11px;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.btn-ghost:hover { color: var(--c-text); border-color: var(--c-bh); background: var(--c-hglow); }

/* ── Theme toggle ────────────────────────────────────────────────────────── */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 5px 8px;
  color: var(--c-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, border-color .15s, background .15s;
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--c-text); border-color: var(--c-bh); background: var(--c-hglow); }

/* ── Toggle switch ───────────────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: var(--c-border);
  cursor: pointer;
  transition: background .2s;
  border: 1px solid var(--c-bh);
}
.toggle-switch input:checked + .toggle-track { background: #FA4616; border-color: #FA4616; }
.toggle-thumb {
  position: absolute;
  height: 14px; width: 14px;
  left: 2px; top: 2px;
  background: var(--c-text);
  border-radius: 50%;
  transition: transform .2s;
  pointer-events: none;
}
.toggle-switch input:checked + .toggle-track .toggle-thumb {
  transform: translateX(16px);
}

/* ── Toast notification ──────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 400px;
  width: calc(100vw - 32px);
}
.toast {
  pointer-events: all;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left: 3px solid #FA4616;
  border-radius: 4px;
  padding: 10px 12px 10px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  box-shadow: 0 4px 24px var(--c-tst-shadow), 0 0 0 1px var(--c-glow);
  animation: toast-in .2s ease-out;
}
.toast.toast-error  { border-left-color: #FA4616; }
.toast.toast-warn   { border-left-color: #FFB800; }
.toast.toast-info   { border-left-color: var(--c-blue); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0);    }
}
.toast-icon { flex-shrink: 0; margin-top: 1px; color: #FA4616; }
.toast.toast-warn .toast-icon { color: #FFB800; }
.toast.toast-info .toast-icon { color: var(--c-blue); }
.toast-body { flex: 1; min-width: 0; }
.toast-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text);
  margin-bottom: 2px;
  letter-spacing: .01em;
}
.toast-message {
  font-size: 11px;
  color: var(--c-flabel);
  line-height: 1.5;
  word-break: break-word;
}
.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--c-muted);
  cursor: pointer;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  transition: color .15s;
  margin-top: -1px;
}
.toast-close:hover { color: var(--c-text); }
.toast-detail {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--c-border);
  font-size: 11px;
  color: var(--c-flabel);
  line-height: 1.6;
}
.toast-detail ol { margin: 4px 0 0 16px; padding: 0; }
.toast-detail li { margin-bottom: 3px; }
.toast-detail strong { color: var(--c-blue); font-weight: 600; }

/* ── Legend dot ──────────────────────────────────────────────────────────── */
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

/* ── Month navigation ────────────────────────────────────────────────────── */
.month-nav button {
  background: transparent;
  border: none;
  color: var(--c-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 18px;
  line-height: 1;
  transition: color .15s;
}
.month-nav button:hover { color: var(--c-text); }

/* ── Header ──────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  padding: 11px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 var(--c-glow);
}

/* ── "More events" overflow ──────────────────────────────────────────────── */
.more-events {
  font-size: 10px;
  font-weight: 500;
  color: var(--c-muted);
  padding: 1px 4px;
  cursor: pointer;
  background: none;
  border: none;
  font-family: 'Inter', system-ui, sans-serif;
  letter-spacing: .01em;
}
.more-events:hover { color: var(--c-text); }

/* ── Section label ───────────────────────────────────────────────────────── */
.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--c-muted);
  margin-bottom: 8px;
}

/* ── Divider ─────────────────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--c-border); margin: 14px 0; }

/* ── View switcher ───────────────────────────────────────────────────────── */
.view-switcher {
  display: flex;
  gap: 2px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 2px;
}
.view-btn {
  background: transparent;
  border: none;
  border-radius: 3px;
  padding: 4px 10px;
  font-size: 11px;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--c-muted);
  cursor: pointer;
  transition: background .13s, color .13s;
  white-space: nowrap;
}
.view-btn:hover  { background: var(--c-hglow); color: var(--c-text); }
.view-btn.active { background: #FA4616; color: #fff; }

/* ── Collapsible sidebar section ─────────────────────────────────────────── */
.collapsible-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: none;
  border-radius: 4px;
  padding: 5px 4px;
  cursor: pointer;
  color: var(--c-text);
  transition: background .13s;
  gap: 6px;
}
.collapsible-btn:hover { background: var(--c-hglow); }
.collapsible-chevron { flex-shrink: 0; color: var(--c-muted); transition: transform .2s; }
.collapsible-chevron.open { transform: rotate(180deg); }

/* ── Time-grid ───────────────────────────────────────────────────────────── */
.tg-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
.tg-header {
  display: flex;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
  background: var(--c-surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.tg-gutter { width: 52px; flex-shrink: 0; }
.tg-day-hdr {
  flex: 1;
  text-align: center;
  padding: 6px 4px 8px;
  border-left: 1px solid var(--c-border);
  min-width: 0;
}
.tg-day-hdr:first-child { border-left: none; }
.tg-day-weekday {
  font-size: 10px;
  font-weight: 600;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 3px;
}
.tg-day-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--c-text);
}
.tg-day-num.today { background: #FA4616; color: #fff; }
.tg-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; }
.tg-body { display: flex; position: relative; }
.tg-time-col { width: 52px; flex-shrink: 0; position: relative; pointer-events: none; }
.tg-time-label {
  position: absolute;
  right: 8px;
  font-size: 10px;
  font-weight: 500;
  color: var(--c-muted);
  transform: translateY(-50%);
  white-space: nowrap;
  line-height: 1;
}
.tg-col { flex: 1; position: relative; border-left: 1px solid var(--c-border); min-width: 0; }
.tg-hour-line {
  position: absolute; left: 0; right: 0;
  border-top: 1px solid var(--c-border);
  pointer-events: none;
}
.tg-half-line {
  position: absolute; left: 0; right: 0;
  border-top: 1px dashed var(--c-half-line);
  pointer-events: none;
}
.tg-now-line {
  position: absolute; left: 0; right: 0;
  border-top: 2px solid #FA4616;
  z-index: 3;
  pointer-events: none;
}
.tg-now-dot {
  position: absolute;
  left: -4px; top: -4px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #FA4616;
}
.tg-event {
  position: absolute;
  border-radius: 3px;
  padding: 2px 5px;
  overflow: hidden;
  cursor: pointer;
  z-index: 1;
  font-size: 10px;
  font-weight: 600;
  font-family: 'Inter', system-ui, sans-serif;
  line-height: 1.3;
  transition: filter .1s;
}
.tg-event:hover { filter: brightness(1.15); z-index: 2; }
.tg-event-warn { box-shadow: inset 0 0 0 1px #FFB80066 !important; }
.tg-event-time { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg-event-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .88; }

/* ── Warn badge on event chip ─────────────────────────────────────────────── */
.event-warn-badge {
  font-size: 9px;
  margin-right: 2px;
  vertical-align: middle;
  line-height: 1;
  display: inline-block;
}

/* ── Gap strip between tightly-packed events ─────────────────────────────── */
.tg-gap-strip {
  position: absolute;
  left: 1px;
  right: 1px;
  height: 3px;
  background: linear-gradient(90deg, #FFB80066, #FA461644);
  border-radius: 2px;
  z-index: 2;
  pointer-events: none;
}

/* ── Machine template slot background bars ───────────────────────────────── */
.tg-template-slot {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(0,174,239,0.04);
  border-right: 1px dashed rgba(0,174,239,0.12);
  pointer-events: none;
  z-index: 0;
}

/* ── URL preview block ───────────────────────────────────────────────────── */
.url-preview {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 7px 9px;
  margin-bottom: 10px;
}
.url-preview-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--c-muted);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: .07em;
}
.url-preview-value {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 10px;
  color: var(--c-blue);
  word-break: break-all;
  line-height: 1.5;
}

/* ── Popover (anchored dropdown) ─────────────────────────────────────────────── */
.popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 320px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.55);
  z-index: 500;
  display: flex;
  flex-direction: column;
  overflow: visible;
}
/* Caret arrow */
.popover::before {
  content: '';
  position: absolute;
  top: -5px;
  left: 16px;
  width: 10px;
  height: 10px;
  background: var(--c-surface);
  border-left: 1px solid var(--c-border);
  border-top: 1px solid var(--c-border);
  transform: rotate(45deg);
}
/* Right-aligned variant (caret on right side) */
.popover-right {
  left: auto;
  right: 0;
}
.popover-right::before {
  left: auto;
  right: 16px;
}
.popover-header {
  padding: 11px 16px 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}
.popover-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: min(460px, calc(100vh - 120px));
  overflow-y: auto;
  overflow-x: visible;
}
.popover-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--c-border);
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Modal-field (reused inside popovers) ────────────────────────────────────── */
.modal-field { display: flex; flex-direction: column; gap: 4px; }
.field-hint {
  font-size: 11px;
  color: var(--c-muted);
  line-height: 1.5;
}

/* ── Hint icon + tooltip ─────────────────────────────────────────────────────── */
.hint-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: help;
  margin-left: 5px;
  flex-shrink: 0;
}
.hint-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--c-border);
  color: var(--c-muted);
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  font-style: normal;
  user-select: none;
  transition: background .15s, color .15s;
}
.hint-wrap:hover .hint-icon {
  background: var(--c-bh);
  color: var(--c-text);
}
/* Tooltip rendered via fixed position in JS — just needs styling */
.hint-tooltip {
  position: fixed;
  transform: translate(-50%, calc(-100% - 8px));
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 7px;
  padding: 7px 11px;
  font-size: 11px;
  font-weight: 400;
  color: var(--c-text);
  line-height: 1.55;
  z-index: 9000;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  white-space: normal;
  max-width: 220px;
}

/* Light-mode overrides */
[data-theme="light"] .popover {
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .hint-tooltip {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}
