@import url('styles/tokens.css');

/* === Focus Ring (global) ===
   Give interactive elements a transparent base outline (specificity 0,0,1)
   so the browser never reports outlineStyle:'none', then override with brand
   orange via :focus-visible (specificity 0,1,0 — intentionally higher). */
a, button, input, select, textarea {
  outline: transparent solid 1px;
}
:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Montserrat', sans-serif;
  color: var(--neutral-900);
  background: white;
  line-height: 1.6;
  font-size: 15px;
}
a { color: var(--purple); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Header === */
.site-header {
  background: var(--purple);
  color: white;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: white;
  text-decoration: none;
  flex-shrink: 0;
}
.header-logo {
  width: 36px;
  height: 36px;
  filter: brightness(0) invert(1);
}
.header-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.brand-name {
  font-family: 'Montserrat Alternates', 'Montserrat', sans-serif;
}
.header-search {
  flex: 1;
  max-width: 480px;
}
.header-search input {
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  background: rgba(255,255,255,0.15);
  color: white;
  transition: background 0.2s;
}
.header-search input::placeholder { color: rgba(255,255,255,0.6); }
.header-search input:focus { background: rgba(255,255,255,0.25); }

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.header-user-name {
  color: rgba(255,255,255,0.8);
  font-size: 12px;
  font-weight: 600;
}
.header-logout-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.7);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.header-logout-btn:hover {
  background: rgba(255,255,255,0.15);
  color: white;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}
.header-nav-link {
  color: rgba(255,255,255,0.75);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.header-nav-link:hover {
  background: rgba(255,255,255,0.12);
  color: white;
  text-decoration: none;
}
.header-nav-link.active {
  background: rgba(255,255,255,0.18);
  color: white;
}

.header-admin-link {
  color: rgba(255,255,255,0.7);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.header-admin-link:hover {
  background: rgba(255,255,255,0.15);
  color: white;
  text-decoration: none;
}

.mobile-menu-btn {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}
.mobile-menu-btn span {
  display: block;
  width: 24px;
  height: 2px;
  background: white;
  border-radius: 2px;
  transition: transform 0.2s;
}

/* === Layout === */
.layout {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  min-height: calc(100vh - 64px - 120px);
}

/* === Sidebar === */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  padding: 24px;
  border-right: 1px solid var(--neutral-400);
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  overflow-y: auto;
}
.sidebar-section { margin-bottom: 28px; }
.sidebar-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--neutral-800);
  margin-bottom: 12px;
  font-weight: 600;
}
.category-list { list-style: none; }
.category-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 13px;
  color: var(--neutral-900);
  cursor: pointer;
  border-radius: 6px;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.category-btn:hover { background: var(--neutral-100); }
.category-btn.active {
  background: var(--purple);
  color: white;
  font-weight: 600;
}
.category-btn .count {
  font-size: 11px;
  opacity: 0.7;
}
.sidebar-link {
  display: block;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--purple);
  border-radius: 6px;
  transition: background 0.15s;
}
.sidebar-link:hover { background: var(--neutral-100); text-decoration: none; }

/* === Toggle Filter === */
.toggle-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.toggle-filter input { display: none; }
.toggle-slider {
  width: 36px;
  height: 20px;
  background: var(--neutral-500);
  border-radius: 10px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-filter input:checked + .toggle-slider { background: var(--purple); }
.toggle-filter input:checked + .toggle-slider::after { transform: translateX(16px); }

/* === Content === */
.content {
  flex: 1;
  padding: 32px;
  min-width: 0;
}

/* === Section Headers === */
.section-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 24px;
}
h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--orange);
  margin-bottom: 8px;
}
.section-desc {
  color: var(--neutral-800);
  font-size: 14px;
  margin-bottom: 20px;
}
.results-count {
  font-size: 13px;
  color: var(--neutral-800);
}

/* === System Cards === */
.systems-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}
.system-card {
  border: 1px solid var(--neutral-400);
  border-radius: 10px;
  padding: 20px;
  transition: box-shadow 0.2s, border-color 0.2s;
  background: white;
}
.system-card:hover {
  box-shadow: 0 4px 16px rgba(92,57,119,0.1);
  border-color: var(--purple);
}
.system-card.deprecated {
  opacity: 0.6;
}
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
}
.card-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--purple);
}
.card-name a { color: var(--purple); }
.card-badges {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-active { background: #e6f4ea; color: #1e7e34; }
.badge-phasing { background: #fff3e0; color: #e65100; }
.badge-retired { background: var(--neutral-300); color: var(--neutral-900); }
.badge-api { background: var(--purple-wash); color: var(--purple); }
.card-meta {
  font-size: 13px;
  color: var(--neutral-800);
  margin-bottom: 8px;
}
.card-meta strong { color: var(--neutral-900); }
.card-notes {
  font-size: 13px;
  color: var(--neutral-800);
  margin-bottom: 12px;
  line-height: 1.5;
}
.card-notes a {
  color: var(--purple);
  text-decoration: underline;
  word-break: break-all;
}
.card-notes a:hover {
  color: var(--orange);
}
.card-notes .notes-para {
  margin: 0 0 6px 0;
}
.card-notes .notes-heading {
  display: block;
  margin: 8px 0 4px 0;
  color: var(--neutral-900);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.card-notes .notes-list {
  margin: 0 0 6px 0;
  padding-left: 18px;
  list-style: disc;
}
.card-notes .notes-list li {
  margin-bottom: 4px;
}
.card-detail {
  display: none;
  border-top: 1px solid var(--neutral-300);
  padding-top: 12px;
  margin-top: 12px;
}
.card-detail.open { display: block; }
.card-detail-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--neutral-800);
  margin-top: 10px;
  margin-bottom: 4px;
}
.card-detail-label:first-child { margin-top: 0; }
.card-detail-value {
  font-size: 13px;
  color: var(--neutral-900);
}
.card-detail-value code {
  background: var(--neutral-100);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}
.card-recs {
  list-style: none;
  padding: 0;
}
.card-recs li {
  font-size: 12px;
  padding: 4px 0;
  border-bottom: 1px solid var(--neutral-100);
  font-family: 'Courier New', monospace;
}
.card-recs li:last-child { border-bottom: none; }
/* Environment table inside cards */
.env-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 6px;
}
.env-table th {
  background: var(--neutral-100);
  color: var(--neutral-900);
  padding: 6px 8px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.env-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--neutral-300);
  vertical-align: top;
}
.env-table code {
  background: var(--neutral-100);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}
.env-name { white-space: nowrap; }
.env-rules { font-size: 11px; color: var(--neutral-800); }

.card-toggle {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 12px;
  color: var(--purple);
  cursor: pointer;
  padding: 0;
  font-weight: 600;
}
.card-toggle:hover { text-decoration: underline; }

.no-results {
  text-align: center;
  padding: 60px 20px;
  color: var(--neutral-800);
  font-size: 16px;
}

/* === Tables === */
.table-wrapper {
  overflow-x: auto;
  margin-bottom: 32px;
}
.usage-table, .api-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.usage-table th, .api-table th {
  background: var(--purple);
  color: white;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.usage-table thead, .api-table thead {
  position: relative;
  z-index: 2;
}
.usage-table td, .api-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--neutral-300);
  vertical-align: top;
}
.usage-table tr:nth-child(even), .api-table tr:nth-child(even) {
  background: var(--neutral-100);
}
.usage-table .check {
  text-align: center;
  color: var(--purple);
  font-weight: 700;
}
.usage-table .system-name-col {
  font-weight: 600;
  white-space: nowrap;
}

/* === Suggest Form === */
.suggest-section {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 2px solid var(--neutral-100);
}
.suggest-form {
  max-width: 640px;
}
.form-row {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}
.form-group {
  flex: 1;
  margin-bottom: 16px;
}
.form-row .form-group { margin-bottom: 0; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--neutral-800);
  margin-bottom: 6px;
}
.form-group input, .form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--neutral-400);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  color: var(--neutral-900);
  transition: border-color 0.2s;
}
.form-group input:focus-visible, .form-group textarea:focus-visible {
  border-color: var(--purple);
}
.dept-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.dept-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  padding: 6px 12px;
  border: 1px solid var(--neutral-400);
  border-radius: 20px;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.dept-check:hover { border-color: var(--purple); }
.dept-check input { display: none; }
.dept-check:has(input:checked) {
  background: var(--purple-wash);
  border-color: var(--purple);
  color: var(--purple);
  font-weight: 600;
}
.btn-primary {
  background: var(--purple);
  color: white;
  border: none;
  padding: 12px 28px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--purple-dark); }

/* === Footer === */
.site-footer {
  background: var(--neutral-100);
  border-top: 1px solid var(--neutral-400);
  padding: 32px 24px;
}
.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 24px;
}
.footer-logo { height: 28px; }
.footer-info p {
  font-size: 12px;
  color: var(--neutral-800);
  margin-bottom: 2px;
}
.footer-info a { color: var(--purple); }
.footer-generated { font-style: italic; }

/* === Matrix Section === */
.matrix-section, .api-section {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 2px solid var(--neutral-100);
}

/* === Usage Table Fix === */
.usage-table {
  min-width: 900px;
}
.usage-table .system-name-col {
  width: 140px;
  white-space: nowrap;
}
.usage-table th:not(:first-child),
.usage-table td:not(:first-child) {
  text-align: center;
  width: 76px;
  white-space: nowrap;
  font-size: 12px;
}

/* === API Table Fix === */
.api-table {
  min-width: 800px;
}
.api-table .system-name-col {
  width: 120px;
  white-space: nowrap;
}
.api-table td:nth-child(2) { width: 160px; }
.api-table td:nth-child(3) { word-break: break-all; }
.api-table td:nth-child(4) { width: 200px; }

/* === Interactive Matrix Cells === */
.matrix-cell {
  cursor: pointer;
  text-align: center;
  transition: background 0.15s;
  position: relative;
  user-select: none;
}
.matrix-cell:hover {
  background: rgba(92, 57, 119, 0.08) !important;
}
.matrix-cell.has-usage { color: var(--purple); font-weight: 700; }
.matrix-cell.matrix-changed {
  background: #fff3e0 !important;
  outline: 2px solid var(--orange);
  outline-offset: -2px;
}
.matrix-cell .cell-hint {
  display: none;
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--neutral-900);
  color: white;
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}
.matrix-cell:hover .cell-hint { display: block; }

/* === Matrix Submit Bar === */
.matrix-submit-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--neutral-100);
  border-radius: 8px;
  margin-top: 16px;
}
.change-count {
  font-size: 14px;
  font-weight: 600;
  color: var(--orange);
}
.btn-secondary {
  background: white;
  color: var(--neutral-900);
  border: 1px solid var(--neutral-400);
  padding: 10px 20px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--neutral-300); }

/* === Toast === */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--purple);
  color: white;
  padding: 14px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 1000;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.3s, transform 0.3s;
}
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--orange); }

/* === Responsive === */
@media (max-width: 900px) {
  .mobile-menu-btn { display: flex; }
  .sidebar {
    position: fixed;
    top: 64px;
    left: -300px;
    width: 280px;
    height: calc(100vh - 64px);
    background: white;
    z-index: 99;
    transition: left 0.3s;
    box-shadow: 2px 0 12px rgba(0,0,0,0.1);
  }
  .sidebar.open { left: 0; }
  .layout { display: block; }
  .content { padding: 20px 16px; }
  .systems-grid {
    grid-template-columns: 1fr;
  }
  .header-search { max-width: none; }
  .form-row { flex-direction: column; gap: 0; }
  .footer-inner { flex-direction: column; text-align: center; }
  .usage-table th, .api-table th { position: static; }
}
@media (max-width: 480px) {
  .header-title { display: none; }
  .header-inner { gap: 12px; }
}
