/* files.css
 * Extracted from public/styles.css (Phase 0.3).
 * Lazy-loaded by public/modules/panels/nav.js on openPanel('files')
 * or relevant tab switch in switchMode().
 */

.file-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-sm);
  font-size: var(--md-sys-typescale-label-large-size);
  line-height: var(--md-sys-typescale-label-large-line);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  color: var(--md-sys-color-on-surface-variant);
  animation: messageIn var(--duration-fast) var(--ease-out);
}

.file-chip .file-icon {
  font-size: 15px;
  flex-shrink: 0;
}

.file-chip .file-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-chip .file-remove {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}

.file-chip .file-remove:hover {
  color: var(--md-sys-color-error);
  background: var(--md-sys-color-error-container);
}

.file-chip .file-remove:active {
  transform: scale(0.9);
}

.file-chip img.file-thumb {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: var(--md-sys-shape-corner-xs);
}

.msg-attachment .file-icon {
  font-size: var(--md-sys-typescale-body-medium-size);
}

#files-view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.files-tabs {
  display: flex;
  padding: 4px;
  margin: 8px 12px 0;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-md);
  gap: 4px;
}

.files-tab {
  flex: 1;
  min-width: 0;
  padding: 7px 4px;
  background: none;
  border: none;
  border-radius: var(--md-sys-shape-corner-sm);
  color: var(--md-sys-color-on-surface-variant);
  font-family: var(--md-sys-typescale-font-family);
  font-size: var(--md-sys-typescale-label-small-size);
  line-height: var(--md-sys-typescale-label-small-line);
  font-weight: var(--md-sys-typescale-label-small-weight);
  letter-spacing: var(--md-sys-typescale-label-small-tracking);
  cursor: pointer;
  transition: background var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  min-height: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  isolation: isolate;
}

.files-tab::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--md-sys-color-on-surface);
  opacity: 0;
  pointer-events: none;
  z-index: -1;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}

.files-tab svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}

@media (hover: hover) {
  .files-tab:hover::after { opacity: var(--md-sys-state-hover-opacity); }
  .files-tab:hover svg { opacity: 0.8; }
}

.files-tab:active::after { opacity: var(--md-sys-state-pressed-opacity); }

.files-tab.active {
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-high);
  box-shadow: var(--md-sys-elevation-1);
}

.files-tab.active svg {
  opacity: 1;
  color: var(--md-sys-color-primary);
}

.files-dropzone {
  padding: 24px 20px;
  margin: 12px;
  border: 1.5px dashed var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-md);
  text-align: center;
  transition: border-color var(--md-sys-motion-duration-medium1) var(--md-sys-motion-easing-emphasized-decel), background var(--md-sys-motion-duration-medium1) var(--md-sys-motion-easing-emphasized-decel);
  cursor: pointer;
  background: var(--md-sys-color-surface-container);
}

.files-dropzone:hover, .files-dropzone.dragover {
  border-color: var(--md-sys-color-primary);
  background: var(--accent-subtle);
}

.files-dropzone.dragover {
  border-style: solid;
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.files-dropzone-icon {
  margin-bottom: 8px;
  color: var(--md-sys-color-on-surface-variant);
  transition: color var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard),
              transform var(--md-sys-motion-duration-medium1) var(--md-sys-motion-easing-emphasized-decel);
}

.files-dropzone:hover .files-dropzone-icon,
.files-dropzone.dragover .files-dropzone-icon {
  color: var(--md-sys-color-primary);
  transform: translateY(-2px);
}

.files-dropzone-label {
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-large-size);
  line-height: var(--md-sys-typescale-body-large-line);
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
  margin-bottom: 12px;
}

.files-dropzone-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

/* M3 outlined button */
.files-dropzone-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  background: transparent;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-full);
  color: var(--md-sys-color-primary);
  font-family: var(--md-sys-typescale-font-family);
  font-size: var(--md-sys-typescale-label-large-size);
  line-height: var(--md-sys-typescale-label-large-line);
  font-weight: var(--md-sys-typescale-label-large-weight);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  transition: background var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  min-height: 40px;
  -webkit-tap-highlight-color: transparent;
}

.files-dropzone-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  pointer-events: none;
  z-index: -1;
}

.files-dropzone-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

@media (hover: hover) {
  .files-dropzone-btn:hover::after { opacity: var(--md-sys-state-hover-opacity); }
}

.files-dropzone-btn:active::after { opacity: var(--md-sys-state-pressed-opacity); }

.files-upload-progress {
  padding: 10px 16px;
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height var(--md-sys-motion-duration-medium1) var(--md-sys-motion-easing-emphasized-decel), opacity var(--md-sys-motion-duration-medium1) var(--md-sys-motion-easing-emphasized-decel), padding var(--md-sys-motion-duration-medium1) var(--md-sys-motion-easing-emphasized-decel);
}

.files-upload-progress.active {
  max-height: 50px;
  opacity: 1;
  padding: 10px 16px;
}

.files-upload-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.files-progress-bar {
  height: 3px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

.files-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 2px;
  transition: width var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized-decel);
}

.files-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: none;
}

.files-list::-webkit-scrollbar {
  display: none;
}

.files-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-large-size);
  line-height: var(--md-sys-typescale-body-large-line);
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
  gap: 8px;
}

.files-empty-icon {
  font-size: var(--md-sys-typescale-headline-large-size);
  margin-bottom: 4px;
  opacity: 0.4;
  color: var(--md-sys-color-on-surface-variant);
}

.files-empty-hint {
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
  opacity: 0.7;
}

.files-clear-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--md-sys-color-outline);
}

.files-count {
  font-size: var(--md-sys-typescale-label-medium-size);
  line-height: var(--md-sys-typescale-label-medium-line);
  font-weight: var(--md-sys-typescale-label-medium-weight);
  letter-spacing: var(--md-sys-typescale-label-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
}

/* M3 outlined chip */
.files-clear-btn {
  font-family: var(--md-sys-typescale-font-family);
  font-size: var(--md-sys-typescale-label-medium-size);
  line-height: var(--md-sys-typescale-label-medium-line);
  font-weight: var(--md-sys-typescale-label-medium-weight);
  letter-spacing: var(--md-sys-typescale-label-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
  background: none;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-sm);
  padding: 6px 12px;
  cursor: pointer;
  min-height: 32px;
  transition: color var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard),
              border-color var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  text-transform: uppercase;
}

.files-clear-btn:hover {
  color: var(--md-sys-color-error);
  border-color: var(--md-sys-color-error);
}

/* M3 list-item with state-layer overlay.
   TODO(m3-markup): migrate to .m3-list-item primitive class in v1.2.0. */
.file-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  cursor: pointer;
  position: relative;
  isolation: isolate;
  transition: background var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  min-height: 56px;
  -webkit-tap-highlight-color: transparent;
}

.file-row::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--md-sys-color-on-surface);
  opacity: 0;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  pointer-events: none;
  z-index: -1;
}

.file-row:last-child {
  border-bottom: none;
}

@media (hover: hover) {
  .file-row:hover::after { opacity: var(--md-sys-state-hover-opacity); }
}

.file-row:active::after { opacity: var(--md-sys-state-pressed-opacity); }

.file-row-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}

.file-row-icon svg {
  width: 18px;
  height: 18px;
}

.file-row-icon.file-icon-image { background: rgba(66, 188, 221, 0.1); color: #42bcdd; }

.file-row-icon.file-icon-pdf { background: rgba(224, 96, 96, 0.1); color: #e06060; }

.file-row-icon.file-icon-doc { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }

.file-row-icon.file-icon-sheet { background: rgba(92, 184, 122, 0.1); color: #5cb87a; }

.file-row-icon.file-icon-code { background: rgba(168, 216, 216, 0.1); color: #a8d8d8; }

.file-row-icon.file-icon-video { background: rgba(200, 120, 220, 0.1); color: #c878dc; }

.file-row-icon.file-icon-audio { background: rgba(255, 180, 100, 0.1); color: #ffb464; }

.file-row-icon.file-icon-archive { background: rgba(180, 160, 120, 0.1); color: #b4a078; }

.file-row-icon.file-icon-folder { background: rgba(245, 158, 11, 0.1); color: #f59e0b; }

.file-row-info {
  flex: 1;
  min-width: 0;
}

.file-row-name {
  font-size: var(--md-sys-typescale-body-large-size);
  line-height: var(--md-sys-typescale-body-large-line);
  font-weight: 600;
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
  color: var(--md-sys-color-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-row-meta {
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 2px;
}

.file-row-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--duration-fast);
}

.file-row:hover .file-row-actions {
  opacity: 1;
}

/* M3 icon button (state-layer overlay) */
.file-row-actions button {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  transition: background var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  -webkit-tap-highlight-color: transparent;
}

.file-row-actions button::after {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  pointer-events: none;
  z-index: -1;
}

@media (hover: hover) {
  .file-row-actions button:hover { color: var(--md-sys-color-on-surface); }
  .file-row-actions button:hover::after { opacity: var(--md-sys-state-hover-opacity); }
}

.file-row-actions button:active::after { opacity: var(--md-sys-state-pressed-opacity); }

.file-row-actions button.file-delete-btn:hover { color: var(--md-sys-color-error); }

#file-preview-modal .preview-body img,
#file-preview-modal .preview-body video {
  animation: previewFadeIn var(--duration-normal) var(--ease-out);
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--md-sys-color-surface-container);
  border-bottom: 1px solid var(--md-sys-color-outline);
  min-height: 56px;
  gap: 12px;
}

@supports (padding-top: env(safe-area-inset-top)) {
  .preview-header {
    padding-top: calc(12px + env(safe-area-inset-top));
  }
}

.preview-title {
  font-size: var(--md-sys-typescale-title-medium-size);
  line-height: var(--md-sys-typescale-title-medium-line);
  font-weight: var(--md-sys-typescale-title-medium-weight);
  letter-spacing: var(--md-sys-typescale-title-medium-tracking);
  color: var(--md-sys-color-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.preview-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* M3 outlined button */
.preview-actions button {
  padding: 10px 24px;
  background: transparent;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-full);
  color: var(--md-sys-color-primary);
  font-family: var(--md-sys-typescale-font-family);
  font-size: var(--md-sys-typescale-label-large-size);
  line-height: var(--md-sys-typescale-label-large-line);
  font-weight: var(--md-sys-typescale-label-large-weight);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  cursor: pointer;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  transition: background var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  -webkit-tap-highlight-color: transparent;
}

.preview-actions button::after {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  pointer-events: none;
  z-index: -1;
}

@media (hover: hover) {
  .preview-actions button:hover::after { opacity: var(--md-sys-state-hover-opacity); }
}

.preview-actions button:active::after { opacity: var(--md-sys-state-pressed-opacity); }

.preview-actions button svg {
  width: 14px;
  height: 14px;
}

.preview-close-btn {
  background: transparent !important;
  border: none !important;
  width: 40px;
  padding: 8px !important;
  justify-content: center;
}

.preview-close-btn:hover::after { opacity: var(--md-sys-state-hover-opacity); }

@media (pointer: coarse) {
  .preview-close-btn { width: 48px; min-height: 48px; }
}

.preview-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 16px;
  touch-action: none;
}

.preview-body img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--md-sys-shape-corner-xs);
  touch-action: none;
}

.preview-body video {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--md-sys-shape-corner-xs);
}

.preview-body iframe {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: var(--md-sys-shape-corner-xs);
}

.preview-body .preview-text {
  width: 100%;
  max-width: 800px;
  background: var(--md-sys-color-surface-container);
  padding: 20px;
  border-radius: var(--md-sys-shape-corner-md);
  font-family: var(--font-mono);
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: 1.6;
  color: var(--md-sys-color-on-surface);
  white-space: pre-wrap;
  overflow-y: auto;
  align-self: flex-start;
  border: 1px solid var(--md-sys-color-outline);
}

.files-skeleton {
  padding: 0;
}

.files-skeleton-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  min-height: 56px;
}

.files-skeleton-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--md-sys-color-surface-container-high);
  animation: skeletonPulse 1.5s ease-in-out infinite;
}

.files-skeleton-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.files-skeleton-line {
  height: 12px;
  border-radius: var(--md-sys-shape-corner-xs);
  background: var(--md-sys-color-surface-container-high);
  animation: skeletonPulse 1.5s ease-in-out infinite;
}

.files-skeleton-line:first-child { width: 60%; }

.files-skeleton-line:last-child { width: 35%; height: 10px; }

@media (max-width: 600px) {
  /* Compact upload zone on mobile */
  .files-dropzone {
    border: 1.5px dashed var(--md-sys-color-outline);
    padding: 16px 12px;
    margin: 8px 12px;
  }
  .files-dropzone-icon { display: none; }
  .files-dropzone-label { display: none; }
  .files-dropzone-buttons { width: 100%; }
  .files-dropzone-btn { flex: 1; justify-content: center; }

  .message { max-width: 100%; }
  .message.user { max-width: 85%; }
  .message.assistant { max-width: 100%; }
  #chat { padding: 16px 12px; }
  #header { padding: 6px 8px; }
  #input-area { padding: 8px 12px 10px; }
  #file-preview { padding-left: 12px; padding-right: 12px; }
  #empty-state .greeting {
    font-size: var(--md-sys-typescale-title-large-size);
    line-height: var(--md-sys-typescale-title-large-line);
  }
  #empty-state .empty-greet-zone { height: 120px; }

  /* Always show interactive elements (no hover on touch) */
  .code-copy-btn { opacity: 1; }
  .msg-copy-btn { opacity: 1; }
  .file-row-actions { opacity: 1; }

  /* Larger touch targets for tool cards */
  .tool-card .tool-header {
    min-height: 48px;
    font-size: var(--md-sys-typescale-body-large-size);
    line-height: var(--md-sys-typescale-body-large-line);
    padding: 8px 0;
  }
  .tool-card .tool-header .arrow { font-size: var(--md-sys-typescale-body-medium-size); }
  .tool-card .tool-summary {
    font-size: var(--md-sys-typescale-body-medium-size);
    line-height: var(--md-sys-typescale-body-medium-line);
  }
  .tool-card .tool-detail {
    font-size: var(--md-sys-typescale-body-medium-size);
    line-height: var(--md-sys-typescale-body-medium-line);
    max-height: 200px;
  }
  .tool-group-header {
    min-height: 48px;
    font-size: var(--md-sys-typescale-body-large-size);
    line-height: var(--md-sys-typescale-body-large-line);
  }

  /* Smaller textarea on mobile with keyboard */
  #input-area textarea { max-height: 100px; }

  /* Search buttons bigger */
  #search-bar button { width: 48px; height: 48px; min-width: 48px; }

  /* Floor: never below labelMedium (12/16) for body-equivalent metadata. */
  .message .time {
    font-size: var(--md-sys-typescale-label-medium-size);
    line-height: var(--md-sys-typescale-label-medium-line);
  }
  #history-list .m3-list-item__support {
    font-size: var(--md-sys-typescale-label-medium-size);
    line-height: var(--md-sys-typescale-label-medium-line);
  }
  .file-row-meta {
    font-size: var(--md-sys-typescale-label-medium-size);
    line-height: var(--md-sys-typescale-label-medium-line);
  }

  /* Tool file action buttons -- coarse touch target */
  .tool-file-actions button { padding: 10px 16px; min-height: 48px; }

  /* Code blocks */
  .bubble pre {
    font-size: var(--md-sys-typescale-body-medium-size);
    line-height: var(--md-sys-typescale-body-medium-line);
    padding: 12px;
  }
  .code-copy-btn {
    padding: 8px 12px;
    font-size: var(--md-sys-typescale-label-medium-size);
    min-height: 48px;
  }
}

#app.more-mode #more-view #files-view {
  display: none;
}

@media (pointer: coarse) {
  .files-dropzone-btn { min-height: 48px; }
  .files-clear-btn { min-height: 48px; }
  .file-row-actions button { width: 48px; height: 48px; }
  .preview-actions button { min-height: 48px; }
}
