:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel-2: #1f2940;
  --border: #2a3550;
  --text: #e7ecf5;
  --muted: #93a0bd;
  --accent: #4f8cff;
  --accent-2: #6ee7b7;
  --danger: #ff6b6b;
  --warn: #ffcc66;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; letter-spacing: 0.2px; }
.build-badge { font-size: 11px; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.dur { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dur select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px;
}

.btn {
  background: var(--accent); color: #fff; border: none;
  padding: 7px 14px; border-radius: 7px; font-size: 13px; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }

.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; }
.pill-muted { background: var(--panel-2); color: var(--muted); }
.pill-ok { background: rgba(110,231,183,0.15); color: var(--accent-2); }
.pill-bad { background: rgba(255,107,107,0.15); color: var(--danger); }

.banner {
  padding: 10px 18px; background: rgba(255,204,102,0.12);
  color: var(--warn); border-bottom: 1px solid var(--border); font-size: 13px;
}
.banner code { background: rgba(0,0,0,0.3); padding: 1px 5px; border-radius: 4px; }
.hidden { display: none !important; }

.layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 320px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 4px;
}
.sidebar-head h2 { font-size: 14px; margin: 0; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.count { background: var(--panel-2); color: var(--text); font-size: 12px; padding: 2px 9px; border-radius: 999px; }
.sidebar-hint { color: var(--muted); font-size: 12px; margin: 4px 16px 10px; }
.ticket-list { overflow-y: auto; padding: 0 12px 16px; flex: 1; }

.ticket-card {
  background: var(--panel-2); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 8px;
  cursor: grab; transition: transform 0.05s ease, border-color 0.1s ease;
}
.ticket-card:hover { border-color: var(--accent); }
.ticket-card:active { cursor: grabbing; transform: scale(0.99); }
.ticket-card .tc-top { display: flex; justify-content: space-between; gap: 8px; }
.ticket-card .tc-ref { font-size: 11px; color: var(--muted); }
.ticket-card .tc-status { font-size: 11px; color: var(--accent-2); white-space: nowrap; }
.ticket-card .tc-summary { font-size: 13px; margin: 4px 0 2px; line-height: 1.35; }
.ticket-card .tc-meta { font-size: 11px; color: var(--muted); }

.empty { color: var(--muted); font-size: 13px; padding: 20px 6px; text-align: center; }

.calendar-wrap { flex: 1; min-width: 0; padding: 14px; overflow: hidden; }
#calendar { height: 100%; background: var(--panel); border-radius: 10px; padding: 10px; }

/* FullCalendar dark tweaks */
.fc { --fc-border-color: var(--border); --fc-page-bg-color: var(--panel);
  --fc-neutral-bg-color: var(--panel-2); --fc-today-bg-color: rgba(79,140,255,0.08); }
.fc .fc-toolbar-title { font-size: 20px; }
/* Make the header toolbar a 3-column grid so the title is TRULY centered
   (default space-between shifts it right when the left buttons outweigh the
   right ones), keeping it aligned with the centered legend below it. */
.fc .fc-header-toolbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.fc .fc-header-toolbar .fc-toolbar-chunk:nth-child(1) { justify-self: start; }
.fc .fc-header-toolbar .fc-toolbar-chunk:nth-child(2) { justify-self: center; }
.fc .fc-header-toolbar .fc-toolbar-chunk:nth-child(3) { justify-self: end; }
.fc .fc-button { background: var(--panel-2); border-color: var(--border); font-size: 13px; }
.fc .fc-button-primary:not(:disabled).fc-button-active,
.fc .fc-button-primary:hover { background: var(--accent); border-color: var(--accent); }
.fc-theme-standard td, .fc-theme-standard th { border-color: var(--border); }
.fc .fc-col-header-cell-cushion, .fc .fc-timegrid-slot-label-cushion,
.fc .fc-daygrid-day-number { color: var(--muted); }
.fc-event { border: none; border-radius: 6px; padding: 1px 3px; cursor: grab; }
.fc-event .fc-event-main { font-size: 14px; line-height: 1.3; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  padding: 10px 18px; border-radius: 8px; font-size: 13px; z-index: 50;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}
.toast-ok { background: #123524; color: var(--accent-2); border: 1px solid #1f6b45; }
.toast-bad { background: #3a1720; color: var(--danger); border: 1px solid #7a2b39; }

/* Legend */
.legend { display: flex; gap: 12px; align-items: center; justify-content: center; margin: -2px 0 10px; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.swatch-ticket { background: #4f8cff; }
.swatch-appt { background: #6b7280; }

/* Existing-appointment (busy) events: read-only, muted, striped */
.appt-event { cursor: default !important; }
.appt-event .fc-event-main { color: #fff; font-style: italic; }

/* Ticket-linked appointments: solid, editable */
.ticket-appt-event { cursor: grab; }
.ticket-appt-event .fc-event-main { color: #fff; }

/* Click-to-open ticket + remove control */
.ticket-appt-event { position: relative; cursor: pointer; }
.appt-del {
  position: absolute; top: 2px; right: 2px;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; line-height: 1; color: #fff;
  background: rgba(0, 0, 0, 0.35); border-radius: 6px;
  cursor: pointer; opacity: 0.55; z-index: 3;
}
.ticket-appt-event:hover .appt-del { opacity: 0.9; }
.appt-del:hover { opacity: 1; background: var(--danger); }

/* Larger calendar chrome for readability */
.fc .fc-col-header-cell-cushion { font-size: 14px; font-weight: 600; padding: 6px 4px; }
.fc .fc-timegrid-slot-label-cushion { font-size: 13px; }
.fc .fc-timegrid-slot { height: 2.2em; }
.fc .fc-timegrid-axis-cushion { font-size: 12px; }

/* Sidebar status filter */
.sidebar-filter { display: flex; align-items: center; gap: 8px; padding: 0 16px 10px; }
.sidebar-filter label {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.sidebar-filter select {
  flex: 1; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font-size: 12px;
}
.ticket-card .tc-status { font-weight: 600; }

/* Ticket cards are clickable (open in Halo) as well as draggable */
.ticket-card:hover { cursor: pointer; }

/* Agent selector */
.agent-select { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.agent-select select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font-size: 12px;
}

/* Sign-in overlay (oauth mode) */
.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 14, 22, 0.86);
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 32px 36px; text-align: center; max-width: 360px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}
.login-card h2 { margin: 0 0 8px; font-size: 20px; }
.login-card p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.login-card .btn { padding: 10px 20px; font-size: 14px; }

/* Inline "new appointment" modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(10, 14, 22, 0.86);
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px 26px; width: 340px; max-width: calc(100vw - 32px);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}
.modal-card h2 { margin: 0 0 4px; font-size: 18px; }
.modal-sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.modal-field {
  display: block; font-size: 12px; color: var(--muted); margin-bottom: 14px;
}
.modal-field input {
  display: block; width: 100%; margin-top: 6px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px; padding: 9px 10px;
  font-size: 14px;
}
.modal-field input:focus { outline: none; border-color: var(--accent); }
.modal-err { color: var(--danger); font-size: 12px; margin: -4px 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.btn-ghost { background: var(--panel-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }

/* Right-click context menu */
.ctx-menu {
  position: fixed; z-index: 200; min-width: 170px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.ctx-item {
  display: block; width: 100%; text-align: left;
  background: transparent; color: var(--text); border: none;
  padding: 8px 12px; font-size: 13px; border-radius: 6px; cursor: pointer;
  white-space: nowrap;
}
.ctx-item:hover { background: var(--accent); color: #fff; }
.ctx-item:disabled { color: var(--muted); cursor: default; }
.ctx-item:disabled:hover { background: transparent; color: var(--muted); }

/* Completed appointments: light green, dark text */
.swatch-done { background: #86efac; }
.completed-appt-event { cursor: pointer; }
.completed-appt-event .fc-event-main { color: #0f1420; }

/* ---- Tabbed interface ---------------------------------------------------- */
.tabs {
  display: flex; gap: 4px; align-items: flex-end;
  padding: 0 14px; background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.tab {
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-bottom: none;
  padding: 9px 16px; font-size: 13px; cursor: pointer;
  border-radius: 8px 8px 0 0; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text); background: var(--bg);
  border-color: var(--border); border-bottom: 1px solid var(--bg);
}

/* Panels fill the remaining height; only the active one is shown. */
.tab-panels { flex: 1; display: flex; min-height: 0; }
.tab-panel { flex: 1; min-height: 0; display: none; }
.tab-panel.active { display: flex; }

/* Placeholder styling for future tab content. */
.tab-placeholder {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px;
}

/* ---- Kanban board -------------------------------------------------------- */
.kanban {
  flex: 1; display: flex; gap: 12px; padding: 16px;
  overflow-x: auto; overflow-y: hidden; align-items: flex-start;
}
/* Kanban - Client: stack the client picker above the board. */
.tab-panel[data-panel="kanban-client"] { flex-direction: column; }
.client-bar { display: flex; align-items: center; gap: 8px; padding: 12px 16px 0; }
.client-bar label {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.client-bar select {
  min-width: 260px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font-size: 13px;
}
.client-hint { font-size: 12px; color: var(--muted); font-style: italic; }
.kb-col {
  flex: 0 0 280px; max-width: 280px; max-height: 100%;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border);
  border-top: 3px solid var(--accent); border-radius: 10px;
}
.kb-col-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.kb-col-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.kb-col-count { background: var(--panel-2); color: var(--text); font-size: 12px; padding: 2px 9px; border-radius: 999px; }
.kb-col-body { padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.kb-card {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; cursor: pointer;
  transition: border-color 0.1s ease;
}
.kb-card:hover { border-color: var(--accent); }
.kb-card[draggable="true"] { cursor: grab; }
.kb-card[draggable="true"]:active { cursor: grabbing; }
/* Drop-target highlight while dragging one ticket onto another (merge). */
.merge-target {
  border-color: var(--accent-2) !important;
  box-shadow: 0 0 0 2px var(--accent-2) inset;
}
.kb-card-ref { font-size: 11px; color: var(--muted); }
.kb-card-summary { font-size: 13px; margin: 4px 0 2px; line-height: 1.35; }
.kb-card-meta { font-size: 11px; color: var(--muted); }
.kb-card-action { font-size: 11px; color: var(--muted); margin-top: 4px; }
.tc-action { font-size: 11px; color: var(--muted); margin-top: 4px; }
/* Ticket age label colour by staleness: green <2d, orange 2-4d, red 4+d. */
.age-green { color: #86efac; }
.age-orange { color: var(--warn); }
.age-red { color: var(--danger); }

/* Per-column "sort by last action date" toggle in each Kanban column header. */
.kb-col-head { gap: 8px; }
.kb-col-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-sort {
  flex: 0 0 auto; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; line-height: 1; padding: 3px 7px; cursor: pointer;
}
.kb-sort:hover { color: var(--text); border-color: var(--accent); }

/* Daily logged-time rows (Admin / Client / Total) injected into the timegrid
   header, directly above the all-day slot; cells align to the day columns.
   Vertical borders are removed so the labels (which overflow the narrow time
   axis column) are never cut by a gridline; only the block is framed. */
.fc .fc-time-totals-row td {
  border: 0 !important;
  border-top: 1px solid var(--border) !important; /* horizontal gridlines between rows */
  font-size: 12px; text-align: center; padding: 3px 4px;
  color: #fff; background: var(--panel-2); vertical-align: middle;
}
.fc .fc-time-totals-total td {
  border-bottom: 1px solid var(--border) !important;
  font-weight: 700; background: var(--panel);
}
.fc .fc-time-totals-row .fc-tt-label {
  text-align: right !important; white-space: nowrap; font-weight: 600;
  color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.4px; font-size: 11px; padding-right: 8px;
}
/* Total row is colour-coded by hours: <=4 red, >4 & <8 orange, >=8 green.
   Admin/Client values stay white (from the base rule above). */
.fc .fc-time-totals-total .tt-red { color: var(--danger); }
.fc .fc-time-totals-total .tt-orange { color: var(--warn); }
.fc .fc-time-totals-total .tt-green { color: #86efac; }
