/* === desktopkit Web UI — Dark Theme === */

:root {
  --bg: #1a1a2e;
  --sidebar-bg: #0f1a2e;
  --bar-bg: #16213e;
  --accent: #e94560;
  --accent-hover: #d63352;
  --text: #e0e0e0;
  --text-muted: #888;
  --border: #0f3460;
  --input-bg: #0f1a2e;
  --input-border: #333;
  --danger: #c0392b;
  --danger-hover: #a93226;
  --success: #27ae60;
  --sidebar-width: 48px;
  --topbar-height: 40px;
  --panel-width: 280px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* === Login Screen === */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: var(--bg);
}

.login-card {
  background: var(--bar-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px 40px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  letter-spacing: 1px;
}

.login-username {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.login-error {
  background: rgba(201, 57, 43, 0.15);
  color: #e74c3c;
  border: 1px solid rgba(201, 57, 43, 0.3);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 12px;
  text-align: center;
}

/* === Common Controls === */

.input {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
  width: 100%;
}

.input:focus {
  border-color: var(--accent);
}

.input-num {
  width: 100%;
  text-align: right;
}

.textarea {
  resize: vertical;
  min-height: 80px;
  max-height: 160px;
  width: 100%;
  font-family: monospace;
  font-size: 12px;
}

.btn {
  background: var(--bar-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

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

.btn:active {
  transform: scale(0.97);
}

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

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

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-small {
  padding: 3px 10px;
  font-size: 11px;
}

.btn-preset {
  padding: 4px 10px;
  font-size: 12px;
  min-width: 32px;
}

.btn-block {
  width: 100%;
}

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

.control-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  white-space: nowrap;
}

/* === App Layout === */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr auto;
  grid-template-areas: "sidebar topbar" "sidebar main" "sidebar history";
  width: 100%;
  height: 100%;
}

.app.sidebar-pinned {
  grid-template-columns: auto 1fr;
}

.app.history-expanded {
  grid-template-rows: var(--topbar-height) 1fr var(--history-height, 180px);
}

/* === Top Bar === */

.top-bar {
  grid-area: topbar;
  background: var(--bar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.top-bar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

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

.top-bar-user {
  color: var(--text-muted);
  font-size: 12px;
}

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

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

/* === Sidebar Zone === */

.sidebar-zone {
  grid-area: sidebar;
  display: flex;
  height: 100%;
  position: relative;
  z-index: 50;
}

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 6px 0;
  gap: 2px;
  width: var(--sidebar-width);
  overflow: hidden;
  transition: width 0.15s ease;
  flex-shrink: 0;
}

.sidebar-zone:hover .sidebar,
.sidebar-zone.pinned .sidebar {
  width: 150px;
}

.sidebar-btn {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: transparent;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
  white-space: nowrap;
  margin: 0 4px;
}

.sidebar-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.sidebar-label {
  opacity: 0;
  transition: opacity 0.15s ease;
  font-size: 12px;
}

.sidebar-zone:hover .sidebar-label,
.sidebar-zone.pinned .sidebar-label {
  opacity: 1;
}

.sidebar-btn:hover {
  background: var(--border);
  color: var(--text);
}

.sidebar-btn.active {
  background: var(--accent);
  color: #fff;
}

.sidebar-spacer {
  flex: 1;
}

/* === Flyout Panel === */

.flyout-panel {
  width: 0;
  overflow: hidden;
  background: var(--bar-bg);
  border-right: 1px solid var(--border);
  transition: width 0.15s ease;
  flex-shrink: 0;
}

.sidebar-zone:hover .flyout-panel.has-active,
.sidebar-zone.pinned .flyout-panel.has-active {
  width: var(--panel-width);
}

.flyout-inner {
  width: var(--panel-width);
  height: 100%;
  display: flex;
  flex-direction: column;
}

.panel-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
}

.panel-section {
  margin-bottom: 14px;
}

.panel-section:last-child {
  margin-bottom: 0;
}

.panel-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.field-row:last-child {
  margin-bottom: 0;
}

.field-label {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 28px;
}

.btn-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.btn-row:last-child {
  margin-bottom: 0;
}

.panel-tab {
  display: none;
  height: 100%;
  flex-direction: column;
}

.panel-tab.active {
  display: flex;
}

/* === Main Area === */

.main-area {
  grid-area: main;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

.canvas-container {
  width: 100%;
  height: 100%;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}

#screenshot-canvas {
  display: block;
  cursor: crosshair;
  image-rendering: pixelated;
}

/* === Context Menu === */

.ctx-menu {
  position: fixed;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 0;
  z-index: 200;
  min-width: 180px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.ctx-menu-item {
  padding: 7px 14px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
}

.ctx-menu-item:hover {
  background: var(--accent);
  color: #fff;
}

/* === Cursor Tooltip === */

.cursor-tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 150;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-family: monospace;
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 4px;
  white-space: nowrap;
  display: none;
}

/* === Window Items === */

.win-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  margin-bottom: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.win-item:hover {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.06);
}

.win-item.focused {
  border-color: var(--success);
  background: rgba(39, 174, 96, 0.1);
}

.win-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.win-item-id {
  color: var(--text-muted);
  font-family: monospace;
  font-size: 10px;
  flex-shrink: 0;
}

.win-item-process {
  color: var(--text-muted);
  font-size: 10px;
  flex-shrink: 0;
}

.win-focus-badge {
  font-size: 9px;
  color: var(--success);
  font-weight: 600;
  flex-shrink: 0;
}

/* === History Bottom Bar === */

.history-bar {
  grid-area: history;
  background: var(--bar-bg);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.history-bar.collapsed {
  min-height: 0;
}

.history-bar.collapsed .history-stream {
  display: none;
}

.history-bar.collapsed .history-resize {
  display: none;
}

.history-bar.collapsed .history-toolbar {
  cursor: pointer;
}

.history-bar.collapsed .history-last-entry {
  display: inline;
}

.history-bar:not(.collapsed) .history-last-entry {
  display: none;
}

.history-resize {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  cursor: row-resize;
  z-index: 10;
}

.history-resize:hover,
.history-resize:active {
  background: var(--accent);
}

.history-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 11px;
}

.history-last-entry {
  font-family: monospace;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-last-entry .hl-action {
  color: var(--accent);
  font-weight: 600;
}

.history-last-entry .hl-dur {
  color: var(--text-muted);
}

.history-toolbar-title {
  font-weight: 700;
  color: var(--accent);
  font-size: 12px;
}

.history-stream {
  flex: 1;
  overflow-y: auto;
  font-family: monospace;
  font-size: 11px;
  padding: 4px 0;
}

.history-entry {
  padding: 3px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  cursor: pointer;
}

.history-entry:hover {
  background: rgba(233, 69, 96, 0.04);
}

.history-entry-header {
  display: flex;
  gap: 10px;
  align-items: center;
}

.history-entry-time {
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 10px;
}

.history-entry-action {
  color: var(--accent);
  font-weight: 600;
}

.history-entry-err .history-entry-action {
  color: var(--danger);
}

.history-entry-detail {
  display: none;
  margin-top: 4px;
  padding: 4px 8px;
  background: var(--bg);
  border-radius: 4px;
  font-size: 10px;
}

.history-entry-detail-row {
  color: var(--text-muted);
  margin-bottom: 2px;
  word-break: break-all;
  white-space: pre-wrap;
}

.history-entry-detail-row:last-child {
  margin-bottom: 0;
}

.history-entry-detail-label {
  color: var(--text);
  font-weight: 600;
}

.history-entry.open .history-entry-detail {
  display: block;
}

/* === Debug Panel === */

.debug-panel {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 380px;
  max-height: calc(100% - 16px);
  overflow-y: auto;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  z-index: 100;
  font-size: 11px;
}

.debug-title {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
  font-size: 13px;
}

.debug-section {
  margin-bottom: 8px;
}

.debug-label {
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 2px;
}

.debug-pre {
  background: var(--bg);
  border: 1px solid var(--input-border);
  border-radius: 3px;
  padding: 6px 8px;
  font-family: monospace;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
  max-height: 120px;
  overflow-y: auto;
}

/* === Data Tables === */

.table-scroll {
  overflow: auto;
  max-height: 80px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.data-table th,
.data-table td {
  padding: 3px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

.data-table th {
  background: var(--sidebar-bg);
  color: var(--text-muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table tr:hover td {
  background: rgba(233, 69, 96, 0.06);
}

.data-table .btn {
  padding: 2px 8px;
  font-size: 10px;
}

/* === Scrollbar styling === */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

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

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

/* === Range inputs === */

input[type="range"] {
  accent-color: var(--accent);
}

input[type="color"] {
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  width: 30px;
  height: 24px;
  padding: 1px;
  border-radius: 3px;
  cursor: pointer;
}

input[type="checkbox"] {
  accent-color: var(--accent);
}

select {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  color: var(--text);
  padding: 4px 6px;
  font-size: 12px;
  width: 100%;
}

select:focus {
  border-color: var(--accent);
}
