/* ─── Variables ──────────────────────────────────────────────── */
:root {
  --accent:       #F97316;
  --accent-dark:  #EA580C;
  --accent-light: #FFF7ED;
  --bg:           #F9FAFB;
  --surface:      #FFFFFF;
  --border:       #E5E7EB;
  --text:         #111827;
  --text-muted:   #6B7280;
  --radius:       8px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08);
  --shadow-md:    0 4px 16px rgba(0,0,0,.1);
}

/* ─── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Utilities ──────────────────────────────────────────────── */
.hidden { display: none !important; }

.empty-text, .loading-text {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.error-text {
  text-align: center;
  padding: 2rem 1rem;
  color: #DC2626;
}

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary  { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: #9CA3AF; }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }

.btn-danger { background: #DC2626; color: #fff; border-color: #DC2626; }
.btn-danger:hover:not(:disabled) { background: #B91C1C; border-color: #B91C1C; }

.btn-sm { padding: .3rem .7rem; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }

/* ─── Form elements ──────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .4rem; }

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  resize: vertical;
}

.form-group select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .65rem center;
  padding-right: 2.2rem;
  cursor: pointer;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(249,115,22,.15);
}

.input-password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-password-wrap input {
  padding-right: 2.5rem;
}

.eye-btn {
  position: absolute;
  right: .5rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  padding: .25rem;
  border-radius: 4px;
  transition: color .15s;
}
.eye-btn:hover { color: var(--text); }

.form-error {
  font-size: 13px;
  color: #DC2626;
  padding: .5rem .75rem;
  background: #FEF2F2;
  border-radius: var(--radius);
  border: 1px solid #FECACA;
}

/* ─── Tooltips ───────────────────────────────────────────────── */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  white-space: nowrap;
  padding: .3rem .6rem;
  border-radius: 5px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s .4s;
  z-index: 1000;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ─── Chips / filter toggles ─────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  padding: .3rem .7rem;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ─── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
}
.badge-backlog    { background: #F3F4F6; color: #6B7280; }
.badge-open       { background: #EFF6FF; color: #2563EB; }
.badge-in_progress{ background: var(--accent-light); color: var(--accent); }
.badge-done       { background: #F0FDF4; color: #16A34A; }

.vis-badge {
  font-size: 12px;
  color: var(--text-muted);
}

/* ─── Auth pages ─────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-sm);
}

.auth-brand {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1.5rem;
  text-align: center;
  letter-spacing: -.02em;
}

#auth-content h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 1.25rem;
}

#auth-content form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-switch {
  text-align: center;
  margin-top: 1.25rem;
  color: var(--text-muted);
  font-size: 13px;
}

/* ─── Sidebar layout ─────────────────────────────────────────── */
#app-section {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 200;
  transition: transform .25s ease;
}

.sidebar-brand {
  padding: 1.25rem 1.25rem 1rem;
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -.02em;
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -.02em;
}

.sidebar-nav {
  flex: 1;
  padding: .75rem .625rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
  overflow-y: auto;
}

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: .65rem;
  width: 100%;
  padding: .55rem .85rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background .15s, color .15s;
}
.sidebar-btn:hover  { background: var(--bg); color: var(--text); }
.sidebar-btn.active {
  background: var(--accent-light);
  color: var(--accent);
}
.sidebar-btn svg { flex-shrink: 0; }

.sidebar-footer {
  padding: 1.1rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: .5rem;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-width: 0;
  flex: 1;
}

.sidebar-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-user-email {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.sidebar-logout:hover { background: #FEF2F2; color: #DC2626; }

/* ─── Mobile top bar ─────────────────────────────────────────── */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: .75rem;
  padding: 0 1rem;
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 150;
}

.sidebar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  padding: .3rem;
  border-radius: var(--radius);
  transition: color .15s, background .15s;
}
.sidebar-toggle:hover { background: var(--bg); color: var(--text); }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 190;
}

/* ─── App main ───────────────────────────────────────────────── */
.app-main {
  margin-left: 220px;
  flex: 1;
  padding: 2rem 2.5rem;
  min-width: 0;
}

/* ─── Page header ────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.02em;
}

/* ─── Page header actions ────────────────────────────────────── */
.page-header-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.view-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
  position: relative;
}
.view-toggle-btn + .view-toggle-btn { border-left: 1px solid var(--border); }
.view-toggle-btn:hover { background: var(--bg); color: var(--text); }
.view-toggle-btn.active { background: var(--accent-light); color: var(--accent); }

/* ─── Kanban board ───────────────────────────────────────────── */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  align-items: start;
}

.kanban-col {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}

.kanban-col--over {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(249,115,22,.12);
}

.kanban-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .65rem .875rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.kanban-col-title { font-size: 13px; font-weight: 600; }

.kanban-col-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .1rem .45rem;
  min-width: 20px;
  text-align: center;
}

.kanban-cards {
  padding: .5rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  min-height: 60px;
}

.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .65rem .75rem;
  cursor: grab;
  transition: border-color .15s, box-shadow .15s;
  user-select: none;
}
.kanban-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(249,115,22,.1);
}
.kanban-card:active { cursor: grabbing; }
.kanban-card--dragging { opacity: .4; }

.kanban-card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: .3rem;
  line-height: 1.4;
}

.kanban-card-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: .3rem;
}

.kanban-empty {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 1rem .5rem;
}

/* ─── Filters bar ────────────────────────────────────────────── */
.filters-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .875rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: center;
}

.filters-bar-search {
  flex: 1;
  min-width: 180px;
  padding: .4rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.filters-bar-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(249,115,22,.15);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}

.filter-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.filter-chips, .filter-owner { display: flex; gap: .3rem; flex-wrap: wrap; }

/* ─── Multiselect dropdown ───────────────────────────────────── */
.ms-wrap { position: relative; }

.ms-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .3rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, color .15s;
  line-height: 1.4;
}
.ms-btn:hover { border-color: var(--accent); color: var(--accent); }
.ms-btn--active { border-color: var(--accent); color: var(--accent); }
.ms-btn--open { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(249,115,22,.12); }
.ms-btn--open svg { transform: rotate(180deg); }
.ms-btn svg { transition: transform .15s; flex-shrink: 0; }

.ms-dropdown {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.1);
  min-width: 160px;
  padding: .25rem 0;
}

.ms-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem .75rem;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  user-select: none;
  transition: background .1s;
}
.ms-item:hover { background: var(--bg); }
.ms-item input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }
.ms-item--selected { color: var(--accent); font-weight: 500; }

.filter-sort { gap: .4rem; }
.filter-sort select,
.select-sm {
  appearance: none;
  -webkit-appearance: none;
  padding: .3rem 1.8rem .3rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .5rem center;
  color: var(--text);
  cursor: pointer;
  outline: none;
}
.filter-sort select:focus,
.select-sm:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(249,115,22,.15); }

/* override form-group's width:100% for compact selects */
.form-group .select-sm { width: auto; }

/* ─── Ticket list ────────────────────────────────────────────── */
#tickets-list { display: flex; flex-direction: column; gap: .5rem; }

.ticket-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .875rem 1rem;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.ticket-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(249,115,22,.1);
}

.ticket-card-top {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .4rem;
}

.ticket-card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: .35rem;
  color: var(--text);
}

.ticket-card-meta {
  display: flex;
  gap: .4rem;
  font-size: 12px;
  color: var(--text-muted);
}

/* ─── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.page-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.page-btn:hover:not(:disabled)  { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

.page-ellipsis {
  min-width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ─── Modal ──────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 1rem;
}

#modal-box {
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  gap: .75rem;
}

.modal-header-left { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

.modal-header-right { display: flex; align-items: center; gap: .25rem; }

.modal-title-sm { font-size: 15px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  padding: .25rem .5rem;
  border-radius: var(--radius);
  line-height: 1;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.3;
}

.modal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  font-size: 12px;
  color: var(--text-muted);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .5rem;
  padding: .875rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* ─── Fullscreen modal ───────────────────────────────────────── */
#modal-overlay.modal-fullscreen { padding: 0; align-items: stretch; }

#modal-box.modal-fullscreen {
  max-width: none;
  max-height: none;
  width: 100%;
  height: 100%;
  border-radius: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#modal-box.modal-fullscreen #modal-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.modal-fs-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.modal-fs-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

.modal-fs-layout--edit .modal-fs-main { overflow: hidden; }

.modal-fs-desc-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.modal-fs-desc-write {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.modal-fs-desc-write #f-desc {
  flex: 1;
  min-height: 0;
  resize: none;
}

.modal-fs-side {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.5rem;
  overflow-y: auto;
}

.modal-fs-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: .25rem;
}

.modal-fs-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

/* ─── Markdown preview tabs ──────────────────────────────────── */
.md-tabs {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: none;
  overflow: hidden;
}

.md-tab {
  padding: .35rem .85rem;
  border: none;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, color .15s;
}
.md-tab.active { background: var(--surface); color: var(--text); font-weight: 500; }
.md-tab:hover:not(.active) { background: var(--border); }

#md-write textarea {
  border-radius: 0 0 var(--radius) var(--radius);
  border: 1px solid var(--border);
}

#md-preview {
  min-height: 160px;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--bg);
}

/* ─── Visibility toggle (in form) ────────────────────────────── */
.vis-toggle { display: flex; gap: .4rem; }

/* ─── Markdown body ──────────────────────────────────────────── */
.markdown-body { line-height: 1.65; color: var(--text); }
.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  font-weight: 600; margin: 1rem 0 .4rem; letter-spacing: -.01em;
}
.markdown-body h1 { font-size: 1.3em; }
.markdown-body h2 { font-size: 1.15em; }
.markdown-body h3 { font-size: 1em; }
.markdown-body p  { margin: .5rem 0; }
.markdown-body ul, .markdown-body ol { padding-left: 1.5rem; margin: .5rem 0; }
.markdown-body li { margin: .2rem 0; }
.markdown-body a  { color: var(--accent); }
.markdown-body code {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: .88em;
  background: #F3F4F6;
  padding: .15em .35em;
  border-radius: 4px;
}
.markdown-body pre {
  background: #1E293B;
  color: #E2E8F0;
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: .75rem 0;
}
.markdown-body pre code { background: none; padding: 0; color: inherit; }
.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  color: var(--text-muted);
  margin: .75rem 0;
  font-style: italic;
}
.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}
.markdown-body table { border-collapse: collapse; width: 100%; margin: .75rem 0; }
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: .4rem .75rem;
  text-align: left;
}
.markdown-body th { background: var(--bg); font-weight: 600; }
.no-description { color: var(--text-muted); font-style: italic; font-size: 13px; }

/* ─── Settings page ──────────────────────────────────────────── */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
}
.section-header h2 { font-size: 16px; font-weight: 600; }

.section-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 1.25rem; }

.keys-list { display: flex; flex-direction: column; gap: .5rem; }

.key-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  gap: 1rem;
}

.key-info { display: flex; flex-direction: column; gap: .2rem; min-width: 0; }

.key-name { font-weight: 500; font-size: 14px; }

.key-meta { font-size: 12px; color: var(--text-muted); }

.key-warning {
  font-size: 13px;
  color: #92400E;
  background: #FEF3C7;
  border: 1px solid #FDE68A;
  border-radius: var(--radius);
  padding: .5rem .75rem;
  margin-bottom: .75rem;
}

.key-display {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem .75rem;
}

.key-display code {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
  flex: 1;
  color: var(--text);
}

/* ─── Toast notification ─────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: .6rem 1rem;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transform: translateY(.5rem);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  max-width: 320px;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.toast-success { background: #111827; color: #fff; }
.toast-error   { background: #DC2626; color: #fff; }

/* ─── Agent page ─────────────────────────────────────────────── */
#app-section:has(#agent-page:not(.hidden)) .app-main {
  padding: 0;
}

.agent-page-chat .chat-panel-header {
  padding: 1.25rem 1.25rem 1rem;
  font-size: 17px;
}

.agent-page-chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--surface);
  overflow: hidden;
}

/* ─── Chat messages area ─────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.chat-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 14px;
}

.chat-msg { display: flex; flex-direction: column; gap: .25rem; }

.chat-msg-user  { align-items: flex-end; }
.chat-msg-assistant { align-items: flex-start; }

.chat-bubble {
  max-width: 80%;
  padding: .6rem .875rem;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}

.chat-msg-user .chat-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble-assistant {
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-tool-call {
  font-size: 12px;
  color: var(--text-muted);
  padding: .2rem .5rem;
  background: var(--bg);
  border-radius: 4px;
  border: 1px solid var(--border);
  align-self: flex-start;
  max-width: 80%;
}

/* ─── Agent steps (verbose mode) ────────────────────────────── */
.chat-steps { display: flex; flex-direction: column; gap: .25rem; align-self: flex-start; max-width: 90%; }

.chat-step {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.chat-step-call {
  padding: .3rem .6rem;
  font-family: monospace;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

.chat-step-meta {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 10px;
  color: var(--text-muted);
  opacity: .75;
  white-space: nowrap;
}

.chat-usage-summary {
  font-size: 11px;
  color: var(--text-muted);
  opacity: .7;
  margin-top: .4rem;
  padding: .2rem .1rem;
  align-self: flex-start;
}

.chat-step-result {
  padding: .3rem .6rem;
  font-size: 11px;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 80px;
  overflow-y: auto;
}

/* ─── Typing indicator ───────────────────────────────────────── */
.chat-typing .chat-bubble {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: .75rem 1rem;
}

.chat-typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: dot-bounce .9s infinite ease-in-out;
}
.chat-typing .dot:nth-child(2) { animation-delay: .15s; }
.chat-typing .dot:nth-child(3) { animation-delay: .3s; }
.chat-typing-tool {
  font-size: 13px;
  color: var(--text-muted);
  margin-right: 4px;
}

@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%            { transform: translateY(-5px); }
}

/* ─── Chat input ─────────────────────────────────────────────── */
.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-input {
  flex: 1;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  outline: none;
  resize: none;
  max-height: 140px;
  line-height: 1.5;
  transition: border-color .15s, box-shadow .15s;
}
.chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(249,115,22,.15);
}

.chat-send-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.chat-send-btn:hover { background: var(--accent-dark); }
.chat-send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ─── Floating chat button ───────────────────────────────────── */
.chat-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(249,115,22,.4);
  z-index: 300;
  transition: background .15s, transform .15s, box-shadow .15s;
}
.chat-fab:hover { background: var(--accent-dark); transform: scale(1.05); }
.chat-fab--open { background: var(--accent-dark); }

/* ─── Chat panel (floating) ──────────────────────────────────── */
.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  min-width: 380px;
  max-width: 50vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px rgba(0,0,0,.08);
  z-index: 300;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: panel-slide-in .22s ease;
}

.chat-panel-resizer {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 5px;
  cursor: ew-resize;
  z-index: 10;
  transition: background .15s;
}
.chat-panel-resizer:hover,
.chat-panel-resizer.dragging { background: rgba(249,115,22,.35); }

@keyframes panel-slide-in {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-panel-title { font-size: 15px; font-weight: 600; }

.chat-panel-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.chat-panel-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}

/* ─── Status badges ──────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.status-badge-active  { background: #DCFCE7; color: #166534; }
.status-badge-pending { background: #FEF9C3; color: #854D0E; }
.status-badge-blocked { background: #FEE2E2; color: #991B1B; }

.you-badge {
  display: inline-flex;
  align-items: center;
  padding: .1rem .45rem;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  background: var(--accent-light);
  color: var(--accent-dark);
}

/* ─── Users table ────────────────────────────────────────────── */
.users-table {
  width: 100%;
  border-collapse: collapse;
}
.users-table th,
.users-table td {
  padding: .65rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.users-table th {
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  white-space: nowrap;
}
.users-table tbody tr:last-child td { border-bottom: none; }
.users-table tbody tr:hover { background: var(--bg); }
.users-table-id { color: var(--text-muted); width: 48px; }
.users-table-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ─── Status screen (pending / blocked) ─────────────────────── */
.status-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 4rem 2rem;
  text-align: center;
  max-width: 440px;
  margin: 0 auto;
}
.status-screen-icon { font-size: 3rem; line-height: 1; }
.status-screen h2 { font-size: 22px; font-weight: 700; }
.status-screen p { color: var(--text-muted); line-height: 1.6; }

/* ─── Statistics page ───────────────────────────────────────── */
.stats-tabs {
  display: flex;
  gap: .25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.stats-tab {
  padding: .45rem 1.1rem;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}
.stats-tab:hover { color: var(--text); }
.stats-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.stats-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.stats-card-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
}

.stats-card-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: .2rem;
}

.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.stats-panel { padding: 1.25rem; }
.stats-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 1rem;
}

.stats-bars { display: flex; flex-direction: column; gap: .5rem; }

.stats-bar-row {
  display: grid;
  grid-template-columns: 56px 1fr 32px;
  align-items: center;
  gap: .5rem;
  font-size: 12px;
}

.stats-bar-label { color: var(--text-muted); white-space: nowrap; text-align: right; }

.stats-bar-track {
  height: 10px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.stats-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  min-width: 2px;
  transition: width .3s ease;
}

.stats-bar-value { color: var(--text); font-weight: 500; }

.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table th, .stats-table td {
  padding: .45rem .6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.stats-table th { color: var(--text-muted); font-weight: 600; font-size: 12px; }
.stats-table tbody tr:last-child td { border-bottom: none; }

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

/* Filters */
.stats-filters {
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.stats-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: flex-end;
}

.stats-filter-input {
  width: 140px;
  padding: .4rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
}
.stats-filter-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(249,115,22,.15);
}
.stats-filter-input[type="date"] { width: 150px; }

.stats-filter-actions {
  display: flex;
  gap: .4rem;
}

.stats-filter-row .ms-btn,
.stats-filter-row .stats-filter-actions .btn {
  height: 34px;
  padding-top: 0;
  padding-bottom: 0;
  font-size: 13px;
  line-height: 1;
}

.stats-count { font-size: 12px; color: var(--text-muted); margin-top: .5rem; }

/* Sessions table */
.stats-sessions-card { overflow: visible; }
.sessions-tool-name [data-tooltip]::after { bottom: auto; top: calc(100% + 6px); }
.stats-sessions-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-sessions-table thead tr th:first-child { border-top-left-radius: var(--radius); }
.stats-sessions-table thead tr th:last-child  { border-top-right-radius: var(--radius); }
.stats-sessions-table th, .stats-sessions-table td {
  padding: .6rem .875rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.stats-sessions-table th {
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  font-size: 12px;
  white-space: nowrap;
}
.stats-sessions-table tbody tr.sessions-row { cursor: pointer; }
.stats-sessions-table tbody tr.sessions-row:hover { background: var(--bg); }
.stats-sessions-table tbody tr.sessions-row.expanded { background: var(--accent-light); }
.sessions-time { color: var(--text-muted); white-space: nowrap; font-size: 12px; }
.sessions-msg { max-width: 280px; }
.sessions-tokens { color: var(--text-muted); white-space: nowrap; font-size: 12px; }
.sessions-expand { color: var(--text-muted); font-size: 11px; text-align: right; }

/* Session detail */
.sessions-detail-row td { padding: 0; background: var(--bg); }
.sessions-detail {
  padding: 1rem 1.25rem;
  border-bottom: 2px solid var(--accent-light);
}

.sessions-detail-msg {
  font-size: 13px;
  color: var(--text);
  margin-bottom: .75rem;
  padding: .5rem .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.sessions-detail-error {
  font-size: 12px;
  color: #991B1B;
  background: #FEE2E2;
  border: 1px solid #FECACA;
  border-radius: var(--radius);
  padding: .4rem .75rem;
  margin-bottom: .75rem;
}

.sessions-detail-empty { font-size: 13px; color: var(--text-muted); }

.sessions-token-breakdown {
  margin-bottom: .75rem;
  padding: .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.sessions-tool-call {
  margin-top: .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.sessions-tool-name {
  padding: .4rem .75rem;
  font-size: 12px;
  font-family: monospace;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .5rem;
}

.sessions-tool-io { display: flex; gap: 0; }
.sessions-tool-section { flex: 1; padding: .5rem .75rem; min-width: 0; }
.sessions-tool-section + .sessions-tool-section { border-left: 1px solid var(--border); }
.sessions-tool-label { font-size: 11px; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: .25rem; }
.sessions-tool-pre {
  font-size: 11px;
  font-family: 'SFMono-Regular', Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
  margin: 0;
  max-height: 120px;
  overflow-y: auto;
}

/* Pagination */
.stats-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}
.stats-page-info { font-size: 13px; color: var(--text-muted); }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .mobile-topbar { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    top: 0;
  }
  .sidebar.open { transform: translateX(0); }

  .app-main {
    margin-left: 0;
    padding: 1rem;
    padding-top: calc(48px + 1rem);
  }

  .filters-bar { flex-direction: column; align-items: flex-start; }
  .filters-bar-search { width: 100%; }
  #modal-box { max-height: 95vh; }
  .modal-footer { flex-wrap: wrap; }

  .chat-panel {
    width: 100%;
    border-left: none;
  }

  .chat-fab { bottom: 1rem; right: 1rem; }

  .kanban-board { grid-template-columns: repeat(2, 1fr); }
  .stats-row { grid-template-columns: 1fr; }
  .stats-cards { grid-template-columns: repeat(2, 1fr); }
  .stats-filter-row { flex-direction: column; }
  .stats-filter-input { width: 100%; }

  .agent-page-chat {
    height: calc(100vh - 48px);
    margin-top: 48px;
    border-left: none;
  }
}
