/*
 * Window manager chrome and application-content scaffolding.
 * State hooks: .is-focused/.is-active, .is-minimized, .is-maximized,
 * .is-fullscreen, .is-dragging, and .is-resizing.
 */

.window-layer {
  position: absolute;
  z-index: var(--z-window-base);
  inset: 0 0 var(--taskbar-total-height);
  overflow: hidden;
  pointer-events: none;
}

.app-window {
  --window-x: 12vw;
  --window-y: 9vh;
  --window-width: min(880px, 76vw);
  --window-height: min(590px, 72vh);
  position: absolute;
  left: var(--window-x);
  top: var(--window-y);
  z-index: var(--z-window-base);
  display: grid;
  grid-template-rows: var(--titlebar-height) minmax(0, 1fr);
  width: var(--window-width);
  height: var(--window-height);
  min-width: min(var(--window-min-width), calc(100vw - 12px));
  min-height: min(var(--window-min-height), calc(100vh - var(--taskbar-total-height) - 12px));
  overflow: visible;
  contain: layout style;
  border: 1px solid var(--border-window-inactive);
  border-radius: var(--radius-window);
  color: var(--text-primary);
  background: var(--surface-window-inactive);
  box-shadow: var(--shadow-window-inactive);
  opacity: 0.99;
  pointer-events: auto;
  touch-action: none;
  transform-origin: center;
  transition:
    border-color var(--duration-medium) ease,
    box-shadow var(--duration-medium) ease,
    opacity var(--duration-medium) ease,
    border-radius var(--duration-medium) ease;
  contain: layout style;
}

.app-window::after {
  content: "";
  position: absolute;
  z-index: 20;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset;
  pointer-events: none;
}

.app-window.is-focused,
.app-window.is-active,
.app-window[aria-selected="true"] {
  z-index: var(--z-window-active);
  border-color: var(--border-window);
  background: var(--surface-window);
  box-shadow: var(--shadow-window);
  opacity: 1;
}

.app-window.is-minimized,
.app-window[data-state="minimized"] {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.app-window.is-maximized,
.app-window[data-state="maximized"] {
  inset: 0 0 var(--taskbar-total-height) 0 !important;
  width: auto !important;
  height: auto !important;
  min-width: 0;
  min-height: 0;
  border-width: 0;
  border-radius: 0;
  transform: none !important;
}

.app-window.is-fullscreen,
.app-window[data-state="fullscreen"] {
  position: fixed;
  z-index: calc(var(--z-overlay) - 1) !important;
  inset: 0 !important;
  grid-template-rows: minmax(0, 1fr);
  width: auto !important;
  height: auto !important;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 0;
  transform: none !important;
}

.app-window.is-fullscreen .window-titlebar,
.app-window[data-state="fullscreen"] .window-titlebar,
.app-window.is-fullscreen .resize-handle,
.app-window[data-state="fullscreen"] .resize-handle {
  display: none;
}

.window-titlebar {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  min-width: 0;
  height: var(--titlebar-height);
  overflow: hidden;
  border-radius: calc(var(--radius-window) - 1px) calc(var(--radius-window) - 1px) 0 0;
  background: var(--surface-titlebar-inactive);
  cursor: default;
  touch-action: none;
  transition: background-color var(--duration-medium) ease;
}

.window-titlebar::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 1px;
  background: var(--border-subtle);
  pointer-events: none;
}

.app-window.is-focused .window-titlebar,
.app-window.is-active .window-titlebar,
.app-window[aria-selected="true"] .window-titlebar {
  background: var(--surface-titlebar);
}

.app-window.is-maximized .window-titlebar,
.app-window[data-state="maximized"] .window-titlebar {
  border-radius: 0;
}

.app-window.is-dragging .window-titlebar {
  cursor: grabbing;
}

.window-title {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
  padding: 0 12px;
  color: var(--text-secondary);
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-regular);
  letter-spacing: 0.005em;
  pointer-events: none;
}

.app-window.is-focused .window-title,
.app-window.is-active .window-title {
  color: var(--text-primary);
}

.window-title-icon {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  overflow: hidden;
  border-radius: 4px;
}

.window-title-icon.app-icon {
  --icon-size: 18px;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.window-title-icon .app-icon__mark {
  font-size: 9px;
}

.window-title-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.window-controls {
  position: relative;
  z-index: 1;
  display: flex;
  height: var(--titlebar-height);
}

.window-control {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px;
  height: var(--titlebar-height);
  color: var(--text-secondary);
  background: transparent;
  transition:
    color var(--duration-fast) linear,
    background-color var(--duration-fast) linear;
}

.window-control:hover {
  color: var(--text-primary);
  background: var(--control-hover);
}

.window-control:active {
  background: var(--control-pressed);
}

.window-control:focus-visible {
  z-index: 1;
  outline-offset: -3px;
}

.window-control--close:hover,
.window-control[data-action="close"]:hover,
.window-control[data-window-action="close"]:hover {
  color: #fff;
  background: var(--danger-hover);
}

.window-control--close:active,
.window-control[data-action="close"]:active,
.window-control[data-window-action="close"]:active {
  color: #fff;
  background: var(--danger-pressed);
}

.window-control-glyph--minimize,
.window-control-glyph--maximize,
.window-control-glyph--restore,
.window-control-glyph--close {
  position: relative;
  display: block;
  width: 12px;
  height: 12px;
  pointer-events: none;
}

.window-control-glyph--minimize::before {
  content: "";
  position: absolute;
  inset: 8px 1px auto;
  height: 1px;
  background: currentColor;
}

.window-control-glyph--maximize::before {
  content: "";
  position: absolute;
  inset: 1px;
  border: 1px solid currentColor;
  border-radius: 1px;
}

.window-control-glyph--restore::before,
.window-control-glyph--restore::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border: 1px solid currentColor;
  border-radius: 1px;
}

.window-control-glyph--restore::before {
  inset: 1px auto auto 3px;
}

.window-control-glyph--restore::after {
  inset: 3px auto auto 1px;
  background: var(--surface-titlebar);
}

.window-control-glyph--close::before,
.window-control-glyph--close::after {
  content: "";
  position: absolute;
  top: 5.5px;
  left: 0;
  width: 12px;
  height: 1px;
  background: currentColor;
}

.window-control-glyph--close::before {
  transform: rotate(45deg);
}

.window-control-glyph--close::after {
  transform: rotate(-45deg);
}

.window-content {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  border-radius: 0 0 calc(var(--radius-window) - 1px) calc(var(--radius-window) - 1px);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.016), transparent 80px),
    var(--surface-window);
  user-select: text;
  -webkit-user-select: text;
  touch-action: pan-x pan-y;
}

.app-window.is-maximized .window-content,
.app-window[data-state="maximized"] .window-content,
.app-window.is-fullscreen .window-content,
.app-window[data-state="fullscreen"] .window-content {
  border-radius: 0;
}

.window-content > iframe,
.window-iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
  transform: translateZ(0);
}

.window-content-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  background: var(--surface-window);
}

.resize-handle {
  position: absolute;
  z-index: 30;
  pointer-events: auto;
  touch-action: none;
}

.resize-handle[data-resize="n"],
.resize-handle[data-direction="n"] {
  inset: calc(var(--resize-handle-size) / -2) var(--resize-handle-size) auto;
  height: var(--resize-handle-size);
  cursor: ns-resize;
}

.resize-handle[data-resize="e"],
.resize-handle[data-direction="e"] {
  inset: var(--resize-handle-size) calc(var(--resize-handle-size) / -2) var(--resize-handle-size) auto;
  width: var(--resize-handle-size);
  cursor: ew-resize;
}

.resize-handle[data-resize="s"],
.resize-handle[data-direction="s"] {
  inset: auto var(--resize-handle-size) calc(var(--resize-handle-size) / -2);
  height: var(--resize-handle-size);
  cursor: ns-resize;
}

.resize-handle[data-resize="w"],
.resize-handle[data-direction="w"] {
  inset: var(--resize-handle-size) auto var(--resize-handle-size) calc(var(--resize-handle-size) / -2);
  width: var(--resize-handle-size);
  cursor: ew-resize;
}

.resize-handle[data-resize="ne"],
.resize-handle[data-direction="ne"],
.resize-handle[data-resize="se"],
.resize-handle[data-direction="se"],
.resize-handle[data-resize="sw"],
.resize-handle[data-direction="sw"],
.resize-handle[data-resize="nw"],
.resize-handle[data-direction="nw"] {
  width: calc(var(--resize-handle-size) * 1.75);
  height: calc(var(--resize-handle-size) * 1.75);
}

.resize-handle[data-resize="ne"],
.resize-handle[data-direction="ne"] {
  inset: calc(var(--resize-handle-size) / -2) calc(var(--resize-handle-size) / -2) auto auto;
  cursor: nesw-resize;
}

.resize-handle[data-resize="se"],
.resize-handle[data-direction="se"] {
  inset: auto calc(var(--resize-handle-size) / -2) calc(var(--resize-handle-size) / -2) auto;
  cursor: nwse-resize;
}

.resize-handle[data-resize="sw"],
.resize-handle[data-direction="sw"] {
  inset: auto auto calc(var(--resize-handle-size) / -2) calc(var(--resize-handle-size) / -2);
  cursor: nesw-resize;
}

.resize-handle[data-resize="nw"],
.resize-handle[data-direction="nw"] {
  inset: calc(var(--resize-handle-size) / -2) auto auto calc(var(--resize-handle-size) / -2);
  cursor: nwse-resize;
}

.app-window.is-maximized .resize-handle,
.app-window[data-state="maximized"] .resize-handle,
.app-window[data-resizable="false"] .resize-handle {
  display: none;
}

.window-snap-preview {
  position: absolute;
  z-index: calc(var(--z-window-active) - 1);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-window);
  background: rgba(27, 134, 211, 0.22);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  pointer-events: none;
}

.app-placeholder {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100%;
  color: var(--text-primary);
  background:
    radial-gradient(circle at 84% 8%, var(--accent-subtle), transparent 34%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.025), transparent 45%);
}

.placeholder-hero {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  padding: clamp(24px, 5vw, 48px) clamp(24px, 6vw, 58px) 24px;
}

.placeholder-hero .app-icon {
  --icon-size: 64px;
  border-radius: 15px;
}

.placeholder-hero__copy {
  min-width: 0;
}

.placeholder-hero h1,
.placeholder-title {
  overflow: hidden;
  font-size: clamp(24px, 4vw, 36px);
  font-weight: var(--font-weight-semibold);
  line-height: 1.15;
  letter-spacing: -0.035em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.placeholder-hero p,
.placeholder-subtitle {
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: var(--font-size-subtitle);
}

.placeholder-status {
  align-self: start;
  display: grid;
  gap: 1px;
  margin: 0 clamp(24px, 6vw, 58px);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-medium);
  background: var(--border-subtle);
}

.placeholder-status__row,
.placeholder-status > p,
.placeholder-status > div {
  display: grid;
  grid-template-columns: minmax(110px, 0.35fr) minmax(0, 1fr);
  gap: 16px;
  min-height: 42px;
  padding: 10px 14px;
  background: var(--surface-card);
}

.placeholder-status__label,
.placeholder-status dt {
  color: var(--text-secondary);
}

.placeholder-status__value,
.placeholder-status dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.placeholder-status code {
  font-family: var(--font-mono);
  font-size: 12px;
}

.placeholder-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 24px clamp(24px, 6vw, 58px) clamp(24px, 5vw, 44px);
}

.about-panel,
.settings-panel {
  min-height: 100%;
  padding: clamp(24px, 4vw, 44px);
}

.about-panel {
  display: grid;
  align-content: start;
  justify-items: center;
  text-align: center;
}

.about-brand {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 14px 0 26px;
}

.about-brand .blink-logo {
  width: 84px;
  height: 84px;
  border-radius: 21px;
  font-size: 38px;
}

.about-brand h1 {
  font-size: var(--font-size-display);
  font-weight: var(--font-weight-semibold);
  letter-spacing: -0.035em;
}

.about-brand p {
  max-width: 48ch;
  color: var(--text-secondary);
}

.about-panel__details {
  width: min(480px, 100%);
  padding: 18px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-medium);
  background: var(--surface-card);
  text-align: left;
}

.settings-panel {
  display: grid;
  align-content: start;
  gap: 20px;
}

.settings-panel > h1 {
  font-size: var(--font-size-display);
  font-weight: var(--font-weight-semibold);
  letter-spacing: -0.035em;
}

.settings-group {
  display: grid;
  gap: 2px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-medium);
  background: var(--border-subtle);
}

.settings-group__title {
  margin: 4px 2px 8px;
  color: var(--text-secondary);
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-medium);
}

.settings-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  min-height: 58px;
  padding: 10px 14px;
  background: var(--surface-card);
}

.settings-option:hover {
  background: var(--surface-layer-hover);
}

.settings-option__title {
  font-weight: var(--font-weight-medium);
}

.settings-option__description {
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: var(--font-size-caption);
}

.settings-option select {
  min-height: 30px;
  padding: 4px 30px 4px 10px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-control);
  color: var(--text-primary);
  background: var(--surface-input);
}

.settings-option input[type="checkbox"] {
  appearance: none;
  position: relative;
  width: 40px;
  height: 20px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-round);
  background: var(--surface-layer);
  transition:
    background-color var(--duration-fast) ease,
    border-color var(--duration-fast) ease;
}

.settings-option input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition:
    left var(--duration-medium) var(--ease-standard),
    background-color var(--duration-fast) ease;
}

.settings-option input[type="checkbox"]:checked {
  border-color: var(--accent);
  background: var(--accent);
}

.settings-option input[type="checkbox"]:checked::after {
  left: 23px;
  background: var(--text-on-accent);
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  min-height: 100%;
  padding: 40px 24px;
  color: var(--text-secondary);
  text-align: center;
}

.empty-state__icon {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin-bottom: 4px;
  border: 1px solid var(--border-default);
  border-radius: 50%;
  color: var(--text-tertiary);
  background: var(--surface-card);
  font-size: 28px;
}

.empty-state h2 {
  color: var(--text-primary);
  font-size: var(--font-size-title);
  font-weight: var(--font-weight-medium);
}

.empty-state p {
  max-width: 42ch;
}

@media (max-width: 700px) {
  .app-window:not(.is-maximized):not([data-state="maximized"]):not(.is-fullscreen) {
    max-width: calc(100vw - 8px);
    max-height: calc(100vh - var(--taskbar-total-height) - 8px);
  }

  .window-control {
    width: 42px;
  }

  .placeholder-hero {
    grid-template-columns: 1fr;
  }

  .placeholder-hero .app-icon {
    --icon-size: 54px;
  }

  .placeholder-status__row,
  .placeholder-status > p,
  .placeholder-status > div {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

@media (forced-colors: active) {
  .app-window,
  .app-window.is-focused,
  .app-window.is-active {
    border: 1px solid CanvasText;
    box-shadow: none;
  }

  .window-titlebar {
    border-bottom: 1px solid CanvasText;
  }

  .window-control:hover {
    color: HighlightText;
    background: Highlight;
    forced-color-adjust: none;
  }

  .window-control--close:hover,
  .window-control[data-action="close"]:hover,
  .window-control[data-window-action="close"]:hover {
    color: HighlightText;
    background: Highlight;
  }

  .settings-option input[type="checkbox"] {
    appearance: auto;
    width: auto;
    height: auto;
  }

  .settings-option input[type="checkbox"]::after {
    display: none;
  }
}
