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

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface-2: #232736;
  --border:    #2d3248;
  --text:      #e1e4ed;
  --text-muted:#8b8fa3;
  --accent:    #6c8cff;
  --accent-dim:#4a6ad8;
  --red:       #f04452;
  --orange:    #f59e0b;
  --yellow:    #eab308;
  --green:     #22c55e;
  --purple:    #a855f7;
  --gray:      #6b7280;
}

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

/* ── Layout ───────────────────────────────────────────────── */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ── Header ────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: 20px;
  font-weight: 600;
}

.header h1 a {
  color: var(--text);
  text-decoration: none;
}

.header .badge {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 4px 10px;
  border-radius: 12px;
}

.header .badge a {
  color: var(--accent);
  text-decoration: none;
}

/* ── Search Bar ────────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.search-bar input[type="text"] {
  flex: 1;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}

.search-bar input[type="text"]:focus {
  border-color: var(--accent);
}

.search-bar button {
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}

.search-bar button:hover {
  background: var(--accent-dim);
}

/* ── Filter Chips ──────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 5px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all .15s;
}

.filter-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.filter-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.filter-chip.p0 { border-color: var(--red); color: var(--red); }
.filter-chip.p0.active { background: var(--red); color: #fff; }
.filter-chip.p1 { border-color: var(--orange); color: var(--orange); }
.filter-chip.p1.active { background: var(--orange); color: #fff; }
.filter-chip.p2 { border-color: var(--yellow); color: var(--yellow); }
.filter-chip.p2.active { background: var(--yellow); color: #000; }
.filter-chip.p3 { border-color: var(--gray); color: var(--gray); }
.filter-chip.p3.active { background: var(--gray); color: #fff; }

/* ── Ticket List ───────────────────────────────────────────── */
.ticket-table {
  width: 100%;
  border-collapse: collapse;
}

.ticket-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.ticket-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.ticket-table tr {
  transition: background .1s;
}

.ticket-table tr:hover {
  background: var(--surface);
}

.ticket-table tr a {
  color: var(--text);
  text-decoration: none;
}

.ticket-table tr:hover a {
  color: var(--accent);
}

.ticket-id {
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 13px;
  color: var(--text-muted);
  min-width: 80px;
}

.ticket-title {
  font-weight: 500;
}

/* ── Priority / Status Tags ────────────────────────────────── */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tag-p0 { background: rgba(240,68,82,.15); color: var(--red); }
.tag-p1 { background: rgba(245,158,11,.15); color: var(--orange); }
.tag-p2 { background: rgba(234,179,8,.15); color: var(--yellow); }
.tag-p3 { background: rgba(107,114,128,.15); color: var(--gray); }

.status-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

.status-open { background: rgba(34,197,94,.12); color: var(--green); }
.status-in_progress { background: rgba(108,140,255,.12); color: var(--accent); }
.status-review { background: rgba(168,85,247,.12); color: var(--purple); }
.status-closed { background: rgba(107,114,128,.12); color: var(--gray); }
.status-overdue { background: rgba(240,68,82,.12); color: var(--red); }

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state p { font-size: 16px; }

/* ── Ticket Detail ─────────────────────────────────────────── */
.ticket-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.ticket-detail-header {
  padding: 24px;
  border-bottom: 1px solid var(--border);
}

.ticket-detail-header .id-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.ticket-detail-header .id-row .ticket-id {
  font-size: 16px;
}

.ticket-detail-header h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 12px;
}

.ticket-detail-header .meta-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta-item .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.meta-item .value {
  font-size: 14px;
  font-weight: 500;
}

.ticket-detail-header .description {
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ── Status Actions ────────────────────────────────────────── */
.status-actions {
  display: flex;
  gap: 8px;
  padding: 16px 24px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.status-actions form {
  display: inline;
}

.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  transition: all .15s;
  text-decoration: none;
  display: inline-block;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

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

.btn-primary:hover {
  background: var(--accent-dim);
}

.btn-success { border-color: var(--green); color: var(--green); }
.btn-success:hover { background: rgba(34,197,94,.1); }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(240,68,82,.1); }

/* ── Comments ──────────────────────────────────────────────── */
.comments-section {
  padding: 24px;
}

.comments-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-muted);
}

.comment {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.comment:last-child {
  border-bottom: none;
}

.comment .meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.comment .author {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

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

.comment .text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
}

.comment-form {
  margin-top: 20px;
}

.comment-form textarea {
  width: 100%;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: border-color .15s;
}

.comment-form textarea:focus {
  border-color: var(--accent);
}

.comment-form .form-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.comment-form .form-row input[type="text"] {
  flex: 1;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.comment-form .form-row input[type="text"]:focus {
  border-color: var(--accent);
}

.comment-form .form-row label {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Back Link ─────────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 16px;
  transition: color .15s;
}

.back-link:hover {
  color: var(--accent);
}

/* ── Flash Messages ────────────────────────────────────────── */
.flash {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}

.flash-success {
  background: rgba(34,197,94,.1);
  color: var(--green);
  border: 1px solid rgba(34,197,94,.2);
}

.flash-error {
  background: rgba(240,68,82,.1);
  color: var(--red);
  border: 1px solid rgba(240,68,82,.2);
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 640px) {
  .container { padding: 16px 12px; }
  .ticket-table th:nth-child(4),
  .ticket-table td:nth-child(4) { display: none; }
  .ticket-detail-header { padding: 16px; }
  .meta-grid { gap: 12px; }
}
