/* ====================================================================
   KR TERMINAL — floating window + brutal terminal content
   ====================================================================
   Two layers stacked here:
     1. .kr-surface — the draggable window chrome (header from SysPulse
        surfaces-header, body container, maximize toggle).
     2. .brutal-terminal-content + .term-* — the terminal output lines,
        custom caret, input row. Original brutal-terminal class names
        preserved so the ported JS stays diff-clean against the source.
   ==================================================================== */

/* Terminus — the bitmap font xterm and gnome-terminal default to. The
   original brutal-terminal aliased this as "TT"; we keep the same alias
   so the content selector lines up with the source. */
@font-face {
  font-family: 'TT';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/Terminus.woff2') format('woff2');
}

/* ─── surface (window chrome) ──────────────────────────────────────── */

/* Optional blur layer behind a surface — when opts.backdrop=true the shim
   inserts a .kr-surface-backdrop sibling at z-index 249 (just below the
   surface). Fades in alongside the spawn animation. Click-through is NOT
   wired: terminals are persistent workspaces, only the close button kills
   them. Drag still works because pointermove/up are on document. */
.kr-surface-backdrop {
  position: fixed; inset: 0;
  z-index: 249;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(0);
          backdrop-filter: blur(0);
  opacity: 0;
  transition: opacity 0.22s ease, backdrop-filter 0.22s ease, -webkit-backdrop-filter 0.22s ease;
  pointer-events: none;        /* never blocks anything */
}
.kr-surface-backdrop.open {
  opacity: 1;
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
}

.kr-surface {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 900px; height: 600px;
  background: var(--io-surface-base);
  border: none;
  border-radius: var(--io-radius-xs);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 250;        /* above search(240) so a terminal open over search is on top */
  font-family: var(--io-font-mono);
  transition: width 0.3s cubic-bezier(0.4,0,0.2,1),
              height 0.3s cubic-bezier(0.4,0,0.2,1),
              top 0.3s cubic-bezier(0.4,0,0.2,1),
              left 0.3s cubic-bezier(0.4,0,0.2,1),
              transform 0.3s cubic-bezier(0.4,0,0.2,1),
              border-radius 0.3s cubic-bezier(0.4,0,0.2,1);
}
.kr-surface.dragging { transition: none; user-select: none; cursor: move; }
.kr-surface.maximized {
  width: 100% !important;
  height: 100% !important;
  top: 0 !important; left: 0 !important;
  transform: none !important;
  border-radius: 0;
}
.kr-surface.kr-surface-spawn { animation: kr-surface-spawn 0.18s ease; }
@keyframes kr-surface-spawn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.96); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ─── header (ported from SysPulse surfaces-header) ─────────────────── */

.kr-surface-header {
  display: flex;
  align-items: stretch;
  height: 36px;
  flex-shrink: 0;
  background: var(--io-surface-raised);
  border-bottom: 1px solid var(--io-border);
  cursor: move;
  user-select: none;
  position: relative;
}

/* hamburger menu (far-left section) */
.kr-surface-menu { display: flex; align-items: stretch; position: relative; }
.kr-surface-menu-btn {
  width: 38px;
  height: 100%;
  background: transparent;
  border: none;
  border-right: 1px solid var(--io-border);
  color: var(--io-text-tertiary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--io-fs-sm);
  padding: 0;
  transition: background 0.12s ease, color 0.12s ease;
}
.kr-surface-menu-btn:hover { background: var(--io-surface-hover); color: var(--io-accent); }
.kr-surface-menu-btn.is-open { background: var(--io-surface-hover); color: var(--io-accent); }

/* dropdown — portal below the hamburger, slide-in fade */
.kr-surface-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--io-surface-raised);
  border: 1px solid var(--io-border);
  min-width: 200px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
  transition: opacity 0.16s ease, transform 0.16s ease;
  z-index: 100;
}
.kr-surface-dropdown.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.kr-surface-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: var(--io-text-secondary);
  cursor: pointer;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--io-border-subtle);
  font-family: var(--io-font-mono);
  font-size: var(--io-fs-sm);
  width: 100%;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}
.kr-surface-dropdown-item:last-child { border-bottom: none; }
.kr-surface-dropdown-item:hover {
  background: var(--io-surface-hover);
  color: var(--io-text-primary);
}
.kr-surface-dropdown-item i {
  color: var(--io-accent);
  width: 14px;
  text-align: center;
  opacity: 0.7;
  font-size: var(--io-fs-micro);
}

.kr-surface-icon-tile {
  width: 36px;
  display: flex; align-items: center; justify-content: center;
  color: var(--io-accent);
  font-size: var(--io-fs-sm);
  background: transparent;
  border-right: 1px solid var(--io-border-subtle);
  flex-shrink: 0;
}
.kr-surface-title {
  display: flex; align-items: center;
  flex: 1;
  min-width: 0;
  padding: 0 16px;
  color: var(--io-text-primary);
  font-size: var(--io-fs-sm);
  letter-spacing: 0.04em;
  font-weight: 500;
}
.kr-surface-title::before {
  content: '//';
  color: var(--io-accent);
  margin-right: 6px;
  font-weight: 400;
  flex-shrink: 0;
}
.kr-surface-title-text {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kr-surface-controls {
  display: flex; align-items: stretch;
  border-left: 1px solid var(--io-border);
  margin-left: auto;
}
.kr-surface-btn {
  width: 38px; height: 100%;
  background: transparent;
  border: none;
  border-left: 1px solid var(--io-border-subtle);
  color: var(--io-text-tertiary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  font-size: var(--io-fs-micro);
  transition: background 0.12s ease, color 0.12s ease;
}
.kr-surface-btn:first-child { border-left: none; }
.kr-surface-btn:hover { background: var(--io-surface-hover); color: var(--io-accent); }
.kr-surface-btn-close:hover { background: var(--io-accent); color: var(--io-on-accent); }
/* fa-window-minimize sits low in its glyph box — nudge it up so it reads
   as a centered bar like the SysPulse render. */
.kr-surface-btn-min i { transform: translateY(-4px); }

.kr-surface-body {
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ─── terminal content (ported from brutal-terminal.css) ────────────── */

.brutal-terminal-content {
  flex: 1;
  background: var(--io-surface-base);
  padding: 16px;
  padding-bottom: 100px;
  overflow-y: auto;
  overflow-x: hidden;
  font-family: 'TT', ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: var(--io-fs-base);
  line-height: 1;
  color: var(--io-text-primary);
  cursor: text;
}

.term-line { white-space: pre-wrap; word-wrap: break-word; }
.term-line.blank { min-height: 8px; }

.term-line.cmd {
  display: flex; gap: 0;
  margin-bottom: 4px;
}
.term-line.cmd .prompt {
  color: var(--io-text-secondary);
  flex-shrink: 0;
}
.term-line.cmd .cmd-text {
  color: var(--io-text-primary);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  flex: 1;
}

/* live input */
.term-input-line { display: flex; gap: 0; }
.term-input-prompt {
  color: var(--io-text-secondary);
  user-select: none;
  flex-shrink: 0;
  line-height: 1;
}
.term-input-wrapper {
  flex: 1;
  position: relative;
  min-height: 21px;
  margin-left: 8px;
}
.term-input {
  width: 100%;
  outline: none;
  color: var(--io-text-primary);
  background: transparent;
  border: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  line-height: 1;
  caret-color: transparent;
  max-width: 100%;
}
.term-input-caret {
  position: absolute;
  width: 8px; height: 14px;
  background: var(--io-accent);
  pointer-events: none;
  opacity: 0;
}
.term-input:focus + .term-input-caret {
  animation: caret-blink 1s infinite;
  opacity: 1;
  margin-top: 2px;
}
@keyframes caret-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* output line types */
.term-line.json    { margin: 4px 0; color: var(--io-text-secondary); white-space: pre; }
.term-line.table   { margin: 4px 0; color: var(--io-text-primary);   white-space: pre; }
.term-line.error   { color: var(--io-error); }
.term-line.success { color: var(--io-success); }
.term-line.warning { color: var(--io-warning); }
.term-line.info    { color: var(--io-accent); }
.term-line.sep     { margin: 8px 0; color: var(--io-text-disabled); }

.brutal-terminal-content ::selection { background: var(--io-accent-subtle); color: inherit; }

@media (max-width: 768px) {
  .kr-surface { width: 100%; height: 100%; top: 0; left: 0; transform: none; border-radius: 0; }
  .kr-surface-header { height: 32px; }
  .kr-surface-btn { width: 34px; }
  .kr-surface-icon-tile { width: 32px; }
}
