:root {
  --bg: #e8eef4;
  --bg-deep: #0f2744;
  --panel: #ffffff;
  --ink: #122033;
  --muted: #5b6b7c;
  --line: #d5dee8;
  --accent: #0d8a6a;
  --accent-ink: #065344;
  --danger: #b42318;
  --warn: #b54708;
  --shadow: 0 18px 50px rgba(15, 39, 68, 0.12);
  --radius: 16px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #cfe3f7 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #b8ebe0 0%, transparent 45%),
    var(--bg);
}

button,
input {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.view {
  min-height: 100vh;
}

/* Login */
.login-view {
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
}

.login-backdrop {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(15, 39, 68, 0.92), rgba(13, 138, 106, 0.55)),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.06'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  z-index: 0;
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  background: var(--panel);
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  animation: rise 0.45s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.brand-mark {
  margin: 0;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-ink);
}

.login-card h1 {
  margin: 8px 0 10px;
  font-family: var(--display);
  font-size: 2.1rem;
  line-height: 1.1;
}

.login-sub {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.5;
}

.login-card label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 0.92rem;
  font-weight: 600;
}

.login-card input,
#search-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #f7fafc;
}

.login-card input:focus,
#search-input:focus {
  outline: 2px solid rgba(13, 138, 106, 0.35);
  border-color: var(--accent);
}

.form-error {
  color: var(--danger);
  margin: 0 0 12px;
  font-size: 0.9rem;
}

.login-foot {
  margin: 18px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0 0 18px;
  padding: 4px;
  background: #eef4fa;
  border-radius: 12px;
}

.auth-tab {
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}

.auth-tab.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(15, 39, 68, 0.08);
}

.field-hint {
  margin: -4px 0 10px;
  font-size: 0.82rem;
  color: var(--muted);
}

.back-top {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 40;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--bg-deep);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(15, 39, 68, 0.28);
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.back-top:hover {
  transform: translateY(-2px);
}

/* Buttons */
.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.secondary {
  background: #e7eef6;
  color: var(--ink);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
}

.btn.sm {
  padding: 8px 10px;
  font-size: 0.85rem;
}

.btn.block {
  width: 100%;
}

.btn.danger {
  background: #fee4e2;
  color: var(--danger);
}

/* Drive layout */
.drive-view {
  display: grid;
  grid-template-columns: minmax(260px, 300px) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar-backdrop {
  display: none;
}

.sidebar {
  background: var(--bg-deep);
  color: #eef5ff;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow: auto;
}

.sidebar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-top .icon-btn {
  display: none;
  color: #fff;
}

.mobile-bar {
  display: none;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.selection-count {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.sort-select {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--panel);
  min-width: 140px;
}

.file-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(13, 138, 106, 0.2);
}

.file-check {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  z-index: 2;
}

.sidebar-brand {
  display: grid;
  gap: 2px;
}

.sidebar-brand .brand-mark {
  color: #8fdcc8;
}

.sidebar-brand strong {
  font-family: var(--display);
  font-size: 1.55rem;
}

.side-nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  text-align: left;
  background: transparent;
  color: #d7e4f5;
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.quota-panel {
  margin-top: auto;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 14px;
}

.quota-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.quota-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.quota-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3dcea8, #f6c945);
  transition: width 0.35s ease;
}

.quota-fill.warn {
  background: linear-gradient(90deg, #f6c945, #f04438);
}

.quota-text {
  margin: 10px 0 4px;
  font-size: 0.92rem;
  font-weight: 600;
}

.quota-hint {
  margin: 0;
  font-size: 0.78rem;
  color: #9fb3c9;
}

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-user strong,
.sidebar-user small {
  display: block;
}

.sidebar-user small {
  color: #9fb3c9;
  font-size: 0.78rem;
}

.main {
  padding: 28px 32px 40px;
}

.main-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.main-header h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.8rem;
}

.muted {
  margin: 6px 0 0;
  color: var(--muted);
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

#search-input {
  min-width: 220px;
  background: var(--panel);
}

.transfer-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(15, 39, 68, 0.06);
  transition: opacity 0.45s ease, transform 0.45s ease, max-height 0.45s ease;
  max-height: 420px;
  overflow: hidden;
}

.transfer-panel.is-hiding {
  opacity: 0;
  transform: translateY(-8px);
  max-height: 0;
  margin-bottom: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-width: 0;
}

.transfer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.transfer-panel h3 {
  margin: 0;
  font-size: 0.95rem;
}

.transfer-status {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-ink);
  letter-spacing: 0.02em;
}

#transfer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.transfer-item {
  display: grid;
  gap: 6px;
  transition: opacity 0.3s ease;
}

.transfer-item.is-done {
  opacity: 0.72;
}

.transfer-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.88rem;
}

.progress {
  height: 7px;
  border-radius: 999px;
  background: #e7eef6;
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0d8a6a, #1f6f8a);
  transition: width 0.15s linear;
}

.progress.done > span {
  background: #027a48;
}

.progress.error > span {
  background: var(--danger);
  width: 100% !important;
}

.state-box {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  border: 1px dashed var(--line);
}

.state-box.error {
  border-style: solid;
  border-color: #fecdca;
  background: #fff8f7;
}

.state-box.arch-state {
  border-color: #9bb8c9;
  background:
    linear-gradient(180deg, rgba(232, 242, 248, 0.9), #fff),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 19px,
      rgba(31, 111, 138, 0.08) 20px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 19px,
      rgba(31, 111, 138, 0.08) 20px
    );
}

/* Architect loading */
.arch-loader {
  position: relative;
  width: 88px;
  height: 88px;
  margin: 0 auto 14px;
  color: #1f4e66;
}

.arch-blueprint {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(31, 78, 102, 0.35);
  border-radius: 8px;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 7px,
      rgba(31, 111, 138, 0.12) 8px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 7px,
      rgba(31, 111, 138, 0.12) 8px
    ),
    #f4f8fb;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.arch-scan {
  position: absolute;
  left: 4px;
  right: 4px;
  height: 2px;
  top: 8px;
  background: linear-gradient(90deg, transparent, #0d8a6a, transparent);
  animation: arch-scan 1.6s ease-in-out infinite;
  opacity: 0.85;
}

.arch-compass {
  position: absolute;
  inset: 16px;
  width: 56px;
  height: 56px;
  animation: arch-rotate 3.2s linear infinite;
}

.arch-loader-text,
.arch-state p {
  margin: 0;
  font-family: var(--display);
  font-size: 1.05rem;
  color: #1f4e66;
  letter-spacing: 0.01em;
}

.ajax-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  background: rgba(244, 248, 251, 0.78);
  backdrop-filter: blur(2px);
  border-radius: var(--radius);
  animation: arch-fade-in 0.25s ease;
}

@keyframes arch-scan {
  0% {
    top: 10%;
    opacity: 0.2;
  }
  50% {
    opacity: 1;
  }
  100% {
    top: 88%;
    opacity: 0.2;
  }
}

@keyframes arch-rotate {
  to {
    transform: rotate(360deg);
  }
}

@keyframes arch-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.file-grid.is-reloading {
  opacity: 0.45;
  filter: grayscale(0.15);
  transition: opacity 0.25s ease;
}

.sidebar-actions {
  display: grid;
  gap: 8px;
}

.title-block h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.8rem;
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 0.9rem;
}

.crumb {
  color: var(--muted);
}

.crumb.current {
  color: var(--ink);
  font-weight: 700;
}

.crumb.link {
  border: 0;
  background: transparent;
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.crumb-sep {
  color: #9aabbc;
}

.view-toggle {
  display: inline-flex;
  gap: 4px;
  background: #e7eef6;
  padding: 3px;
  border-radius: 12px;
}

.view-toggle .btn.active {
  background: #fff;
  box-shadow: 0 1px 4px rgba(15, 39, 68, 0.12);
}

.toolbar-mobile {
  display: none;
  gap: 8px;
  margin-bottom: 12px;
}

.drop-zone {
  position: relative;
  min-height: 320px;
  border-radius: var(--radius);
  outline: none;
}

.drop-zone.is-dragover {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
  background: rgba(13, 138, 106, 0.06);
}

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(15, 39, 68, 0.55);
  border-radius: var(--radius);
  pointer-events: none;
}

.drop-overlay-card {
  background: #fff;
  border-radius: 16px;
  padding: 22px 28px;
  text-align: center;
  display: grid;
  gap: 6px;
  box-shadow: var(--shadow);
}

.drop-overlay-card strong {
  font-size: 1.1rem;
}

.drop-overlay-card span {
  color: var(--muted);
  font-size: 0.9rem;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}

.file-grid.view-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.file-grid.view-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.file-grid.view-list .file-card {
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 12px;
}

.file-grid.view-list .file-thumb {
  height: 56px;
  width: 56px;
}

.file-grid.view-list .file-actions {
  justify-content: flex-end;
}

.file-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  display: grid;
  gap: 10px;
  animation: rise 0.3s ease both;
  cursor: default;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.file-card:hover,
.file-card:focus-visible {
  border-color: #9ec9b8;
  box-shadow: 0 8px 20px rgba(15, 39, 68, 0.08);
  outline: none;
}

.folder-card {
  cursor: pointer;
}

.folder-thumb {
  background: linear-gradient(145deg, #fff6df, #ffe8b0);
}

.folder-icon {
  font-size: 2rem;
  line-height: 1;
}

.folder-form {
  padding: 0 16px 16px;
  display: grid;
  gap: 12px;
}

.folder-form label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

.folder-form input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #f7fafc;
}

.modal-card-sm {
  width: min(440px, 100%);
}

.modal-card-sm .modal-foot {
  justify-content: flex-end;
  gap: 8px;
  border: 0;
  padding: 0;
}

.file-thumb {
  height: 120px;
  border-radius: 10px;
  background: #eef4fa;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.file-thumb img,
.file-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-name {
  margin: 0;
  font-weight: 700;
  font-size: 0.95rem;
  word-break: break-word;
}

.file-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.file-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 22, 38, 0.55);
}

.modal-card {
  position: relative;
  width: min(900px, 100%);
  max-height: min(90vh, 820px);
  background: var(--panel);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-head,
.modal-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-foot {
  border-bottom: 0;
  border-top: 1px solid var(--line);
}

.modal-head h3 {
  margin: 0;
  font-size: 1rem;
}

.preview-body {
  padding: 16px;
  overflow: auto;
  min-height: 240px;
  display: grid;
  place-items: center;
}

.preview-body img,
.preview-body video {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 10px;
}

.preview-body iframe {
  width: 100%;
  height: 60vh;
  border: 0;
  border-radius: 10px;
}

.preview-fallback {
  text-align: center;
  color: var(--muted);
}

.preview-text {
  width: 100%;
  max-height: 60vh;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border-radius: 10px;
  background: #0f2744;
  color: #e8f0f8;
  font-size: 0.85rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  text-align: left;
}

@media (max-width: 1024px) {
  .drive-view {
    grid-template-columns: 1fr;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(10, 22, 38, 0.45);
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(320px, 88vw);
    z-index: 46;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    border-radius: 0;
    height: 100dvh;
  }

  .drive-view.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-top .icon-btn {
    display: inline-flex;
  }

  .mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(232, 238, 244, 0.92);
    backdrop-filter: blur(8px);
    padding: 10px 0;
  }

  .mobile-bar-title {
    font-size: 0.95rem;
  }

  .main {
    padding: 12px 14px calc(28px + env(safe-area-inset-bottom));
  }

  .main-header {
    align-items: stretch;
    gap: 12px;
  }

  .title-block h2 {
    font-size: 1.35rem;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  #search-input,
  .sort-select {
    min-width: 0;
    flex: 1 1 140px;
  }

  .file-grid.view-grid {
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
    gap: 10px;
  }

  .file-grid.view-list .file-card {
    grid-template-columns: 44px 1fr;
  }

  .file-grid.view-list .file-actions {
    grid-column: 1 / -1;
  }

  .file-actions .btn {
    flex: 1 1 auto;
    min-height: 36px;
  }

  .login-card {
    padding: 24px 18px;
    border-radius: 18px;
  }

  .login-card h1 {
    font-size: 1.75rem;
  }

  .modal-card {
    width: 100%;
    max-height: 92dvh;
    border-radius: 14px;
  }

  .back-top {
    width: 44px;
    height: 44px;
  }
}

@media (max-width: 480px) {
  .file-grid.view-grid {
    grid-template-columns: 1fr 1fr;
  }

  .view-toggle {
    width: 100%;
  }

  .view-toggle .btn {
    flex: 1;
  }

  .selection-count {
    width: 100%;
    margin-left: 0;
  }
}

@media (hover: none) {
  .file-card:hover {
    box-shadow: none;
  }

  .btn:hover {
    transform: none;
  }
}
