/* Coder App - Monaco-powered Code Editor */
/* Terracotta dark theme matching the Her aesthetic */

:host {
  position: fixed;
  inset: 0;
  z-index: 950;
  display: flex;
  flex-direction: column;
  background: var(--color-red, oklch(0.55 0.155 25));
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
  dynamic-range-limit: no-limit;
}

:host([open]) {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid oklch(1 0 0 / 0.12);
  flex-shrink: 0;
  background: oklch(0 0 0 / 0.15);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 120px;
}

.header-left {
  justify-content: flex-start;
}

.header-right {
  justify-content: flex-end;
}

/* Back and Close buttons - elegant style */
.back-btn,
.close-btn {
  background: transparent;
  border: 1px solid oklch(1 0 0 / 0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.15s ease;
  width: 2.25rem;
  height: 2.25rem;
}

.back-btn:hover,
.close-btn:hover {
  border-color: oklch(1 0 0 / 0.7);
  background: oklch(1 0 0 / 0.1);
  transform: scale(1.02);
}

.back-btn:active,
.close-btn:active {
  transform: scale(0.96);
  transition: transform 0.08s ease;
}

.back-btn svg,
.close-btn svg {
  width: 1rem;
  height: 1rem;
  stroke: oklch(1 0 0 / 0.6);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  transition: stroke 0.15s ease;
}

.back-btn:hover svg,
.close-btn:hover svg {
  stroke: oklch(1 0 0 / 0.95);
}

/* Title area */
.title-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.title {
  font-family: var(--font-body, 'Cormorant Garamond', serif);
  font-size: 0.95rem;
  font-style: italic;
  font-weight: 400;
  color: oklch(1 0 0 / 0.85);
  letter-spacing: 0.06em;
}

.title.dirty::after {
  content: ' •';
  color: oklch(1 0 0 / 0.6);
}

.status {
  font-family: var(--font-body, 'Cormorant Garamond', serif);
  font-size: 0.7rem;
  font-style: italic;
  color: oklch(1 0 0 / 0.5);
  letter-spacing: 0.06em;
  min-height: 1em;
}

/* Save button - elegant pill style */
.save-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid oklch(1 0 0 / 0.35);
  background: transparent;
  border-radius: var(--radius-lg, 30px);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font-body, 'Cormorant Garamond', serif);
  font-size: 0.8rem;
  font-style: italic;
  color: oklch(1 0 0 / 0.6);
  letter-spacing: 0.08em;
}

.save-btn:hover {
  border-color: oklch(1 0 0 / 0.7);
  background: oklch(1 0 0 / 0.1);
  color: oklch(1 0 0 / 0.95);
  transform: scale(1.02);
}

.save-btn:active {
  transform: scale(0.96);
  transition: transform 0.08s ease;
}

:host([dirty]) .save-btn {
  border-color: oklch(1 0 0 / 0.7);
  color: oklch(1 0 0 / 0.95);
}

.save-btn svg {
  width: 0.9rem;
  height: 0.9rem;
  stroke: currentColor;
  stroke-width: 1.25;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Editor Container */
.editor-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #1A1210;
  min-height: 0; /* Important for flex child to shrink properly */
}

.editor-wrapper {
  position: absolute;
  inset: 0;
}

/* Loading Overlay */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: #1A1210;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 10;
}

.loading-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.loading-spinner {
  width: 2rem;
  height: 2rem;
  border: 2px solid oklch(1 0 0 / 0.1);
  border-top-color: oklch(1 0 0 / 0.5);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  font-family: var(--font-body, 'Cormorant Garamond', serif);
  font-size: 0.85rem;
  font-style: italic;
  color: oklch(1 0 0 / 0.5);
  letter-spacing: 0.06em;
}

/* Footer */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid oklch(1 0 0 / 0.12);
  flex-shrink: 0;
  background: oklch(0 0 0 / 0.15);
}

.language-info,
.cursor-position {
  font-family: var(--font-body, 'Cormorant Garamond', serif);
  font-size: 0.7rem;
  font-style: italic;
  color: oklch(1 0 0 / 0.4);
  letter-spacing: 0.06em;
}

.language-info {
  padding: 0.25rem 0.6rem;
  background: oklch(1 0 0 / 0.06);
  border-radius: 4px;
}

/* Monaco Editor Overrides */
/* These apply to the Monaco editor inside the shadow DOM */
.editor-wrapper :global(.monaco-editor) {
  --vscode-editor-background: #1A1210;
}

.editor-wrapper :global(.monaco-editor .margin) {
  background: #1A1210;
}

.editor-wrapper :global(.monaco-editor .monaco-scrollable-element > .scrollbar) {
  background: transparent;
}

/* HDR Enhancement */
@media (dynamic-range: high) {
  .back-btn:hover,
  .close-btn:hover,
  .save-btn:hover {
    border-color: var(--hdr-white-bright, oklch(1.15 0 0));
  }

  .title {
    color: var(--hdr-white-bright, oklch(1.15 0 0));
  }
}

/* Mobile adjustments */
@media (max-width: 600px) {
  .header {
    padding: 1rem;
  }
  
  .save-btn span {
    display: none;
  }
  
  .save-btn {
    padding: 0.5rem;
    border-radius: 50%;
    width: 2.25rem;
    height: 2.25rem;
  }
  
  .footer {
    padding: 0.6rem 1rem;
  }
  
  .language-info,
  .cursor-position {
    font-size: 0.65rem;
  }
}

/* Safe area insets for iOS */
@supports (padding: env(safe-area-inset-bottom)) {
  .footer {
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
  }
}
