/* ==============================
   BASE RESET
   ============================== */

* {
  box-sizing: border-box;
}

:root {
  --control-height: 1.6rem;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  margin: 0;
  padding: 0;
}

/* ==============================
   DEFAULT LINK AFFORDANCE
   (INTENT VIOLATION = LOUD)
   ============================== */

a:not(.nav-link):not(.btn) {
  background: #b00000;      /* red */
  color: #ffeb3b;           /* yellow */
  padding: 0 0.2em;
  text-decoration: underline;
}

/* ==============================
   NAVIGATION INTENT
   ============================== */

.nav-link {
  text-decoration: none;
}

.nav-link:hover {
  text-decoration: underline;
}

/* ==============================
   LAYOUT
   ============================== */

main.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
}

main.container > header,
main.container > section {
  margin-block: 2.5rem;
}

main.container > header:first-child,
main.container > section:first-child {
  margin-top: 0;
}

main.container > header:last-child,
main.container > section:last-child {
  margin-bottom: 0;
}

.intent-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.intent-header-left {
  flex: 0 0 auto;
}

.intent-header-right {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.editor-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  width: 100%;
}

.action-group {
  display: block;
  width: 100%;
}

.action-block {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  margin-bottom: 1.5rem;
}

.action-label {
  font-size: 0.8rem;
  color: #7b7b7b;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* ==============================
   FORM ELEMENTS
   ============================== */

label {
  font-weight: 600;
  font-size: 0.9rem;
}

.intent-label-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.intent-help {
  position: relative;
  top: -3px;   /* adjust: -2px to -4px usually enough */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  height: 1.1rem;
  width: 1.1rem;
  min-width: 1.1rem;
  font-size: 0.7rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  vertical-align: middle; /*baseline;*/
  margin-left: auto;
}

.intent-help-popover {
  position: absolute;
  z-index: 900;
  max-width: 260px;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  background: var(--bg-panel, #ffffff);
  color: var(--text-main, #111111);
  border: 1px solid var(--border-subtle, #d0d0d0);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  font-size: 0.8rem;
  line-height: 1.3;
}

input,
textarea,
select {
  width: 100%;
  font-size: 0.9rem;
  padding: 0.4rem;
  height: var(--control-height);
  border: 1px solid transparent;
  border-radius: 4px;
}

textarea {
  min-height: 6rem;
}

/* ==============================
   ACTION INTENT
   ============================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--control-height);
  padding: 0 0.75rem;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
}

.btn:hover,
.btn:active {
  text-decoration: none;
}

/* Works for <a> and <button> */
a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--control-height);
}

/* ==============================
   LAYOUT HELPERS
   ============================== */

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

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

.form-row.three {
  grid-template-columns: repeat(3, 1fr);
}

/* ==============================
   REVISION HISTORY
   ============================== */

.revision-history-panel {
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle, #d0d0d0);
  background: var(--bg-panel, #ffffff);
}

.revision-history-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.revision-history-status {
  font-size: 0.85rem;
  color: var(--text-muted, #6b6b6b);
}

.revision-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.revision-history-table th,
.revision-history-table td {
  padding: 0.5rem 0.4rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle, #e0e0e0);
}

.revision-history-table th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted, #6b6b6b);
}

.revision-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 0.5rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-main, #111111);
  background: rgba(42, 111, 214, 0.2);
  border: 1px solid var(--accent-blue, #2a6fd6);
}

.revision-action-btn {
  height: 1.4rem;
  font-size: 0.8rem;
  padding: 0 0.5rem;
}

/* ==============================
   HISTORICAL REVISION VIEW
   ============================== */

.revision-viewer {
  border-radius: 8px;
  border: 1px solid var(--border-subtle, #d0d0d0);
  padding: 1rem;
  background: rgba(247, 201, 72, 0.08);
}

.revision-viewer-banner {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  background: rgba(247, 201, 72, 0.2);
  border: 1px solid rgba(247, 201, 72, 0.6);
  font-weight: 600;
}

.revision-viewer-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.revision-viewer-status {
  font-size: 0.85rem;
  color: var(--text-muted, #6b6b6b);
}

.revision-viewer-content {
  margin: 0;
  padding: 0.75rem;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border-subtle, #d0d0d0);
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
}

#history-mode {
  display: none;
}

body.history-mode #editor-mode {
  display: none;
}

body.history-mode #history-mode {
  display: block;
}

/* ==============================
   MODALS — CANONICAL CONTRACT
   ============================== */

/* Backdrop */
section[id$="-modal"]:not([hidden]) {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

/* Panel */
.modal-panel {
  width: min(520px, 100%);
  background: var(--bg-panel);
  color: var(--text-main);
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  padding: 1rem;

  /* THIS IS THE CRITICAL RESTORED CONTRACT */
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-panel > form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin: 0;
}

/* Structural spacing */
.modal-header h2 {
  margin: 0;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ==============================
   RESPONSIVE
   ============================== */

@media (max-width: 768px) {
  .form-row,
  .form-row.three {
    grid-template-columns: 1fr;
  }
}
