/* ===========================
   Postgres Client WebBase
   Dark Premium Theme
   =========================== */

:root {
  /* Color palette */
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2333;
  --bg-elevated: #21262d;
  --bg-hover: #292e36;
  --bg-active: #2d333b;

  --border-default: #30363d;
  --border-muted: #21262d;
  --border-accent: #3b82f6;

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --text-accent: #58a6ff;

  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.15);

  --success: #3fb950;
  --success-bg: rgba(63, 185, 80, 0.1);
  --warning: #d29922;
  --danger: #f85149;
  --danger-bg: rgba(248, 81, 73, 0.1);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* Sizing */
  --sidebar-width: 280px;
  --topbar-height: 48px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Effects */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --glass-bg: rgba(22, 27, 34, 0.85);
  --glass-blur: blur(12px);

  --transition: 0.2s ease;
}

/* Reset & Base */
*, *::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;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===========================
   Top Bar
   =========================== */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-default);
  z-index: 100;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.logo-icon {
  font-size: 20px;
}
.logo-text {
  font-weight: 600;
  font-size: 15px;
  background: linear-gradient(135deg, #58a6ff, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.3px;
}

.connection-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  background: var(--success-bg);
  border: 1px solid rgba(63, 185, 80, 0.2);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  color: var(--success);
  transition: var(--transition);
}
.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===========================
   Buttons
   =========================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 0 0 0 var(--accent-glow);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 20px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.icon-btn.small {
  width: 26px;
  height: 26px;
}

/* ===========================
   Main Layout
   =========================== */
#main-layout {
  display: flex;
  height: calc(100vh - var(--topbar-height));
}

/* ===========================
   Sidebar
   =========================== */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.3s ease, min-width 0.3s ease, opacity 0.3s ease;
}
#sidebar.collapsed {
  width: 0;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-section:last-child {
  flex: 1;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
}
.sidebar-header h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.sidebar-divider {
  height: 1px;
  background: var(--border-default);
  margin: 4px 0;
}

.sidebar-list {
  list-style: none;
  padding: 0 6px;
  overflow-y: auto;
  max-height: 200px;
}

.sidebar-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 13px;
  color: var(--text-secondary);
}
.sidebar-list li:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.sidebar-list li.active {
  background: var(--accent-glow);
  color: var(--text-accent);
}
.sidebar-list li .conn-name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  overflow: hidden;
}
.sidebar-list li .conn-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-list li .conn-icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.sidebar-list li.active .conn-icon {
  background: var(--success);
}
.sidebar-list li .conn-actions {
  display: none;
  gap: 2px;
}
.sidebar-list li:hover .conn-actions {
  display: flex;
}
.conn-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.conn-action-btn:hover {
  background: var(--bg-active);
  color: var(--text-primary);
}
.conn-action-btn.delete:hover {
  color: var(--danger);
}

/* Schema Tree */
.schema-tree {
  overflow-y: auto;
  padding: 0 6px 12px;
  flex: 1;
}
.schema-tree .tree-empty {
  padding: 16px 10px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}
.tree-node {
  user-select: none;
}
.tree-node-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.tree-node-header:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.tree-node-header .tree-arrow {
  font-size: 10px;
  transition: transform 0.15s;
  color: var(--text-muted);
  width: 12px;
  text-align: center;
}
.tree-node-header .tree-arrow.expanded {
  transform: rotate(90deg);
}
.tree-node-header .tree-icon {
  font-size: 13px;
}
.tree-node-header .tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-node-children {
  padding-left: 16px;
  display: none;
}
.tree-node-children.expanded {
  display: block;
}
.tree-leaf {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.tree-leaf:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.tree-leaf .col-type {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  opacity: 0.7;
}

/* ===========================
   Content Area
   =========================== */
#content {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

#query-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Editor Panel */
#editor-panel {
  display: flex;
  flex-direction: column;
  min-height: 150px;
  flex: 1;
}

/* ===========================
   Table Definition Panel
   =========================== */
#tabledef-panel {
  width: 480px;
  min-width: 380px;
  max-width: 600px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: tabledef-in 0.25s ease;
}
@keyframes tabledef-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.tabledef-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-default);
  gap: 8px;
}
.tabledef-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.tabledef-title-group h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
}
.tabledef-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
}

.tabledef-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.tabledef-section {
  border-bottom: 1px solid var(--border-default);
}
.tabledef-section:last-child {
  border-bottom: none;
}

.tabledef-section-title {
  padding: 10px 14px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.tabledef-table-wrap {
  overflow-x: auto;
}

.tabledef-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.tabledef-table th {
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
.tabledef-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-muted);
  color: var(--text-primary);
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 12px;
}
.tabledef-table tr:hover td {
  background: var(--bg-hover);
}

.td-col-ordinal {
  color: var(--text-muted);
  text-align: center;
  width: 40px;
}

.td-name-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.td-name-text {
  font-weight: 500;
  color: var(--text-primary);
}
.td-badges {
  display: flex;
  gap: 3px;
}

.td-badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 0.5px;
}
.td-badge.pk {
  background: rgba(236, 72, 153, 0.15);
  color: #ec4899;
  border: 1px solid rgba(236, 72, 153, 0.3);
}
.td-badge.fk {
  background: rgba(168, 85, 247, 0.15);
  color: #a855f7;
  border: 1px solid rgba(168, 85, 247, 0.3);
}
.td-badge.uq {
  background: rgba(6, 182, 212, 0.15);
  color: #06b6d4;
  border: 1px solid rgba(6, 182, 212, 0.3);
}
.td-badge.ck {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.td-type-label {
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  background: rgba(59, 130, 246, 0.1);
  color: var(--text-accent);
}

.td-nullable {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 600;
  font-family: var(--font-mono);
}
.td-nullable.yes {
  background: rgba(245, 158, 11, 0.12);
  color: #f59e0b;
}
.td-nullable.no {
  background: rgba(63, 185, 80, 0.12);
  color: #3fb950;
}

.td-col-actions {
  display: flex;
  gap: 4px;
}

.td-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  opacity: 0;
}
.tabledef-table tr:hover .td-action-btn {
  opacity: 1;
}
.td-action-btn:hover {
  background: var(--bg-active);
  color: var(--text-primary);
}
.td-action-btn.drop-col-btn:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

/* Form select (for data type dropdown) */
.form-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%238b949e' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 8px center;
  background-repeat: no-repeat;
  background-size: 16px 12px;
  cursor: pointer;
}
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-select option,
.form-select optgroup {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

#editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-default);
}

.tab-bar {
  display: flex;
  gap: 2px;
}
.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}
.tab.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.tab-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  opacity: 0.6;
  transition: all var(--transition);
}
.tab-close:hover {
  background: rgba(255, 255, 255, 0.1);
  opacity: 1;
}

.editor-actions {
  display: flex;
  gap: 2px;
}

#editor-container {
  flex: 1;
  overflow: auto;
}

/* CodeMirror overrides */
#editor-container .cm-editor {
  height: 100%;
  font-family: var(--font-mono);
  font-size: 14px;
}
#editor-container .cm-editor .cm-scroller {
  font-family: var(--font-mono);
}
#editor-container .cm-editor.cm-focused {
  outline: none;
}
#editor-container .cm-editor .cm-gutters {
  background: var(--bg-tertiary);
  border-right: 1px solid var(--border-default);
}
#editor-container .cm-editor .cm-activeLineGutter {
  background: var(--bg-elevated);
}
#editor-container .cm-editor .cm-activeLine {
  background: rgba(59, 130, 246, 0.06);
}

/* Resize Handle */
#resize-handle {
  height: 6px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-default);
  border-bottom: 1px solid var(--border-default);
  cursor: row-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
#resize-handle:hover, #resize-handle.active {
  background: var(--accent-glow);
}
.handle-line {
  width: 40px;
  height: 2px;
  background: var(--border-default);
  border-radius: 1px;
}
#resize-handle:hover .handle-line {
  background: var(--text-muted);
}

/* Results Panel */
#results-panel {
  display: flex;
  flex-direction: column;
  min-height: 120px;
  height: 280px;
  background: var(--bg-primary);
}

#results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-default);
  font-size: 12px;
  color: var(--text-secondary);
}

.results-actions {
  display: flex;
  gap: 4px;
}

#results-container {
  flex: 1;
  overflow: auto;
  position: relative;
}

/* Placeholder */
#results-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 8px;
  color: var(--text-muted);
}
#results-placeholder p {
  font-size: 13px;
}
#results-placeholder .hint {
  font-size: 12px;
  opacity: 0.6;
}
#results-placeholder kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border-default);
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--bg-elevated);
}

/* Results Table */
#results-table-wrapper {
  min-width: 100%;
}
#results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-family: var(--font-mono);
}
#results-table th {
  position: sticky;
  top: 0;
  padding: 6px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
  z-index: 1;
}
.th-content {
  display: flex;
  align-items: center;
  gap: 6px;
}
.col-name {
  flex: 1;
}
.col-type {
  font-size: 9px;
  font-weight: 500;
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.8;
}
.col-type.type-num { background: rgba(6, 182, 212, 0.15); color: #06b6d4; }
.col-type.type-text { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.col-type.type-date { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.col-type.type-json { background: rgba(168, 85, 247, 0.15); color: #a855f7; }
.col-type.type-uuid { background: rgba(236, 72, 153, 0.15); color: #ec4899; }
.col-type.type-bool { background: rgba(249, 115, 22, 0.15); color: #f97316; }
.col-type.type-binary { background: rgba(107, 114, 128, 0.15); color: #6b7280; }
.col-type.type-other { background: rgba(107, 114, 128, 0.1); color: #6b7280; }
.col-pk {
  font-size: 10px;
  line-height: 1;
}
#results-table td {
  padding: 5px 12px;
  border-bottom: 1px solid var(--border-muted);
  white-space: nowrap;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}
#results-table td.cell-editable {
  cursor: pointer;
  transition: background var(--transition);
}
#results-table td.cell-editable:hover {
  background: rgba(99, 102, 241, 0.12);
}
#results-table tr:hover td {
  background: var(--bg-hover);
}
#results-table tr:hover td.cell-editable:hover {
  background: rgba(99, 102, 241, 0.18);
}
#results-table td.null-value {
  color: var(--text-muted);
  font-style: italic;
}

/* Edit Cell Modal */
.edit-cell-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.edit-cell-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-family: var(--font-mono);
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent);
  border: 1px solid rgba(99, 102, 241, 0.3);
}
.edit-cell-badge.col {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.3);
}
#edit-cell-original {
  background: var(--bg-primary) !important;
  color: var(--text-muted) !important;
  font-family: var(--font-mono);
  font-size: 12px;
}
#edit-cell-input {
  font-family: var(--font-mono);
  font-size: 13px;
  resize: vertical;
  min-height: 60px;
}
.sql-preview-box {
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  max-height: 140px;
  overflow-y: auto;
}
.sql-preview-box code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--warning);
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.6;
}

/* Error display */
#results-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  padding: 20px;
}
.error-icon {
  font-size: 32px;
}
#error-message {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-bg);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(248, 81, 73, 0.2);
  max-width: 600px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===========================
   Modal
   =========================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden {
  display: none;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.modal-content {
  position: relative;
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-in 0.2s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-default);
}
.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border-default);
}

/* Form elements */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-group textarea {
  font-family: var(--font-mono);
  font-size: 12px;
  resize: vertical;
}

.form-row {
  display: flex;
  gap: 12px;
}
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

.checkbox-group {
  margin-bottom: 10px;
}
.checkbox-label, .radio-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
}
.radio-group {
  display: flex;
  gap: 16px;
  margin-top: 4px;
}

.form-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
.form-divider::before, .form-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-default);
}

.ssh-fields {
  padding: 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  margin-top: 8px;
}

/* ===========================
   Toast
   =========================== */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--text-primary);
  animation: toast-in 0.3s ease;
  max-width: 360px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }

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

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

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===========================
   Responsive (mobile)
   =========================== */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 260px;
  }

  #sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    z-index: 50;
    box-shadow: var(--shadow-lg);
  }
  #sidebar.collapsed {
    transform: translateX(-100%);
  }

  .logo-text {
    display: none;
  }

  .modal {
    align-items: flex-end; /* Align to bottom for bottom sheet */
  }

  .modal-content {
    width: 100%;
    max-width: 100%;
    max-height: 90vh; /* Don't cover entire screen */
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: bottom-sheet-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border-bottom: none;
    border-left: none;
    border-right: none;
  }

  /* Drag handle for mobile bottom sheet */
  .modal-drag-handle {
    display: flex;
    justify-content: center;
    padding: 12px 0 4px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .modal-drag-handle::after {
    content: '';
    width: 40px;
    height: 4px;
    background: var(--border-default);
    border-radius: 2px;
  }

  .modal-header {
    padding-top: 8px; /* Reduce top padding since we have the drag handle */
  }

  @keyframes bottom-sheet-in {
    from { transform: translateY(100%); opacity: 1; }
    to { transform: translateY(0); opacity: 1; }
  }
}
