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

:root {
  --red:    #C8102E;
  --red-dk: #a00d24;
  --blue:   #3B82F6;
  --amber:  #F59E0B;
  --green:  #10B981;
  --bg:     #0f1117;
  --bg2:    #1a1d27;
  --bg3:    #222535;
  --border: #2e3148;
  --text:   #e2e4ef;
  --muted:  #8b90a8;
  --radius: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,.4);
}

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

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

/* ── Header ───────────────────────────────────────────────────────────── */
.site-header {
  background: #0a0c12;
  border-bottom: 3px solid var(--red);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-group { display: flex; flex-direction: column; gap: .12rem; }
.brand {
  display: flex;
  align-items: baseline;
  gap: .4rem;
  white-space: nowrap;
  font-size: 1.05rem;
}
.brand-appid {
  font-family: 'Courier New', monospace;
  font-size: .75rem;
  font-weight: 700;
  color: var(--red);
  background: rgba(220,38,38,.1);
  border: 1px solid rgba(220,38,38,.22);
  border-radius: 4px;
  padding: .18rem .45rem;
  letter-spacing: .1em;
  align-self: center;
  flex-shrink: 0;
}
.brand-sub { font-size: .6rem; color: var(--muted); opacity: .55; padding-left: .1rem; }
.brand-rev-date { opacity: .75; }

.brand-m {
  color: var(--red);
  font-weight: 800;
  font-size: 1.3rem;
  position: relative;
  top: -3px;
}
.brand-rest { color: #fff; font-weight: 600; }
.brand-word { display: inline-flex; }
.brand-divider { color: var(--border); margin: 0 .3rem; }
.brand-fsd { color: var(--muted); font-size: .9rem; }

.site-nav { display: flex; gap: .25rem; align-items: center; flex-shrink: 0; }

.nav-link {
  color: var(--muted);
  padding: .35rem .75rem;
  border-radius: var(--radius);
  font-size: .875rem;
  transition: color .15s, background .15s;
}
.nav-link:hover { color: var(--text); background: var(--bg3); text-decoration: none; }
.nav-link.active { color: #fff; background: var(--bg3); }
.nav-logout { color: #e44; }
.nav-logout:hover { color: #fff; background: #3a1010; }

/* ── Container ────────────────────────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

/* ── Flash messages ───────────────────────────────────────────────────── */
.flash-list { margin-bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.flash {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .9rem;
}
.flash-success { background: #0d2e1e; border: 1px solid #1a5c38; color: #4ade80; }
.flash-error   { background: #2e0d0d; border: 1px solid #5c1a1a; color: #f87171; }

/* ── Search section ───────────────────────────────────────────────────── */
.search-section { margin-bottom: 1.25rem; }

.search-bar-wrap {
  position: relative;
  margin-bottom: .75rem;
}

.search-input {
  width: 100%;
  padding: .8rem 1rem .8rem 2.8rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--red); }
.search-input::placeholder { color: var(--muted); }

.search-icon {
  position: absolute;
  left: .9rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  pointer-events: none;
  opacity: .5;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}

.filter-btn {
  padding: .35rem .9rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--muted);
  font-size: .85rem;
  cursor: pointer;
  transition: all .15s;
}
.filter-btn:hover { border-color: var(--red); color: var(--text); }
.filter-btn.active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  font-weight: 600;
}

.result-count { margin-left: auto; color: var(--muted); font-size: .85rem; }

/* ── Product badges ───────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 4px;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.badge-CMM  { background: rgba(59,130,246,.18); color: #93c5fd; border: 1px solid rgba(59,130,246,.3); }
.badge-FORM { background: rgba(245,158,11,.15); color: #fcd34d; border: 1px solid rgba(245,158,11,.3); }
.badge-VIS  { background: rgba(16,185,129,.15); color: #6ee7b7; border: 1px solid rgba(16,185,129,.3); }
.badge-MI   { background: rgba(168,85,247,.15);  color: #d8b4fe; border: 1px solid rgba(168,85,247,.3); }
.badge-ALL  { background: rgba(139,144,168,.12); color: var(--muted); border: 1px solid var(--border); }

/* ── Ticket cards ─────────────────────────────────────────────────────── */
.ticket-list { display: flex; flex-direction: column; gap: .75rem; }

.ticket-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color .15s;
}
.ticket-card:hover { border-color: #444969; }
.ticket-card.expanded { border-color: var(--red); }

.ticket-header {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .9rem 1rem;
  cursor: pointer;
  user-select: none;
}

.ticket-badge-col { flex-shrink: 0; padding-top: .1rem; }

.ticket-meta { flex: 1; min-width: 0; }

.ticket-subject {
  font-size: .975rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .3rem;
  line-height: 1.4;
}

.ticket-subline {
  font-size: .8rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: .5rem .9rem;
}

.ticket-toggle {
  flex-shrink: 0;
  color: var(--muted);
  font-size: .75rem;
  padding-top: .2rem;
  transition: transform .2s;
}
.ticket-card.expanded .ticket-toggle { transform: rotate(180deg); color: var(--red); }

.ticket-body {
  display: none;
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--border);
  margin-top: 0;
}
.ticket-card.expanded .ticket-body { display: block; padding-top: .9rem; }

.ticket-section-label {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .35rem;
  margin-top: .8rem;
}
.ticket-section-label:first-child { margin-top: 0; }

.ticket-resolution {
  font-size: .9rem;
  color: #c8cce0;
  line-height: 1.65;
  white-space: pre-wrap;
}

.ticket-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-top: .4rem;
}
.tag-chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .15rem .5rem;
  font-size: .75rem;
  color: var(--muted);
}
.tag-edit-row { display: flex; align-items: center; gap: .5rem; margin-top: .4rem; flex-wrap: wrap; }
.tag-edit-input { background: var(--bg3); border: 1px solid var(--border); border-radius: 4px; padding: .25rem .55rem; font-size: .78rem; color: var(--text); flex: 1; min-width: 180px; }
.tag-edit-input:focus { outline: none; border-color: var(--red); }
.edit-tags-btn { margin-left: auto; flex-shrink: 0; }

/* ── Keyword highlight ────────────────────────────────────────────────── */
mark {
  background: rgba(245,158,11,.3);
  color: #fde68a;
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Resource grid ────────────────────────────────────────────────────── */
.resource-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.resource-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  transition: border-color .15s;
}
.resource-card:hover { border-color: #444969; }

.resource-type-icon { font-size: 1.5rem; }

.resource-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
}

.resource-desc { font-size: .82rem; color: var(--muted); }

.resource-meta {
  font-size: .75rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: .4rem .8rem;
  margin-top: auto;
}

.resource-actions { display: flex; gap: .5rem; margin-top: .25rem; flex-wrap: wrap; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem .9rem;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  text-decoration: none;
}
.btn-primary {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.btn-primary:hover { background: var(--red-dk); border-color: var(--red-dk); text-decoration: none; color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: #444969; text-decoration: none; }
.btn-danger {
  background: transparent;
  color: #f87171;
  border-color: #5c1a1a;
}
.btn-danger:hover { background: #3a1010; text-decoration: none; color: #f87171; }
.btn-sm { padding: .28rem .65rem; font-size: .78rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Forms ────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-group label { font-size: .82rem; color: var(--muted); font-weight: 500; }

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

input[type="text"],
input[type="number"],
input[type="password"],
input[type="search"],
input[type="email"],
select,
textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: .55rem .8rem;
  font-size: .9rem;
  width: 100%;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); }
input[type="file"] { padding: .45rem .8rem; cursor: pointer; }
select option { background: var(--bg3); }
textarea { resize: vertical; }

/* ── Cards ────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

/* ── Admin ────────────────────────────────────────────────────────────── */
.page-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 1.25rem; color: #fff; }

.admin-upload-card { margin-bottom: 2rem; }
.admin-upload-card h3 { font-size: 1rem; margin-bottom: 1rem; color: var(--text); }

.upload-form { display: flex; flex-direction: column; gap: .85rem; }

.admin-resource-section h3 { font-size: 1rem; color: var(--text); }

.admin-resource-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
}

.filter-bar-inline { margin: 0; }

.admin-resource-table { width: 100%; border-collapse: collapse; }
.admin-resource-table th {
  text-align: left;
  padding: .5rem .75rem;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.admin-resource-table td {
  padding: .65rem .75rem;
  font-size: .875rem;
  border-bottom: 1px solid var(--bg3);
  vertical-align: middle;
}
.admin-resource-table tr:last-child td { border-bottom: none; }
.admin-resource-table tr:hover td { background: var(--bg3); }

/* ── Login ────────────────────────────────────────────────────────────── */
.login-wrap {
  max-width: 380px;
  margin: 4rem auto 0;
}
.login-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: #fff;
}
.login-form { display: flex; flex-direction: column; gap: .9rem; }

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

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: .85rem;
}
.modal-box h3 { font-size: 1rem; color: #fff; margin-bottom: .25rem; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .25rem; }

/* ── Empty / loading ──────────────────────────────────────────────────── */
.loading, .empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
  font-size: .9rem;
}

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

/* ── Print block ──────────────────────────────────────────────────────── */
@media print {
  body * { visibility: hidden !important; }
  body::after {
    visibility: visible !important;
    content: "Printing and downloading of FSD Knowledge Base content is not permitted.";
    display: block;
    font-size: 18px;
    text-align: center;
    margin-top: 40px;
    color: #000;
  }
}

/* ── Mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .header-inner { height: auto; padding: .6rem 1rem; flex-wrap: wrap; gap: .5rem; }
  .brand-fsd { display: none; }
  .form-row { grid-template-columns: 1fr; }
  .resource-grid { grid-template-columns: 1fr; }
  .ticket-header { gap: .5rem; }
  .ticket-subline { gap: .3rem .6rem; }
  .admin-resource-table th:nth-child(3),
  .admin-resource-table td:nth-child(3) { display: none; }
}

/* ── Site footer ──────────────────────────────────────────────────────── */
.site-footer {
  text-align: right;
  padding: .6rem 1.25rem;
  color: var(--border);
  font-size: .6rem;
  opacity: .3;
  letter-spacing: .06em;
}