/* =====================================================================
   GlobalPad — design system
   Apple minimalism · Notion cleanliness · Linear consistency · Vercel feel
   ===================================================================== */

:root {
  /* Light palette */
  --bg: #f6f7fb;
  --bg-grad-1: #eef2ff;
  --bg-grad-2: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --text: #0f172a;
  --text-soft: #475569;
  --text-mute: #94a3b8;
  --border: #e6e9f0;
  --border-strong: #d7dce5;
  --primary: #4f46e5;
  --primary-strong: #4338ca;
  --primary-soft: #eef2ff;
  --primary-contrast: #ffffff;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #e11d48;
  --danger-soft: #ffe4e6;
  --warning: #d97706;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 18px 50px rgba(15, 23, 42, 0.14);
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-brd: rgba(255, 255, 255, 0.55);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 22px;
  --ring: 0 0 0 4px rgba(79, 70, 229, 0.18);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme='dark'] {
  --bg: #0b1020;
  --bg-grad-1: #131a33;
  --bg-grad-2: #0b1020;
  --surface: #131a2e;
  --surface-2: #18213a;
  --surface-3: #1e2942;
  --text: #e8ecf5;
  --text-soft: #aab4c9;
  --text-mute: #6b7689;
  --border: #243049;
  --border-strong: #2f3c59;
  --primary: #7c83ff;
  --primary-strong: #636bf0;
  --primary-soft: #1b2240;
  --primary-contrast: #0b1020;
  --success: #22c55e;
  --success-soft: #123524;
  --danger: #fb7185;
  --danger-soft: #3a1622;
  --warning: #fbbf24;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 22px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 22px 60px rgba(0, 0, 0, 0.55);
  --glass-bg: rgba(19, 26, 46, 0.66);
  --glass-brd: rgba(255, 255, 255, 0.08);
  --ring: 0 0 0 4px rgba(124, 131, 255, 0.28);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, var(--bg-grad-1), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, var(--bg-grad-1), transparent 55%),
    var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  transition: background-color 0.4s var(--ease), color 0.3s var(--ease);
}

h1,
h2,
h3 {
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 650;
}

button {
  font-family: inherit;
}

/* ----------------------------- Utilities ----------------------------- */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

.glass {
  background: var(--glass-bg);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  border: 1px solid var(--glass-brd);
}

.fade-in {
  animation: fadeIn 0.5s var(--ease) both;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ------------------------------ Buttons ------------------------------ */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1.05rem;
  font-size: 0.92rem;
  font-weight: 560;
  cursor: pointer;
  transition: transform 0.15s var(--ease), background 0.2s var(--ease),
    box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  white-space: nowrap;
  color: var(--text);
  background: var(--surface-2);
}

.btn:hover {
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0);
}
.btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.btn-primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  color: var(--primary-contrast);
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.28);
}
.btn-primary:hover {
  box-shadow: 0 10px 26px rgba(79, 70, 229, 0.38);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-soft);
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--primary);
}

.btn-danger-ghost {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger-ghost:hover {
  background: var(--danger-soft);
}

.btn-block {
  width: 100%;
  padding: 0.78rem 1rem;
  font-size: 1rem;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  font-size: 1.05rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s var(--ease), transform 0.15s var(--ease);
}
.icon-btn:hover {
  background: var(--surface-3);
  transform: translateY(-1px);
}
.icon-btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font: inherit;
  font-weight: 560;
  cursor: pointer;
  padding: 0;
}
.link-btn:hover {
  text-decoration: underline;
}

/* ------------------------------ Inputs ------------------------------ */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.field-grow {
  flex: 1;
  min-height: 0;
}
.field-label {
  font-size: 0.8rem;
  font-weight: 560;
  color: var(--text-soft);
  letter-spacing: 0.01em;
}
.field-label .optional {
  color: var(--text-mute);
  font-weight: 400;
}

input[type='text'],
input[type='password'],
textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease),
    background 0.2s var(--ease);
}
input::placeholder,
textarea::placeholder {
  color: var(--text-mute);
}
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
  background: var(--surface);
}
textarea {
  resize: vertical;
  line-height: 1.6;
}

/* Switch */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  user-select: none;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-track {
  width: 40px;
  height: 23px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  transition: background 0.25s var(--ease);
}
.switch-thumb {
  position: absolute;
  top: 2.5px;
  left: 2.5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s var(--ease);
}
.switch input:checked + .switch-track {
  background: var(--primary);
}
.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(17px);
}
.switch input:focus-visible + .switch-track {
  box-shadow: var(--ring);
}
.switch-label {
  font-size: 0.88rem;
  color: var(--text-soft);
  font-weight: 500;
}

/* ============================= ACCESS VIEW ============================= */
.access-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  border-radius: var(--radius-lg);
  padding: 2.4rem 2.1rem;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.55s var(--ease) both;
}
@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}
.brand {
  text-align: center;
  margin-bottom: 1.6rem;
}
.logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 0.9rem;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff;
  font-weight: 700;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 30px rgba(79, 70, 229, 0.4);
}
.brand h1 {
  font-size: 1.9rem;
}
.tagline {
  color: var(--text-soft);
  font-size: 0.95rem;
  margin-top: 0.35rem;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.hint {
  font-size: 0.8rem;
  color: var(--text-mute);
  text-align: center;
  margin-top: 0.3rem;
}

/* ============================= WORKSPACE ============================= */
.workspace {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.4rem;
  margin: 0.9rem 1.4rem 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.logo-sm {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  font-size: 0.95rem;
  margin: 0;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.35);
}
.topbar-title {
  font-weight: 650;
  font-size: 1rem;
}
.topbar-sub {
  font-size: 0.78rem;
  color: var(--text-mute);
}
.topbar-sub span {
  color: var(--text-soft);
  font-weight: 560;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
}
.badge-lock {
  background: var(--warning);
  color: #1f1300;
}

.workspace-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.4rem;
  padding: 1.4rem;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: fadeIn 0.5s var(--ease) both;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.card-head h2 {
  font-size: 1.15rem;
}
.count-pill {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--surface-3);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  min-width: 28px;
  text-align: center;
}

/* Note card */
.note-card {
  position: sticky;
  top: 92px;
}
.note-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: auto;
  padding-top: 0.4rem;
}
.note-actions .spacer {
  flex: 1;
}
.save-status {
  font-size: 0.78rem;
  font-weight: 560;
  color: var(--text-mute);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.save-status.saving {
  color: var(--primary);
}
.save-status.saved {
  color: var(--success);
}
.save-status.error {
  color: var(--danger);
}

.locked-banner {
  background: var(--primary-soft);
  border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
  color: var(--text);
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

input.locked,
textarea.locked {
  background: var(--surface-3);
  color: var(--text-mute);
  cursor: not-allowed;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 1.6rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease),
    transform 0.15s var(--ease);
  background: var(--surface-2);
  position: relative;
}
.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--primary);
  background: var(--primary-soft);
  outline: none;
}
.dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: scale(1.01);
}
.dropzone-icon {
  font-size: 1.6rem;
  margin-bottom: 0.4rem;
  color: var(--primary);
}
.dropzone-title {
  font-weight: 560;
  color: var(--text);
}
.dropzone-sub {
  font-size: 0.8rem;
  color: var(--text-mute);
  margin-top: 0.2rem;
}

.upload-progress {
  margin-top: 0.9rem;
}
.progress-track {
  height: 8px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #8b5cf6);
  border-radius: 999px;
  transition: width 0.2s var(--ease);
}
.progress-label {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-soft);
}

.file-toolbar {
  display: flex;
  justify-content: flex-end;
}

/* File list */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.3rem;
  min-height: 60px;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.8rem 0.95rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease),
    border-color 0.18s var(--ease);
  animation: rowIn 0.35s var(--ease) both;
}
.file-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
@keyframes rowIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.file-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  background: var(--primary-soft);
  flex-shrink: 0;
}
.file-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.file-name {
  font-weight: 540;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-sub {
  font-size: 0.76rem;
  color: var(--text-mute);
}
.file-actions {
  display: flex;
  gap: 0.45rem;
  flex-shrink: 0;
}
.file-actions .btn {
  padding: 0.45rem 0.7rem;
  font-size: 0.82rem;
}

.file-locked {
  opacity: 0.92;
}
.file-locked .file-name {
  filter: blur(0.4px);
}

/* Empty + loading states */
.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-mute);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}
.empty-state .empty-icon {
  font-size: 1.8rem;
  display: block;
  margin-bottom: 0.5rem;
}

.skeleton {
  height: 58px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

/* =============================== MODAL =============================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 26, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  z-index: 100;
  animation: fadeIn 0.2s var(--ease);
}
.modal {
  width: 100%;
  max-width: 380px;
  border-radius: var(--radius-lg);
  padding: 1.6rem;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.3s var(--ease) both;
}
.modal h3 {
  font-size: 1.2rem;
  margin-bottom: 0.4rem;
}
.modal-desc {
  color: var(--text-soft);
  font-size: 0.88rem;
  margin-bottom: 1rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.1rem;
}

/* ============================== TOASTS ============================== */
.toasts {
  position: fixed;
  bottom: 1.4rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  z-index: 200;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  color: var(--text);
  animation: toastIn 0.3s var(--ease) both;
}
.toast.out {
  animation: toastOut 0.3s var(--ease) both;
}
.toast .toast-icon {
  font-size: 1.05rem;
}
.toast.success {
  border-left: 3px solid var(--success);
}
.toast.error {
  border-left: 3px solid var(--danger);
}
.toast.info {
  border-left: 3px solid var(--primary);
}
@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(14px);
  }
}

/* =========================== LOADING OVERLAY =========================== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 26, 0.35);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}
.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 4px solid var(--surface-3);
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================= RESPONSIVE ============================= */
@media (max-width: 900px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
  .note-card {
    position: static;
  }
}

@media (max-width: 600px) {
  .topbar {
    flex-wrap: wrap;
    margin: 0.6rem;
    padding: 0.7rem 0.9rem;
  }
  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }
  .workspace-grid {
    padding: 0.9rem;
    gap: 1rem;
  }
  .card {
    padding: 1.1rem;
  }
  .file-item {
    flex-wrap: wrap;
  }
  .file-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .note-actions {
    flex-wrap: wrap;
  }
  .note-actions .spacer {
    width: 100%;
    order: -1;
  }
}

/* Accessibility: respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
