@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
  --bg0: #0b1220;
  --bg1: #122033;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #0d9488;
  --accent-2: #14b8a6;
  --accent-ink: #f0fdfa;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --shadow: 0 20px 50px rgba(15, 23, 42, 0.12);
  --radius: 18px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --font: 'Plus Jakarta Sans', ui-sans-serif, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(20, 184, 166, 0.28), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(56, 189, 248, 0.18), transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1) 55%, #0f2744);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: #f1f5f9;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}

.muted {
  color: var(--muted);
}

/* ——— Auth / Login ——— */
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(1.25rem, var(--safe-top)) 1.25rem max(1.25rem, var(--safe-bottom));
}

.auth-shell {
  width: min(440px, 100%);
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  color: #e2e8f0;
}

.brand-mark .logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--accent-2), #0f766e);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: white;
  box-shadow: 0 10px 24px rgba(13, 148, 136, 0.35);
}

.brand-mark .brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.brand-mark strong {
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.brand-mark span {
  font-size: 0.8rem;
  color: #94a3b8;
}

.card {
  width: 100%;
  background: var(--panel);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: calc(var(--radius) + 4px);
  padding: 1.5rem 1.35rem 1.35rem;
  box-shadow: var(--shadow);
}

.card h1 {
  margin: 0;
  font-size: clamp(1.45rem, 4vw, 1.75rem);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.card .lead {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.build-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 1rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: #ecfdf5;
  color: #0f766e;
  font-size: 0.72rem;
  font-weight: 600;
}

label {
  display: block;
  margin: 1.1rem 0 0.4rem;
  font-size: 0.86rem;
  font-weight: 600;
  color: #334155;
}

input[type='password'],
input[type='text'] {
  width: 100%;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

input[type='password']:focus,
input[type='text']:focus {
  outline: none;
  border-color: #5eead4;
  box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.15);
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.65rem 1.05rem;
  font-size: 0.92rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    background 0.15s ease,
    border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:active,
.btn:active {
  transform: scale(0.98);
}

button[type='submit'],
.btn.primary {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  border-color: transparent;
  color: var(--accent-ink);
  margin-top: 1.15rem;
  width: 100%;
  min-height: 48px;
  box-shadow: 0 12px 24px rgba(13, 148, 136, 0.28);
}

.actions .btn.primary {
  width: auto;
  margin-top: 0;
  min-height: 42px;
  padding-inline: 1.15rem;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 166, 0.08);
  color: #e2e8f0;
}

.file-btn {
  position: relative;
  overflow: hidden;
}

.error {
  color: var(--danger);
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  font-weight: 500;
}

.hint-row {
  margin-top: 1rem;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
}

.debug-box {
  margin-top: 1rem;
  padding: 0.75rem;
  background: #0f172a;
  color: #99f6e4;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
}

.debug-box[hidden] {
  display: none !important;
}

.debug-toggle {
  margin-top: 0.75rem;
  width: 100%;
  background: transparent;
  border-style: dashed;
  color: var(--muted);
  font-size: 0.8rem;
}

/* ——— App shell ——— */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(0.75rem, var(--safe-top)) 0.85rem max(0.85rem, var(--safe-bottom));
}

.app-frame {
  width: min(1100px, 100%);
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  color: #f8fafc;
}

.top h1 {
  margin: 0;
  font-size: clamp(1.15rem, 3.5vw, 1.4rem);
  letter-spacing: -0.02em;
}

.top .muted {
  color: #94a3b8;
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.quota-card {
  background: var(--panel-solid);
  border-radius: var(--radius);
  padding: 0.95rem 1.1rem;
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 10px 30px rgba(2, 8, 23, 0.08);
}

.quota-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
  font-size: 0.86rem;
  font-weight: 600;
}

.quota-bar {
  height: 9px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.quota-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0d9488, #38bdf8);
  transition: width 0.3s ease;
}

.banner {
  margin: 0;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid #a7f3d0;
  font-weight: 500;
}

.banner.bad {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #fecaca;
}

.table-wrap {
  background: var(--panel-solid);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(2, 8, 23, 0.08);
  flex: 1;
}

.files-desktop {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
}

.files-desktop th,
.files-desktop td {
  text-align: left;
  padding: 0.95rem 1rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.files-desktop th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: #f8fafc;
  font-weight: 700;
}

.files-desktop tr:last-child td {
  border-bottom: none;
}

.files-desktop tr:hover td {
  background: #f8fafc;
}

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

.file-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.file-icon.word {
  background: linear-gradient(145deg, #3b82f6, #1d4ed8);
}
.file-icon.cell {
  background: linear-gradient(145deg, #22c55e, #15803d);
}
.file-icon.slide {
  background: linear-gradient(145deg, #f97316, #c2410c);
}
.file-icon.file {
  background: linear-gradient(145deg, #64748b, #334155);
}

.file-name strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: min(42vw, 320px);
}

.row-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.btn.danger {
  color: var(--danger);
  border-color: #fecaca;
  background: #fff;
}

.btn.small {
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  min-height: 36px;
}

.empty {
  padding: 2.5rem 1.25rem;
  margin: 0;
  text-align: center;
}

.empty-illu {
  width: 64px;
  height: 64px;
  margin: 0 auto 0.85rem;
  border-radius: 18px;
  background: linear-gradient(145deg, #ccfbf1, #e0f2fe);
  display: grid;
  place-items: center;
  font-size: 1.5rem;
}

/* Mobile file cards */
.files-mobile {
  display: none;
  padding: 0.75rem;
  gap: 0.65rem;
}

.file-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem;
  background: #fff;
  display: grid;
  gap: 0.7rem;
}

.file-card .meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.file-card .row-actions {
  justify-content: stretch;
}

.file-card .row-actions .btn {
  flex: 1;
}

/* Edit page */
body.edit-page {
  background: #0b1220;
  height: 100dvh;
  overflow: hidden;
}

.edit-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  padding-top: max(0.7rem, var(--safe-top));
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
}

.edit-top strong {
  display: block;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: min(60vw, 420px);
}

.edit-top .muted {
  color: #94a3b8;
  font-size: 0.78rem;
}

#placeholder {
  padding: 1.5rem;
  color: #94a3b8;
}

#editor {
  height: calc(100dvh - 58px - var(--safe-top));
  width: 100%;
  background: #fff;
}

@media (max-width: 820px) {
  .top {
    flex-direction: column;
    align-items: stretch;
  }

  .actions {
    width: 100%;
  }

  .actions .btn,
  .actions .file-btn {
    flex: 1;
  }

  .files-desktop {
    display: none;
  }

  .files-mobile {
    display: grid;
  }
}

@media (min-width: 821px) {
  .files-mobile {
    display: none !important;
  }
}

@media (max-width: 480px) {
  .card {
    padding: 1.25rem 1.1rem;
  }

  .auth {
    padding-inline: 0.85rem;
  }

  .hint-row {
    font-size: 0.78rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
