/* ============================================================
   style.css — RelAlg Explorer
   ============================================================ */

/* Color palette */
:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #dee2e6;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --header-bg: #1e293b;
  --node-leaf: #2563eb;
  --node-unary: #16a34a;
  --node-binary: #d97706;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
}

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

html {
  height: 100%;
}

body {
  height: 100%;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* ---- Header ---- */
header {
  background: var(--header-bg);
  color: white;
  padding: 12px 24px;
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
  z-index: 10;
  position: relative;
}

.header-content {
  display: flex;
  align-items: baseline;
  gap: 16px;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: white;
}

.subtitle {
  color: #94a3b8;
  font-size: 0.85rem;
}

/* ---- App layout ---- */
.app-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ---- Left panel ---- */
.left-panel {
  width: 300px;
  min-width: 240px;
  max-width: 340px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.panel-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-header h2 {
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* ---- Relation cards ---- */
.relation-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.relation-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.relation-name-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  outline: none;
  cursor: text;
  min-width: 0;
}

.relation-name-input:focus {
  color: var(--primary);
}

.relation-body {
  padding: 8px 10px;
}

.attr-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.attr-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.attr-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  font-size: 0.8rem;
  color: var(--text);
  outline: none;
  min-width: 0;
}

.attr-input:focus {
  border-color: var(--primary);
}

/* ---- Tuple table in card ---- */
.tuple-table-wrapper {
  overflow-x: auto;
}

.tuple-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.tuple-table th {
  background: var(--primary);
  color: white;
  padding: 4px 6px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

.tuple-table td {
  padding: 2px 4px;
  border-bottom: 1px solid #f0f4f8;
}

.tuple-cell-input {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 0.78rem;
  color: var(--text);
  outline: none;
  padding: 1px 2px;
}

.tuple-cell-input:focus {
  background: var(--primary-light);
  border-radius: 2px;
}

.add-row-btn {
  margin-top: 6px;
  width: 100%;
  justify-content: center;
}

/* ---- Preset panel ---- */
.preset-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.preset-controls select {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 0.85rem;
  color: var(--text);
  background: white;
  outline: none;
  cursor: pointer;
}

.preset-controls select:focus {
  border-color: var(--primary);
}

.example-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.example-query-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.1s, border-color 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.example-query-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

/* ---- Right panel ---- */
.right-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- Expression area ---- */
.expression-area {
  padding: 16px 20px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.expression-area h2 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ---- Symbol bar ---- */
.symbol-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.symbol-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  font-family: 'Georgia', serif;
  line-height: 1.4;
  white-space: nowrap;
}

.symbol-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.symbol-btn:active {
  background: var(--primary);
  color: white;
}

/* ---- Expression textarea ---- */
.expr-input-row {
  margin-bottom: 8px;
}

#expression-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.95rem;
  font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
  color: var(--text);
  background: white;
  resize: vertical;
  outline: none;
  line-height: 1.5;
  transition: border-color 0.15s;
}

#expression-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ---- Expression controls ---- */
.expr-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ---- Error display ---- */
.error-display {
  margin-top: 8px;
  background: var(--danger-light);
  border: 1px solid #fca5a5;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--danger);
  line-height: 1.4;
}

.error-display.hidden {
  display: none;
}

/* ---- Panels row ---- */
.panels-row {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ---- Tree area ---- */
.tree-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: auto;
  min-width: 0;
}

.tree-area h2 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 12px 16px 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.hint {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-light);
  text-transform: none;
  letter-spacing: 0;
}

#tree-container {
  flex: 1;
  overflow: auto;
  background: #fafbfc;
  padding: 16px;
  min-height: 200px;
}

#tree-container svg {
  display: block;
  min-width: 100%;
}

/* ---- Result area ---- */
.result-area {
  flex: 0 0 380px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

.result-area h2 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ---- Step controls ---- */
.step-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--warning-light);
  border-bottom: 1px solid #fcd34d;
  font-size: 0.8rem;
  color: #92400e;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 6px;
}

.step-controls.hidden {
  display: none;
}

#step-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

/* ---- Result display ---- */
#result-display {
  flex: 1;
  overflow: auto;
  padding: 12px;
}

.placeholder-text {
  color: var(--text-muted);
  font-style: italic;
  padding: 16px 0;
}

.result-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.result-step-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 6px;
  font-family: monospace;
}

.result-table-wrapper {
  overflow-x: auto;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.result-table th {
  background: var(--primary);
  color: white;
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.result-table td {
  padding: 5px 10px;
  border-bottom: 1px solid #f0f4f8;
  white-space: nowrap;
}

.result-table tr.even td {
  background: #f8fafc;
}

.result-table tr.odd td {
  background: white;
}

.result-table tr:hover td {
  background: var(--primary-light);
}

.empty-result {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: 12px !important;
}

/* ---- Buttons ---- */
button {
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  border: none;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary);
  color: white;
  padding: 7px 16px;
  font-weight: 500;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-primary:active {
  background: #1e40af;
}

.btn-secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 16px;
}

.btn-secondary:hover {
  background: var(--bg);
  border-color: #adb5bd;
}

.btn-secondary.active {
  background: var(--success-light);
  border-color: var(--success);
  color: var(--success);
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  padding: 7px 12px;
}

.btn-ghost:hover {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
}

.btn-small {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.btn-icon {
  background: transparent;
  border: none;
  padding: 2px 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  line-height: 1;
}

.btn-icon:hover {
  background: var(--bg);
  color: var(--text);
}

.btn-icon.delete-btn:hover {
  background: var(--danger-light);
  color: var(--danger);
}

/* ---- Scrollbar styling ---- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .left-panel {
    width: 240px;
    min-width: 200px;
  }
  .result-area {
    flex: 0 0 280px;
    min-width: 240px;
  }
}

@media (max-width: 700px) {
  .app-layout {
    flex-direction: column;
  }
  .left-panel {
    width: 100%;
    max-width: none;
    height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .panels-row {
    flex-direction: column;
  }
  .tree-area {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .result-area {
    flex: 0 0 auto;
    min-height: 200px;
  }
}

/* ============================================================
   Footer
   ============================================================ */

.app-footer {
  flex-shrink: 0;
  background: #1e293b;
  color: #94a3b8;
  border-top: 2px solid #0f172a;
  z-index: 5;
}

/* ---- Expandable reference panel ---- */
.footer-panel {
  display: none;
  overflow-y: auto;
  max-height: 260px;
  border-bottom: 1px solid #334155;
}

.footer-panel.open {
  display: block;
}

.footer-inner {
  display: grid;
  grid-template-columns: 210px 1fr 300px;
  min-width: 0;
}

.footer-col {
  padding: 14px 16px;
  border-right: 1px solid #334155;
  min-width: 0;
}

.footer-col:last-child {
  border-right: none;
}

/* ---- About column ---- */
.footer-brand {
  font-size: 0.9rem;
  font-weight: 700;
  color: white;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
}

.footer-attribution {
  font-size: 11px;
  line-height: 1.5;
  color: #94a3b8;
  margin-bottom: 8px;
}

.footer-attribution strong {
  color: #cbd5e1;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 8px;
  align-items: center;
  margin-bottom: 10px;
  font-size: 11px;
}

.footer-links span {
  color: #475569;
}

.footer-links a {
  color: #60a5fa;
  text-decoration: none;
}

.footer-links a:hover {
  color: #93c5fd;
  text-decoration: underline;
}

.footer-resources {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
}

.footer-res-label {
  color: #64748b;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 2px;
}

.footer-resources a {
  color: #60a5fa;
  text-decoration: none;
}

.footer-resources a:hover {
  color: #93c5fd;
  text-decoration: underline;
}

/* ---- Column title ---- */
.footer-col-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #94a3b8;
  margin-bottom: 7px;
}

/* ---- Reference table ---- */
.ref-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 11px;
  line-height: 1.4;
}

.ref-table td {
  padding: 3px 6px;
  vertical-align: top;
  color: #94a3b8;
  border-top: 1px solid #1e293b;
}

.ref-table tr:first-child td {
  border-top: none;
}

.ref-sym {
  white-space: nowrap;
  font-family: 'Georgia', 'Times New Roman', serif;
  color: #e2e8f0;
  padding-right: 10px !important;
  min-width: 120px;
  font-size: 11.5px;
}

.ref-table em {
  color: #7dd3fc;
  font-style: normal;
}

.ref-table code {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  background: #0f172a;
  color: #7dd3fc;
  padding: 1px 3px;
  border-radius: 2px;
}

/* ---- Tips list ---- */
.tip-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 11px;
  color: #94a3b8;
}

.tip-list li {
  position: relative;
  padding: 2px 0 2px 12px;
  line-height: 1.5;
}

.tip-list li::before {
  content: '›';
  position: absolute;
  left: 0;
  color: #60a5fa;
  font-size: 13px;
  line-height: 1.4;
}

.tip-list kbd {
  background: #0f172a;
  border: 1px solid #475569;
  border-radius: 3px;
  padding: 0 4px;
  font-size: 10px;
  font-family: monospace;
  color: #e2e8f0;
}

.tip-list strong {
  color: #e2e8f0;
}

.tip-list em {
  color: #cbd5e1;
  font-style: normal;
}

.tip-list code {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  background: #0f172a;
  color: #7dd3fc;
  padding: 1px 3px;
  border-radius: 2px;
}

/* ---- Always-visible bottom bar ---- */
.footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  gap: 12px;
  min-height: 36px;
}

.footer-bar-left {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 11px;
  color: #475569;
}

.footer-copyright {
  color: #475569;
}

.footer-sep {
  color: #334155;
}

.footer-bar-left a {
  color: #60a5fa;
  text-decoration: none;
}

.footer-bar-left a:hover {
  color: #93c5fd;
  text-decoration: underline;
}

/* ---- Toggle button ---- */
.footer-toggle {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid #334155;
  color: #94a3b8;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-family: inherit;
}

.footer-toggle:hover {
  background: #334155;
  color: #e2e8f0;
}

.footer-toggle.open {
  color: #60a5fa;
  border-color: #3b82f6;
}
