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

:root {
  --bg:          #0a0e14;
  --bg-surface:  #0d1117;
  --bg-sidebar:  #010409;
  --bg-hover:    #161b22;
  --bg-active:   #1c2128;
  --border:      #21262d;
  --border-light:#30363d;
  --text:        #c9d1d9;
  --text-muted:  #484f58;
  --text-dim:    #6e7681;
  --green:       #3fb950;
  --green-dim:   #238636;
  --blue:        #58a6ff;
  --red:         #f85149;
  --font:        'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'SF Mono', 'Consolas', monospace;
  --sidebar-w:   260px;
  --topbar-h:    48px;
  --radius:      6px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── Login Screen ─────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(63,185,80,0.06) 0%, transparent 60%);
}

.login-box {
  width: 400px;
  padding: 40px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 70px rgba(0,0,0,0.5);
}

.login-header {
  font-size: 18px;
  color: var(--green);
  margin-bottom: 8px;
  font-weight: 600;
}

.prompt-sign {
  color: var(--green);
  margin-right: 4px;
}

.login-subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 28px;
}

.input-row {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 0 12px;
  transition: border-color 0.2s;
}

.input-row:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(63,185,80,0.15);
}

.input-prompt {
  color: var(--green);
  margin-right: 8px;
  white-space: nowrap;
  font-size: 13px;
}

#password-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 12px 0;
  outline: none;
}

/* TOTP Code Input */
.code-input-row {
  display: flex;
  justify-content: center;
}

.code-input {
  width: 100%;
  max-width: 280px;
  background: var(--bg);
  border: 2px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--green);
  font-family: var(--font);
  font-size: 32px;
  font-weight: 600;
  letter-spacing: 12px;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}

.code-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(63,185,80,0.15);
}

.code-input::placeholder {
  color: var(--text-muted);
  letter-spacing: 12px;
}

/* QR Code */
.qr-container {
  display: flex;
  justify-content: center;
  margin: 20px 0;
}

.qr-container img {
  border-radius: var(--radius);
  border: 4px solid #fff;
}

/* Secret Display */
.secret-display {
  text-align: center;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px dashed var(--border-light);
}

.secret-label {
  display: block;
  color: var(--text-dim);
  font-size: 12px;
  margin-bottom: 8px;
}

.secret-code {
  display: block;
  color: var(--green);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  word-break: break-all;
  user-select: all;
}

.login-error {
  color: var(--red);
  font-size: 12px;
  min-height: 20px;
  margin-top: 8px;
  text-align: center;
}

#login-error {
  color: var(--red);
  font-size: 12px;
  min-height: 20px;
  margin-top: 8px;
}

.login-btn {
  width: 100%;
  padding: 10px;
  margin-top: 8px;
  background: var(--green-dim);
  color: #fff;
  border: 1px solid var(--green);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.login-btn:hover { background: var(--green); color: #000; }

.login-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 24px;
}

/* ── App Layout ───────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
}

.hidden { display: none !important; }

/* ── Sidebar ──────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-left 0.3s ease;
}

#sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-w));
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  color: var(--green);
  font-size: 16px;
  font-weight: 700;
}

#new-term-btn {
  width: 30px;
  height: 30px;
  background: var(--bg-hover);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

#new-term-btn:hover {
  background: var(--green-dim);
  border-color: var(--green);
  color: #fff;
}

#term-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.term-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  margin: 2px 0;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13px;
  transition: all 0.15s;
  white-space: nowrap;
  overflow: hidden;
}

.term-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.term-item.active {
  background: var(--bg-active);
  color: var(--text);
  border-left: 2px solid var(--green);
}

.term-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.term-item-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  margin-right: 8px;
  flex-shrink: 0;
}

.term-item-status.dead {
  background: var(--text-muted);
}

.term-item-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 12px;
  border-radius: 4px;
  flex-shrink: 0;
}

.term-item:hover .term-item-close { display: block; }
.term-item-close:hover { color: var(--red); background: rgba(248,81,73,0.1); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

#logout-btn {
  width: 100%;
  padding: 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

#logout-btn:hover {
  border-color: var(--red);
  color: var(--red);
}

/* ── Main Area ────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

#topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

#sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  display: none;
}

#term-title {
  font-size: 14px;
  color: var(--text);
}

/* ── Terminal Container ───────────────────────────── */
#terminal-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

.term-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px;
  display: none;
}

.term-wrapper.active {
  display: block;
}

/* xterm.js overrides */
.xterm {
  height: 100%;
}

.xterm-viewport {
  background: var(--bg) !important;
}

/* Welcome */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
}

.ascii-art {
  color: var(--green);
  font-size: 12px;
  line-height: 1.2;
  margin-bottom: 20px;
  opacity: 0.6;
}

.welcome p {
  font-size: 14px;
}

.welcome strong {
  color: var(--green);
}

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
    transform: translateX(0);
    transition: transform 0.3s ease;
  }

  #sidebar.collapsed {
    transform: translateX(-100%);
  }

  #sidebar-toggle { display: block; }

  #topbar {
    padding: 0 12px;
  }

  .term-wrapper {
    padding: 4px;
  }

  .xterm {
    font-size: 12px !important;
  }

  /* Prevent iOS zoom on input focus */
  select, textarea, input {
    font-size: 16px !important;
  }
}

/* Handle virtual keyboard on mobile */
@supports (height: 100dvh) {
  html, body {
    height: 100dvh;
  }
  #app {
    height: 100dvh;
  }
}

/* When visualViewport changes (keyboard open/close) */
html {
  --vh: 100vh;
}

#app {
  height: var(--vh);
}

/* ── Scrollbar ────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }
