* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: #f1f5f9;
  color: #0f172a;
}
.hidden { display: none !important; }
.view { min-height: 100vh; }
.muted { color: #64748b; font-size: 13px; }
input, textarea, button { font: inherit; }

/* ---------- Login ---------- */
#login-view { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.card {
  background: #fff; padding: 32px; border-radius: 16px; width: 340px;
  box-shadow: 0 4px 24px rgba(0,0,0,.06);
}
.card h2 { margin: 0 0 4px; }
.card input, .card button {
  width: 100%; margin-top: 12px; padding: 10px 12px;
  border-radius: 8px; border: 1px solid #cbd5e1;
}
.card button {
  background: #2563eb; color: #fff; border: none; cursor: pointer; font-weight: 600;
}
.card button:hover { background: #1d4ed8; }
.card button:disabled { opacity: .6; cursor: wait; }
#otp { letter-spacing: 8px; text-align: center; font-size: 20px; }
.msg { margin-top: 12px; font-size: 13px; }
.msg.err { color: #dc2626; }
.msg.ok  { color: #16a34a; }
.otp-timer { margin-top: 8px; font-size: 12px; text-align: center; color: #64748b; }
.otp-timer.expired { color: #dc2626; font-weight: 600; }
#btn-resend {
  margin-top: 8px; background: #f1f5f9 !important;
  color: #2563eb !important; border: 1px solid #2563eb !important;
}
#btn-resend:hover { background: #e0e7ff !important; }

/* ---------- App layout ---------- */
#app-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.breadcrumb {
  font-size: 14px;
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
}
.crumb {
  cursor: pointer;
  color: #2563eb;
  white-space: nowrap;
}
.crumb:hover { text-decoration: underline; }
.crumb.active { color: #0f172a; font-weight: 600; cursor: default; text-decoration: none; }

#search {
  flex: 1;
  max-width: 400px;
  margin: 0 auto;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  font-size: 14px;
}
#search:focus { outline: none; border-color: #2563eb; background: #fff; }

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #475569;
}
.user-info span { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini {
  padding: 4px 10px; border-radius: 6px; border: 1px solid #cbd5e1;
  background: #f1f5f9; cursor: pointer; font-size: 12px;
}
.mini:hover { background: #e2e8f0; }

/* ---------- File area ---------- */
.filearea {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  position: relative;
}
.hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 14px;
  pointer-events: none;
}
.hint.hidden { display: none; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.item {
  background: #fff;
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  border: 1px solid #e2e8f0;
  transition: box-shadow .15s, border-color .15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  user-select: none;
  position: relative;
}
.item:hover {
  border-color: #2563eb;
  box-shadow: 0 2px 8px rgba(37,99,235,.15);
}
.item.selected {
  background: #eff6ff;
  border-color: #2563eb;
}
.item .icon {
  font-size: 40px;
  line-height: 1;
}
.item .name {
  font-size: 13px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}
.item .badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: #16a34a;
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
}

/* ---------- Editor panel ---------- */
.editor-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 50%;
  max-width: 700px;
  background: #fff;
  box-shadow: -4px 0 24px rgba(0,0,0,.1);
  display: flex;
  flex-direction: column;
  padding: 20px;
  z-index: 20;
}
.editor-head {
  display: flex;
  gap: 12px;
  align-items: center;
}
#note-title {
  flex: 1;
  font-size: 20px;
  font-weight: 700;
  border: none;
  outline: none;
  padding: 4px 0;
  background: transparent;
}
#note-content {
  flex: 1;
  margin-top: 16px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px;
  font-size: 15px;
  line-height: 1.6;
  resize: none;
  outline: none;
}
#note-content:focus { border-color: #93c5fd; }
.editor-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}
.save-btn {
  padding: 8px 20px;
  border-radius: 8px;
  border: none;
  background: #2563eb;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.save-btn:hover { background: #1d4ed8; }
.save-btn.dirty {
  background: #f59e0b;
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.65} }

/* ---------- Context menu ---------- */
.ctx-menu {
  position: fixed;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,.15);
  border: 1px solid #e2e8f0;
  min-width: 180px;
  padding: 6px 0;
  z-index: 100;
}
.ctx-item {
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ctx-item:hover { background: #f1f5f9; }
.ctx-item.danger { color: #dc2626; }
.ctx-sep { height: 1px; background: #e2e8f0; margin: 4px 0; }
.ctx-header {
  padding: 6px 16px;
  font-size: 11px;
  text-transform: uppercase;
  color: #94a3b8;
  font-weight: 600;
}

/* ---------- Public share view ---------- */
#share-view { background: #f1f5f9; padding: 40px 20px; }
.share-container {
  max-width: 800px;
  margin: 0 auto;
  background: #fff;
  padding: 40px;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,.06);
}
.share-container h1 { margin: 0 0 8px; }
.share-meta { margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid #e2e8f0; }
.share-content { font-size: 15px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .topbar { flex-wrap: wrap; padding: 10px; }
  #search { order: 3; flex-basis: 100%; max-width: none; margin: 6px 0 0; }
  .editor-panel { width: 100%; max-width: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .item .icon { font-size: 32px; }
}
