/* Modern Dark/Slate Palette */
:root {
  --bg-page: #0f172a; /* Deep slate background */
  --bg-panel: #1e293b; /* Slightly lighter panel background */
  --bg-input: #334155; /* Input background */
  --bg-input-hover: #475569;

  --border-light: #475569;
  --border-focus: #3b82f6;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-terminal: #4ade80; /* Neon green for logs */

  /* Button Accents */
  --color-green: #10b981;
  --color-green-hover: #059669;
  --color-grey: #475569;
  --color-grey-hover: #334155;
  --color-purple: #8b5cf6;
  --color-purple-hover: #7c3aed;
  --color-orange: #f59e0b;
  --color-orange-hover: #d97706;
  --color-slate: #64748b;
  --color-slate-hover: #475569;
  --color-blue: #3b82f6;
  --color-blue-hover: #2563eb;
  --color-red: #ef4444;
  --color-red-hover: #dc2626;

  --radius: 6px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}

* {
  box-sizing: border-box;
}

body {
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family:
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
  margin: 0;
  padding: 1.5rem;
  font-size: 14px;
}

.container {
  display: flex;
  max-width: 1400px;
  height: calc(100vh - 3rem);
  margin: 0 auto;
  gap: 1.5rem;
}

/* PANELS */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.left-panel {
  width: 480px;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
}

.left-panel::-webkit-scrollbar {
  width: 8px;
}
.left-panel::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 4px;
}

.right-panel {
  flex: 1;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 0.5rem;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.badge {
  background: var(--color-blue);
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: bold;
}

/* FORMS & INPUTS */
.form-section {
  background: rgba(0, 0, 0, 0.15);
  padding: 10px; /* Slightly reduced from 12px */
  border-radius: var(--radius);
  margin-bottom: 0.5rem; /* Reduced from 1rem */
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.form-row {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.form-row:last-child {
  margin-bottom: 0;
}

.form-row label {
  width: 120px;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-col {
  display: flex;
  flex-direction: column;
}

.form-col label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-box {
  display: flex;
  flex-direction: column;
}

.stat-box label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 3px;
  text-transform: uppercase;
}

input[type="text"],
input[type="number"],
select {
  flex: 1;
  width: 100%;
  padding: 8px 10px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  border-radius: 4px;
  font-size: 0.9rem;
  transition:
    border-color 0.2s,
    background-color 0.2s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--border-focus);
  background-color: var(--bg-input-hover);
}

input:disabled,
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.section-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 0.75rem 0 0.25rem 0;
}

.helper-text {
  font-size: 0.75rem;
  color: var(--color-orange);
  margin: 4px 0 0 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-row label {
  font-size: 0.85rem;
  color: var(--text-main);
  cursor: pointer;
}

/* KEYWORD SCROLLBOX */
.scroll-container {
  flex: 1;
  min-height: 200px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow-y: auto;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.scroll-container::-webkit-scrollbar {
  width: 6px;
}
.scroll-container::-webkit-scrollbar-thumb {
  background: var(--border-light);
}

#keywordList {
  display: flex;
  flex-direction: column;
  padding: 8px;
}

.kw-item {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}

.kw-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.kw-item input[type="checkbox"] {
  margin-right: 10px;
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--primary);
}

.kw-item label {
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-main);
  user-select: none;
  flex: 1;
  padding: 2px 0;
}

/* BUTTONS */
button {
  border: none;
  color: white;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition:
    background-color 0.2s,
    transform 0.1s;
}

button:active {
  transform: translateY(1px);
}

.actions-container {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-main {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.btn-tool {
  flex: 1;
  padding: 10px;
  font-size: 0.85rem;
}

.tool-frame {
  display: flex;
  gap: 10px;
}

.btn-green {
  background: var(--color-green);
}
.btn-green:hover {
  background: var(--color-green-hover);
}
.btn-grey {
  background: var(--color-grey);
}
.btn-grey:hover {
  background: var(--color-grey-hover);
}
.btn-purple {
  background: var(--color-purple);
}
.btn-purple:hover {
  background: var(--color-purple-hover);
}
.btn-orange {
  background: var(--color-orange);
}
.btn-orange:hover {
  background: var(--color-orange-hover);
}
.btn-slate {
  background: var(--color-slate);
}
.btn-slate:hover {
  background: var(--color-slate-hover);
}
.btn-blue {
  background: var(--color-blue);
}
.btn-blue:hover {
  background: var(--color-blue-hover);
}
.btn-red {
  background: var(--color-red);
}
.btn-red:hover {
  background: var(--color-red-hover);
}

/* AUDIT LOG TERMINAL */
.terminal-wrapper {
  background: #000;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  flex: 1;
  display: flex;
  overflow: hidden;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
}

#outputLog,
.code-preview,
#simResults {
  flex: 1;
  margin: 0;
  padding: 1.5rem;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-terminal);
  overflow-y: auto;
  white-space: pre-wrap;
}

.code-preview {
  background: #000;
  color: #38bdf8; /* Light blue for JSON preview */
}

/* MODALS */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(3px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  width: 800px;
  max-height: 90vh;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  padding: 2rem;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
}

.modal-header h2 {
  margin: 0;
  color: white;
}

.close-btn {
  color: var(--text-muted);
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
  transition: color 0.2s;
}

.close-btn:hover {
  color: white;
}

/* MODAL SPLIT LAYOUT (Side-by-Side) */
.split-layout {
  display: flex;
  gap: 1.5rem;
  flex: 1;
  min-height: 0; /* Gives modals a good baseline height */
}

.modal-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 50%;
  overflow-y: auto;
  padding-right: 15px;
}

.modal-right {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* TABLE STYLES (Library) */
.filter-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.table-scroll {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--bg-page);
}

table {
  width: 100%;
  border-collapse: collapse;
}
th {
  background: var(--bg-input);
  color: var(--text-muted);
  position: sticky;
  top: 0;
  text-align: left;
  padding: 12px;
  font-size: 0.85rem;
  text-transform: uppercase;
  border-bottom: 2px solid var(--border-light);
  z-index: 10;
}
td {
  padding: 12px;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border-light);
}

table tbody tr {
  cursor: pointer;
  transition: background 0.2s;
}
table tbody tr:hover {
  background: var(--bg-input);
}

.selected-row,
.selected-row:hover {
  background-color: rgba(59, 130, 246, 0.2) !important;
  border-left: 3px solid var(--color-blue);
}

/* Navigation Header */
.top-nav {
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-light);
  padding: 0.75rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand-logo {
  max-height: 32px;
  width: auto;
}

.nav-links {
  display: flex;
  gap: 12px;
}

.nav-btn {
  padding: 6px 16px;
  background-color: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

.nav-btn:hover {
  background-color: var(--bg-input-hover);
  border-color: var(--border-focus);
}

/* Accent for the Army Builder link */
.builder-btn:hover {
  background-color: var(--color-blue) !important;
  border-color: var(--color-blue) !important;
  color: white;
}

.donate-btn {
  background-color: #ffdd00 !important;
  color: #000 !important;
  border-color: #ffdd00 !important;
}

.donate-btn:hover {
  background-color: #ffea00 !important;
}

/* Layout Adjustments */
body {
  padding: 0; /* Removed top padding to accommodate sticky header */
}

.container {
  padding: 1.5rem;
  height: calc(100vh - 60px); /* Adjust height to account for header */
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(5px);
  z-index: 10000; /* Ensure it's above other modals */
  display: flex;
  justify-content: center;
  align-items: center;

  /* Hiding logic */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* Ensure the list is readable */
.kw-entry {
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}
.kw-name {
  color: var(--accent);
  font-weight: bold;
  text-transform: uppercase;
}

#keywordReferenceDisplay {
  overflow-y: auto;
  max-height: 60vh; /* Limits the list height so the header stays visible */
  padding-right: 10px;
}

#keywordReferenceDisplay::-webkit-scrollbar {
  width: 6px;
}

#keywordReferenceDisplay::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

.export-dropdown {
  position: relative;
  display: flex;
  align-items: stretch;
}

.export-dropdown .btn-tool {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.export-dropdown-content {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  background-color: #ffffff;
  min-width: 140px;
  box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.3);
  z-index: 10;
  border-radius: 4px;
  border: 1px solid #cccccc;
}

.export-dropdown-content a {
  color: #333333;
  padding: 10px 15px;
  text-decoration: none;
  display: block;
  font-family: sans-serif;
  font-size: 0.9rem;
  font-weight: bold;
}

.export-dropdown-content a:hover {
  background-color: #f1f1f1;
}

.export-dropdown:hover .export-dropdown-content {
  display: block;
}
