/* ============================================================
   Aetherium Drive — web client shell.
   A faithful Material 3 copy of the Aetherium Drive Android app
   (values/colors.xml + values-night/colors.xml). Loaded after
   main.css / aetherium-apps.css so the app look wins.
   ============================================================ */

:root {
  --m3-primary: #505B92;
  --m3-on-primary: #FFFFFF;
  --m3-primary-container: #DEE1FF;
  --m3-on-primary-container: #384379;
  --m3-secondary: #4D5C92;
  --m3-secondary-container: #DCE1FF;
  --m3-on-secondary-container: #354479;
  --m3-tertiary: #29638A;
  --m3-tertiary-container: #CBE6FF;
  --m3-on-tertiary-container: #014B71;
  --m3-error: #904A43;
  --m3-on-error: #FFFFFF;
  --m3-error-container: #FFDAD6;
  --m3-on-error-container: #73332D;
  --m3-background: #FBF8FF;
  --m3-on-background: #1B1B21;
  --m3-surface: #FAF8FF;
  --m3-on-surface: #1A1B21;
  --m3-surface-variant: #E2E1EC;
  --m3-on-surface-variant: #45464F;
  --m3-outline: #767680;
  --m3-outline-variant: #C6C5D0;
  --m3-sc-lowest: #FFFFFF;
  --m3-sc-low: #F4F3FA;
  --m3-sc: #EEEDF4;
  --m3-sc-high: #E8E7EF;
  --m3-sc-highest: #E3E2E9;
  --m3-inverse-surface: #2F3036;
  --m3-inverse-on-surface: #F1F0F7;
  --m3-shadow: 0 1px 3px rgba(0,0,0,.20), 0 1px 2px rgba(0,0,0,.12);
  --m3-shadow-lg: 0 8px 24px rgba(0,0,0,.28);
  --m3-radius: 12px;
  --m3-radius-lg: 16px;
  --m3-radius-xl: 28px;
  --m3-font: 'Aetherium Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --m3-mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}

html[data-theme="dark"],
html.dark {
  --m3-primary: #B9C3FF;
  --m3-on-primary: #212C61;
  --m3-primary-container: #384379;
  --m3-on-primary-container: #DEE1FF;
  --m3-secondary: #B6C4FF;
  --m3-secondary-container: #354479;
  --m3-on-secondary-container: #DCE1FF;
  --m3-tertiary: #97CCF9;
  --m3-tertiary-container: #014B71;
  --m3-on-tertiary-container: #CBE6FF;
  --m3-error: #FFB4AB;
  --m3-on-error: #561E19;
  --m3-error-container: #73332D;
  --m3-on-error-container: #FFDAD6;
  --m3-background: #121318;
  --m3-on-background: #E3E1E9;
  --m3-surface: #121318;
  --m3-on-surface: #E3E2E9;
  --m3-surface-variant: #45464F;
  --m3-on-surface-variant: #C6C5D0;
  --m3-outline: #90909A;
  --m3-outline-variant: #45464F;
  --m3-sc-lowest: #0D0E13;
  --m3-sc-low: #1A1B21;
  --m3-sc: #1E1F25;
  --m3-sc-high: #292A2F;
  --m3-sc-highest: #33343A;
  --m3-inverse-surface: #E3E2E9;
  --m3-inverse-on-surface: #2F3036;
  --m3-shadow: 0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
  --m3-shadow-lg: 0 12px 32px rgba(0,0,0,.6);
}

html, body { height: 100%; }

html.drive, html.drive body {
  background: var(--m3-surface) !important;
  color: var(--m3-on-surface) !important;
  font-family: var(--m3-font);
  -webkit-font-smoothing: antialiased;
}

html.drive body { margin: 0; overflow-x: hidden; }

.drive * { box-sizing: border-box; }

/* The `hidden` attribute must always win over our flex/grid display rules. */
[hidden] { display: none !important; }

/* Hide the marketing chrome if a legacy header/footer is present. */
.drive .site-header, .drive .site-footer, .drive .site-disclaimer, .drive .bg-grid { display: none !important; }
.drive body::after, html.drive body::after { display: none !important; content: none !important; }

/* ---------- Top app bar ---------- */
.drive-appbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 64px;
  padding: 0 4px 0 4px;
  background: var(--m3-sc-low);
  color: var(--m3-on-surface);
  transition: box-shadow .2s ease, background .2s ease;
}
.drive-appbar.scrolled { box-shadow: var(--m3-shadow); background: var(--m3-sc); }
.drive-appbar-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0 4px;
  font-size: 22px;
  font-weight: 500;
  line-height: 28px;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drive-appbar-actions { display: flex; align-items: center; gap: 2px; }

.m3-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--m3-on-surface-variant);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.m3-icon-btn:hover { background: color-mix(in srgb, var(--m3-on-surface) 8%, transparent); }
.m3-icon-btn:active { background: color-mix(in srgb, var(--m3-on-surface) 14%, transparent); }
.m3-icon-btn:focus-visible { outline: 2px solid var(--m3-primary); outline-offset: 2px; }

/* ---------- Search bar ---------- */
.drive-searchbar {
  position: sticky;
  top: 64px;
  z-index: 39;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--m3-sc-low);
  border-bottom: 1px solid var(--m3-outline-variant);
}
.drive-searchbar.open { display: flex; }
.drive-searchbar input {
  flex: 1 1 auto;
  height: 44px;
  padding: 0 16px;
  border: 1px solid var(--m3-outline-variant);
  border-radius: 22px;
  background: var(--m3-sc-highest);
  color: var(--m3-on-surface);
  font: inherit;
  font-size: 15px;
}
.drive-searchbar input::placeholder { color: var(--m3-on-surface-variant); }
.drive-searchbar input:focus { outline: 2px solid var(--m3-primary); outline-offset: -1px; }

/* ---------- Navigation drawer ---------- */
.drive-scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0,0,0,.42);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s ease;
}
.drive-scrim.open { opacity: 1; visibility: visible; }

.drive-drawer {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 61;
  display: flex;
  flex-direction: column;
  width: min(320px, 86vw);
  height: 100dvh;
  background: var(--m3-sc-low);
  color: var(--m3-on-surface);
  border-top-right-radius: var(--m3-radius-lg);
  border-bottom-right-radius: var(--m3-radius-lg);
  box-shadow: var(--m3-shadow-lg);
  transform: translateX(-102%);
  transition: transform .24s cubic-bezier(.2,0,0,1);
  overflow: hidden;
}
.drive-drawer.open { transform: translateX(0); }

.drive-drawer-header {
  padding: 22px 20px 16px;
  border-bottom: 1px solid var(--m3-outline-variant);
}
.drive-drawer-brand {
  font-size: 20px;
  font-weight: 700;
  color: var(--m3-primary);
  letter-spacing: .2px;
}
.drive-drawer-name {
  margin-top: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--m3-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drive-drawer-quota {
  display: inline-block;
  margin-top: 10px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--m3-secondary-container);
  color: var(--m3-on-secondary-container);
  font-size: 12px;
  font-weight: 600;
}

.drive-drawer-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 12px 24px;
}
.drive-drawer-label {
  padding: 16px 12px 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--m3-on-surface-variant);
}
.cloud-nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  margin: 2px 0;
  border: 0;
  border-radius: var(--m3-radius-xl);
  background: transparent;
  color: var(--m3-on-surface-variant);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.cloud-nav-item .ic { flex: 0 0 22px; font-size: 18px; text-align: center; }
.cloud-nav-item .nm { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cloud-nav-item:hover { background: color-mix(in srgb, var(--m3-on-surface) 8%, transparent); }
.cloud-nav-item.active {
  background: var(--m3-secondary-container);
  color: var(--m3-on-secondary-container);
}
.drive-drawer-divider {
  height: 1px;
  margin: 10px 12px;
  background: var(--m3-outline-variant);
}

/* ---------- Main content ---------- */
.drive-main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 8px 12px 120px;
}
.drive-crumbbar {
  position: sticky;
  top: 64px;
  z-index: 20;
  margin: 0 -12px 6px;
  padding: 6px 12px;
  background: var(--m3-surface);
}
.drive-crumbs {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  white-space: nowrap;
  padding-bottom: 2px;
}
.drive-crumbs::-webkit-scrollbar { display: none; }
.drive-crumb {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--m3-on-surface-variant);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.drive-crumb:hover { background: color-mix(in srgb, var(--m3-on-surface) 8%, transparent); }
.drive-crumb.current { color: var(--m3-primary); font-weight: 700; }
.drive-crumb-sep { color: var(--m3-outline); font-size: 14px; padding: 0 1px; }
.drive-crumb-home { font-size: 17px; }

/* ---------- Item grid ---------- */
.drive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 10px;
  padding: 6px 0;
}
.cloud-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 132px;
  padding: 16px 14px 14px;
  border: 1px solid var(--m3-outline-variant) !important;
  border-radius: var(--m3-radius) !important;
  background: var(--m3-sc) !important;
  color: var(--m3-on-surface);
  text-align: left;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .05s ease;
}
.cloud-item:hover { background: var(--m3-sc-high) !important; }
.cloud-item:active { transform: scale(.99); }
.cloud-item:focus-visible { outline: 2px solid var(--m3-primary); outline-offset: 2px; }
.cloud-item-icon { font-size: 34px; line-height: 1; }
.cloud-item-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 19px;
  color: var(--m3-on-surface);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.cloud-item-meta {
  font-size: 12px;
  font-weight: 500;
  color: var(--m3-on-surface-variant);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cloud-item-more {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--m3-on-surface-variant);
  font-size: 18px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s ease, background .12s ease;
}
.cloud-item:hover .cloud-item-more,
.cloud-item:focus-within .cloud-item-more { opacity: 1; }
.cloud-item-more:hover { background: color-mix(in srgb, var(--m3-on-surface) 12%, transparent); }

/* ---------- Empty state ---------- */
.cloud-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 72px 20px;
  text-align: center;
  color: var(--m3-on-surface-variant);
}
.cloud-empty-icon { font-size: 56px; line-height: 1; opacity: .9; }
.cloud-empty-title { font-size: 17px; font-weight: 600; color: var(--m3-on-surface); }
.cloud-empty-sub { font-size: 14px; max-width: 42ch; }

/* ---------- Buttons ---------- */
.drive-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: 20px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.drive-btn.filled { background: var(--m3-primary); color: var(--m3-on-primary); }
.drive-btn.tonal { background: var(--m3-secondary-container); color: var(--m3-on-secondary-container); }
.drive-btn.outline { background: transparent; color: var(--m3-primary); border-color: var(--m3-outline); }
.drive-btn.danger { background: var(--m3-error-container); color: var(--m3-on-error-container); }
.drive-btn:hover { filter: brightness(1.06); }

/* ---------- FAB ---------- */
.drive-fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  z-index: 45;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 16px;
  background: var(--m3-primary-container);
  color: var(--m3-on-primary-container);
  font-size: 26px;
  line-height: 1;
  box-shadow: var(--m3-shadow-lg);
  cursor: pointer;
}
.drive-fab:hover { filter: brightness(1.05); }
.drive-fab:active { transform: scale(.96); }

/* ---------- Upload progress ---------- */
.drive-upload {
  position: fixed;
  left: 50%;
  bottom: 92px;
  z-index: 44;
  width: min(420px, calc(100vw - 32px));
  transform: translateX(-50%);
  padding: 12px 16px;
  border: 1px solid var(--m3-outline-variant);
  border-radius: var(--m3-radius);
  background: var(--m3-sc-high);
  box-shadow: var(--m3-shadow-lg);
}
.drive-upload-label { font-size: 13px; font-weight: 600; color: var(--m3-on-surface); margin-bottom: 8px; }
.drive-upload-track { height: 6px; border-radius: 3px; background: var(--m3-sc-highest); overflow: hidden; }
.drive-upload-fill { height: 100%; width: 0; background: var(--m3-primary); transition: width .15s ease; }

/* ---------- Bottom sheet ---------- */
.drive-sheet-root { position: fixed; inset: 0; z-index: 70; }
.drive-sheet-scrim { position: absolute; inset: 0; background: rgba(0,0,0,.42); opacity: 0; transition: opacity .2s ease; }
.drive-sheet-root.open .drive-sheet-scrim { opacity: 1; }
.drive-sheet {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(640px, 100vw);
  max-height: 82dvh;
  overflow-y: auto;
  transform: translate(-50%, 102%);
  transition: transform .26s cubic-bezier(.2,0,0,1);
  padding: 8px 0 14px;
  background: var(--m3-sc-low);
  color: var(--m3-on-surface);
  border-top-left-radius: var(--m3-radius-xl);
  border-top-right-radius: var(--m3-radius-xl);
  box-shadow: var(--m3-shadow-lg);
}
.drive-sheet-root.open .drive-sheet { transform: translate(-50%, 0); }
.drive-sheet-handle { width: 32px; height: 4px; margin: 6px auto 6px; border-radius: 2px; background: var(--m3-outline-variant); }
.drive-sheet-title {
  padding: 8px 24px 10px;
  font-size: 16px;
  font-weight: 600;
  color: var(--m3-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drive-sheet-sub { padding: 0 24px 10px; font-size: 13px; color: var(--m3-on-surface-variant); }
.drive-sheet-divider { height: 1px; margin: 6px 0; background: var(--m3-outline-variant); }
.sheet-item {
  display: flex;
  align-items: center;
  gap: 18px;
  width: 100%;
  min-height: 52px;
  padding: 0 24px;
  border: 0;
  background: transparent;
  color: var(--m3-on-surface);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.sheet-item:hover { background: color-mix(in srgb, var(--m3-on-surface) 8%, transparent); }
.sheet-item .ic { flex: 0 0 22px; font-size: 19px; text-align: center; }
.sheet-item.danger { color: var(--m3-error); }
.sheet-item[aria-checked="true"] .ic { color: var(--m3-primary); }

/* ---------- Modal (editor / inputs) ---------- */
.drive-modal-root { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; padding: 16px; }
.drive-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.cloud-modal {
  position: relative;
  width: min(560px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  padding: 22px;
  border: 1px solid var(--m3-outline-variant);
  border-radius: var(--m3-radius-xl);
  background: var(--m3-sc-low);
  color: var(--m3-on-surface);
  box-shadow: var(--m3-shadow-lg);
}
.cloud-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--m3-on-surface-variant);
  font-size: 20px;
  cursor: pointer;
}
.cloud-modal-close:hover { background: color-mix(in srgb, var(--m3-on-surface) 10%, transparent); }
.cloud-modal-title { font-size: 20px; font-weight: 600; margin: 0 0 6px; padding-right: 44px; color: var(--m3-on-surface); }
.cloud-modal-sub { font-size: 13px; color: var(--m3-on-surface-variant); margin: 0 0 16px; }
.cloud-modal-input,
.cloud-editor {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--m3-outline);
  border-radius: var(--m3-radius);
  background: var(--m3-sc-highest);
  color: var(--m3-on-surface);
  font: inherit;
  font-size: 15px;
}
.cloud-editor { min-height: 220px; resize: vertical; font-family: var(--m3-mono); font-size: 13px; }
.cloud-modal-input:focus, .cloud-editor:focus { outline: 2px solid var(--m3-primary); outline-offset: -1px; }
.cloud-modal-label { display: block; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--m3-on-surface-variant); margin: 14px 0 6px; }
.cloud-modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.drive-keyhex {
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid var(--m3-outline-variant);
  border-radius: var(--m3-radius);
  background: var(--m3-sc-highest);
  color: var(--m3-on-surface);
  font-family: var(--m3-mono);
  font-size: 12px;
  line-height: 1.5;
  word-break: break-all;
}

/* ---------- Toast ---------- */
.drive-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 90;
  transform: translate(-50%, 20px);
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 10px;
  background: var(--m3-inverse-surface);
  color: var(--m3-inverse-on-surface);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--m3-shadow-lg);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, transform .2s ease, visibility .2s ease;
}
.drive-toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.drive-toast.error { background: var(--m3-error-container); color: var(--m3-on-error-container); }

/* ---------- Loading overlay ---------- */
.drive-progress {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--m3-surface) 72%, transparent);
}
.drive-spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid var(--m3-surface-variant);
  border-top-color: var(--m3-primary);
  animation: drive-spin .9s linear infinite;
}
@keyframes drive-spin { to { transform: rotate(360deg); } }

/* ---------- Auth required ---------- */
.drive-auth {
  max-width: 460px;
  margin: 56px auto;
  padding: 28px;
  border: 1px solid var(--m3-outline-variant);
  border-radius: var(--m3-radius-lg);
  background: var(--m3-sc-low);
  text-align: center;
}
.drive-auth h2 { margin: 0 0 8px; font-size: 20px; font-weight: 600; color: var(--m3-on-surface); }
.drive-auth p { margin: 0 0 18px; font-size: 14px; color: var(--m3-on-surface-variant); }

/* ---------- Selection bar (kept for parity with the app) ---------- */
.drive-selection {
  position: fixed;
  left: 50%;
  top: 12px;
  z-index: 65;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--m3-radius-xl);
  background: var(--m3-sc-high);
  box-shadow: var(--m3-shadow-lg);
}
.drive-selection.open { display: flex; }

@media (max-width: 520px) {
  .drive-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .drive-appbar-title { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .drive-drawer, .drive-sheet, .cloud-item, .drive-toast { transition: none !important; }
}
