/* ============================================================
   PyIDE — style.css
   ============================================================ */

/* ── Custom Properties ──────────────────────────────────── */
:root {
  --bg:          #0d1117;
  --bg-surface:  #161b22;
  --bg-raised:   #1c2128;
  --bg-overlay:  #22272e;

  --border:      #30363d;
  --border-soft: #21262d;

  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --text-dim:    #6e7681;

  --accent:      #58a6ff;
  --accent-bg:   rgba(88, 166, 255, 0.1);
  --accent-dark: #1f6feb;

  --green:       #3fb950;
  --green-dark:  #238636;
  --green-bg:    rgba(63, 185, 80, 0.12);

  --red:         #f85149;
  --orange:      #e3b341;

  --font-ui:   system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, 'Courier New', monospace;

  --h-header:    48px;
  --h-status:    24px;
  --r-sm:        4px;
  --r-md:        6px;
  --ease:        130ms ease;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

button { cursor: pointer; user-select: none; -webkit-user-select: none; }
svg    { display: block; flex-shrink: 0; }
a      { color: var(--accent); }

/* ── App Shell ──────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh; /* fallback */
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--h-header);
  padding: 0 14px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-right: 4px;
}

.brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

/* Mode Tabs */
.mode-tabs {
  display: flex;
  background: var(--bg-overlay);
  border-radius: var(--r-md);
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}

.tab {
  padding: 4px 16px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: color var(--ease), background var(--ease), box-shadow var(--ease);
  -webkit-tap-highlight-color: transparent;
}

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

.tab.active {
  background: var(--bg-raised);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.35), 0 0 0 1px var(--border-soft);
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.btn-ghost {
  padding: 6px 12px;
  border-radius: var(--r-md);
  font-size: 13px;
  color: var(--text-muted);
  transition: color var(--ease), background var(--ease);
  -webkit-tap-highlight-color: transparent;
}

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

.btn-run {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  background: var(--green-dark);
  color: #fff;
  border: 1px solid rgba(240,246,252,0.1);
  transition: background var(--ease), transform 80ms ease, opacity var(--ease);
  -webkit-tap-highlight-color: transparent;
  min-height: 32px;
}

.btn-run:hover  { background: #2ea043; }
.btn-run:active { transform: scale(0.97); }

.btn-run:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* ── SQL Toolbar ─────────────────────────────────────────── */
#sql-toolbar {
  display: flex;
  align-items: center;
  min-height: 46px;
  padding: 0 14px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#sql-toolbar.hidden { display: none; }

.sql-toolbar-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-width: max-content;
  padding: 6px 0;
}

.dialect-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.segmented {
  display: flex;
  background: var(--bg-overlay);
  border-radius: var(--r-md);
  padding: 2px;
  gap: 2px;
}

.seg {
  padding: 3px 10px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  transition: color var(--ease), background var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.seg:hover { color: var(--text); }

.seg.active {
  background: var(--bg-raised);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

/* Connection form */
.conn-form {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.conn-form.hidden { display: none; }

.conn-form input {
  height: 28px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--text);
  width: 115px;
  transition: border-color var(--ease);
  -webkit-appearance: none;
}

.conn-form input::placeholder { color: var(--text-dim); }
.conn-form input:focus         { border-color: var(--accent); }

#inp-port { width: 62px; }

.btn-connect {
  height: 28px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--text-muted);
  transition: color var(--ease), border-color var(--ease);
  flex-shrink: 0;
}

.btn-connect:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* DB indicator */
.db-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
  flex-shrink: 0;
}

/* ── Dots ────────────────────────────────────────────────── */
.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-green  { background: var(--green);  box-shadow: 0 0 5px rgba(63,185,80,0.45); }
.dot-red    { background: var(--red); }
.dot-orange { background: var(--orange); }

.dot-pulse {
  background: var(--orange);
  animation: dot-pulse 1.5s ease-in-out infinite;
}

@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.25; }
}

/* ── Workspace ───────────────────────────────────────────── */
#workspace {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
  overflow: hidden;
}

#workspace.vertical { flex-direction: column; }

.pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* ── Pane bars ───────────────────────────────────────────── */
.pane-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 30px;
  padding: 0 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.pane-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.pane-bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-bg);
  padding: 1px 7px;
  border-radius: var(--r-sm);
}

.mono-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.btn-link {
  font-size: 11px;
  color: var(--text-dim);
  padding: 2px 7px;
  border-radius: var(--r-sm);
  transition: color var(--ease), background var(--ease);
}

.btn-link:hover { color: var(--text-muted); background: var(--bg-overlay); }

/* ── Editor ──────────────────────────────────────────────── */
#editor-wrap {
  flex: 1;
  overflow: hidden;
  position: relative;
}

#editor-wrap .CodeMirror {
  height: 100%;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.65;
  background: var(--bg);
}

#editor-wrap .CodeMirror-scroll {
  -webkit-overflow-scrolling: touch;
}

#editor-wrap .CodeMirror-gutters {
  background: var(--bg-surface);
  border-right: 1px solid var(--border-soft);
}

#editor-wrap .CodeMirror-linenumber {
  color: var(--text-dim);
  padding: 0 8px 0 4px;
  font-size: 12px;
}

#editor-wrap .CodeMirror-activeline-background {
  background: rgba(255,255,255,0.028);
}

#editor-wrap .CodeMirror-selected {
  background: rgba(88, 166, 255, 0.16);
}

#editor-wrap .CodeMirror-cursor {
  border-left: 2px solid var(--accent) !important;
}

#editor-wrap .CodeMirror-matchingbracket {
  color: var(--green) !important;
  font-weight: bold;
  text-decoration: underline;
}

/* ── Resize Gutter ───────────────────────────────────────── */
#gutter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 5px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-left:  1px solid var(--border);
  border-right: 1px solid var(--border);
  cursor: col-resize;
  transition: background var(--ease);
  position: relative;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
}

#gutter:hover,
#gutter.dragging {
  background: var(--accent-bg);
}

#gutter:hover .gutter-bar,
#gutter.dragging .gutter-bar {
  background: var(--accent);
}

.gutter-bar {
  width: 1px;
  height: 36px;
  background: var(--border);
  border-radius: 1px;
  pointer-events: none;
  transition: background var(--ease);
}

/* Mobile: gutter becomes horizontal */
#workspace.vertical #gutter {
  width: auto;
  height: 5px;
  cursor: row-resize;
  border-left:   none;
  border-right:  none;
  border-top:    1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

#workspace.vertical .gutter-bar {
  width: 36px;
  height: 1px;
}

/* ── Output Wrap ─────────────────────────────────────────── */
#output-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* Console */
#console {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 11px 15px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  word-break: break-word;
  min-height: 0;
}

.console-idle {
  color: var(--text-dim);
  font-style: italic;
}

/* Console lines */
.cline {
  display: block;
  white-space: pre-wrap;
}

.cline.stdout  { color: var(--text); }
.cline.stderr  { color: var(--red); }
.cline.result  { color: var(--accent); }
.cline.info    { color: var(--text-muted); }
.cline.dim     { color: var(--text-dim); }
.cline.success { color: var(--green); }
.cline.error   { color: var(--red); }

.cline.sep {
  display: block;
  height: 1px;
  background: var(--border-soft);
  margin: 7px 0;
}

.ctimestamp {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 5px;
}

/* Running indicator */
.running-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--orange);
  font-size: 12px;
  margin-top: 2px;
}

.spinner {
  width: 11px;
  height: 11px;
  border: 2px solid var(--border);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── SQL Results Table ───────────────────────────────────── */
#results {
  flex-shrink: 0;
  max-height: 52%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
}

#results.hidden { display: none; }

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.rtable {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.rtable th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-raised);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 7px 14px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.rtable td {
  padding: 6px 14px;
  color: var(--text);
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rtable tr:nth-child(even) td { background: rgba(255,255,255,0.016); }
.rtable tr:hover           td { background: rgba(88,166,255,0.055); }

.cell-null {
  color: var(--text-dim);
  font-style: italic;
}

.table-meta {
  flex-shrink: 0;
  padding: 5px 14px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-soft);
}

/* ── Status Bar ──────────────────────────────────────────── */
#statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--h-status);
  padding: 0 10px;
  background: var(--accent-dark);
  flex-shrink: 0;
}

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

.status-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.status-item .dot {
  width: 6px;
  height: 6px;
}

.status-sep {
  width: 1px;
  height: 10px;
  background: rgba(255,255,255,0.22);
}

#py-label,
#sql-label {
  font-size: 11px;
  color: rgba(255,255,255,0.78);
}

#status-cursor {
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(255,255,255,0.68);
}

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

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --h-header: 52px;
  }

  #header { padding: 0 10px; gap: 6px; }

  .brand-name { display: none; }

  .tab { padding: 5px 12px; min-height: 34px; }

  .btn-run  { padding: 7px 14px; min-height: 36px; }
  .btn-ghost { min-height: 36px; }

  #editor-wrap .CodeMirror { font-size: 13px; }

  #console { font-size: 12px; padding: 10px 12px; }

  .conn-form input  { width: 86px; }
  #inp-port         { width: 56px; }

  .rtable th,
  .rtable td { padding: 5px 10px; }
}

@media (max-width: 480px) {
  .field-label { display: none; }

  .seg { padding: 4px 9px; }

  .conn-form {
    flex-wrap: wrap;
    padding: 4px 0;
  }

  .conn-form input  { width: 76px; }
  #inp-port         { width: 50px; }
}

/* ── iOS safe area ───────────────────────────────────────── */
@supports (padding: max(0px)) {
  #header {
    padding-left:  max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }

  #statusbar {
    padding-left:   max(10px, env(safe-area-inset-left));
    padding-right:  max(10px, env(safe-area-inset-right));
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(var(--h-status) + env(safe-area-inset-bottom));
  }
}
