/**
 * RoccOS Window Chrome
 * Nezu — minimal editorial windows, monochrome controls, clean surfaces
 */

/* ── Window ── */
.os-window {
  position: absolute;
  display: flex;
  flex-direction: column;
  min-width: min(320px, calc(100vw - 16px));
  min-height: 200px;
  background: var(--os-surface-opaque);
  border: 1px solid var(--os-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  pointer-events: auto;
  transition: opacity 0.15s, box-shadow 0.2s ease, border-color 0.2s ease;
}

/* Ensure border is always visible on all windows */
.os-window,
.os-window.focused {
  border: 1px solid var(--os-border);
}

.os-window.focused {
  border-color: rgba(0, 0, 0, 0.14);
  box-shadow: var(--shadow-lg);
}

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

.os-window.closing {
  animation: scaleOut 0.2s var(--ease-in-out) forwards;
}

.os-window.minimizing {
  transition: transform 0.3s var(--ease-in-out), opacity 0.3s var(--ease-in-out);
  transform: scale(0.2);
  opacity: 0;
}

/* ── Title Bar — Win98 grey bevel ── */
.window-title-bar {
  display: flex;
  align-items: center;
  height: 28px;
  padding: 0 10px 0 12px;
  background: var(--win98-face);
  color: var(--win98-text);
  border-bottom: 0;
  box-shadow:
    inset 0 1px 0 var(--win98-light),
    inset 0 -1px 0 var(--win98-shadow);
  cursor: var(--cur-grab); --crt-cursor: grab;
  flex-shrink: 0;
  -webkit-app-region: drag;
  gap: 8px;
}

.os-window.focused .window-title-bar {
  background: var(--win98-face);
}

.window-title-bar:active {
  cursor: var(--cur-grabbing); --crt-cursor: grabbing;
}

/* ── Window Title Icon (small app icon) ── */
.window-title-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  pointer-events: none;
  opacity: 0.5;
}

/* ── Window Controls — Win98 raised square buttons ── */
.window-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
  -webkit-app-region: no-drag;
  position: relative;
  z-index: 2;
}

/* Win98 raised control button */
.window-btn {
  width: 16px;
  height: 14px;
  border-radius: 0;
  border: none;
  cursor: var(--cur-hand); --crt-cursor: hand;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--win98-face);
  color: var(--win98-dark);
  flex-shrink: 0;
  font-family: var(--font-system);
  box-shadow:
    inset -1px -1px 0 var(--win98-dark),
    inset 1px 1px 0 var(--win98-light),
    inset -2px -2px 0 var(--win98-shadow),
    inset 2px 2px 0 var(--win98-hilight);
}

/* 44px tap target via transparent pseudo */
.window-btn::before {
  content: '';
  position: absolute;
  inset: -14px;
}

/* Order: minimize, maximize, close */
.window-btn-minimize { order: 0; }
.window-btn-maximize { order: 1; }
.window-btn-close { order: 2; margin-left: 2px; }

.window-btn:active {
  box-shadow:
    inset 1px 1px 0 var(--win98-dark),
    inset -1px -1px 0 var(--win98-light),
    inset 2px 2px 0 var(--win98-shadow),
    inset -2px -2px 0 var(--win98-hilight);
}

.window-btn:focus-visible {
  outline: 2px solid var(--os-accent);
  outline-offset: 2px;
}

/* Glyphs always visible — black, bold */
.window-btn::after {
  font-size: 10px;
  font-weight: var(--weight-bold);
  line-height: 1;
  z-index: 1;
  color: var(--win98-dark);
}

.window-btn-close::after {
  content: '\00d7';
  font-size: 12px;
}

.window-btn-minimize::after {
  content: '\2212';
  font-size: 11px;
}

.window-btn-maximize::after {
  content: '\25a1';
  font-size: 8px;
}

/* Coarse pointers: bigger tap targets, still square */
@media (pointer: coarse) {
  .window-title-bar {
    height: 40px;
    padding: 0 10px;
  }

  .window-controls {
    gap: 4px;
  }

  .window-btn {
    width: 20px;
    height: 20px;
  }

  .window-btn::before {
    inset: -16px;
  }
}

/* Inactive window buttons — Win98 buttons don't fade */

/* Title text — Win98, bold black when focused */
.window-title {
  flex: 1;
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--win98-text);
  pointer-events: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.os-window:not(.focused) .window-title,
.os-window:not(.focused) .window-title-icon {
  color: var(--win98-shadow);
  opacity: 0.6;
}

/* ── Window Content ── */
.window-content {
  flex: 1;
  overflow: auto;
  position: relative;
}

/* ── Resize Handles ── */
.window-resize {
  position: absolute;
  z-index: 1;
}

.window-resize-e {
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: var(--cur-ew); --crt-cursor: ew;
}

.window-resize-s {
  bottom: -3px;
  left: 0;
  width: 100%;
  height: 6px;
  cursor: var(--cur-ns); --crt-cursor: ns;
}

.window-resize-se {
  bottom: -3px;
  right: -3px;
  width: 12px;
  height: 12px;
  cursor: var(--cur-nwse); --crt-cursor: nwse;
}

.window-resize-sw {
  bottom: -3px;
  left: -3px;
  width: 12px;
  height: 12px;
  cursor: var(--cur-nesw); --crt-cursor: nesw;
}

.window-resize-ne {
  top: -3px;
  right: -3px;
  width: 12px;
  height: 12px;
  cursor: var(--cur-nesw); --crt-cursor: nesw;
}

.window-resize-nw {
  top: -3px;
  left: -3px;
  width: 12px;
  height: 12px;
  cursor: var(--cur-nwse); --crt-cursor: nwse;
}

.window-resize-n {
  top: -3px;
  left: 0;
  width: 100%;
  height: 6px;
  cursor: var(--cur-ns); --crt-cursor: ns;
}

.window-resize-w {
  top: 0;
  left: -3px;
  width: 6px;
  height: 100%;
  cursor: var(--cur-ew); --crt-cursor: ew;
}

/* ── Snap Preview Overlay ── */
.snap-preview {
  position: fixed;
  z-index: var(--z-overlay);
  background: var(--os-accent-muted);
  border: 2px dashed var(--os-accent);
  border-radius: var(--radius-lg);
  pointer-events: none;
  transition: left 0.15s var(--ease-out),
    top 0.15s var(--ease-out),
    width 0.15s var(--ease-out),
    height 0.15s var(--ease-out);
}

.snap-preview[hidden] {
  display: none;
}

/* Case-study sharing: text control stays discoverable beside the window controls. */
.window-share {
  padding: 0 8px;
  min-height: 22px;
  color: #111;
  background: var(--win98-surface, #c0c0c0);
  border: 1px outset #eee;
  font: 12px var(--font-mono, monospace);
  cursor: var(--cur-hand);
  --crt-cursor: hand;
}
.window-share:focus-visible, .share-dialog :focus-visible { outline: 2px solid #1c4030; outline-offset: 2px; }
.share-dialog {
  width: min(430px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  box-sizing: border-box;
  overflow: auto;
  padding: 24px;
  color: #171717;
  background: #f4f0e5;
  border: 3px outset #eee;
  font: 14px/1.5 var(--font-mono, monospace);
}
.share-dialog::backdrop { background: rgb(0 0 0 / 55%); }
.share-dialog h2 { margin: 0 0 16px; font-size: 19px; }
.share-dialog label { display: block; margin: 12px 0 6px; }
.share-dialog input, .share-dialog select {
  width: 100%; box-sizing: border-box; padding: 10px;
  color: #111; background: #fff; border: 1px solid #777; font: inherit;
}
.share-note { font-size: 12px; margin: 8px 0; }
.share-status { min-height: 3em; margin: 12px 0; font-size: 12px; }
.share-actions { display: flex; gap: 12px; justify-content: flex-end; }
.share-actions button {
  min-height: 44px; padding: 8px 14px; color: #111;
  background: #c0c0c0; border: 2px outset #eee; font: inherit;
  cursor: var(--cur-hand); --crt-cursor: hand;
}
