/* ==========================================================================
   windows.css — window chrome, content, resize handles, settings UI
   ========================================================================== */

.win {
  position: absolute;
  display: flex;
  flex-direction: column;
  min-width: 320px;
  min-height: 200px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-window);
  z-index: var(--z-window-base);
  opacity: 0;
  will-change: transform, opacity;
}

.win.focused {
  box-shadow: var(--shadow-window-active);
  border-color: var(--border-2);
}

.win.maximized {
  border-radius: 0;
}

.win-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 38px;
  padding: 0 8px 0 14px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-1);
  cursor: default;
}
.win.dragging .win-titlebar {
  cursor: grabbing;
}

.win-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-1);
  min-width: 0;
  overflow: hidden;
}
.win.focused .win-title {
  color: var(--text-0);
}
.win-title img {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
}
.win-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.win-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}
.win-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-1);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.win-btn:hover {
  background: var(--surface-2);
  color: var(--text-0);
}
.win-btn.close:hover {
  background: #e5484d;
  color: #fff;
}
.win-btn svg {
  width: 13px;
  height: 13px;
}

.win-body {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: var(--bg-1);
}

.win-body iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

.win-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-1);
  color: var(--text-2);
  font-size: 13px;
  gap: 10px;
  transition: opacity var(--dur-med) var(--ease-out);
}
.win-loading .spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
.win-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.win-blocked {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: var(--bg-1);
  color: var(--text-1);
}
.win-blocked p {
  margin: 0;
  font-size: 13px;
  max-width: 360px;
  color: var(--text-2);
}
.win-blocked a.open-external {
  padding: 9px 18px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--text-on-accent);
  font-size: 13px;
  font-weight: 600;
}
.win-blocked a.open-external:hover {
  text-decoration: none;
  background: var(--accent-strong);
}

/* Markdown content windows */
.win-markdown {
  height: 100%;
  overflow-y: auto;
  padding: 26px 32px;
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.65;
}
.win-markdown h1, .win-markdown h2, .win-markdown h3 {
  color: var(--text-0);
  line-height: 1.3;
}
.win-markdown h1 { font-size: 22px; margin: 0 0 14px; }
.win-markdown h2 { font-size: 17px; margin: 26px 0 10px; }
.win-markdown h3 { font-size: 15px; margin: 20px 0 8px; }
.win-markdown p { margin: 0 0 14px; }
.win-markdown ul, .win-markdown ol { margin: 0 0 14px; padding-left: 22px; }
.win-markdown li { margin-bottom: 4px; }
.win-markdown code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12.5px;
  font-family: "Cascadia Code", "SF Mono", Consolas, monospace;
}
.win-markdown pre {
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  padding: 14px;
  overflow-x: auto;
}
.win-markdown pre code {
  background: none;
  padding: 0;
}
.win-markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 16px;
  font-size: 13px;
}
.win-markdown th, .win-markdown td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-1);
}
.win-markdown th {
  color: var(--text-0);
  font-weight: 600;
}
.win-markdown strong { color: var(--text-0); }
.win-markdown hr {
  border: none;
  border-top: 1px solid var(--border-1);
  margin: 18px 0;
}

/* Resize handles */
.win-resize-handle {
  position: absolute;
  z-index: 2;
}
.rh-n  { top: -4px; left: 8px; right: 8px; height: 8px; cursor: ns-resize; }
.rh-s  { bottom: -4px; left: 8px; right: 8px; height: 8px; cursor: ns-resize; }
.rh-e  { right: -4px; top: 8px; bottom: 8px; width: 8px; cursor: ew-resize; }
.rh-w  { left: -4px; top: 8px; bottom: 8px; width: 8px; cursor: ew-resize; }
.rh-ne { top: -4px; right: -4px; width: 14px; height: 14px; cursor: nesw-resize; }
.rh-nw { top: -4px; left: -4px; width: 14px; height: 14px; cursor: nwse-resize; }
.rh-se { bottom: -4px; right: -4px; width: 14px; height: 14px; cursor: nwse-resize; }
.rh-sw { bottom: -4px; left: -4px; width: 14px; height: 14px; cursor: nesw-resize; }

/* ---------- Settings app ---------- */
.settings-body {
  height: 100%;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.settings-row .label {
  font-size: 13.5px;
  color: var(--text-0);
}
.settings-row .desc {
  font-size: 11.5px;
  color: var(--text-2);
  margin-top: 2px;
}
.settings-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-swatches {
  display: flex;
  gap: 8px;
}
.settings-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}
.settings-swatch.active {
  border-color: var(--text-0);
}

.toggle {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--dur-fast) var(--ease-out);
}
.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--dur-fast) var(--ease-out);
}
.toggle.on {
  background: var(--accent);
}
.toggle.on::after {
  transform: translateX(18px);
}

.segmented {
  display: flex;
  background: var(--surface-1);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}
.segmented button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-1);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.segmented button.active {
  background: var(--surface-3);
  color: var(--text-0);
}

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

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