/* ==========================================================================
   Tuimux — Main Theme (Tokyo Night)
   ========================================================================== */

/* ---------- Custom Properties ---------- */
:root {
  --bg-primary: #1a1b26;
  --bg-secondary: #16161e;
  --bg-elevated: #24283b;
  --bg-hover: #292e42;
  --bg-active: #33467c;
  --text-primary: #c0caf5;
  --text-secondary: #565f89;
  --text-muted: #414868;
  --accent: #7aa2f7;
  --accent-hover: #89b4fa;
  --success: #9ece6a;
  --warning: #e0af68;
  --error: #f7768e;
  --border: #292e42;
  --scrollbar: #414868;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sidebar-width: 260px;
  --tabbar-height: 36px;
  --toolbar-height: 40px;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

ul, ol {
  list-style: none;
}

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

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

::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

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

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}

/* ---------- App Layout ---------- */
.app-container {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  min-width: 180px;
  max-width: 500px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header .logo {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
  white-space: nowrap;
}

.sidebar-header .actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.sidebar-search-wrap {
  padding: 8px 12px;
  flex-shrink: 0;
}

.sidebar-search {
  width: 100%;
  height: 30px;
  padding: 0 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s;
}

.sidebar-search::placeholder {
  color: var(--text-muted);
}

.sidebar-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(122, 162, 247, 0.15);
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 0;
}

.sidebar-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Resize handle */
.sidebar-resize {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
}

.sidebar-resize:hover,
.sidebar-resize.active {
  background: var(--accent);
  opacity: 0.4;
}

/* ---------- Main Area ---------- */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ---------- Toolbar ---------- */
.toolbar {
  height: var(--toolbar-height);
  min-height: var(--toolbar-height);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.toolbar-spacer {
  flex: 1;
}

/* ---------- Tab Bar ---------- */
.tab-bar {
  height: var(--tabbar-height);
  min-height: var(--tabbar-height);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: row;
  align-items: stretch;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  border-bottom: 1px solid var(--border);
}

.tab-bar::-webkit-scrollbar {
  height: 2px;
}

.tab {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: 100%;
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
  user-select: none;
  position: relative;
}

.tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.tab .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.tab .status-dot.connected    { background: var(--success); }
.tab .status-dot.disconnected { background: var(--text-muted); }
.tab .status-dot.error        { background: var(--error); }

.tab .close-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  margin-left: 2px;
  padding: 0;
  transition: background 0.1s, color 0.1s;
}

.tab:hover .close-btn {
  display: flex;
}

.tab .close-btn:hover {
  background: var(--bg-active);
  color: var(--error);
}

.tab-add {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 100%;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  transition: color 0.15s, background 0.15s;
}

.tab-add:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

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

.terminal-wrapper {
  position: absolute;
  inset: 0;
  display: none;
}

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

/* ---------- Login Page ---------- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100vh;
  background: var(--bg-primary);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.login-card h1 {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

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

.login-card .form-group {
  margin-bottom: 18px;
}

.login-card .form-group:last-of-type {
  margin-bottom: 24px;
}

.login-card .error-msg {
  color: var(--error);
  font-size: 12px;
  margin-bottom: 14px;
  padding: 8px 10px;
  background: rgba(247, 118, 142, 0.1);
  border: 1px solid rgba(247, 118, 142, 0.25);
  border-radius: 6px;
  display: none;
}

.login-card .error-msg.visible {
  display: block;
}

/* ---------- Form Elements ---------- */
label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="search"],
select,
textarea {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea {
  height: auto;
  padding: 8px 10px;
  resize: vertical;
  min-height: 80px;
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23565f89' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(122, 162, 247, 0.15);
}

input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

/* Checkbox / toggle */
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
}

.toggle input[type="checkbox"] {
  width: 36px;
  height: 20px;
  appearance: none;
  background: var(--bg-hover);
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
  border: none;
  padding: 0;
}

.toggle input[type="checkbox"]::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  background: var(--text-muted);
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s, background 0.2s;
}

.toggle input[type="checkbox"]:checked {
  background: var(--accent);
}

.toggle input[type="checkbox"]:checked::after {
  transform: translateX(16px);
  background: #fff;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  user-select: none;
  outline: none;
}

.btn:focus-visible {
  box-shadow: 0 0 0 2px rgba(122, 162, 247, 0.3);
}

.btn-primary {
  background: var(--accent);
  color: #1a1b26;
  font-weight: 600;
}

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

.btn-primary:active {
  background: #6d93e0;
}

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

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

.btn-danger {
  background: var(--error);
  color: #1a1b26;
  font-weight: 600;
}

.btn-danger:hover {
  background: #ff8fa3;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

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

.btn-icon {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  font-size: 16px;
}

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

.btn-sm {
  height: 26px;
  padding: 0 10px;
  font-size: 11px;
  border-radius: 4px;
}

.btn-lg {
  height: 40px;
  padding: 0 20px;
  font-size: 14px;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  transform: scale(0.95) translateY(8px);
  transition: transform 0.2s;
}

.modal-overlay.open .modal {
  transform: scale(1) translateY(0);
}

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

.modal-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-header .modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  font-size: 18px;
  transition: background 0.15s, color 0.15s;
}

.modal-header .modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
}

.modal-body .form-group {
  margin-bottom: 16px;
}

.modal-body .form-group:last-child {
  margin-bottom: 0;
}

.modal-body .form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------- Toast Notifications ---------- */
.toast-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 13px;
  color: var(--text-primary);
  max-width: 380px;
  pointer-events: all;
  animation: toast-in 0.25s ease-out;
}

.toast.removing {
  animation: toast-out 0.2s ease-in forwards;
}

.toast-icon {
  flex-shrink: 0;
  font-size: 16px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.success .toast-icon { color: var(--success); }

.toast.error { border-left: 3px solid var(--error); }
.toast.error .toast-icon { color: var(--error); }

.toast.warning { border-left: 3px solid var(--warning); }
.toast.warning .toast-icon { color: var(--warning); }

.toast.info { border-left: 3px solid var(--accent); }
.toast.info .toast-icon { color: var(--accent); }

.toast-dismiss {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px;
}

.toast-dismiss:hover {
  color: var(--text-primary);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(40px);
  }
}

/* ---------- Context Menu ---------- */
.context-menu {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 180px;
  padding: 4px 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 200;
  font-size: 13px;
  animation: ctx-in 0.1s ease-out;
}

@keyframes ctx-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.1s;
}

.context-menu-item:hover {
  background: var(--bg-hover);
}

.context-menu-item .shortcut {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.context-menu-item.danger {
  color: var(--error);
}

.context-menu-item.danger:hover {
  background: rgba(247, 118, 142, 0.1);
}

.context-menu-item.disabled {
  color: var(--text-muted);
  cursor: default;
  pointer-events: none;
}

.context-menu-separator {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.context-menu-label {
  padding: 6px 12px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

/* ---------- Command Palette ---------- */
.command-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 250;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
}

.command-palette-overlay.open {
  opacity: 1;
  visibility: visible;
}

.command-palette {
  width: 560px;
  max-width: 90%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  transform: scale(0.95) translateY(-8px);
  transition: transform 0.15s;
}

.command-palette-overlay.open .command-palette {
  transform: scale(1) translateY(0);
}

.command-palette-input-wrap {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}

.command-palette-input-wrap .search-icon {
  color: var(--text-muted);
  font-size: 18px;
  flex-shrink: 0;
}

.command-palette-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-sans);
}

.command-palette-input::placeholder {
  color: var(--text-muted);
}

.command-palette-results {
  max-height: 360px;
  overflow-y: auto;
  padding: 4px 0;
}

.command-palette-group-label {
  padding: 8px 16px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.command-palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.1s;
}

.command-palette-item:hover,
.command-palette-item.selected {
  background: var(--bg-hover);
}

.command-palette-item .icon {
  width: 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  flex-shrink: 0;
}

.command-palette-item .label {
  flex: 1;
  color: var(--text-primary);
  font-size: 13px;
}

.command-palette-item .shortcut {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.command-palette-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.command-palette-footer {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 16px;
  font-size: 11px;
  color: var(--text-muted);
}

.command-palette-footer kbd {
  display: inline-block;
  padding: 1px 5px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-secondary);
  margin: 0 2px;
}

/* ---------- Utility ---------- */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.text-accent  { color: var(--accent); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-error   { color: var(--error); }
.text-muted   { color: var(--text-muted); }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
}

.badge-accent {
  background: rgba(122, 162, 247, 0.2);
  color: var(--accent);
}

.badge-success {
  background: rgba(158, 206, 106, 0.2);
  color: var(--success);
}

.badge-warning {
  background: rgba(224, 175, 104, 0.2);
  color: var(--warning);
}

.badge-error {
  background: rgba(247, 118, 142, 0.2);
  color: var(--error);
}

/* Kbd */
kbd {
  display: inline-block;
  padding: 2px 6px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Divider */
.divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 40px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 13px;
  max-width: 300px;
  line-height: 1.5;
}
