/* Version 1.1.0 */

:root {
  --bg: #0f172a; /* slate-900 */
  --panel: #111827; /* gray-900 */
  --panel-2: #1f2937; /* gray-800 */
  --text: #e5e7eb; /* gray-200 */
  --muted: #9ca3af; /* gray-400 */
  --accent: #60a5fa; /* blue-400 */
  --border: #374151; /* gray-700 */
}

/* ====== Base (UI uses system font, NOT Courier) ====== */
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue",
    Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
}
.topbar {
  display: flex;
  flex-direction: column; /* stack brand and actions */
  gap: 0.5rem;
}

.topbar .brand {
  display: flex;
  align-items: center;
  padding: 14px 14px;
  justify-content: center;
  gap: 0.5rem;
  font-size: 1.75rem;
  font-weight: bold;
}

.topbar .actions-row {
  display: flex;
  flex-wrap: wrap; /* buttons wrap on small screens */
  gap: 0.5rem;
}
/* .topbar{ */
/* display:flex; align-items:center; justify-content:space-between; */
/* padding:10px 14px; background:var(--panel); border-bottom:1px solid var(--border); */
/* position:sticky; top:0; z-index:50; */
/* } */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}
.logo {
  font-size: 1.75rem;
}
.title {
  letter-spacing: 0.3px;
}
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
button,
select,
input[type="file"] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}
button:hover {
  border-color: var(--accent);
}
select {
  cursor: pointer;
}
.sidebar-toggle {
  display: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 8px;
  font-weight: 800;
}

/* ====== Layout ====== */
.layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 14px;
  padding: 14px;
  min-height: calc(100vh - 120px);
}

.editor-pane {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ====== ONLY the script uses Courier New 12pt ====== */
.script-area {
  font-family: "Courier New", Courier, monospace !important;
  font-size: 12pt !important;
  line-height: 1.5;
}

/* ruler + editor */
.ruler {
  position: relative;
  height: 22px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  padding-left: 8px;
  gap: 80px;
}
.ruler .tick {
  opacity: 0.7;
}

#editor {
  width: 100%;
  height: calc(75vh);
  min-height: 400px;
  resize: vertical;
  padding: 16px;
  background: transparent;
  color: var(--text);
  border: 0;
  outline: none;
  white-space: pre;
  tab-size: 2;
}

/* hidden on screen, shown for print */
#printArea {
  display: none;
  white-space: pre-wrap;
  color: #000;
  background: #fff;
  padding: 0; /* margins via @page */
}

.statusbar {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--panel-2);
}

/* sidebar */
.sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  position: sticky;
  top: 66px;
  height: fit-content;
}
.sidebar h2 {
  margin: 4px 0 10px 0;
}
.group {
  border-top: 1px dashed var(--border);
  padding-top: 12px;
  margin-top: 12px;
}
.group h3 {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: var(--muted);
}
.group small {
  display: block;
  margin: -6px 0 8px 0;
  color: var(--muted);
}
.group button {
  display: block;
  width: 100%;
  text-align: left;
  margin: 6px 0;
}
.transitions {
  display: flex;
  gap: 6px;
}
.help ul {
  margin: 6px 0 0 16px;
  padding: 0;
}
.help li {
  margin: 4px 0;
}
kbd {
  background: #111;
  border: 1px solid var(--border);
  border-bottom-color: #000;
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 12px;
}

.footer {
  padding: 16px;
  text-align: center;
  color: var(--muted);
}

/* ====== Mobile responsive ====== */
@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 56px;
    right: 12px;
    bottom: 12px;
    width: 86%;
    max-width: 360px;
    transform: translateX(120%);
    transition: transform 0.25s ease;
    overflow: auto;
    z-index: 60;
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  .sidebar-toggle {
    display: inline-block;
  }
  #editor {
    height: 60vh;
  }
}

/* ====== Print styles (browser print -> Save as PDF) ====== */
@media print {
  @page {
    /* US Letter — screenplay margins: Left 1.5", Right 1", Top/Bottom 1" */
    size: letter;
    margin: 1in 1in 1in 1.5in;
  }

  body {
    background: #fff;
    color: #000;
  }
  .topbar,
  .sidebar,
  .statusbar,
  .ruler,
  .footer {
    display: none !important;
  }
  .layout,
  .editor-pane {
    border: none;
  }
  #editor {
    display: none !important;
  }
  #printArea {
    display: block !important;
  }
}

/* ===== Technical Enhancements + Screenplay-Specific Enhancements (CSS) ===== */

/* Dark theme toggle (default: dark as your app already is). 
   Add .light on <body> to switch. */
body.light {
  --bg: #ffffff;
  --panel: #f6f7fb;
  --panel-2: #eef0f6;
  --text: #0f172a;
  --muted: #475569;
  --border: #cbd5e1;
  --accent: #2563eb;
  background: var(--bg);
  color: var(--text);
}
body.light .editor-pane,
body.light .sidebar,
body.light .topbar {
  background: var(--panel);
  border-color: var(--border);
}
body.light #editor {
  color: var(--text);
}

/* Status metrics */
.status-metrics {
  display: flex;
  gap: 12px;
  align-items: center;
  font-variant-numeric: tabular-nums;
}

/* Find/Replace panel */
.find-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 90;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  gap: 6px;
  padding: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.find-panel input {
  background: transparent;
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: 8px;
  outline: none;
  color: var(--text);
}
.find-panel button {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}

/* Outline list injected at the end of the sidebar */
#outline {
  margin-top: 14px;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
}
#outline h3 {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: var(--muted);
}
#outline ul {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow: auto;
}
#outline li {
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}
#outline li:hover {
  background: var(--panel-2);
}

/* Character highlight in preview-only blocks (if you add any) */
.char-highlight {
  font-weight: bold;
  text-decoration: underline;
}

#themeToggle {
  margin-left: auto; /* pushes it to the right */
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  font-size: 1.2rem;
  transition: background 0.3s;
}

#themeToggle:hover {
  background: rgba(0, 0, 0, 0.1);
}
