/* ===== Virtual Window Manager =====
 * macOS/Windows-style floating windows with iframe content
 * Compatible with light/dark themes of WebStack Nav
 */

/* ---- Window Chrome ---- */
.wm-window {
  position: fixed;
  z-index: 1000;
  background: var(--wm-bg, rgba(255,255,255,0.96));
  border: 1px solid var(--wm-border, rgba(0,0,0,0.08));
  border-radius: 12px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  min-width: 320px;
  min-height: 200px;
  overflow: hidden;
  width: 820px;
  height: 580px;
  top: 80px;
  left: 100px;
  animation: wmFadeIn 0.2s ease;
  will-change: transform, opacity, left, top, width, height;
}

@keyframes wmFadeIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.wm-window.wm-maximized {
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  border-radius: 0;
  border: none;
}

.wm-window.wm-hidden {
  display: none;
}

/* ---- Title Bar ---- */
.wm-titlebar {
  display: flex;
  align-items: center;
  height: 36px;
  min-height: 36px;
  background: var(--wm-titlebar-bg, rgba(240,240,240,0.7));
  border-bottom: 1px solid var(--wm-border, rgba(0,0,0,0.06));
  border-radius: 12px 12px 0 0;
  cursor: default;
  user-select: none;
  flex-shrink: 0;
  padding: 0 10px;
}
.wm-titlebar.wm-dragging {
  cursor: grabbing;
}

/* macOS-style traffic light buttons */
.wm-controls {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-right: 10px;
  order: -1; /* always left */
}

.wm-btn {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  line-height: 1;
  padding: 0;
  color: transparent;
  transition: color 0.12s;
  position: relative;
}
.wm-btn:hover {
  color: rgba(0, 0, 0, 0.55);
}

.wm-btn-close {
  background: #ff5f57;
  border: 1px solid #e0443e;
}
.wm-btn-close:hover {
  background: #e0443e;
}

.wm-btn-minimize {
  background: #febc2e;
  border: 1px solid #e5a820;
}
.wm-btn-minimize:hover {
  background: #e5a820;
}

.wm-btn-maximize {
  background: #28c840;
  border: 1px solid #20b030;
}
.wm-btn-maximize:hover {
  background: #20b030;
}
.wm-btn-restore {
  /* State marker — inherits .wm-btn-maximize styling */
}
.wm-btn-ext {
  /* Title bar action buttons styled via .wm-title-actions button */
  font-size: 15px;
}

/* Window title text */
.wm-title {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--wm-title-color, #333);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  margin: 0 4px;
}

/* Extra title bar actions (open in new tab) */
.wm-title-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}
.wm-title-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--wm-text, #888);
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: background 0.1s;
}
.wm-title-actions button:hover {
  background: var(--wm-border, #ddd);
  color: var(--wm-title-color, #333);
}

/* ---- Window Body (content area) ---- */
.wm-body {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--wm-bg, #ffffff);
}

.wm-body iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Loading indicator */
.wm-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--wm-bg, #fff);
  z-index: 1;
  color: var(--wm-text, #999);
  font-size: 14px;
}

.wm-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--wm-border, #e0e0e0);
  border-top-color: var(--accent-color, #4a90d9);
  border-radius: 50%;
  animation: wmSpin 0.7s linear infinite;
  margin-bottom: 14px;
}

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

/* ---- Error overlay (X-Frame-Options / load failure) ---- */
.wm-error-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--wm-bg, #f8f9fa);
  color: var(--wm-text, #666);
  padding: 30px;
  text-align: center;
  z-index: 2;
}

.wm-error-overlay .wm-error-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.45;
}
.wm-error-overlay h3 {
  font-size: 18px;
  margin: 0 0 6px;
  color: var(--wm-title-color, #333);
}
.wm-error-overlay p {
  font-size: 14px;
  margin: 0 0 14px;
  max-width: 420px;
  color: var(--wm-text, #666);
  line-height: 1.5;
}
.wm-error-overlay .wm-error-url {
  font-size: 12px;
  color: var(--wm-muted, #999);
  margin: 0 0 16px;
  word-break: break-all;
  max-width: 420px;
}
.wm-error-overlay .wm-btn-newtab {
  padding: 9px 28px;
  background: var(--accent-color, #4a90d9);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}
.wm-error-overlay .wm-btn-newtab:hover {
  background: var(--accent-hover, #357abd);
}

/* ---- Resize handles ---- */
.wm-rz-n,
.wm-rz-s,
.wm-rz-e,
.wm-rz-w,
.wm-rz-ne,
.wm-rz-nw,
.wm-rz-se,
.wm-rz-sw {
  position: absolute;
  z-index: 10;
}

.wm-rz-n {
  top: -4px;
  left: 5px;
  right: 5px;
  height: 8px;
  cursor: n-resize;
}
.wm-rz-s {
  bottom: -4px;
  left: 5px;
  right: 5px;
  height: 8px;
  cursor: s-resize;
}
.wm-rz-e {
  right: -4px;
  top: 5px;
  bottom: 5px;
  width: 8px;
  cursor: e-resize;
}
.wm-rz-w {
  left: -4px;
  top: 5px;
  bottom: 5px;
  width: 8px;
  cursor: w-resize;
}
.wm-rz-ne {
  top: -4px;
  right: -4px;
  width: 12px;
  height: 12px;
  cursor: ne-resize;
}
.wm-rz-nw {
  top: -4px;
  left: -4px;
  width: 12px;
  height: 12px;
  cursor: nw-resize;
}
.wm-rz-se {
  bottom: -4px;
  right: -4px;
  width: 12px;
  height: 12px;
  cursor: se-resize;
}
.wm-rz-sw {
  bottom: -4px;
  left: -4px;
  width: 12px;
  height: 12px;
  cursor: sw-resize;
}

/* ---- Taskbar (bottom bar) ---- */
.wm-taskbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 42px;
  background: var(--wm-taskbar, rgba(30, 30, 42, 0.92));
  display: flex;
  align-items: center;
  padding: 0 10px;
  z-index: 9999;
  gap: 5px;
  border-top: 1px solid var(--wm-border, rgba(255, 255, 255, 0.08));
}

.wm-taskbar-item {
  display: flex;
  align-items: center;
  height: 32px;
  padding: 0 14px;
  background: var(--wm-taskbar-item, rgba(255, 255, 255, 0.1));
  border-radius: 6px;
  color: var(--wm-taskbar-text, #ddd);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  transition: background 0.1s;
  border: none;
  font-family: inherit;
}
.wm-taskbar-item:hover {
  background: var(--wm-taskbar-item-hover, rgba(255, 255, 255, 0.18));
}
.wm-taskbar-item.wm-active {
  background: var(--accent-color, #4a90d9);
  color: #fff;
}

/* ---- Theme variables ---- */
:root {
  --wm-bg: #ffffff;
  --wm-titlebar-bg: #f0f0f0;
  --wm-border: #d0d0d0;
  --wm-title-color: #333333;
  --wm-text: #666666;
  --wm-muted: #999999;
  --wm-taskbar: rgba(30, 30, 42, 0.88);
  --wm-taskbar-item: rgba(255, 255, 255, 0.1);
  --wm-taskbar-item-hover: rgba(255, 255, 255, 0.18);
  --wm-taskbar-text: #ddd;
}

[data-theme="dark"] {
  --wm-bg: rgba(42, 42, 52, 0.96);
  --wm-titlebar-bg: rgba(56, 56, 66, 0.95);
  --wm-border: rgba(255, 255, 255, 0.08);
  --wm-title-color: #e4e4e4;
  --wm-text: #aaaaaa;
  --wm-muted: #777777;
  --wm-taskbar: rgba(12, 12, 20, 0.92);
  --wm-taskbar-item: rgba(255, 255, 255, 0.08);
  --wm-taskbar-item-hover: rgba(255, 255, 255, 0.15);
  --wm-taskbar-text: #cccccc;
}

/* ---- Mobile adjustments ---- */
@media (max-width: 768px) {
  .wm-window {
    width: calc(100vw - 16px) !important;
    height: calc(100vh - 100px) !important;
    top: 8px !important;
    left: 8px !important;
    border-radius: 10px;
    min-width: 0;
    min-height: 0;
  }
  .wm-titlebar {
    height: 36px;
    min-height: 36px;
    border-radius: 10px 10px 0 0;
    padding: 0 8px;
  }
  .wm-btn {
    width: 11px;
    height: 11px;
  }
  .wm-title {
    font-size: 12px;
  }
  .wm-taskbar {
    height: 38px;
    padding: 0 6px;
  }
  .wm-taskbar-item {
    height: 28px;
    font-size: 11px;
    max-width: 140px;
    padding: 0 10px;
  }
}
