:root {
  --color-bg: #f5f6fa;
  --color-surface: #ffffff;
  --color-border: #e1e4e8;
  --color-text: #24292e;
  --color-text-secondary: #586069;
  --color-primary: #0366d6;
  --color-primary-hover: #0256b9;
  --color-danger: #d73a49;
  --color-danger-hover: #c62838;
  --color-success: #28a745;
  --color-warning: #f9a825;
  --color-info: #0366d6;

  --badge-new: #0366d6;
  --badge-in-review: #e36209;
  --badge-resolved: #28a745;
  --badge-closed: #6a737d;

  --badge-bug: #d73a49;
  --badge-suggestion: #6f42c1;
  --badge-question: #0366d6;

  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

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

/* Login */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  width: 360px;
}
.login-box h1 { font-size: 1.5rem; margin-bottom: 1.5rem; text-align: center; }
.login-box input {
  width: 100%; padding: 0.6rem 0.8rem; margin-bottom: 1rem;
  border: 1px solid var(--color-border); border-radius: var(--radius);
  font-size: 0.95rem;
}
.login-box button {
  width: 100%; padding: 0.7rem; background: var(--color-primary);
  color: #fff; border: none; border-radius: var(--radius); font-size: 1rem;
  cursor: pointer;
}
.login-box button:hover { background: var(--color-primary-hover); }
.login-error { color: var(--color-danger); font-size: 0.85rem; margin-bottom: 0.5rem; display: none; }

/* Layout */
.app { display: none; }
.app.visible { display: block; }
.header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.8rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header h1 { font-size: 1.2rem; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 0.75rem; }
.content { padding: 1.5rem; max-width: 1400px; margin: 0 auto; }

/* Tabs */
.tabs {
  display: flex; gap: 0; margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--color-border);
}
.tab-btn {
  padding: 0.6rem 1.2rem; background: none; border: none; border-bottom: 2px solid transparent;
  margin-bottom: -2px; cursor: pointer; font-size: 0.95rem; color: var(--color-text-secondary);
}
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }
.tab-btn:hover { color: var(--color-text); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-card .stat-value { font-size: 2rem; font-weight: 700; }
.stat-card .stat-label { font-size: 0.8rem; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card.new .stat-value { color: var(--badge-new); }
.stat-card.in-review .stat-value { color: var(--badge-in-review); }
.stat-card.resolved .stat-value { color: var(--badge-resolved); }
.stat-card.closed .stat-value { color: var(--badge-closed); }

/* Filters */
.filters {
  display: flex; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center;
}
.filters select, .filters input {
  padding: 0.45rem 0.6rem; border: 1px solid var(--color-border); border-radius: var(--radius);
  font-size: 0.85rem; background: var(--color-surface);
}
.filters input[type="text"] { min-width: 200px; }

/* Table */
.table-wrapper {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead th {
  text-align: left; padding: 0.75rem 1rem; border-bottom: 2px solid var(--color-border);
  font-weight: 600; color: var(--color-text-secondary); font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap;
}
tbody tr { cursor: pointer; transition: background 0.15s; }
tbody tr:hover { background: #f0f4ff; }
tbody td { padding: 0.65rem 1rem; border-bottom: 1px solid var(--color-border); }
.desc-preview { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.date-cell { white-space: nowrap; font-size: 0.8rem; color: var(--color-text-secondary); }

/* Badges */
.badge {
  display: inline-block; padding: 0.15rem 0.55rem; border-radius: 12px;
  font-size: 0.75rem; font-weight: 600; color: #fff; text-transform: capitalize;
}
.badge.status-new { background: var(--badge-new); }
.badge.status-in-review { background: var(--badge-in-review); }
.badge.status-resolved { background: var(--badge-resolved); }
.badge.status-closed { background: var(--badge-closed); }
.badge.cat-bug { background: var(--badge-bug); }
.badge.cat-suggestion { background: var(--badge-suggestion); }
.badge.cat-question { background: var(--badge-question); }

/* Pagination */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; font-size: 0.85rem; color: var(--color-text-secondary);
}
.pagination button {
  padding: 0.35rem 0.75rem; border: 1px solid var(--color-border); border-radius: var(--radius);
  background: var(--color-surface); cursor: pointer; font-size: 0.85rem;
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination button:hover:not(:disabled) { background: #f0f4ff; }

/* Detail Panel / Modal */
.modal-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 200; align-items: flex-start; justify-content: center;
  padding: 3rem 1rem; overflow-y: auto;
}
.modal-overlay.visible { display: flex; }
.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 800px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0; background: var(--color-surface); z-index: 1;
}
.modal-header h2 { font-size: 1.1rem; }
.modal-close {
  background: none; border: none; font-size: 1.5rem; cursor: pointer;
  color: var(--color-text-secondary); line-height: 1;
}
.modal-body { padding: 1.5rem; }

.detail-section { margin-bottom: 1.5rem; }
.detail-section h3 {
  font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--color-text-secondary); margin-bottom: 0.5rem;
  padding-bottom: 0.3rem; border-bottom: 1px solid var(--color-border);
}

.detail-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 1.5rem;
}
.detail-field label { font-size: 0.8rem; color: var(--color-text-secondary); display: block; }
.detail-field span { font-size: 0.95rem; }

.detail-description {
  background: var(--color-bg); padding: 1rem; border-radius: var(--radius);
  white-space: pre-wrap; font-size: 0.9rem; max-height: 200px; overflow-y: auto;
}

.context-json {
  background: #1e1e1e; color: #d4d4d4; padding: 1rem; border-radius: var(--radius);
  font-family: 'Consolas', 'Courier New', monospace; font-size: 0.8rem;
  max-height: 200px; overflow-y: auto; white-space: pre-wrap;
}

.screenshot-preview {
  max-width: 100%; border: 1px solid var(--color-border); border-radius: var(--radius);
}

.file-list { list-style: none; }
.file-list li {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0; border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
}
.file-list li:last-child { border-bottom: none; }
.file-link { color: var(--color-primary); text-decoration: none; cursor: pointer; }
.file-link:hover { text-decoration: underline; }
.file-role {
  font-size: 0.7rem; background: var(--color-bg); padding: 0.1rem 0.4rem;
  border-radius: 4px; color: var(--color-text-secondary);
}
.file-size { font-size: 0.75rem; color: var(--color-text-secondary); }

/* Status control */
.status-control { display: flex; gap: 0.5rem; align-items: center; }
.status-control select {
  padding: 0.4rem 0.6rem; border: 1px solid var(--color-border);
  border-radius: var(--radius); font-size: 0.9rem;
}

/* Notes */
.notes-list { margin-bottom: 1rem; }
.note-item {
  background: var(--color-bg); padding: 0.75rem 1rem; border-radius: var(--radius);
  margin-bottom: 0.5rem;
}
.note-meta { font-size: 0.75rem; color: var(--color-text-secondary); margin-bottom: 0.3rem; }
.note-content { font-size: 0.9rem; }
.note-form { display: flex; gap: 0.5rem; }
.note-form textarea {
  flex: 1; padding: 0.5rem; border: 1px solid var(--color-border);
  border-radius: var(--radius); font-size: 0.9rem; resize: vertical; min-height: 60px;
  font-family: inherit;
}

/* Customer Section */
.customer-form {
  display: flex; gap: 0.5rem; margin-bottom: 1rem; align-items: flex-end; flex-wrap: wrap;
}
.customer-form .field { display: flex; flex-direction: column; gap: 0.2rem; }
.customer-form .field label { font-size: 0.8rem; color: var(--color-text-secondary); }
.customer-form .field input {
  padding: 0.45rem 0.6rem; border: 1px solid var(--color-border);
  border-radius: var(--radius); font-size: 0.9rem;
}
.customer-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.customer-table th, .customer-table td {
  padding: 0.5rem 0.75rem; text-align: left;
  border-bottom: 1px solid var(--color-border);
}
.customer-table th { font-weight: 600; color: var(--color-text-secondary); font-size: 0.8rem; text-transform: uppercase; }

.api-key-display {
  background: #fffbe6; border: 1px solid var(--color-warning); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem; font-family: monospace; word-break: break-all;
}
.api-key-display .warning { font-weight: 600; color: var(--color-danger); margin-bottom: 0.3rem; }

/* Buttons */
.btn {
  padding: 0.45rem 0.9rem; border: none; border-radius: var(--radius);
  font-size: 0.85rem; cursor: pointer; font-weight: 500; transition: background 0.15s;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: var(--color-danger-hover); }
.btn-secondary { background: var(--color-bg); color: var(--color-text); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: #e8ecf0; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }

/* Toggle */
.toggle-group { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; }
.toggle-group input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* Empty state */
.empty-state {
  text-align: center; padding: 3rem 1rem; color: var(--color-text-secondary);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 0.5rem; }

/* Responsive */
@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .filters { flex-direction: column; align-items: stretch; }
  .modal { max-height: none; margin: 0; border-radius: 0; }
  .modal-overlay { padding: 0; }
}
