/* === 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;
  --bottombar-height: 140px;
}

* {
  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;
  transition: border-color 0.15s;
}

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

.input-small {
  padding: 4px 6px;
  font-size: 12px;
  width: auto;
}

.input-num {
  width: 70px;
  text-align: right;
}

.textarea {
  resize: vertical;
  min-height: 60px;
  max-height: 100px;
  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, border-color 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);
  border-color: var(--accent-hover);
}

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

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

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

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

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

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

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

.app.history-open {
  grid-template-columns: var(--sidebar-width) 1fr var(--history-width, 320px);
  grid-template-areas:
    "sidebar topbar  history"
    "sidebar main    history"
    "sidebar bottom  history";
}

/* === 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);
  letter-spacing: 0.5px;
}

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

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

/* === Sidebar === */

.sidebar {
  grid-area: sidebar;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0;
  gap: 2px;
}

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

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

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

.sidebar-spacer {
  flex: 1;
}

.sidebar-link {
  margin-bottom: 6px;
}

/* === 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;
}

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

.bottom-bar {
  grid-area: bottom;
  background: var(--bar-bg);
  border-top: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px 12px;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

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

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

/* Clipboard columns */
.clipboard-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* === 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;
}

/* === History Panel (right sidebar) === */

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

.history-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  cursor: col-resize;
  background: transparent;
  z-index: 10;
}

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

.history-panel-header {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

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

.history-panel-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* === History List === */

.history-list {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
}

.history-item {
  background: var(--bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.history-meta {
  color: var(--text-muted);
  font-size: 10px;
}

.history-params {
  color: var(--text-muted);
  font-family: monospace;
  font-size: 10px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-result {
  color: var(--danger);
  font-size: 10px;
  margin-top: 2px;
}

.history-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 12px;
  font-size: 12px;
}

/* === 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;
}

/* === 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);
  width: 100px;
  vertical-align: middle;
}

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);
  vertical-align: middle;
}

select {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 4px;
  color: var(--text);
  padding: 4px 6px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

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