@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #14151a;
  --surface: #1b1d24;
  --surface-raised: #22242c;
  --border: #2c2f3a;
  --text: #eae8e3;
  --text-muted: #8b8d98;
  --accent: #e8a33d;
  --accent-dim: #e8a33d33;
  --success: #5fb88a;
  --success-dim: #5fb88a26;
  --danger: #e2604f;
  --danger-dim: #e2604f26;
  --blocked: #c97fd6;
  --radius: 6px;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --display: 'Space Grotesk', sans-serif;
  --body: 'Inter', sans-serif;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

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

/* --- Sidebar --- */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.brand {
  font-family: var(--display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.brand .dot { color: var(--accent); }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13.5px;
  border-left: 2px solid transparent;
  transition: color 0.15s ease, background 0.15s ease;
}
.nav-link svg { flex-shrink: 0; opacity: 0.85; }
.nav-link:hover { color: var(--text); background: var(--surface-raised); }
.nav-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-dim);
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 20px 0;
  border-top: 1px solid var(--border);
}
.sidebar-user {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.sidebar-user strong { color: var(--text); display: block; font-weight: 600; }
.role-badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--surface-raised);
  color: var(--text-muted);
  border: 1px solid var(--border);
  margin-top: 4px;
}

/* --- Main --- */
.main {
  flex: 1;
  padding: 32px 40px;
  max-width: 1180px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title {
  font-family: var(--display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.page-subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* --- Cards / surfaces --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2), 0 8px 24px -12px rgba(0,0,0,0.35);
}
.card + .card { margin-top: 16px; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--body);
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease, background 0.15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1408;
  box-shadow: 0 4px 14px -4px var(--accent-dim);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Forms --- */
label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }
input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  font-family: var(--body);
  font-size: 13.5px;
}
textarea { resize: vertical; min-height: 50px; }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row > .field { flex: 1; min-width: 140px; }

.checkbox-list { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.checkbox-item { display: flex; align-items: center; gap: 6px; width: auto; font-size: 13.5px; color: var(--text); font-weight: 400; }
.checkbox-item input { width: auto; }

/* --- Table --- */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
.num { font-family: var(--mono); }

/* --- Timesheet calendar + day panel --- */
.week-total {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--accent);
}

.timesheet-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start;
}
/* .card + .card adds vertical spacing for stacked single-column cards
   elsewhere; override it here since these two cards sit side by side. */
.timesheet-layout > .card + .card { margin-top: 0; }

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.calendar-month-label {
  font-family: var(--display);
  font-weight: 600;
  font-size: 15px;
}
.calendar-nav-btns { display: flex; gap: 6px; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.calendar-weekday {
  text-align: center;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding-bottom: 6px;
}
.calendar-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  color: var(--text);
  font-size: 12.5px;
  position: relative;
}
.calendar-day:hover { background: var(--surface-raised); }
.calendar-day.out-of-month { color: var(--text-muted); opacity: 0.4; }
.calendar-day.is-today { border-color: var(--accent); }
.calendar-day.is-selected { background: var(--accent); color: #1a1408; font-weight: 700; }
.calendar-day.is-selected:hover { background: var(--accent); }
.calendar-day .day-hours {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--accent);
}
.calendar-day.is-selected .day-hours { color: #1a1408; }
.calendar-day.has-time:not(.is-selected)::after {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  position: absolute;
  bottom: 5px;
}
.calendar-day.is-complete { background: var(--success-dim); }
.calendar-day.is-incomplete { background: var(--danger-dim); }
.calendar-day.is-selected.is-complete,
.calendar-day.is-selected.is-incomplete { background: var(--accent); }

.day-panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
}
.day-panel-date {
  font-family: var(--display);
  font-size: 19px;
  font-weight: 600;
}
.day-panel-total {
  font-family: var(--mono);
  font-size: 18px;
  color: var(--accent);
  font-weight: 600;
}

.day-entry-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  margin-bottom: 8px;
}
.day-entry-main { flex: 1; min-width: 0; }
.day-entry-title { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 8px; }
.ticket-key {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 6px;
  flex-shrink: 0;
}
.day-entry-project { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.day-entry-notes { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.day-entry-hours { font-family: var(--mono); font-weight: 600; font-size: 14px; flex-shrink: 0; }
.day-entry-hours-form { flex-shrink: 0; }
.day-entry-hours-input {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 14px;
  width: 58px;
  text-align: right;
  padding: 5px 6px;
}

.entry-row { margin-bottom: 10px; align-items: flex-end; }
.entry-remove { flex-shrink: 0; }

/* --- Timesheet weekly overview --- */
.week-overview {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
}
.week-day-col {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 90px;
}
.week-day-col.is-today { border-color: var(--accent); }
.week-day-col.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  background: var(--surface-hover, var(--surface-raised));
}
.week-hint { font-size: 11px; color: var(--text-muted); margin: -4px 0 10px; }
.week-day-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}
.week-day-header:hover { color: var(--accent); }
.week-day-total { font-family: var(--mono); color: var(--text); }
.week-day-empty {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  text-decoration: none;
}
.week-day-empty:hover { color: var(--accent); }
.week-entry { display: flex; align-items: center; gap: 5px; font-size: 11.5px; margin-bottom: 6px; }
.week-entry[draggable="true"] { cursor: grab; }
.week-entry[draggable="true"]:active { cursor: grabbing; }
.week-entry.dragging { opacity: 0.4; }
.week-entry-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.week-entry-hours { font-family: var(--mono); color: var(--text-muted); flex-shrink: 0; }

@media (max-width: 900px) {
  .week-overview { grid-template-columns: repeat(2, 1fr); }
}

/* --- Ticket combobox --- */
.combobox { position: relative; }
.combobox-input { cursor: text; }
.combobox-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 20;
  display: none;
}
.combobox-list.open { display: block; }
.combobox-option {
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}
.combobox-option:last-child { border-bottom: none; }
.combobox-option:hover, .combobox-option.active { background: var(--accent-dim); }
.combobox-option .ticket-key { flex-shrink: 0; }
.combobox-option .opt-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combobox-option .mine-star { color: var(--accent); flex-shrink: 0; }
.combobox-empty { padding: 12px; font-size: 12.5px; color: var(--text-muted); }

/* --- Timeline / Gantt ---
   Fixed pixels-per-day (not percentage-of-container), so the chart has a
   real width wider than the card for any realistic date range — that's
   what makes it scrollable/pannable. Header + bars share one scroll
   container so they can't drift out of sync. */
.gantt-outer { display: flex; gap: 0; align-items: flex-start; }
.gantt-labels-col { width: 220px; flex-shrink: 0; }
.gantt-header-spacer { height: 30px; border-bottom: 1px solid var(--border); }
.gantt-label-row {
  height: 40px;
  display: flex;
  align-items: center;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  padding-right: 12px;
  overflow: hidden;
}
.gantt-label-row:last-child { border-bottom: none; }
.gantt-label-row .ticket-key { flex-shrink: 0; margin-right: 6px; }
.gantt-label-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gantt-label-row { padding-left: 14px; } /* nest under its story header */

.gantt-story-row {
  height: 26px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  border-left: 2px solid transparent;
  padding-left: 6px;
  overflow: hidden;
  white-space: nowrap;
}
.gantt-story-row.is-none { font-style: italic; font-weight: 500; opacity: 0.8; }
.gantt-story-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.gantt-story-count { color: var(--text-muted); font-weight: 400; }
.gantt-story-divider {
  height: 26px;
  border-bottom: 1px solid var(--border);
}

.gantt-scroll {
  flex: 1;
  min-width: 0; /* let the flex item shrink below content width so overflow-x actually scrolls */
  overflow-x: auto;
  overflow-y: hidden;
  cursor: grab;
}
.gantt-scroll.is-dragging { cursor: grabbing; user-select: none; }
.gantt-canvas { position: relative; }

.gantt-header { position: relative; height: 30px; border-bottom: 1px solid var(--border); }
.gantt-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  border-left: 1px dashed var(--border);
  padding-bottom: 4px;
}
.gantt-tick.is-month-start { border-left: 1px solid var(--border); }
.gantt-tick-month {
  position: absolute;
  top: 3px;
  left: 3px;
  font-size: 9.5px;
  color: var(--text-muted);
  white-space: nowrap;
}
.gantt-tick-day { font-size: 11px; color: var(--text-muted); }
.gantt-tick.is-weekend .gantt-tick-day { opacity: 0.5; }

.gantt-rows { position: relative; }
.gantt-row {
  position: relative;
  height: 40px;
  border-bottom: 1px solid var(--border);
}
.gantt-row:last-child { border-bottom: none; }
.gantt-today-line {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: var(--danger);
  z-index: 5;
  pointer-events: none;
}
.gantt-bar {
  position: absolute;
  top: 8px;
  height: 24px;
  border-radius: 4px;
  background: var(--accent);
  color: #1a1408;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  padding: 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 2;
}
.gantt-bar.is-done { background: var(--success); }
.gantt-bar.is-blocked { background: var(--blocked); }

/* --- Chips / tags --- */
.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.tag-open { background: #2c2f3a; color: var(--text-muted); }
.tag-in_progress { background: var(--accent-dim); color: var(--accent); }
.tag-blocked { background: #c97fd633; color: var(--blocked); }
.tag-done { background: #5fb88a33; color: var(--success); }

.project-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; }

/* --- Priority pills --- */
.priority {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.priority-low { background: #2c2f3a; color: var(--text-muted); }
.priority-medium { background: var(--accent-dim); color: var(--accent); }
.priority-high { background: #e2604f33; color: var(--danger); }
.priority-urgent { background: var(--danger); color: #fff; }

/* --- Ticket links (list views -> detail page) --- */
.ticket-link { display: inline-flex; align-items: center; gap: 6px; }
.ticket-link:hover .ticket-title { color: var(--accent); }

/* --- Label chips --- */
.label-chip {
  display: inline-block;
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 10px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  margin: 0 4px 4px 0;
}

/* --- Comments --- */
.comment { padding: 12px 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: none; }
.comment-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; gap: 10px; }
.comment-author { font-weight: 600; font-size: 13px; }
.comment-date { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.comment-body { font-size: 13.5px; white-space: pre-wrap; }

/* --- Bars for reports --- */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.bar-label { width: 140px; font-size: 12.5px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; background: var(--surface-raised); border-radius: 3px; height: 8px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); }
.bar-value { font-family: var(--mono); font-size: 12px; color: var(--text-muted); width: 60px; text-align: right; flex-shrink: 0; }

.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 20px; }
.filters .field { margin-bottom: 0; min-width: 140px; }

.stat-row { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  min-width: 130px;
}
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
.stat-value { font-family: var(--mono); font-size: 22px; font-weight: 600; margin-top: 2px; }

.empty-state {
  color: var(--text-muted);
  font-size: 13px;
  padding: 24px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.banner {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}
.error-text { color: var(--danger); font-size: 13px; margin-bottom: 12px; }
.success-text { color: var(--success); font-size: 13px; margin-bottom: 12px; }

dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2), 0 8px 24px -12px rgba(0,0,0,0.35);
}
dialog::backdrop {
  background: rgba(0,0,0,0.55);
}

/* --- Login --- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px;
}
.login-brand {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.login-brand .dot { color: var(--accent); }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; padding: 10px; align-items: center; }
  .brand { border: none; padding: 0 12px 0 0; margin: 0; }
  .sidebar-footer { display: none; }
  .main { padding: 20px; }
  .timesheet-layout { grid-template-columns: 1fr; }
}
