/* ─── 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 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;
}

/* ─── 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: .875rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

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

.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;
  gap: .5rem;
  width: 100%;
  padding: .45rem .85rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  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;
  max-width: 960px;
}

/* ─── 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;
}

/* ─── 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;
}

.filter-search { flex: 1; min-width: 180px; }
.filter-search input {
  width: 100%;
  padding: .4rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.filter-search input: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; }

.filter-sort { gap: .4rem; }
.filter-sort select {
  padding: .3rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  outline: none;
}
.filter-sort select:focus { border-color: var(--accent); }

/* ─── 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-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);
}

/* ─── 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; }

/* ─── 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; }
  .filter-search { width: 100%; }
  #modal-box { max-height: 95vh; }
  .modal-footer { flex-wrap: wrap; }
}
