/*
 * Naming: BEM-ish — block-element pattern (no __ or -- delimiters).
 * Examples: block-header, block-title, agent-card, agent-dot, task-item, task-meta.
 * State variants use dot-chained classes: .agent-status.ready, .block-status--processing.
 * Tokens: spacing uses --space-*, typography uses --text-*, colors use named vars.
 */

/* ── Block Layout Engine ── */
.layout {
  display: flex;
  height: calc(100vh - var(--statusbar-h));
  width: calc(100vw - var(--sidebar-w));
  gap: 1px;
  background: var(--border);
}
.layout-col {
  display: flex;
  flex-direction: row;
  gap: 1px;
  min-width: 0;
}
.layout-row {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-height: 0;
}
.block {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  position: relative;
}
.block.maximized {
  position: fixed;
  top: 0;
  left: 0;
  width: calc(100vw - var(--sidebar-w));
  height: calc(100vh - var(--statusbar-h));
  z-index: 100;
}
.block.dragging {
  opacity: 0.5;
}
.block--active {
  box-shadow: 0 0 0 1px var(--accent), 0 0 12px rgba(124, 92, 255, 0.2);
}

.block-header {
  height: var(--block-header);
  min-height: var(--block-header);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-3);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  cursor: default;
  user-select: none;
}
.block-header:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring) inset;
}
.block-header[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--accent) inset;
}
.block-icon {
  font-size: var(--text-base);
}
.block-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-dim);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.block-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: var(--text-base);
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: 3px;
  line-height: 1;
}
.block-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}
.block-btn:active {
  background: var(--bg-active);
}
.block-btn:focus-visible {
  box-shadow: var(--focus-ring);
}

/* ── Block Status Indicators ── */
.block-status {
  display: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.block-status--processing {
  display: block;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--green);
  border-top-color: transparent;
  background: none;
  animation: spin 0.8s linear infinite, pulse 2s ease-in-out infinite;
  border-radius: 50%;
}
.block-status--attention {
  display: block;
  background: var(--blue);
}
.block-status--error {
  display: block;
  background: var(--red);
  animation: pulse 1s ease-in-out infinite;
}

.block-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
.block-body::-webkit-scrollbar {
  width: 4px;
}
.block-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ── Resize Handles ── */
.resize-handle {
  background: var(--border);
  flex-shrink: 0;
  position: relative;
}
.resize-handle-row {
  height: 4px;
  cursor: ns-resize;
}
.resize-handle-col {
  width: 4px;
  cursor: ew-resize;
}
.resize-handle:hover {
  background: var(--accent);
}

/* ── Drag & Drop Zones ── */
.drop-zones {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 10;
}
.drop-zone {
  position: absolute;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.15s;
}
.drop-zone.active {
  opacity: 0.3;
}
.drop-zone-top {
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
}
.drop-zone-bottom {
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
}
.drop-zone-left {
  top: 0;
  left: 0;
  bottom: 0;
  width: 50%;
}
.drop-zone-right {
  top: 0;
  right: 0;
  bottom: 0;
  width: 50%;
}
.drop-zone-center {
  top: 25%;
  left: 25%;
  right: 25%;
  bottom: 25%;
}

/* ── Status Bar ── */
.add-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: var(--sidebar-w);
  height: var(--statusbar-h);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: var(--space-5);
  gap: var(--space-4);
  z-index: 50;
}
/* ── User Profile Complication ── */
.user-profile-btn {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: var(--space-1) var(--space-3);
  border-radius: 4px;
  font-size: var(--text-sm);
}
.user-profile-btn:hover {
  background: var(--bg-hover);
}
/* ── Auth Status Complication ── */
.auth-status-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: var(--text-sm);
  cursor: pointer;
  padding: var(--space-1) var(--space-3);
  border-radius: 4px;
}
.auth-status-btn:hover {
  color: var(--accent);
  background: var(--bg-hover);
}
.user-profile-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 600;
  color: #fff;
}
.user-profile-name {
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-profile-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: var(--space-2);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: var(--space-4) var(--space-5);
  min-width: 180px;
  z-index: 60;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.user-profile-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.user-profile-logout {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: var(--space-3) 0;
  font-size: var(--text-base);
  width: 100%;
  text-align: left;
}
.user-profile-logout:hover {
  color: var(--accent);
}
.add-btn {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-5);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.add-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}
.add-btn:active {
  background: var(--bg-active);
}
.add-btn:focus-visible {
  box-shadow: var(--focus-ring);
}

/* ── Complications ── */
.complication {
  display: inline-flex;
  align-items: center;
}
.complication-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: var(--text-sm);
  cursor: pointer;
  padding: var(--space-2) var(--space-4);
  border-radius: 4px;
  transition:
    background 0.12s,
    color 0.12s;
}
.complication-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.complication-btn:active {
  background: var(--bg-active);
}
.complication-btn:focus-visible {
  box-shadow: var(--focus-ring);
}
.wall-clock {
  font-size: var(--text-sm);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

/* ── Widget Sidebar ── */
.widget-sidebar {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-2);
  z-index: 60;
  transition: width 0.2s;
  overflow: visible;
}
.widget-sidebar:hover {
  width: 160px;
}
.widget-sidebar.docked {
  width: 160px;
}
.widget-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: var(--space-4);
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  white-space: nowrap;
  transition: background 0.12s;
}
.widget-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.widget-btn:active {
  background: var(--bg-active);
}
.widget-btn:focus-visible {
  box-shadow: var(--focus-ring);
}
.widget-btn.pinned {
  color: var(--accent);
}
.widget-btn.dragging {
  opacity: 0.4;
}
.widget-btn.drop-target {
  border-top: 2px solid var(--accent);
}
.icon {
  font-size: var(--text-lg);
  min-width: 20px;
  text-align: center;
}
.label {
  font-size: var(--text-sm);
  overflow: hidden;
  width: 0;
  transition:
    width 0.2s,
    opacity 0.2s;
  opacity: 0;
}
.widget-sidebar:hover .label,
.widget-sidebar.docked .label {
  width: auto;
  opacity: 1;
}
.sidebar-pin {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
  opacity: 0;
  transition:
    opacity 0.15s,
    transform 0.2s;
  z-index: 1;
  filter: grayscale(1);
  transform: rotate(45deg);
}
.widget-sidebar:hover .sidebar-pin,
.widget-sidebar.docked .sidebar-pin {
  opacity: 0.5;
}
.sidebar-pin:hover {
  opacity: 1 !important;
  color: var(--text);
}
.widget-sidebar.docked .sidebar-pin {
  opacity: 0.8;
  filter: grayscale(1);
  transform: rotate(0deg);
}
.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-2) 0;
}
.widget-more {
  position: relative;
}
.widget-more-menu {
  position: fixed;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: var(--space-2);
  min-width: 160px;
  max-height: 70vh;
  overflow-y: auto;
  display: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 61;
  isolation: isolate;
}
.widget-more.open .widget-more-menu {
  display: block;
}
.widget-more-menu .label {
  width: auto;
  opacity: 1;
}

/* ── Tablet (≤768px) ── */
@media (max-width: 768px) {
  .layout {
    flex-direction: column;
    width: 100vw;
    overflow-y: auto;
  }
  .layout-col {
    flex-direction: column;
    flex: none !important;
  }
  .block {
    flex: none !important;
    min-height: 300px;
  }
  .block.maximized {
    width: 100vw;
    height: calc(100vh - var(--statusbar-h));
  }
  .resize-handle-col {
    display: none;
  }
  .resize-handle-row {
    height: 2px;
  }
  .widget-sidebar {
    width: 48px;
    position: fixed;
    right: 0;
    transform: translateX(100%);
    transition: transform 0.2s;
  }
  .widget-sidebar:hover {
    width: 48px;
  }
  .widget-sidebar.sidebar-open {
    transform: translateX(0);
  }
  .add-bar {
    right: 0;
    gap: var(--space-2);
    flex-wrap: wrap;
    height: auto;
    min-height: var(--statusbar-h);
    padding: var(--space-3) var(--space-4);
  }
  .add-btn, .complication-btn, .widget-btn {
    min-height: 44px;
    min-width: 44px;
  }
  .mobile-menu-btn {
    min-height: 44px;
    min-width: 44px;
    background: none;
    border: none;
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    border-radius: 6px;
  }
  .mobile-menu-btn:active {
    background: var(--bg-active);
  }
}

/* ── Mobile (≤480px) ── */
@media (max-width: 480px) {
  .block {
    min-height: 250px;
  }
  .block-header {
    padding: 0 var(--space-4);
  }
  .block-title {
    font-size: var(--text-sm);
  }
  .add-bar .complication:not(.mobile-menu-btn):not(.wall-clock) {
    display: none;
  }
}
