/* blob-bridge - Application styling */

/* MARK: View Transitions */
/* Native browser page transitions via View Transitions API */
::view-transition-old(root) {
  animation: page-fade-out 0.2s ease-out forwards;
}

::view-transition-new(root) {
  animation: page-fade-in 0.2s ease-in forwards;
}

@keyframes page-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes page-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none;
  }
}

/* MARK: Design Tokens */
/* Light theme tuned for file browsing */
:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --bg-subtle: #eef1f6;
  --panel: #ffffff;
  --text: #1a2332;
  --muted: #5c6b80;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --border: #d8dee9;
  --border-strong: #c4cdd9;
  --danger: #dc2626;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --folder: #d97706;
  --row-hover: #f8fafc;
  --path-link-hover: color-mix(in srgb, var(--border-strong) 55%, transparent);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

/* MARK: Base Styles */
/* Core element defaults */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: rgba(37, 99, 235, 0.18);
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  text-decoration: underline;
}

/* MARK: Page Layout */
/* Shell, container, and card structure */
.app-shell {
  width: min(1120px, 94vw);
  margin: 0 auto;
  padding: 1rem 0 2rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
  font-weight: 650;
}

.card p {
  margin: 0 0 0.85rem;
  color: var(--muted);
}

.card p:last-child {
  margin-bottom: 0;
}

/* MARK: Site Header */
/* Customer logo and session controls; header hidden until authenticated */
.app-shell:not(.is-authenticated) .site-header {
  display: none;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0 0.85rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}

.customer-logo {
  display: block;
  max-height: 2.5rem;
  width: auto;
  max-width: min(12rem, 34vw);
  object-fit: contain;
  object-position: left center;
}

.customer-logo[hidden] {
  display: none;
}

.brand.has-customer-logo .brand-text h1 {
  font-size: clamp(1.1rem, 3vw, 1.35rem);
}

.brand-text {
  min-width: 0;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(1.25rem, 4vw, 1.6rem);
  line-height: 1.2;
  font-weight: 700;
}

.site-header p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.header-actions[hidden] {
  display: none;
}

.user-badge {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 0.35rem 0.65rem;
  background: var(--bg-subtle);
  border-radius: 999px;
  border: 1px solid var(--border);
}

/* MARK: Test Banner */
/* Visible when running in local test mode */
.test-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.85rem;
  background: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid #fcd34d;
  border-radius: 8px;
  font-size: 0.88rem;
}

.test-banner[hidden] {
  display: none;
}

.test-banner strong {
  font-weight: 700;
}

/* MARK: Buttons */
/* Primary, secondary, and inline actions */
button {
  font: inherit;
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary,
.btn-secondary,
.upload-btn,
.btn-inline {
  display: inline-block;
  border-radius: 8px;
  font-weight: 600;
}

.btn-primary,
.upload-btn {
  border: 0;
  background: var(--accent);
  color: #ffffff;
  padding: 0.5rem 0.9rem;
  font-size: 0.92rem;
  transition: background 0.15s ease;
  text-decoration: none;
}

.btn-primary:hover:not(:disabled),
.upload-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  font-size: 0.92rem;
  transition: background 0.15s ease;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-subtle);
}

.btn-inline {
  padding: 0.28rem 0.55rem;
  font-size: 0.8rem;
  margin-right: 0.3rem;
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--border);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-inline:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.btn-inline.btn-danger {
  color: var(--danger);
}

.btn-inline.btn-danger:hover:not(:disabled) {
  background: #fef2f2;
  border-color: #fca5a5;
}

.btn-primary:focus-visible,
.upload-btn:focus-visible,
.btn-secondary:focus-visible,
.btn-inline:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* MARK: Login View */
/* Centered sign-in card shown before authentication */
main.login-active {
  align-items: center;
  justify-content: center;
}

.login-card {
  width: min(420px, 100%);
  margin: 0 auto;
  padding: 2rem 1.75rem;
  text-align: center;
}

.login-card h2 {
  margin: 0;
  font-size: clamp(1.25rem, 4vw, 1.6rem);
  line-height: 1.2;
  font-weight: 700;
}

.login-tagline {
  margin: 0.2rem 0 1.35rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.btn-microsoft {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  min-width: min(100%, 16.5rem);
  min-height: 2.55rem;
  margin-top: 0;
  padding: 0.55rem 1rem;
  border: 1px solid #8c8c8c;
  border-radius: 4px;
  background: #ffffff;
  color: #5e5e5e;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-microsoft:hover {
  background: #f3f3f3;
  border-color: #707070;
}

.btn-microsoft:focus-visible {
  outline: 2px solid #0078d4;
  outline-offset: 2px;
}

.microsoft-logo {
  width: 1.15rem;
  height: 1.15rem;
  flex-shrink: 0;
}

.auth-error {
  margin: 1rem 0 0;
  color: var(--danger);
  font-size: 0.92rem;
  text-align: center;
}

/* MARK: Storage Info */
/* Target account summary in the explorer chrome bar */
.explorer-chrome {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem 1.25rem;
  padding: 0.9rem 1.15rem;
  background: linear-gradient(180deg, var(--bg-subtle) 0%, var(--panel) 100%);
  border-bottom: 1px solid var(--border);
}

.explorer-chrome-main {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-width: 0;
}

.explorer-location {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.explorer-location-label {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.explorer-current-path {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.35;
  color: var(--text);
  word-break: break-word;
}

.explorer-path-link {
  display: inline-block;
  padding: 0.08rem 0.28rem;
  margin: 0 -0.08rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  font: inherit;
  vertical-align: baseline;
  transition: background-color 0.12s ease;
}

.explorer-path-link:hover:not(:disabled) {
  background: var(--path-link-hover);
}

.explorer-path-link:focus-visible {
  outline: 1px solid var(--border-strong);
  outline-offset: 2px;
}

.explorer-target {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
}

.explorer-target[hidden] {
  display: none;
}

.explorer-target-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.explorer-target-key {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.explorer-target-divider {
  width: 1px;
  height: 1.1rem;
  background: var(--border-strong);
}

.explorer-target code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--panel);
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.explorer-actions {
  display: flex;
  flex-shrink: 0;
  gap: 0.45rem;
  align-items: center;
  padding-top: 0.1rem;
}

/* MARK: Blob Browser */
/* Tree sidebar, file table, and explorer row styling */
.browser-panel {
  padding: 0;
  overflow: hidden;
}

.explorer-layout {
  display: grid;
  grid-template-columns: minmax(11rem, 15rem) minmax(0, 1fr);
  min-height: 22rem;
}

.folder-tree-panel {
  border-right: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-heading {
  padding: 0.6rem 0.9rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.folder-tree-panel .panel-heading {
  background: transparent;
}

.folder-tree {
  list-style: none;
  margin: 0;
  padding: 0.45rem 0;
  overflow: auto;
  flex: 1;
}

.folder-tree[hidden] {
  display: none;
}

.tree-group {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-node {
  margin: 0;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.28rem 0.55rem 0.28rem calc(0.55rem + var(--tree-depth, 0) * 0.85rem);
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  margin: 0 0.25rem;
}

.tree-row:hover {
  background: var(--row-hover);
}

.tree-row.is-selected {
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-weight: 600;
}

.tree-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  flex-shrink: 0;
}

.tree-toggle:not(:disabled):hover {
  color: var(--text);
  background: transparent;
}

.tree-toggle:disabled,
.tree-toggle[hidden] {
  visibility: hidden;
}

.tree-toggle .explorer-icon svg {
  width: 0.75rem;
  height: 0.75rem;
  transition: transform 0.15s ease;
}

.tree-toggle .explorer-icon.is-expanded svg {
  transform: rotate(90deg);
}

.file-list-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}

.file-list-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.browser-status {
  padding: 2rem 1.25rem;
  color: var(--muted);
  text-align: center;
}

.blob-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.blob-table th,
.blob-table td {
  padding: 0.65rem 1rem;
  text-align: left;
  border-top: 1px solid var(--border);
}

.blob-table tbody tr:hover {
  background: var(--row-hover);
}

.blob-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-subtle);
  border-top: 0;
}

.explorer-row {
  cursor: default;
}

.explorer-row.is-selected {
  background: var(--accent-soft);
}

.explorer-row-folder {
  cursor: pointer;
}

.explorer-name {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.explorer-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  flex-shrink: 0;
}

.explorer-icon svg {
  width: 1.15rem;
  height: 1.15rem;
}

.explorer-icon.icon-folder {
  color: var(--folder);
}

.explorer-icon.icon-file {
  color: var(--muted);
}

.explorer-icon.icon-filePdf {
  color: #dc2626;
}

.explorer-icon.icon-fileImage {
  color: #2563eb;
}

.explorer-icon.icon-fileVideo {
  color: #7c3aed;
}

.explorer-icon.icon-fileAudio {
  color: #db2777;
}

.explorer-icon.icon-fileArchive {
  color: #9333ea;
}

.explorer-icon.icon-fileSpreadsheet {
  color: #059669;
}

.explorer-icon.icon-fileDocument {
  color: #0284c7;
}

.explorer-icon.icon-filePresentation {
  color: #ea580c;
}

.explorer-icon.icon-fileCode {
  color: #d97706;
}

.explorer-icon.icon-fileData {
  color: #0d9488;
}

.explorer-icon.icon-fileText {
  color: #16a34a;
}

.explorer-icon.icon-fileWeb {
  color: #0891b2;
}

.explorer-icon.icon-fileFont {
  color: #64748b;
}

.explorer-icon.icon-fileBinary {
  color: #475569;
}

.actions-cell {
  white-space: nowrap;
}

/* MARK: File Preview */
/* Modal overlay and inline viewers for common blob types */
body.preview-open {
  overflow: hidden;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

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

.preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.preview-dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(960px, 96vw);
  max-height: min(88vh, 900px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
  overflow: hidden;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
}

.preview-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.35;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-header-actions {
  display: flex;
  flex-shrink: 0;
  gap: 0.45rem;
}

.preview-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--panel);
}

.preview-status {
  margin: 0;
  padding: 2.5rem 1.25rem;
  text-align: center;
  color: var(--muted);
}

.preview-content {
  min-height: 12rem;
}

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

.preview-text {
  margin: 0;
  padding: 1rem 1.15rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.84rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.preview-image {
  display: block;
  max-width: 100%;
  max-height: min(72vh, 780px);
  margin: 0 auto;
  padding: 1rem;
  object-fit: contain;
}

.preview-video {
  display: block;
  width: 100%;
  max-height: min(72vh, 780px);
  background: #0f172a;
}

.preview-audio {
  display: block;
  width: calc(100% - 2rem);
  margin: 2rem 1rem;
}

.preview-pdf {
  display: block;
  width: 100%;
  height: min(72vh, 780px);
  border: 0;
  background: var(--bg-subtle);
}

/* MARK: Auth Overlay */
/* Full-screen loading state while session is checked */
.auth-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(244, 246, 249, 0.88);
  z-index: 100;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.auth-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.auth-overlay[hidden] {
  display: none;
}

.auth-overlay p {
  color: var(--muted);
}

/* MARK: Site Footer */
/* Centered co-branding and build credit */
.site-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.45rem;
  padding-top: 1.25rem;
  margin-top: auto;
}

.powered-by {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  opacity: 0.75;
}

.powered-by-label {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.ait-logo {
  display: block;
  height: 1.1rem;
  width: auto;
  max-width: 6.75rem;
  object-fit: contain;
}

.footer-note {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

@media (max-width: 640px) {
  .explorer-chrome {
    flex-direction: column;
    align-items: stretch;
  }

  .explorer-actions {
    width: 100%;
    justify-content: flex-end;
    padding-top: 0;
  }

  .explorer-target-divider {
    display: none;
  }

  .explorer-layout {
    grid-template-columns: 1fr;
  }

  .folder-tree-panel {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    max-height: 10rem;
  }

  .blob-table th:nth-child(3),
  .blob-table td:nth-child(3) {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn-primary,
  .upload-btn,
  .btn-secondary,
  .btn-inline,
  .explorer-path-link {
    transition: none;
  }
}
